From ee0bf577d128b0c155de9f6677429c7eb5cf7398 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 3 Sep 2024 18:41:58 +0100 Subject: [PATCH] adding tcp_info struct to linux musl/glibc. --- libc-test/build.rs | 8 +++- libc-test/semver/linux-gnu.txt | 1 + libc-test/semver/linux-musl.txt | 1 + src/unix/linux_like/linux/gnu/mod.rs | 38 +++++++++++++++ src/unix/linux_like/linux/musl/mod.rs | 67 +++++++++++++++++++++++++++ 5 files changed, 114 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 88b37451150b..d20280403997 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -4425,7 +4425,13 @@ fn test_linux(target: &str) { // the `ifr_ifrn` field is an anonymous union (struct_ == "iwreq" && field == "ifr_ifrn") || // the `key` field is a zero-sized array - (struct_ == "iw_encode_ext" && field == "key") + (struct_ == "iw_encode_ext" && field == "key") || + // the `tcpi_snd_rcv_wscale` map two bitfield fields stored in a u8 + (struct_ == "tcp_info" && field == "tcpi_snd_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 8157fd0ec5f1..f775994cd672 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -713,3 +713,4 @@ putgrent execveat close_range epoll_pwait2 +tcp_info diff --git a/libc-test/semver/linux-musl.txt b/libc-test/semver/linux-musl.txt index fa457ddf63cb..c8b5ddbd75c2 100644 --- a/libc-test/semver/linux-musl.txt +++ b/libc-test/semver/linux-musl.txt @@ -91,4 +91,5 @@ pwritev2 pwritev64 reallocarray setutxent +tcp_info timex diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index 4c5f26dbc03b..a7dd919399fd 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -453,6 +453,44 @@ s! { pub aio_flags: ::__u32, pub aio_resfd: ::__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, + /// This contains the bitfields `tcpi_snd_wscale` and `tcpi_rcv_wscale`. + /// Each is 4 bits. + pub tcpi_snd_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 5f2d96eca885..a37da7d24c31 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -344,6 +344,73 @@ 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, + /* + * FIXME(musl): when musl headers are more up to date + /// This contains the bitfields `tcpi_snd_wscale` and `tcpi_rcv_wscale`. + /// Each is 4 bits. + pub tcpi_snd_rcv_wscale: u8, + /// This contains the bitfields `tcpi_delivery_rate_app_limited` (1 bit) and + /// `tcpi_fastopen_client_fail` (2 bits). + pub tcpi_delivery_fastopen_bitfields: 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, + // FIXME(musl): to uncomment once CI musl is updated + //pub tcpi_rcv_ooopack: u32, + //pub tcpi_snd_wnd: u32, + } } s_no_extra_traits! {