From: Shashank Mohan Jain <jain.sm@gmail.com>
To: Eric Dumazet <edumazet@kernel.org>,
Neal Cardwell <ncardwell@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
"David S. Miller" <davem@davemloft.net>
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net] tcp: keep the route window metric when SO_RCVBUF is set before connect
Date: Sun, 11 Oct 2026 10:50:06 +0530 [thread overview]
Message-ID: <20261011052006.60585-1-jain.sm@gmail.com> (raw)
Since commit b025461303d8 ("tcp: update window_clamp when SO_RCVBUF is
set") SO_RCVBUF sets tp->window_clamp from the new buffer size in every
socket state. For a socket without a connection this has a side
effect. tcp_connect_init() and tcp_openreq_init_rwin() use the window
metric of the route (RTAX_WINDOW, "ip route ... window N") only if
window_clamp is zero. The clamp left behind by SO_RCVBUF makes the
metric ineffective for that socket, or for the connections accepted
on a listener.
Example: two network namespaces connected by a veth pair, "window
4096" on the route to the peer on both sides, SO_RCVBUF set to 1 MiB
before connect():
v7.3-rc6: SYN win 65535, wscale 5
TCP_WINDOW_CLAMP 1047128
with that commit reverted: SYN win 2920, no window scaling
TCP_WINDOW_CLAMP 4096
With SO_RCVBUF set on the listener the SYN-ACK and the clamp of the
accepted socket differ in the same way.
The update is not needed in these states. When the connection is set
up with SOCK_RCVBUF_LOCK set, both functions limit a zero or too
large clamp to tcp_full_space(), which is the value tcp_set_rcvbuf()
computes. Skip the update for sockets in TCP_CLOSE and TCP_LISTEN.
Tested in qemu with the setup above. With the route metric, the SYN
and SYN-ACK windows and TCP_WINDOW_CLAMP are the same as with the
commit above reverted. Without the metric they are the same as before
this change, with and without SO_RCVBUF on either side.
Fixes: b025461303d8 ("tcp: update window_clamp when SO_RCVBUF is set")
Assisted-by: LLM
Signed-off-by: Shashank Mohan Jain <jain.sm@gmail.com>
---
Prepared with Claude Code (Anthropic), model Claude Opus 5.5
(claude-opus-5-5).
net/ipv4/tcp.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 87ef6d5cbf..9b6f214411 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1856,6 +1856,14 @@ int tcp_set_rcvlowat(struct sock *sk, int val)
void tcp_set_rcvbuf(struct sock *sk, int val)
{
+ /* Without a connection there is no clamp to update: it is chosen
+ * from the route's window metric and the buffer size when the
+ * connection is set up, see tcp_connect_init() and
+ * tcp_openreq_init_rwin().
+ */
+ if ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN))
+ return;
+
tcp_set_window_clamp(sk, tcp_win_from_space(sk, val));
}
base-commit: a5ebb76233b79db01e82e061173cb73c6d2b5c6b
--
2.43.0
next reply other threads:[~2026-10-11 5:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-11 5:20 Shashank Mohan Jain [this message]
2026-10-11 5:24 ` netdev-bot+sinfo
2026-10-11 5:26 ` shashank Jain
2026-10-11 8:15 ` Eric Dumazet
2026-10-12 4:58 ` Shashank Mohan Jain
2026-10-12 5:33 ` netdev-bot+sashiko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261011052006.60585-1-jain.sm@gmail.com \
--to=jain.sm@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®