Skip to contentSkip to conversation

tcp: Return user_mss for TCP_MAXSEG in CLOSE/LISTEN state if user_mss set

PATCH Superseded Cambda Zhu 3 participants 4 messages May 24, 2023 – May 27, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Cambda Zhu

author
#0 lore raw

PATCH v2 1/1 tcp: Return user_mss for TCP_MAXSEG in CLOSE/LISTEN state if user_mss set

This patch replaces the tp->mss_cache check in getting TCP_MAXSEG with tp->rx_opt.user_mss check for CLOSE/LISTEN sock. Since tp->mss_cache is initialized with TCP_MSS_DEFAULT, checking if it's zero is probably a bug.

With this change, getting TCP_MAXSEG before connecting will return default MSS normally, and return user_mss if user_mss is set.

---
v2:
- Update Fixes tag with commit in current tree.
- Add Jason's Reviewed-by tag.

v1:
- Return default MSS if user_mss not set for backwards compatibility.
- Send patch to net instead of net-next, with Fixes tag.
- Add Eric's tags.

---
 net/ipv4/tcp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/tcp.c +2 -1
index 4d6392c16b7a..3e01a58724b8 100644
@@ -4081,7 +4081,8 @@ 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 (tp->rx_opt.user_mss &&
+		    ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
 			val = tp->rx_opt.user_mss;
 		if (tp->repair)
 			val = tp->rx_opt.mss_clamp;
Signature · 1 line
2.16.6
#1 lore raw
Quoted 44 lines · Cambda Zhu

This patch replaces the tp->mss_cache check in getting TCP_MAXSEG with tp->rx_opt.user_mss check for CLOSE/LISTEN sock. Since tp->mss_cache is initialized with TCP_MSS_DEFAULT, checking if it's zero is probably a bug.

With this change, getting TCP_MAXSEG before connecting will return default MSS normally, and return user_mss if user_mss is set.

---
v2:
- Update Fixes tag with commit in current tree.
- Add Jason's Reviewed-by tag.

v1:
- Return default MSS if user_mss not set for backwards compatibility.
- Send patch to net instead of net-next, with Fixes tag.
- Add Eric's tags.

---
 net/ipv4/tcp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/tcp.c +2 -2
index 4d6392c16b7a..3e01a58724b8 100644
@@ -4081,7 +4081,8 @@ 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 (tp->rx_opt.user_mss &&
+                   ((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
                        val = tp->rx_opt.user_mss;
                if (tp->repair)
                        val = tp->rx_opt.mss_clamp;
--
Quoted 2 lines

2.16.6

Ah, I just realised that you didn't CC other maintainers though reading the patchwork. Please run this command [1] before you submit a patch next time.

[1]: $./scripts/get_maintainer.pl net/ipv4/tcp.c

+CC kuba, davem, dsahern

Thanks,
Jason

maintainer
#2 lore raw
In reply to Cambda Zhu
Quoted 7 lines · On Wed, 24 May 2023 21:13:31 +0800 Cambda Zhu wrote:

This patch replaces the tp->mss_cache check in getting TCP_MAXSEG with tp->rx_opt.user_mss check for CLOSE/LISTEN sock. Since tp->mss_cache is initialized with TCP_MSS_DEFAULT, checking if it's zero is probably a bug.

With this change, getting TCP_MAXSEG before connecting will return default MSS normally, and return user_mss if user_mss is set.

Hi, your patch was marked as "Changes requested" by DaveM (I think). Presumably because of the missing CCs. Would you mind resending one more time with the fuller CC list?

author
#3 lore raw
Quoted 9 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 24 May 2023 21:13:31 +0800 Cambda Zhu wrote:

This patch replaces the tp->mss_cache check in getting TCP_MAXSEG with tp->rx_opt.user_mss check for CLOSE/LISTEN sock. Since tp->mss_cache is initialized with TCP_MSS_DEFAULT, checking if it's zero is probably a bug.

Quoted 6 lines
Quoted 2 lines

With this change, getting TCP_MAXSEG before connecting will return default MSS normally, and return user_mss if user_mss is set.

Hi, your patch was marked as "Changes requested" by DaveM (I think). Presumably because of the missing CCs. Would you mind resending one more time with the fuller CC list?

I have resubmitted the patch and hope I got everything right this time :)

Thanks!

Cambda