From: Eric Dumazet <edumazet@google.com>
To: Cambda Zhu <cambda@linux.alibaba.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
Dust Li <dust.li@linux.alibaba.com>,
Tony Lu <tonylu@linux.alibaba.com>
Subject: Re: net: getsockopt(TCP_MAXSEG) on listen sock returns wrong MSS?
Date: Wed, 17 May 2023 17:58:25 +0200 [thread overview]
Message-ID: <CANn89i+3kL9pYtkxkwxwNMzvC_w3LNUum_2=3u+UyLBmGmifHA@mail.gmail.com> (raw)
In-Reply-To: <34BAAED6-5CD0-42D0-A9FB-82A01962A2D7@linux.alibaba.com>
On Wed, May 17, 2023 at 1:09 PM Cambda Zhu <cambda@linux.alibaba.com> wrote:
>
> I want to call setsockopt(TCP_MAXSEG) on a listen sock to let
> all child socks have smaller MSS. And I found the child sock
> MSS changed but getsockopt(TCP_MAXSEG) on the listen sock
> returns 536 always.
>
I think TCP_MAXSEG is not like a traditional option you can set and get later,
expecting to read back the value you set.
It is probably a bug.
Getting tp->mss_cache should have been a separate socket option, but
it is too late.
> It seems the tp->mss_cache is initialized with TCP_MSS_DEFAULT,
> but getsockopt(TCP_MAXSEG) returns tp->rx_opt.user_mss only when
> tp->mss_cache is 0. I don't understand the purpose of the mss_cache
> check of TCP_MAXSEG. If getsockopt(TCP_MAXSEG) on listen sock makes
> no sense, why does it have a branch for close/listen sock to return
> user_mss? If getsockopt(TCP_MAXSEG) on listen sock is ok, why does
> it check mss_cache for a listen sock?
>
> I tried to find the commit log about TCP_MAXSEG, and found that
> in commit 0c409e85f0ac ("Import 2.3.41pre2"), the mss_cache check
> was added. No more detailed information found. Is this a bug or am
> I misunderstanding something?
I wonder if we should simply do:
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 4d6392c16b7a5a9a853c27e3a4b258d000738304..cb526257a06a6c7a4e65e710fff1770bd382ed2d
100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -4080,9 +4080,10 @@ int do_tcp_getsockopt(struct sock *sk, int level,
switch (optname) {
case TCP_MAXSEG:
- val = tp->mss_cache;
- if (!val && ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
+ if (((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
val = tp->rx_opt.user_mss;
+ else
+ val = tp->mss_cache;
if (tp->repair)
val = tp->rx_opt.mss_clamp;
break;
next prev parent reply other threads:[~2023-05-17 15:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-17 11:08 net: getsockopt(TCP_MAXSEG) on listen sock returns wrong MSS? Cambda Zhu
2023-05-17 15:58 ` Eric Dumazet [this message]
2023-05-17 17:37 ` Cambda Zhu
2023-05-19 8:01 ` [PATCH net-next] net: Return user_mss for TCP_MAXSEG in CLOSE/LISTEN state Cambda Zhu
2023-05-23 10:28 ` Paolo Abeni
2023-05-23 11:52 ` Eric Dumazet
2023-05-24 7:10 ` Cambda Zhu
2023-05-24 9:30 ` Jason Xing
2023-05-23 13:45 ` Paolo Abeni
2023-05-24 1:04 ` Cambda Zhu
2023-05-24 2:11 ` Jason Xing
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='CANn89i+3kL9pYtkxkwxwNMzvC_w3LNUum_2=3u+UyLBmGmifHA@mail.gmail.com' \
--to=edumazet@google.com \
--cc=cambda@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=dust.li@linux.alibaba.com \
--cc=netdev@vger.kernel.org \
--cc=tonylu@linux.alibaba.com \
--cc=xuanzhuo@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).