tcp: add tcp_sock_set_maxseg

Add a helper tcp_sock_set_maxseg() to directly set the TCP_MAXSEG
sockopt from kernel space.

This new helper will be used in the following patch from MPTCP.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Acked-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20250719-net-next-mptcp-tcp_maxseg-v2-2-8c910fbc5307@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
pull/1309/head
Geliang Tang 2025-07-19 00:06:57 +02:00 committed by Jakub Kicinski
parent edd669057c
commit 51a62199a8
2 changed files with 15 additions and 9 deletions

View File

@ -621,6 +621,7 @@ void tcp_sock_set_nodelay(struct sock *sk);
void tcp_sock_set_quickack(struct sock *sk, int val); void tcp_sock_set_quickack(struct sock *sk, int val);
int tcp_sock_set_syncnt(struct sock *sk, int val); int tcp_sock_set_syncnt(struct sock *sk, int val);
int tcp_sock_set_user_timeout(struct sock *sk, int val); int tcp_sock_set_user_timeout(struct sock *sk, int val);
int tcp_sock_set_maxseg(struct sock *sk, int val);
static inline bool dst_tcp_usec_ts(const struct dst_entry *dst) static inline bool dst_tcp_usec_ts(const struct dst_entry *dst)
{ {

View File

@ -3751,6 +3751,19 @@ int tcp_set_window_clamp(struct sock *sk, int val)
return 0; return 0;
} }
int tcp_sock_set_maxseg(struct sock *sk, int val)
{
/* Values greater than interface MTU won't take effect. However
* at the point when this call is done we typically don't yet
* know which interface is going to be used
*/
if (val && (val < TCP_MIN_MSS || val > MAX_TCP_WINDOW))
return -EINVAL;
tcp_sk(sk)->rx_opt.user_mss = val;
return 0;
}
/* /*
* Socket option code for TCP. * Socket option code for TCP.
*/ */
@ -3883,15 +3896,7 @@ int do_tcp_setsockopt(struct sock *sk, int level, int optname,
switch (optname) { switch (optname) {
case TCP_MAXSEG: case TCP_MAXSEG:
/* Values greater than interface MTU won't take effect. However err = tcp_sock_set_maxseg(sk, val);
* at the point when this call is done we typically don't yet
* know which interface is going to be used
*/
if (val && (val < TCP_MIN_MSS || val > MAX_TCP_WINDOW)) {
err = -EINVAL;
break;
}
tp->rx_opt.user_mss = val;
break; break;
case TCP_NODELAY: case TCP_NODELAY: