[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <17B26478-41C0-46BD-B47F-812DA12A3699@linux.alibaba.com>
Date: Thu, 18 May 2023 01:37:20 +0800
From: Cambda Zhu <cambda@...ux.alibaba.com>
To: Eric Dumazet <edumazet@...gle.com>
Cc: netdev@...r.kernel.org,
"David S. Miller" <davem@...emloft.net>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>,
Dust Li <dust.li@...ux.alibaba.com>,
Tony Lu <tonylu@...ux.alibaba.com>
Subject: Re: net: getsockopt(TCP_MAXSEG) on listen sock returns wrong MSS?
> On May 17, 2023, at 23:58, Eric Dumazet <edumazet@...gle.com> wrote:
>
> On Wed, May 17, 2023 at 1:09 PM Cambda Zhu <cambda@...ux.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.
>
I understand now. It seems setting/getting TCP_MAXSEG has different meaning. :)
>
>> 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;
This fix is a good solution for me. Will you send a patch later?
Thanks,
Cambda
Powered by blists - more mailing lists