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=P0KHzS6d; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id B566B5A004E for ; Thu, 24 Oct 2024 06:59:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1729745963; bh=shJSA7Y8+5Tku0UWfBhcbHPWjpUroPAbf2xQiepE+58=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P0KHzS6d2G5DaIIBGwgMpcxOyimYENK1odXNYeUzIxi2zp191+RRvRqHj1pAFxgED FpfEM+Hqe1tbgbk6ka9/38ARa+xRQ4EhOTIfhx/2RZ06BPBnXsU8w6Yet+NTQg8y9G LzwgbWHjWJ+IzEsUQViPpfxMMemT/3iGdOVOsfG/KnfUWm+yQbH/vWc+Xdl90QYzOC bOLe1RuvngZCU6+9XeOh3h+7ApL0+YxrQhsJZFtU+u1yagj/TWPXfft41NmoBbtITX PxhpXOOMdqnpBfeQq5noAIZ8+2x+VhUvp3NpS/mWcTbr7wmyUQqs7QMRKwjyNjwAVv 4f0x5gIk52edg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4XYtxR1gPsz4x04; Thu, 24 Oct 2024 15:59:23 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 2/3] tcp: Generalise probing for tcpi_snd_wnd field Date: Thu, 24 Oct 2024 15:59:21 +1100 Message-ID: <20241024045922.3900584-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241024045922.3900584-1-david@gibson.dropbear.id.au> References: <20241024045922.3900584-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: AHI3TYZZP2TZKKEKYCVCRLWCO6NBZTXJ X-Message-ID-Hash: AHI3TYZZP2TZKKEKYCVCRLWCO6NBZTXJ 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 the tcpi_snd_wnd field from the TCP_INFO getsockopt() we need the field to be supported in the runtime kernel (snd_wnd_cap). In fact we should check that for for every tcp_info field we want to use, beyond the very old ones shared with BSD. Prepare to do that, by generalising the probing from setting a single bool to instead record the size of the returned TCP_INFO structure. We can then use that recorded value to check for the presence of any field we need. Signed-off-by: David Gibson --- tcp.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tcp.c b/tcp.c index 2a0b272..998e56d 100644 --- a/tcp.c +++ b/tcp.c @@ -361,10 +361,15 @@ char tcp_buf_discard [MAX_WINDOW]; /* Does the kernel support TCP_PEEK_OFF? */ bool peek_offset_cap; -/* Does the kernel report sending window in TCP_INFO (kernel commit - * 8f7baad7f035) - */ -bool snd_wnd_cap; +/* Size of data returned by TCP_INFO getsockopt() */ +socklen_t tcp_info_size; + +#define tcp_info_cap(f_) \ + ((offsetof(struct tcp_info_linux, tcpi_##f_) + \ + sizeof(((struct tcp_info_linux *)NULL)->tcpi_##f_)) <= tcp_info_size) + +/* Kernel reports sending window in TCP_INFO (kernel commit 8f7baad7f035) */ +#define snd_wnd_cap tcp_info_cap(snd_wnd) /* sendmsg() to socket */ static struct iovec tcp_iov [UIO_MAXIOV]; @@ -2571,11 +2576,11 @@ static bool tcp_probe_peek_offset_cap(sa_family_t af) } /** - * tcp_probe_snd_wnd_cap() - Check if TCP_INFO reports tcpi_snd_wnd + * tcp_probe_tcp_info() - Check what data TCP_INFO reports * - * Return: true if supported, false otherwise + * Return: Number of bytes returned by TCP_INFO getsockopt() */ -static bool tcp_probe_snd_wnd_cap(void) +static socklen_t tcp_probe_tcp_info(void) { struct tcp_info_linux tinfo; socklen_t sl = sizeof(tinfo); @@ -2595,11 +2600,7 @@ static bool tcp_probe_snd_wnd_cap(void) close(s); - if (sl < (offsetof(struct tcp_info_linux, tcpi_snd_wnd) + - sizeof(tinfo.tcpi_snd_wnd))) - return false; - - return true; + return sl; } /** @@ -2635,9 +2636,12 @@ int tcp_init(struct ctx *c) (!c->ifi6 || tcp_probe_peek_offset_cap(AF_INET6)); debug("SO_PEEK_OFF%ssupported", peek_offset_cap ? " " : " not "); - snd_wnd_cap = tcp_probe_snd_wnd_cap(); - debug("TCP_INFO tcpi_snd_wnd field%ssupported", - snd_wnd_cap ? " " : " not "); + tcp_info_size = tcp_probe_tcp_info(); + +#define dbg_tcpi(f_) debug("TCP_INFO tcpi_%s field%s supported", \ + STRINGIFY(f_), tcp_info_cap(f_) ? " " : " not ") + dbg_tcpi(snd_wnd); +#undef dbg_tcpi return 0; } -- 2.47.0