From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202410 header.b=QGA0vkMb; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id E374A5A061A for ; Wed, 23 Oct 2024 02:43:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1729644174; bh=nDrS+/fXcTyDGygUfIFTNrhiLFZaQXsJJ1frKVqi58E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QGA0vkMbWo8H0yegt1uIHo/cnz23db6Pm96OIHCYQt7o+8mRoyHG99aJ/P6fl3GO2 sWQKDsO86GkDsqHgtHV+z12Du/l6NKMphx18OqYqw7G3AjTYD5BSoObKnzY3OtFNgy Iu7G/hWW0yeFf51dpgDPKX7VDNHgbMCciUTfVxJsSlB6UMX+gb0X6VsiFwwwcIeoyi GkawRK5R+gttKMQQnPDi4CDyoAsfbOKOGE2A4XcCJKtB+XArzGxDZJuZzFCFOC1pf5 KWxeUirrFbGdLAAPgVVhi4/JcMz8r9+BZvUWLrOu/7WMVE1UVzAWVODY+MT6ZCfH/c p6mUUtjLDnFbw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XY9Hy1Jtlz4wc2; Wed, 23 Oct 2024 11:42:54 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/2] tcp: Use runtime tests for TCP_INFO fields Date: Wed, 23 Oct 2024 11:42:53 +1100 Message-ID: <20241023004253.1729124-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241023004253.1729124-1-david@gibson.dropbear.id.au> References: <20241023004253.1729124-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 54X3JRQEY67HWI2YGLGNHNR5YU4W3Y5S X-Message-ID-Hash: 54X3JRQEY67HWI2YGLGNHNR5YU4W3Y5S X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In order to use particular fields from the TCP_INFO getsockopt() we need them to be in the version of the structure we have defined. We test this in the Makefile, setting HAS_BYTES_ACKED and HAS_MIN_RTT accordingly. However, we also need the fields to be present in the runtime kernel we're using, which we don't currently check for those fields. Add logic similar to that for tcpi_snd_wnd to check for these fields too instead of just using the compile time check. Signed-off-by: David Gibson --- tcp.c | 65 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/tcp.c b/tcp.c index 3cca5c6..b5ef1f1 100644 --- a/tcp.c +++ b/tcp.c @@ -380,6 +380,19 @@ socklen_t tcp_info_size; #else #define snd_wnd_cap (false) #endif +#ifdef HAS_BYTES_ACKED +/* Does the kernel report bytes acked in TCP_INFO (kernel commit 0df48c26d84) */ +#define bytes_acked_cap tcp_info_cap(bytes_acked) +#else +#define bytes_acked_cap (false) +#endif +#ifdef HAS_MIN_RTT +/* Does the kernel report minimum RTT TCP_INFO (kernel commit cd9b266095f4) */ +#define min_rtt_cap tcp_info_cap(min_rtt) +#else +#define min_rtt_cap (false) +#endif + /* sendmsg() to socket */ static struct iovec tcp_iov [UIO_MAXIOV]; @@ -687,11 +700,10 @@ static int tcp_rtt_dst_low(const struct tcp_tap_conn *conn) static void tcp_rtt_dst_check(const struct tcp_tap_conn *conn, const struct tcp_info *tinfo) { -#ifdef HAS_MIN_RTT const struct flowside *tapside = TAPFLOW(conn); int i, hole = -1; - if (!tinfo->tcpi_min_rtt || + if (!min_rtt_cap || (int)tinfo->tcpi_min_rtt > LOW_RTT_THRESHOLD) return; @@ -712,10 +724,6 @@ static void tcp_rtt_dst_check(const struct tcp_tap_conn *conn, if (hole == LOW_RTT_TABLE_SIZE) hole = 0; inany_from_af(low_rtt_dst + hole, AF_INET6, &in6addr_any); -#else - (void)conn; - (void)tinfo; -#endif /* HAS_MIN_RTT */ } /** @@ -1131,30 +1139,29 @@ int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn, uint32_t new_wnd_to_tap = prev_wnd_to_tap; int s = conn->sock; -#ifndef HAS_BYTES_ACKED - (void)force_seq; - - conn->seq_ack_to_tap = conn->seq_from_tap; - if (SEQ_LT(conn->seq_ack_to_tap, prev_ack_to_tap)) - conn->seq_ack_to_tap = prev_ack_to_tap; -#else - if ((unsigned)SNDBUF_GET(conn) < SNDBUF_SMALL || tcp_rtt_dst_low(conn) - || CONN_IS_CLOSING(conn) || (conn->flags & LOCAL) || force_seq) { + if (!bytes_acked_cap) { conn->seq_ack_to_tap = conn->seq_from_tap; - } else if (conn->seq_ack_to_tap != conn->seq_from_tap) { - if (!tinfo) { - tinfo = &tinfo_new; - if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl)) - return 0; - } - - conn->seq_ack_to_tap = tinfo->tcpi_bytes_acked + - conn->seq_init_from_tap; - if (SEQ_LT(conn->seq_ack_to_tap, prev_ack_to_tap)) conn->seq_ack_to_tap = prev_ack_to_tap; + } else { + if ((unsigned)SNDBUF_GET(conn) < SNDBUF_SMALL || + tcp_rtt_dst_low(conn) || CONN_IS_CLOSING(conn) || + (conn->flags & LOCAL) || force_seq) { + conn->seq_ack_to_tap = conn->seq_from_tap; + } else if (conn->seq_ack_to_tap != conn->seq_from_tap) { + if (!tinfo) { + tinfo = &tinfo_new; + if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl)) + return 0; + } + + conn->seq_ack_to_tap = tinfo->tcpi_bytes_acked + + conn->seq_init_from_tap; + + if (SEQ_LT(conn->seq_ack_to_tap, prev_ack_to_tap)) + conn->seq_ack_to_tap = prev_ack_to_tap; + } } -#endif /* !HAS_BYTES_ACKED */ if (!snd_wnd_cap) { tcp_get_sndbuf(conn); @@ -2653,6 +2660,12 @@ int tcp_init(struct ctx *c) #ifdef HAS_SND_WND dbg_tcpi(snd_wnd); #endif +#ifdef HAS_BYTES_ACKED + dbg_tcpi(bytes_acked); +#endif +#ifdef HAS_MIN_RTT + dbg_tcpi(min_rtt); +#endif #undef dbg_tcpi return 0; -- 2.47.0