--- embedaddon/iperf/src/tcp_info.c 2021/03/17 00:36:46 1.1.1.2 +++ embedaddon/iperf/src/tcp_info.c 2023/09/27 11:14:54 1.1.1.3 @@ -27,13 +27,13 @@ /* * routines related to collection TCP_INFO using getsockopt() - * + * * Brian Tierney, ESnet (bltierney@es.net) - * + * * Note that this is only really useful on Linux. * XXX: only standard on linux versions 2.4 and later # - * FreeBSD has a limitted implementation that only includes the following: + * FreeBSD has a limited implementation that only includes the following: * tcpi_snd_ssthresh, tcpi_snd_cwnd, tcpi_rcv_space, tcpi_rtt * Based on information on http://wiki.freebsd.org/8.0TODO, I dont think this will be * fixed before v8.1 at the earliest. @@ -60,7 +60,7 @@ int has_tcpinfo(void) { -#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)) \ +#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) \ && defined(TCP_INFO) return 1; #else @@ -75,14 +75,14 @@ has_tcpinfo_retransmits(void) #if defined(linux) && defined(TCP_MD5SIG) /* TCP_MD5SIG doesn't actually have anything to do with TCP ** retransmits, it just showed up in the same rev of the header - ** file. If it's present then struct tcp_info has the + ** file. If it's present then struct tcp_info has the ** tcpi_total_retrans field that we need; if not, not. */ return 1; #else #if defined(__FreeBSD__) && __FreeBSD_version >= 600000 return 1; /* Should work now */ -#elif defined(__NetBSD__) && defined(TCP_INFO) +#elif (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO) return 1; #else return 0; @@ -94,7 +94,7 @@ has_tcpinfo_retransmits(void) void save_tcpinfo(struct iperf_stream *sp, struct iperf_interval_results *irp) { -#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)) && \ +#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && \ defined(TCP_INFO) socklen_t tcp_info_length = sizeof(struct tcp_info); @@ -118,7 +118,7 @@ get_total_retransmits(struct iperf_interval_results *i return irp->tcpInfo.tcpi_total_retrans; #elif defined(__FreeBSD__) && __FreeBSD_version >= 600000 return irp->tcpInfo.tcpi_snd_rexmitpack; -#elif defined(__NetBSD__) && defined(TCP_INFO) +#elif (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO) return irp->tcpInfo.tcpi_snd_rexmitpack; #else return -1; @@ -133,11 +133,13 @@ long get_snd_cwnd(struct iperf_interval_results *irp) { #if defined(linux) && defined(TCP_MD5SIG) - return irp->tcpInfo.tcpi_snd_cwnd * irp->tcpInfo.tcpi_snd_mss; + return (long)irp->tcpInfo.tcpi_snd_cwnd * irp->tcpInfo.tcpi_snd_mss; #elif defined(__FreeBSD__) && __FreeBSD_version >= 600000 return irp->tcpInfo.tcpi_snd_cwnd; #elif defined(__NetBSD__) && defined(TCP_INFO) - return irp->tcpInfo.tcpi_snd_cwnd * irp->tcpInfo.tcpi_snd_mss; + return (long)irp->tcpInfo.tcpi_snd_cwnd * irp->tcpInfo.tcpi_snd_mss; +#elif defined(__OpenBSD__) && defined(TCP_INFO) + return irp->tcpInfo.tcpi_snd_cwnd; #else return -1; #endif @@ -145,6 +147,28 @@ get_snd_cwnd(struct iperf_interval_results *irp) /*************************************************************/ /* + * Return snd_wnd in octets. + */ +long +get_snd_wnd(struct iperf_interval_results *irp) +{ +#if !defined(HAVE_TCP_INFO_SND_WND) + return -1; +#elif defined(linux) && defined(TCP_MD5SIG) + return irp->tcpInfo.tcpi_snd_wnd; +#elif defined(__FreeBSD__) && __FreeBSD_version >= 600000 + return irp->tcpInfo.tcpi_snd_wnd; +#elif defined(__NetBSD__) && defined(TCP_INFO) + return (long)irp->tcpInfo.tcpi_snd_wnd * irp->tcpInfo.tcpi_snd_mss; +#elif defined(__OpenBSD__) && defined(TCP_INFO) + return irp->tcpInfo.tcpi_snd_wnd; +#else + return -1; +#endif +} + +/*************************************************************/ +/* * Return rtt in usec. */ long @@ -154,7 +178,7 @@ get_rtt(struct iperf_interval_results *irp) return irp->tcpInfo.tcpi_rtt; #elif defined(__FreeBSD__) && __FreeBSD_version >= 600000 return irp->tcpInfo.tcpi_rtt; -#elif defined(__NetBSD__) && defined(TCP_INFO) +#elif (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO) return irp->tcpInfo.tcpi_rtt; #else return -1; @@ -172,7 +196,7 @@ get_rttvar(struct iperf_interval_results *irp) return irp->tcpInfo.tcpi_rttvar; #elif defined(__FreeBSD__) && __FreeBSD_version >= 600000 return irp->tcpInfo.tcpi_rttvar; -#elif defined(__NetBSD__) && defined(TCP_INFO) +#elif (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO) return irp->tcpInfo.tcpi_rttvar; #else return -1; @@ -200,14 +224,10 @@ build_tcpinfo_message(struct iperf_interval_results *r #if defined(linux) && defined(TCP_INFO) sprintf(message, report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, r->tcpInfo.tcpi_snd_ssthresh, r->tcpInfo.tcpi_rcv_ssthresh, r->tcpInfo.tcpi_unacked, r->tcpInfo.tcpi_sacked, - r->tcpInfo.tcpi_lost, r->tcpInfo.tcpi_retrans, r->tcpInfo.tcpi_fackets, + r->tcpInfo.tcpi_lost, r->tcpInfo.tcpi_retrans, r->tcpInfo.tcpi_fackets, r->tcpInfo.tcpi_rtt, r->tcpInfo.tcpi_reordering); #endif -#if defined(__FreeBSD__) && defined(TCP_INFO) - sprintf(message, report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, - r->tcpInfo.tcpi_rcv_space, r->tcpInfo.tcpi_snd_ssthresh, r->tcpInfo.tcpi_rtt); -#endif -#if defined(__NetBSD__) && defined(TCP_INFO) +#if (defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO) sprintf(message, report_tcpInfo, r->tcpInfo.tcpi_snd_cwnd, r->tcpInfo.tcpi_rcv_space, r->tcpInfo.tcpi_snd_ssthresh, r->tcpInfo.tcpi_rtt); #endif