Skip to content

Commit

Permalink
Merge pull request #1397 from brad0/openbsd_tcp_info
Browse files Browse the repository at this point in the history
Add support for OpenBSD systems which have TCP_INFO implemented.
  • Loading branch information
bmah888 committed Oct 25, 2022
2 parents 518ca9a + 463571f commit 3d1218b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ AC_CHECK_MEMBER([struct tcp_info.tcpi_snd_wnd],
[#ifdef HAVE_LINUX_TCP_H
#include <linux/tcp.h>
#else
#include <sys/types.h>
#include <netinet/tcp.h>
#endif
])
Expand Down
4 changes: 2 additions & 2 deletions src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ struct iperf_interval_results
int cnt_error;

int omitted;
#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)) && \
#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && \
defined(TCP_INFO)
struct tcp_info tcpInfo; /* getsockopt(TCP_INFO) for Linux, {Free,Net}BSD */
struct tcp_info tcpInfo; /* getsockopt(TCP_INFO) for Linux, {Free,Net,Open}BSD */
#else
/* Just placeholders, never accessed. */
char *tcpInfo;
Expand Down
6 changes: 1 addition & 5 deletions src/iperf_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,7 @@ const char report_receiver_not_available_summary_format[] = "[%3s] (receiver sta
const char report_tcpInfo[] =
"event=TCP_Info CWND=%u SND_SSTHRESH=%u RCV_SSTHRESH=%u UNACKED=%u SACK=%u LOST=%u RETRANS=%u FACK=%u RTT=%u REORDERING=%u\n";
#endif
#if defined(__FreeBSD__)
const char report_tcpInfo[] =
"event=TCP_Info CWND=%u RCV_WIND=%u SND_SSTHRESH=%u RTT=%u\n";
#endif
#if defined(__NetBSD__)
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
const char report_tcpInfo[] =
"event=TCP_Info CWND=%u RCV_WIND=%u SND_SSTHRESH=%u RTT=%u\n";
#endif
Expand Down
22 changes: 11 additions & 11 deletions src/tcp_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,7 +82,7 @@ has_tcpinfo_retransmits(void)
#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;
Expand All @@ -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);

Expand All @@ -118,7 +118,7 @@ get_total_retransmits(struct iperf_interval_results *irp)
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;
Expand All @@ -138,6 +138,8 @@ get_snd_cwnd(struct iperf_interval_results *irp)
return irp->tcpInfo.tcpi_snd_cwnd;
#elif defined(__NetBSD__) && defined(TCP_INFO)
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
Expand All @@ -158,6 +160,8 @@ get_snd_wnd(struct iperf_interval_results *irp)
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
Expand All @@ -174,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;
Expand All @@ -192,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;
Expand Down Expand Up @@ -223,11 +227,7 @@ build_tcpinfo_message(struct iperf_interval_results *r, char *message)
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
Expand Down

0 comments on commit 3d1218b

Please sign in to comment.