| @@ -77,6 +77,8 @@ static bool cfg_epollet; · 76 unmodified lines |
| 77 | static bool cfg_do_listen; | 77 | static bool cfg_do_listen; |
| 78 | static uint16_t dest_port = 9000; | 78 | static uint16_t dest_port = 9000; |
| 79 | static bool cfg_print_nsec; | 79 | static bool cfg_print_nsec; |
| | 80 | static uint32_t ts_opt_id; |
| | 81 | static bool cfg_use_cmsg_opt_id; |
| 80 | | 82 | |
| 81 | static struct sockaddr_in daddr; | 83 | static struct sockaddr_in daddr; |
| 82 | static struct sockaddr_in6 daddr6; | 84 | static struct sockaddr_in6 daddr6; |
| @@ -136,12 +138,13 @@ static void validate_key(int tskey, int tstype) · 53 unmodified lines |
| 136 | /* compare key for each subsequent request | 138 | /* compare key for each subsequent request |
| 137 | * must only test for one type, the first one requested | 139 | * must only test for one type, the first one requested |
| 138 | */ | 140 | */ |
| 139 | if (saved_tskey == -1) | 141 | if (saved_tskey == -1 || cfg_use_cmsg_opt_id) |
| 140 | saved_tskey_type = tstype; | 142 | saved_tskey_type = tstype; |
| 141 | else if (saved_tskey_type != tstype) | 143 | else if (saved_tskey_type != tstype) |
| 142 | return; | 144 | return; |
| 143 | | 145 | |
| 144 | stepsize = cfg_proto == SOCK_STREAM ? cfg_payload_len : 1; | 146 | stepsize = cfg_proto == SOCK_STREAM ? cfg_payload_len : 1; |
| | 147 | stepsize = cfg_use_cmsg_opt_id ? 0 : stepsize; |
| 145 | if (tskey != saved_tskey + stepsize) { | 148 | if (tskey != saved_tskey + stepsize) { |
| 146 | fprintf(stderr, "ERROR: key %d, expected %d\n", | 149 | fprintf(stderr, "ERROR: key %d, expected %d\n", |
| 147 | tskey, saved_tskey + stepsize); | 150 | tskey, saved_tskey + stepsize); |
| @@ -484,7 +487,7 @@ static void fill_header_udp(void *p, bool is_ipv4) · 336 unmodified lines |
| 484 | | 487 | |
| 485 | static void do_test(int family, unsigned int report_opt) | 488 | static void do_test(int family, unsigned int report_opt) |
| 486 | { | 489 | { |
| 487 | char control[CMSG_SPACE(sizeof(uint32_t))]; | 490 | char control[2 * CMSG_SPACE(sizeof(uint32_t))]; |
| 488 | struct sockaddr_ll laddr; | 491 | struct sockaddr_ll laddr; |
| 489 | unsigned int sock_opt; | 492 | unsigned int sock_opt; |
| 490 | struct cmsghdr *cmsg; | 493 | struct cmsghdr *cmsg; |
| @@ -624,18 +627,32 @@ static void do_test(int family, unsigned int report_opt) · 133 unmodified lines |
| 624 | msg.msg_iov = &iov; | 627 | msg.msg_iov = &iov; |
| 625 | msg.msg_iovlen = 1; | 628 | msg.msg_iovlen = 1; |
| 626 | | 629 | |
| 627 | if (cfg_use_cmsg) { | 630 | if (cfg_use_cmsg || cfg_use_cmsg_opt_id) { |
| 628 | memset(control, 0, sizeof(control)); | 631 | memset(control, 0, sizeof(control)); |
| 629 | | 632 | |
| 630 | msg.msg_control = control; | 633 | msg.msg_control = control; |
| 631 | msg.msg_controllen = sizeof(control); | 634 | msg.msg_controllen = cfg_use_cmsg * CMSG_SPACE(sizeof(uint32_t)); |
| | 635 | msg.msg_controllen += cfg_use_cmsg_opt_id * CMSG_SPACE(sizeof(uint32_t)); |
| 632 | | 636 | |
| 633 | cmsg = CMSG_FIRSTHDR(&msg); | 637 | cmsg = NULL; |
| 634 | cmsg->cmsg_level = SOL_SOCKET; | 638 | if (cfg_use_cmsg) { |
| 635 | cmsg->cmsg_type = SO_TIMESTAMPING; | 639 | cmsg = CMSG_FIRSTHDR(&msg); |
| 636 | cmsg->cmsg_len = CMSG_LEN(sizeof(uint32_t)); | 640 | cmsg->cmsg_level = SOL_SOCKET; |
| | 641 | cmsg->cmsg_type = SO_TIMESTAMPING; |
| | 642 | cmsg->cmsg_len = CMSG_LEN(sizeof(uint32_t)); |
| | 643 | |
| | 644 | *((uint32_t *)CMSG_DATA(cmsg)) = report_opt; |
| | 645 | } |
| | 646 | if (cfg_use_cmsg_opt_id) { |
| | 647 | cmsg = cmsg ? CMSG_NXTHDR(&msg, cmsg) : CMSG_FIRSTHDR(&msg); |
| | 648 | cmsg->cmsg_level = SOL_SOCKET; |
| | 649 | cmsg->cmsg_type = SCM_TS_OPT_ID; |
| | 650 | cmsg->cmsg_len = CMSG_LEN(sizeof(uint32_t)); |
| | 651 | |
| | 652 | *((uint32_t *)CMSG_DATA(cmsg)) = ts_opt_id; |
| | 653 | saved_tskey = ts_opt_id; |
| | 654 | } |
| 637 | | 655 | |
| 638 | *((uint32_t *) CMSG_DATA(cmsg)) = report_opt; | | |
| 639 | } | 656 | } |
| 640 | | 657 | |
| 641 | val = sendmsg(fd, &msg, 0); | 658 | val = sendmsg(fd, &msg, 0); |
| @@ -685,6 +702,7 @@ static void __attribute__((noreturn)) usage(const char *filepath) · 43 unmodified lines |
| 685 | " -L listen on hostname and port\n" | 702 | " -L listen on hostname and port\n" |
| 686 | " -n: set no-payload option\n" | 703 | " -n: set no-payload option\n" |
| 687 | " -N: print timestamps and durations in nsec (instead of usec)\n" | 704 | " -N: print timestamps and durations in nsec (instead of usec)\n" |
| | 705 | " -o N: use SCM_TS_OPT_ID control message to provide N as tskey\n" |
| 688 | " -p N: connect to port N\n" | 706 | " -p N: connect to port N\n" |
| 689 | " -P: use PF_PACKET\n" | 707 | " -P: use PF_PACKET\n" |
| 690 | " -r: use raw\n" | 708 | " -r: use raw\n" |
| @@ -705,7 +723,7 @@ static void parse_opt(int argc, char **argv) · 14 unmodified lines |
| 705 | int c; | 723 | int c; |
| 706 | | 724 | |
| 707 | while ((c = getopt(argc, argv, | 725 | while ((c = getopt(argc, argv, |
| 708 | "46bc:CeEFhIl:LnNp:PrRS:t:uv:V:x")) != -1) { | 726 | "46bc:CeEFhIl:LnNo:p:PrRS:t:uv:V:x")) != -1) { |
| 709 | switch (c) { | 727 | switch (c) { |
| 710 | case '4': | 728 | case '4': |
| 711 | do_ipv6 = 0; | 729 | do_ipv6 = 0; |
| @@ -746,6 +764,10 @@ static void parse_opt(int argc, char **argv) · 34 unmodified lines |
| 746 | case 'N': | 764 | case 'N': |
| 747 | cfg_print_nsec = true; | 765 | cfg_print_nsec = true; |
| 748 | break; | 766 | break; |
| | 767 | case 'o': |
| | 768 | ts_opt_id = strtoul(optarg, NULL, 10); |
| | 769 | cfg_use_cmsg_opt_id = true; |
| | 770 | break; |
| 749 | case 'p': | 771 | case 'p': |
| 750 | dest_port = strtoul(optarg, NULL, 10); | 772 | dest_port = strtoul(optarg, NULL, 10); |
| 751 | break; | 773 | break; |
| @@ -803,6 +825,8 @@ static void parse_opt(int argc, char **argv) · 51 unmodified lines |
| 803 | error(1, 0, "cannot ask for pktinfo over pf_packet"); | 825 | error(1, 0, "cannot ask for pktinfo over pf_packet"); |
| 804 | if (cfg_busy_poll && cfg_use_epoll) | 826 | if (cfg_busy_poll && cfg_use_epoll) |
| 805 | error(1, 0, "pass epoll or busy_poll, not both"); | 827 | error(1, 0, "pass epoll or busy_poll, not both"); |
| | 828 | if (cfg_proto == SOCK_STREAM && cfg_use_cmsg_opt_id) |
| | 829 | error(1, 0, "TCP sockets don't support SCM_TS_OPT_ID"); |
| 806 | | 830 | |
| 807 | if (optind != argc - 1) | 831 | if (optind != argc - 1) |
| 808 | error(1, 0, "missing required hostname argument"); | 832 | error(1, 0, "missing required hostname argument"); |