Article View: linux.kernel.netdev
Article #2337[PATCH net-next v3 2/2] selftests/net/packetdrill: cover SO_RCVBUF vs the route window clamp
From: Shashank Mohan Jain
Date: Mon, 12 Oct 2026 13:26
Date: Mon, 12 Oct 2026 13:26
128 lines
14339 bytes
14339 bytes
Add packetdrill tests for the interaction between SO_RCVBUF, a user
TCP_WINDOW_CLAMP and the route "window" metric (RTAX_WINDOW) on the SYN:
- tcp_rcvbuf_before_connect_window.pkt: SO_RCVBUF set before connect()
must not defeat the route metric; the SYN must advertise the
route-clamped window and window scale 0.
- tcp_window_clamp_vs_rcvbuf.pkt: a clamp set with TCP_WINDOW_CLAMP must
be honoured on the SYN and not be overwritten by a later SO_RCVBUF on
the still unconnected socket.
- tcp_fastopen_connect_rcvbuf_window.pkt: with TCP_FASTOPEN_CONNECT the
SYN is deferred to the first write() while the socket sits in
TCP_SYN_SENT; SO_RCVBUF applied in that gap must not defeat the route
metric on the deferred SYN either.
Without the first patch of this series the SYN carried win 65535,
wscale 5 in the first and third cases (the route metric was skipped) and
the SO_RCVBUF-derived window in the second (the user clamp was lost).
The tests are picked up automatically by the packetdrill selftest
Makefile (TEST_PROGS := $(wildcard *.pkt)).
Assisted-by: LLM
Signed-off-by: Shashank Mohan Jain <jain.sm@gmail.com>
---
.../tcp_fastopen_connect_rcvbuf_window.pkt | 22 +++++++++++++++
.../tcp_rcvbuf_before_connect_window.pkt | 27 +++++++++++++++++++
.../tcp_window_clamp_vs_rcvbuf.pkt | 24 +++++++++++++++++
3 files changed, 73 insertions(+)
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_fastopen_connect_rcvbuf_window.pkt
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_rcvbuf_before_connect_window.pkt
create mode 100644 tools/testing/selftests/net/packetdrill/tcp_window_clamp_vs_rcvbuf.pkt
diff --git a/tools/testing/selftests/net/packetdrill/tcp_fastopen_connect_rcvbuf_window.pkt b/tools/testing/selftests/net/packetdrill/tcp_fastopen_connect_rcvbuf_window.pkt
new file mode 100644
index 000000000..7892ac566
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_fastopen_connect_rcvbuf_window.pkt
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0
+// TCP_FASTOPEN_CONNECT defers the SYN until the first write(); between
+// connect() and that write the socket is in TCP_SYN_SENT. SO_RCVBUF applied
+// in that gap must not defeat the route "window" metric on the deferred SYN.
+// optname 30 = TCP_FASTOPEN_CONNECT, 34 = TCP_FASTOPEN_NO_COOKIE on SOL_TCP.
+--ip_version=ipv4
+
+`./defaults.sh
+sysctl -q net.ipv4.tcp_fastopen=5
+ip route replace 192.0.2.1 via 192.168.0.1 dev tun0 window 4096`
+
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_TCP, 30, [1], 4) = 0
+ +0 setsockopt(3, SOL_TCP, 34, [1], 4) = 0
+ +0 connect(3, ..., ...) = 0
+ +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
+ +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
+ +0 write(3, ..., 1) = 1
+
+// The deferred SYN (carrying 1 byte of data) must advertise the route
+// clamped window and window scale 0 (not win 65535, wscale 5).
+ +0 > S 0:1(1) win 2920 <mss 1460,sackOK,TS val 0 ecr 0,nop,wscale 0>
diff --git a/tools/testing/selftests/net/packetdrill/tcp_rcvbuf_before_connect_window.pkt b/tools/testing/selftests/net/packetdrill/tcp_rcvbuf_before_connect_window.pkt
new file mode 100644
index 000000000..7ec7f14d8
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_rcvbuf_before_connect_window.pkt
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0
+// Setting SO_RCVBUF before connect() must not defeat the route "window"
+// metric on the SYN.
+//
+// The route to the peer carries "window 4096" (RTAX_WINDOW). With SO_RCVBUF
+// also set before connect(), the SYN the kernel sends must still advertise
+// the small, route-clamped receive window and a window scale of 0 (the
+// window scale option is sent, with a shift of 0).
+//
+// Since commit b025461303d8 ("tcp: update window_clamp when SO_RCVBUF is
+// set"), setsockopt(SO_RCVBUF) wrote tp->window_clamp while the socket was
+// still in TCP_CLOSE. tcp_connect_init() then treated that as a user clamp
+// and skipped RTAX_WINDOW, so the SYN carried win 65535, wscale 5 instead.
+--ip_version=ipv4
+
+`./defaults.sh
+ip route replace 192.0.2.1 via 192.168.0.1 dev tun0 window 4096`
+
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
+ +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
+ +0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress)
+
+// The SYN must advertise the route-clamped window and window scale 0.
+ +0 > S 0:0(0) win 2920 <mss 1460,sackOK,TS val 0 ecr 0,nop,wscale 0>
+ +.1 < S. 0:0(0) ack 1 win 65535 <mss 1460,nop,wscale 7>
+ +0 > . 1:1(0) ack 1
diff --git a/tools/testing/selftests/net/packetdrill/tcp_window_clamp_vs_rcvbuf.pkt b/tools/testing/selftests/net/packetdrill/tcp_window_clamp_vs_rcvbuf.pkt
new file mode 100644
index 000000000..3d73178df
--- /dev/null
+++ b/tools/testing/selftests/net/packetdrill/tcp_window_clamp_vs_rcvbuf.pkt
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+// A window clamp the user set with setsockopt(TCP_WINDOW_CLAMP) must be
+// honoured on the SYN even when SO_RCVBUF is set afterwards on the still
+// unconnected socket: SO_RCVBUF must not overwrite the user's clamp, and
+// the route "window" metric must not replace it either.
+//
+// TCP_WINDOW_CLAMP is optname 10 on SOL_TCP (this packetdrill build has no
+// symbol for it).
+--ip_version=ipv4
+
+`./defaults.sh
+ip route replace 192.0.2.1 via 192.168.0.1 dev tun0 window 4096`
+
+ 0 socket(..., SOCK_STREAM, IPPROTO_TCP) = 3
+ +0 setsockopt(3, SOL_TCP, 10, [16384], 4) = 0
+ +0 setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
+ +0 fcntl(3, F_SETFL, O_RDWR|O_NONBLOCK) = 0
+ +0 connect(3, ..., ...) = -1 EINPROGRESS (Operation now in progress)
+
+// The SYN advertises the user's clamp (win 16060), not the route window
+// (2920) and not the SO_RCVBUF-derived full window.
+ +0 > S 0:0(0) win 16060 <mss 1460,sackOK,TS val 0 ecr 0,nop,wscale 0>
+ +.1 < S. 0:0(0) ack 1 win 65535 <mss 1460,nop,wscale 7>
+ +0 > . 1:1(0) ack 1
--
2.43.0
Technical Details
Message-ID:
<20261012132622.48550-3-jain.sm@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344994-linux-kernel-netdev=dewy.ruReferences:
<20261012132622.48550-1-jain.sm@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344994-linux-kernel-netdev=dewy.ru
From: jain.sm@gmail.com (Shashank Mohan Jain)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v3 2/2] selftests/net/packetdrill: cover SO_RCVBUF vs the route window clamp
Date: Mon, 12 Oct 2026 18:56:22 +0530
Organization: Usenet Network
Message-ID: <20261012132622.48550-3-jain.sm@gmail.com>
References: <20261012132622.48550-1-jain.sm@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1787738"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Phhrj+/J2t2hLgGXgKMDcDccKWY= sha256:7ibXmtF7mKqqxBatekEVuqtLnAOG5OuPSBSmWf4w2VY=
sha1:M9oibP0/E+fLG1fMcji86LteP2w= sha256:hxbZTprqGktdrTyRPj1QGAVMhFew8rDQu0ve6Cgb5wc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 7E85510FBEC; Mon, 12 Oct 2026 16:44:57 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.848
X-Spam-Status: No, score=-0.848 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001]
autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id HWo8z0PlQA9G;
Mon, 12 Oct 2026 16:44:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-344994-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
by mail.dewy.ru (Postfix) with ESMTPS id 217F210FBD9; Mon, 12 Oct 2026 16:44:43 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
by sto.lore.kernel.org (Postfix) with ESMTP id AB86F60F433; Mon, 12 Oct 2026 13:28:14 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 6CAF33769F8;
Mon, 12 Oct 2026 13:26:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UX4zaLK4"
X-Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182])
(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCB67367B8E
for <netdev@vger.kernel.org>; Mon, 12 Oct 2026 13:26:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.182
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1791811598; cv=none; b=LA2gUc3HZeR5LYxPMz0X05GuBDQWoSY8/HkMXsN/3J28eYAkarFPU3PTd1C0eRFKuCYmprz5vhdfCu5euaSpajbA19IQwh8HkUrYDkkq23iD//eWw7PiOFQJbUm8aFeBQUZlWdoYfiYs+6HzsYMNGNcMWt5UQOnTETOgbj6pG6c=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1791811598; c=relaxed/simple;
bh=tEhgdvR5dXlZ2sBWgNodEMf5jbc63XxHqDMT5EOAe0w=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
MIME-Version; b=d3QGkNURlavLAVB/erkQcvBJQosPl/GmRNsKieCb8E1PNu1vy5QcXd0CE5WSt8N0Hgvsyfr2Rhv4G5kZg5aVDA87e+P/z86905CsLGwDSPPSD5kOA6TdwgLzp8wh1eFswqlJVJ5yfHkqg2c63rYSxi0yxsDlHsYpl3RcaoRWfUY=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UX4zaLK4; arc=none smtp.client-ip=74.125.82.182
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy1-f182.google.com with SMTP id 5a478bee46e88-35a31bb9fb6so2928040eec.1
for <netdev@vger.kernel.org>; Mon, 12 Oct 2026 06:26:36 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1791811596; x=1792416396; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=LlpHzIuYQd2oZxIU0NKyhphISYrEiSsYul67utJZnW0=;
b=UX4zaLK4L5HSbe3GFKB458RNoIuwZrn1Qlf+28Gb+HYNHhVnDiRTqwhHGYdU7qnmoT
PcL26k05Bh4Joh+cB7RgaWU7EtprABjHjUhZgFkRRoxJxDEttfRErWc4vjORckCA4kAy
bpd+4WgjEZc1s1wQDKW4vmrjO9OV4a8W+Uf7AYcknZIH6lYZVSL3I3iaIyJwFHwNqKKX
dqAQFA1zNadP0PUKUd4wnsePKqJeKkbyLtgfwmzYj4epwEBq8zaZgv6NZF9ycF9u2vWo
3PnZoHvB3ID1f5Cwm4oO41AYviQ5OFVaau2JgW/R4GeYky749DdDWlMB/HUBJtehNarJ
IYKw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1791811596; x=1792416396;
h=content-transfer-encoding:mime-version:references:in-reply-to
:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from
:to:cc:subject:date:message-id:reply-to:content-type;
bh=LlpHzIuYQd2oZxIU0NKyhphISYrEiSsYul67utJZnW0=;
b=bsgfqnF9zhl2/dCWy6SN2VQiP6qQxg4EBHy1fQ1bWxVmI73hx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ShpXmpg5yvbslUOsN5pdAcgpPqu9WT/TtkvR4JRuVk0
0j0cd2ax6OBu1Rd+naF2ij13fA1ZhN+VbKoIh8VIQhIRaSQxt3GYj2KWV5TVsmebFf9xXCmDQks
z9B0c+qpvuSYNoT12RRS9QrxvZ5Kdb/bFmmPfKzIf1epSDulL1qEvF6hYsvEsxBwW
X-Received: by 2002:a05:7300:fa15:b0:35b:9851:a896 with SMTP id 5a478bee46e88-35b9851ab64mr1197254eec.10.1791811595645;
Mon, 12 Oct 2026 06:26:35 -0700 (PDT)
X-Received: from FT6N242TWK ([223.181.117.66])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3537ca1b53dsm31467174eec.6.2026.10.12.06.26.32
(version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);
Mon, 12 Oct 2026 06:26:35 -0700 (PDT)
X-Cc: Kuniyuki Iwashima <kuniyu@google.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
X-Mailer: git-send-email 2.54.0
X-In-Reply-To: <20261012132622.48550-1-jain.sm@gmail.com>
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>