Lines Matching +full:poll +full:- +full:retry +full:- +full:count
1 // SPDX-License-Identifier: GPL-2.0-only
8 * - SCHED, SND and ACK timestamps
9 * - RAW, UDP and TCP
10 * - IPv4 and IPv6
11 * - various packet sizes (to test GSO and TSO)
17 * A simple `nc6 [-u] -l -p $DESTPORT` will do
38 #include <poll.h>
85 static int saved_tskey = -1;
86 static int saved_tskey_type = -1;
92 int count; member
103 return ts->tv_sec * NSEC_PER_SEC + ts->tv_nsec; in timespec_to_ns64()
108 return ts->tv_sec * USEC_PER_SEC + ts->tv_nsec / NSEC_PER_USEC; in timespec_to_us64()
113 te->min = INT64_MAX; in init_timing_event()
114 te->max = 0; in init_timing_event()
115 te->total = 0; in init_timing_event()
116 te->count = 0; in init_timing_event()
122 int64_t ts_delta = timespec_to_ns64(t_end) - timespec_to_ns64(t_start); in add_timing_event()
124 te->count++; in add_timing_event()
125 if (ts_delta < te->min) in add_timing_event()
126 te->min = ts_delta; in add_timing_event()
127 if (ts_delta > te->max) in add_timing_event()
128 te->max = ts_delta; in add_timing_event()
129 te->total += ts_delta; in add_timing_event()
139 if (saved_tskey == -1) in validate_key()
165 cur64 - start64, min_delay, max_delay); in validate_timestamp()
183 if (!(cur->tv_sec | cur->tv_nsec)) in __print_timestamp()
188 name, cur->tv_sec, cur->tv_nsec, in __print_timestamp()
192 name, cur->tv_sec, cur->tv_nsec / NSEC_PER_USEC, in __print_timestamp()
196 ts_delta = timespec_to_ns64(cur) - timespec_to_ns64(&ts_usr); in __print_timestamp()
223 validate_timestamp(&tss->ts[0], 0); in print_timestamp()
224 add_timing_event(&usr_enq, &ts_usr, &tss->ts[0]); in print_timestamp()
228 validate_timestamp(&tss->ts[0], cfg_delay_snd); in print_timestamp()
229 add_timing_event(&usr_snd, &ts_usr, &tss->ts[0]); in print_timestamp()
233 validate_timestamp(&tss->ts[0], cfg_delay_ack); in print_timestamp()
234 add_timing_event(&usr_ack, &ts_usr, &tss->ts[0]); in print_timestamp()
240 __print_timestamp(tsname, &tss->ts[0], tskey, payload_len); in print_timestamp()
245 if (!te->count) in print_timing_event()
248 fprintf(stderr, " %s: count=%d", name, te->count); in print_timing_event()
250 __print_ts_delta_formatted((int64_t)(te->total / te->count)); in print_timing_event()
252 __print_ts_delta_formatted(te->min); in print_timing_event()
254 __print_ts_delta_formatted(te->max); in print_timing_event()
303 ret = poll(&pollfd, 1, cfg_poll_timeout); in __poll()
305 error(1, errno, "poll"); in __poll()
316 cm && cm->cmsg_len; in __recv_errmsg_cmsg()
318 if (cm->cmsg_level == SOL_SOCKET && in __recv_errmsg_cmsg()
319 cm->cmsg_type == SCM_TIMESTAMPING) { in __recv_errmsg_cmsg()
321 } else if ((cm->cmsg_level == SOL_IP && in __recv_errmsg_cmsg()
322 cm->cmsg_type == IP_RECVERR) || in __recv_errmsg_cmsg()
323 (cm->cmsg_level == SOL_IPV6 && in __recv_errmsg_cmsg()
324 cm->cmsg_type == IPV6_RECVERR) || in __recv_errmsg_cmsg()
325 (cm->cmsg_level == SOL_PACKET && in __recv_errmsg_cmsg()
326 cm->cmsg_type == PACKET_TX_TIMESTAMP)) { in __recv_errmsg_cmsg()
328 if (serr->ee_errno != ENOMSG || in __recv_errmsg_cmsg()
329 serr->ee_origin != SO_EE_ORIGIN_TIMESTAMPING) { in __recv_errmsg_cmsg()
331 serr->ee_errno, in __recv_errmsg_cmsg()
332 serr->ee_origin); in __recv_errmsg_cmsg()
335 } else if (cm->cmsg_level == SOL_IP && in __recv_errmsg_cmsg()
336 cm->cmsg_type == IP_PKTINFO) { in __recv_errmsg_cmsg()
338 print_pktinfo(AF_INET, info->ipi_ifindex, in __recv_errmsg_cmsg()
339 &info->ipi_spec_dst, &info->ipi_addr); in __recv_errmsg_cmsg()
340 } else if (cm->cmsg_level == SOL_IPV6 && in __recv_errmsg_cmsg()
341 cm->cmsg_type == IPV6_PKTINFO) { in __recv_errmsg_cmsg()
343 print_pktinfo(AF_INET6, info6->ipi6_ifindex, in __recv_errmsg_cmsg()
344 NULL, &info6->ipi6_addr); in __recv_errmsg_cmsg()
347 cm->cmsg_level, cm->cmsg_type); in __recv_errmsg_cmsg()
350 print_timestamp(tss, serr->ee_info, serr->ee_data, in __recv_errmsg_cmsg()
388 if (ret == -1 && errno != EAGAIN) in recv_errmsg()
398 return ret == -1; in recv_errmsg()
421 pseudo_sum += udph->len; in get_udp_csum()
424 csum_start -= alen * 2; in get_udp_csum()
425 csum_len = ntohs(udph->len) + alen * 2; in get_udp_csum()
436 iph->ihl = 5; in fill_header_ipv4()
437 iph->version = 4; in fill_header_ipv4()
438 iph->ttl = 2; in fill_header_ipv4()
439 iph->saddr = daddr.sin_addr.s_addr; /* set for udp csum calc */ in fill_header_ipv4()
440 iph->daddr = daddr.sin_addr.s_addr; in fill_header_ipv4()
441 iph->protocol = IPPROTO_UDP; in fill_header_ipv4()
454 ip6h->version = 6; in fill_header_ipv6()
455 ip6h->payload_len = htons(sizeof(struct udphdr) + cfg_payload_len); in fill_header_ipv6()
456 ip6h->nexthdr = IPPROTO_UDP; in fill_header_ipv6()
457 ip6h->hop_limit = 64; in fill_header_ipv6()
459 ip6h->saddr = daddr6.sin6_addr; in fill_header_ipv6()
460 ip6h->daddr = daddr6.sin6_addr; in fill_header_ipv6()
471 udph->source = ntohs(dest_port + 1); /* spoof */ in fill_header_udp()
472 udph->dest = ntohs(dest_port); in fill_header_udp()
473 udph->len = ntohs(sizeof(*udph) + cfg_payload_len); in fill_header_udp()
474 udph->check = 0; in fill_header_udp()
476 udph->check = get_udp_csum(udph, is_ipv4 ? sizeof(struct in_addr) : in fill_header_udp()
535 saved_tskey = -1; in do_test()
629 cmsg->cmsg_level = SOL_SOCKET; in do_test()
630 cmsg->cmsg_type = SO_TIMESTAMPING; in do_test()
631 cmsg->cmsg_len = CMSG_LEN(sizeof(uint32_t)); in do_test()
654 print_timing_event("USR-ENQ", &usr_enq); in do_test()
655 print_timing_event("USR-SND", &usr_snd); in do_test()
656 print_timing_event("USR-ACK", &usr_ack); in do_test()
669 " -4: only IPv4\n" in usage()
670 " -6: only IPv6\n" in usage()
671 " -h: show this message\n" in usage()
672 " -b: busy poll to read from error queue\n" in usage()
673 " -c N: number of packets for each test\n" in usage()
674 " -C: use cmsg to set tstamp recording options\n" in usage()
675 " -e: use level-triggered epoll() instead of poll()\n" in usage()
676 " -E: use event-triggered epoll() instead of poll()\n" in usage()
677 " -F: poll()/epoll() waits forever for an event\n" in usage()
678 " -I: request PKTINFO\n" in usage()
679 " -l N: send N bytes at a time\n" in usage()
680 " -L listen on hostname and port\n" in usage()
681 " -n: set no-payload option\n" in usage()
682 " -N: print timestamps and durations in nsec (instead of usec)\n" in usage()
683 " -p N: connect to port N\n" in usage()
684 " -P: use PF_PACKET\n" in usage()
685 " -r: use raw\n" in usage()
686 " -R: use raw (IP_HDRINCL)\n" in usage()
687 " -S N: usec to sleep before reading error queue\n" in usage()
688 " -t N: tolerance (usec) for timestamp validation\n" in usage()
689 " -u: use udp\n" in usage()
690 " -v: validate SND delay (usec)\n" in usage()
691 " -V: validate ACK delay (usec)\n" in usage()
692 " -x: show payload (up to 70 bytes)\n", in usage()
703 "46bc:CeEFhIl:LnNp:PrRS:t:uv:V:x")) != -1) { in parse_opt()
727 cfg_poll_timeout = -1; in parse_opt()
794 error(1, 0, "pass -4 or -6, not both"); in parse_opt()
796 error(1, 0, "pass -P, -r, -R or -u, not multiple"); in parse_opt()
802 if (optind != argc - 1) in parse_opt()
812 retry: in resolve_hostname()
818 if (!have_ipv4 && cur->ai_family == AF_INET) { in resolve_hostname()
819 memcpy(&daddr, cur->ai_addr, sizeof(daddr)); in resolve_hostname()
823 else if (!have_ipv6 && cur->ai_family == AF_INET6) { in resolve_hostname()
824 memcpy(&daddr6, cur->ai_addr, sizeof(daddr6)); in resolve_hostname()
828 cur = cur->ai_next; in resolve_hostname()
835 goto retry; in resolve_hostname()
849 if (fd == -1) in do_listen()
902 resolve_hostname(argv[argc - 1]); in main()