From 89df119924ebab05b5332d0c73c94e4a137b9247 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 15 Dec 2023 10:51:49 +0000 Subject: [PATCH] adding tcp_info struct to linux musl/glibc. --- libc-test/build.rs | 10 ++++- libc-test/semver/linux-gnu.txt | 1 + libc-test/semver/linux-musl.txt | 1 + src/unix/linux_like/linux/gnu/mod.rs | 39 ++++++++++++++++ src/unix/linux_like/linux/musl/mod.rs | 65 +++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index a9d04ca81cc15..b8df1e8fbff61 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -4246,7 +4246,15 @@ fn test_linux(target: &str) { // the `ifc_ifcu` field is an anonymous union (struct_ == "ifconf" && field == "ifc_ifcu") || // glibc uses a single array `uregs` instead of individual fields. - (struct_ == "user_regs" && arm) + (struct_ == "user_regs" && arm) || + // the `tcpi_snd_wscale` field is a bitfield + (struct_ == "tcp_info" && field == "tcpi_snd_wscale") || + // the `tcpi_snd_wscale` field is a bitfield + (struct_ == "tcp_info" && field == "tcpi_rcv_wscale") || + // the `tcpi_delivery_rate_app_limited` field is a bitfield on musl + (musl && struct_ == "tcp_info" && field == "tcpi_delivery_rate_app_limited") || + // the `tcpi_fast_open_client_fail` field is a bitfield on musl + (musl && struct_ == "tcp_info" && field == "tcpi_fast_open_client_fail") }); cfg.skip_roundtrip(move |s| match s { diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index 4d95520d3e9de..0a3c9d433e95e 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -700,3 +700,4 @@ putpwent putgrent execveat close_range +tcp_info diff --git a/libc-test/semver/linux-musl.txt b/libc-test/semver/linux-musl.txt index 09a63c7294a76..b6dedec6da14e 100644 --- a/libc-test/semver/linux-musl.txt +++ b/libc-test/semver/linux-musl.txt @@ -81,3 +81,4 @@ strftime strptime dirname basename +tcp_info diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index e7284fd46f096..577218ee15ac4 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -432,6 +432,45 @@ s! { pub len: ::__u32, pub options: ::__u32, } + + // netinet/tcp.h + + pub struct tcp_info { + pub tcpi_state: u8, + pub tcpi_ca_state: u8, + pub tcpi_retransmits: u8, + pub tcpi_probes: u8, + pub tcpi_backoff: u8, + pub tcpi_options: u8, + // bitfields 4 + pub tcpi_snd_wscale: u8, + // bitfields 4 + pub tcpi_rcv_wscale: u8, + pub tcpi_rto: u32, + pub tcpi_ato: u32, + pub tcpi_snd_mss: u32, + pub tcpi_rcv_mss: u32, + pub tcpi_unacked: u32, + pub tcpi_sacked: u32, + pub tcpi_lost: u32, + pub tcpi_retrans: u32, + pub tcpi_fackets: u32, + pub tcpi_last_data_sent: u32, + pub tcpi_last_ack_sent: u32, + pub tcpi_last_data_recv: u32, + pub tcpi_last_ack_recv: u32, + pub tcpi_pmtu: u32, + pub tcpi_rcv_ssthresh: u32, + pub tcpi_rtt: u32, + pub tcpi_rttvar: u32, + pub tcpi_snd_ssthresh: u32, + pub tcpi_snd_cwnd: u32, + pub tcpi_advmss: u32, + pub tcpi_reordering: u32, + pub tcpi_rcv_rtt: u32, + pub tcpi_rcv_space: u32, + pub tcpi_total_retrans: u32, + } } impl siginfo_t { diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 97429a7f3a21a..065d7de4abab7 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -348,6 +348,71 @@ s! { pub len: ::__u32, pub options: ::__u32, } + + // netinet/tcp.h + + pub struct tcp_info { + pub tcpi_state: u8, + pub tcpi_ca_state: u8, + pub tcpi_retransmits: u8, + pub tcpi_probes: u8, + pub tcpi_backoff: u8, + pub tcpi_options: u8, + // bitfields 4 + pub tcpi_snd_wscale: u8, + // bitfields 4 + pub tcpi_rcv_wscale: u8, + // bitfields 1 + pub tcpi_delivery_rate_app_limited: u8, + // bitfields 2 + pub tcpi_fastopen_client_fail: u8, + pub tcpi_rto: u32, + pub tcpi_ato: u32, + pub tcpi_snd_mss: u32, + pub tcpi_rcv_mss: u32, + pub tcpi_unacked: u32, + pub tcpi_sacked: u32, + pub tcpi_lost: u32, + pub tcpi_retrans: u32, + pub tcpi_fackets: u32, + pub tcpi_last_data_sent: u32, + pub tcpi_last_ack_sent: u32, + pub tcpi_last_data_recv: u32, + pub tcpi_last_ack_recv: u32, + pub tcpi_pmtu: u32, + pub tcpi_rcv_ssthresh: u32, + pub tcpi_rtt: u32, + pub tcpi_rttvar: u32, + pub tcpi_snd_ssthresh: u32, + pub tcpi_snd_cwnd: u32, + pub tcpi_advmss: u32, + pub tcpi_reordering: u32, + pub tcpi_rcv_rtt: u32, + pub tcpi_rcv_space: u32, + pub tcpi_total_retrans: u32, + pub tcpi_pacing_rate: u64, + pub tcpi_max_pacing_rate: u64, + pub tcpi_bytes_acked: u64, + pub tcpi_bytes_received: u64, + pub tcpi_segs_out: u32, + pub tcpi_segs_in: u32, + pub tcpi_notsent_bytes: u32, + pub tcpi_min_rtt: u32, + pub tcpi_data_segs_in: u32, + pub tcpi_data_segs_out: u32, + pub tcpi_delivery_rate: u64, + pub tcpi_busy_time: u64, + pub tcpi_rwnd_limited: u64, + pub tcpi_sndbuf_limited: u64, + pub tcpi_delivered: u32, + pub tcpi_delivered_ce: u32, + pub tcpi_bytes_sent: u64, + pub tcpi_bytes_retrans: u64, + pub tcpi_dsack_dups: u32, + pub tcpi_reord_seen: u32, + pub tcpi_rcv_ooopack: u32, + pub tcpi_snd_wnd: u32, + } } s_no_extra_traits! {