Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net-timestamp: no-payload option in txtimestamp test

Demonstrate how SOF_TIMESTAMPING_OPT_TSONLY can be used and
test the implementation.

Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Willem de Bruijn and committed by
David S. Miller
23685923 b245be1f

+24 -4
+24 -4
Documentation/networking/timestamping/txtimestamp.c
··· 70 70 static int cfg_payload_len = 10; 71 71 static bool cfg_show_payload; 72 72 static bool cfg_do_pktinfo; 73 + static bool cfg_loop_nodata; 73 74 static uint16_t dest_port = 9000; 74 75 75 76 static struct sockaddr_in daddr; ··· 142 141 { 143 142 int i; 144 143 144 + if (!len) 145 + return; 146 + 145 147 if (len > 70) 146 148 len = 70; 147 149 ··· 181 177 struct sock_extended_err *serr = NULL; 182 178 struct scm_timestamping *tss = NULL; 183 179 struct cmsghdr *cm; 180 + int batch = 0; 184 181 185 182 for (cm = CMSG_FIRSTHDR(msg); 186 183 cm && cm->cmsg_len; ··· 214 209 } else 215 210 fprintf(stderr, "unknown cmsg %d,%d\n", 216 211 cm->cmsg_level, cm->cmsg_type); 212 + 213 + if (serr && tss) { 214 + print_timestamp(tss, serr->ee_info, serr->ee_data, 215 + payload_len); 216 + serr = NULL; 217 + tss = NULL; 218 + batch++; 219 + } 217 220 } 218 221 219 - if (serr && tss) 220 - print_timestamp(tss, serr->ee_info, serr->ee_data, payload_len); 222 + if (batch > 1) 223 + fprintf(stderr, "batched %d timestamps\n", batch); 221 224 } 222 225 223 226 static int recv_errmsg(int fd) ··· 257 244 if (ret == -1 && errno != EAGAIN) 258 245 error(1, errno, "recvmsg"); 259 246 260 - if (ret > 0) { 247 + if (ret >= 0) { 261 248 __recv_errmsg_cmsg(&msg, ret); 262 249 if (cfg_show_payload) 263 250 print_payload(data, cfg_payload_len); ··· 322 309 opt |= SOF_TIMESTAMPING_SOFTWARE | 323 310 SOF_TIMESTAMPING_OPT_CMSG | 324 311 SOF_TIMESTAMPING_OPT_ID; 312 + if (cfg_loop_nodata) 313 + opt |= SOF_TIMESTAMPING_OPT_TSONLY; 314 + 325 315 if (setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, 326 316 (char *) &opt, sizeof(opt))) 327 317 error(1, 0, "setsockopt timestamping"); ··· 394 378 " -h: show this message\n" 395 379 " -I: request PKTINFO\n" 396 380 " -l N: send N bytes at a time\n" 381 + " -n: set no-payload option\n" 397 382 " -r: use raw\n" 398 383 " -R: use raw (IP_HDRINCL)\n" 399 384 " -p N: connect to port N\n" ··· 409 392 int proto_count = 0; 410 393 char c; 411 394 412 - while ((c = getopt(argc, argv, "46hIl:p:rRux")) != -1) { 395 + while ((c = getopt(argc, argv, "46hIl:np:rRux")) != -1) { 413 396 switch (c) { 414 397 case '4': 415 398 do_ipv6 = 0; ··· 419 402 break; 420 403 case 'I': 421 404 cfg_do_pktinfo = true; 405 + break; 406 + case 'n': 407 + cfg_loop_nodata = true; 422 408 break; 423 409 case 'r': 424 410 proto_count++;