Add TCP_MAXSEG socket option support
Subsystems (3)
Geliang Tang
reviewercover Add TCP_MAXSEG socket option support
From: Geliang Tang <[email protected]>
Geliang Tang (2):
mptcp: add TCP_MAXSEG sockopt support
selftests: mptcp: sockopt: add TCP_MAXSEG sockopt tests
net/mptcp/sockopt.c | 29 +++++++++++++++++++ .../selftests/net/mptcp/mptcp_sockopt.c | 22 ++++++++++++++ 2 files changed, 51 insertions(+)
Signature · 1 line
2.43.0
Geliang Tang
reviewerPATCH 1/2 mptcp: add TCP_MAXSEG sockopt support
From: Geliang Tang <[email protected]>
The TCP_MAXSEG socket option is currently not supported by MPTCP, mainly because it has never been requested before. But there are still valid use-cases, e.g. with HAProxy.
This patch adds its support in MPTCP by propagating the value to all subflows.
--- net/mptcp/sockopt.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
net/mptcp/sockopt.c +29 -0
@@ -798,6 +798,24 @@ static int mptcp_setsockopt_first_sf_only(struct mptcp_sock *msk, int level, intreturn ret; } +static int mptcp_setsockopt_sol_tcp_maxseg (struct mptcp_sock *msk, +sockptr_t optval, +unsigned int optlen) +{ +struct mptcp_subflow_context *subflow; + +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk =mptcp_subflow_tcp_sock (subflow); +int ret; + + ret =tcp_setsockopt (ssk,SOL_TCP ,TCP_MAXSEG , optval, optlen); +if (ret) +return ret; + } + +return 0 ; +} +static int mptcp_setsockopt_sol_tcp (struct mptcp_sock *msk,int optname,sockptr_t optval,unsigned int optlen) {
@@ -819,6 +837,8 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,case TCP_FASTOPEN_NO_COOKIE :return mptcp_setsockopt_first_sf_only (msk,SOL_TCP , optname, optval, optlen); +case TCP_MAXSEG : +return mptcp_setsockopt_sol_tcp_maxseg (msk, optval, optlen); } ret =mptcp_get_int_option (msk, optval, optlen, &val);
@@ -1368,6 +1388,13 @@ static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval,return 0 ; } +static int mptcp_getsockopt_sol_tcp_maxseg (struct mptcp_sock *msk, +char __user *optval, +int __user *optlen) +{ +return tcp_getsockopt (msk->first,SOL_TCP ,TCP_MAXSEG , optval, optlen); +} +static int mptcp_getsockopt_sol_tcp (struct mptcp_sock *msk,int optname,char __user *optval,int __user *optlen) {
@@ -1407,6 +1434,8 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,return mptcp_put_int_option (msk, optval, optlen, msk->notsent_lowat);case TCP_IS_MPTCP :return mptcp_put_int_option (msk, optval, optlen,1 ); +case TCP_MAXSEG : +return mptcp_getsockopt_sol_tcp_maxseg (msk, optval, optlen); }return -EOPNOTSUPP ; }
Signature · 1 line
2.43.0
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v1 1/2] mptcp: add TCP_MAXSEG sockopt support
Hi Geliang,
Quoted 8 lines · Geliang Tang
From: Geliang Tang <[email protected]>
The
TCP_MAXSEGsocket option is currently not supported by MPTCP, mainly because it has never been requested before. But there are still valid use-cases, e.g. with HAProxy.This patch adds its support in MPTCP by propagating the value to all subflows.
Thank you for looking at that.
Quoted 11 lines
Signed-off-by Geliang Tang <[email protected]>--- net/mptcp/sockopt.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)net/mptcp/sockopt.c +0
-0
net/mptcp/sockopt.c static int mptcp_setsockopt_first_sf_only(struct mptcp_sock *msk, int level, int · line 803
Quoted 6 lines
net/mptcp/sockopt.c +3
-0@@ -798,6 +798,24 @@ static int mptcp_setsockopt_first_sf_only(struct mptcp_sock *msk, int level, intreturn ret; } +static int mptcp_setsockopt_sol_tcp_maxseg (struct mptcp_sock *msk, +sockptr_t optval, +unsigned int optlen)
Might be good to have a generic helper, similar to mptcp_setsockopt_first_sf_only(), no?
mptcp_setsockopt_all_subflows()
net/mptcp/sockopt.c static int mptcp_setsockopt_first_sf_only(struct mptcp_sock *msk, int level, int · line 807
Quoted 4 lines
net/mptcp/sockopt.c +4
-0+{ +struct mptcp_subflow_context *subflow; + +mptcp_for_each_subflow (msk, subflow) {
If there is no subflows (listening sockets?), you might need to call mptcp_setsockopt_first_sf_only(), no?
net/mptcp/sockopt.c static int mptcp_setsockopt_first_sf_only(struct mptcp_sock *msk, int level, int · line 811
Quoted 4 lines
net/mptcp/sockopt.c +4
-0+struct sock *ssk =mptcp_subflow_tcp_sock (subflow); +int ret; + + ret =tcp_setsockopt (ssk,SOL_TCP ,TCP_MAXSEG , optval, optlen);
No need to lock around this call?
Quoted 20 lines
net/mptcp/sockopt.c +9
-0+if (ret) +return ret; + } + +return 0 ; +} +static int mptcp_setsockopt_sol_tcp (struct mptcp_sock *msk,int optname,sockptr_t optval,unsigned int optlen) {@@ -819,6 +837,8 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,case TCP_FASTOPEN_NO_COOKIE :return mptcp_setsockopt_first_sf_only (msk,SOL_TCP , optname, optval, optlen); +case TCP_MAXSEG : +return mptcp_setsockopt_sol_tcp_maxseg (msk, optval, optlen); } ret =mptcp_get_int_option (msk, optval, optlen, &val);
net/mptcp/sockopt.c static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval, · line 1395
Quoted 8 lines
net/mptcp/sockopt.c +5
-0@@ -1368,6 +1388,13 @@ static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval,return 0 ; } +static int mptcp_getsockopt_sol_tcp_maxseg (struct mptcp_sock *msk, +char __user *optval, +int __user *optlen) +{ +return tcp_getsockopt (msk->first,SOL_TCP ,TCP_MAXSEG , optval, optlen);
Same here: no need to lock? Also, msk->first can be NULL for listening sockets, no?
Anyway, I think it is best not to change the way the socket options are handled today: the socket option is propagated to existing and future subflows. Look how "msk->keepalive_intvl" is handled in sockopt.c for example.
- setsockopt: store the value (in case of success) in the msk.
- getsockopt: return this value (mptcp_put_int_option())
WDYT?
Quoted 6 lines
net/mptcp/sockopt.c +2
-0+} +static int mptcp_getsockopt_sol_tcp (struct mptcp_sock *msk,int optname,char __user *optval,int __user *optlen) {
net/mptcp/sockopt.c static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 1441
Quoted 8 lines
net/mptcp/sockopt.c +2
-0@@ -1407,6 +1434,8 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,return mptcp_put_int_option (msk, optval, optlen, msk->notsent_lowat);case TCP_IS_MPTCP :return mptcp_put_int_option (msk, optval, optlen,1 ); +case TCP_MAXSEG : +return mptcp_getsockopt_sol_tcp_maxseg (msk, optval, optlen); }return -EOPNOTSUPP ; }
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerPATCH 2/2 selftests: mptcp: sockopt: add TCP_MAXSEG sockopt tests
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
This patch adds the TCP_MAXSEG sockopt tests in mptcp_sockopt.c. Since in getsockopt TCP_MAXSEG, the "user_mss" value can be obtained only in the LISTEN state (see do_tcp_getsockopt in net/ipv4/tcp.c), the test items are added to server() instead of client().
--- .../selftests/net/mptcp/mptcp_sockopt.c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +22 -0
@@ -689,6 +689,26 @@ static int xaccept(int s)return fd; } +static void test_tcp_maxseg_sockopt (int fd) +{ +int maxseg =1000 ; +socklen_t s; +int r; + + s =sizeof (maxseg); + r =setsockopt (fd,IPPROTO_TCP ,TCP_MAXSEG , &maxseg, s); +if (r !=0 ) +die_perror ("setsockopt TCP_MAXSEG" ); + + maxseg =0 ; + r =getsockopt (fd,IPPROTO_TCP ,TCP_MAXSEG , &maxseg, &s); +if (r !=-1 && errno !=EINVAL ) +die_perror ("getsockopt TCP_MAXSEG did not indicate -EINVAL" ); + +if (maxseg !=1000 ) +xerror ("maxseg=%d" , maxseg); +} +static int server (int pipefd) {int fd =-1 , r;
@@ -713,6 +733,8 @@ static int server(int pipefd)process_one_client (r, pipefd); +test_tcp_maxseg_sockopt (fd); +return 0 ; }
Signature · 1 line
2.43.0
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v1 2/2] selftests: mptcp: sockopt: add TCP_MAXSEG sockopt tests
Hi Geliang,
Quoted 6 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch adds the
TCP_MAXSEGsockopt tests inmptcp_sockopt.c. Since in getsockoptTCP_MAXSEG, the "user_mss" value can be obtained only in the LISTEN state (seedo_tcp_getsockoptinnet/ipv4/tcp.c), the test items are added toserver()instead ofclient().
I think it is better to use packetdrill to do such validation, similar to what was done with other socket options. No?
Quoted 22 lines
Signed-off-by Geliang Tang <[email protected]>--- .../selftests/net/mptcp/mptcp_sockopt.c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+)tools/testing/selftests/net/mptcp/mptcp_sockopt.c +9
-0@@ -689,6 +689,26 @@ static int xaccept(int s)return fd; } +static void test_tcp_maxseg_sockopt (int fd) +{ +int maxseg =1000 ; +socklen_t s; +int r; + + s =sizeof (maxseg); + r =setsockopt (fd,IPPROTO_TCP ,TCP_MAXSEG , &maxseg, s); +if (r !=0 )
tools/testing/selftests/net/mptcp/mptcp_sockopt.c static int xaccept(int s) · line 710
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +10
-0+die_perror ("setsockopt TCP_MAXSEG" ); + + maxseg =0 ; + r =getsockopt (fd,IPPROTO_TCP ,TCP_MAXSEG , &maxseg, &s); +if (r !=-1 && errno !=EINVAL ) +die_perror ("getsockopt TCP_MAXSEG did not indicate -EINVAL" ); + +if (maxseg !=1000 ) +xerror ("maxseg=%d" , maxseg); +}
Here, you set and get the value, but you don't really check the behaviour is the one we expect.
It is important to check the behaviour. It would be easier to do that with packetdrill I think.
tools/testing/selftests/net/mptcp/mptcp_sockopt.c static int server(int pipefd) · line 740
Quoted 13 lines
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +3
-0+static int server (int pipefd) {int fd =-1 , r;@@ -713,6 +733,8 @@ static int server(int pipefd)process_one_client (r, pipefd); +test_tcp_maxseg_sockopt (fd); +return 0 ; }
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Geliang Tang
reviewerRe: [PATCH mptcp-next v1 2/2] selftests: mptcp: sockopt: add TCP_MAXSEG sockopt tests
Hi Matt,
Thanks for the review.
Quoted 56 lines
Hi Geliang,
Quoted 9 lines · Geliang Tang
From: Geliang Tang <[email protected]>
This patch adds the
TCP_MAXSEGsockopt tests inmptcp_sockopt.c. Since
in getsockoptTCP_MAXSEG, the "user_mss" value can be obtained only in
the LISTEN state (seedo_tcp_getsockoptinnet/ipv4/tcp.c), the test
items are added toserver()instead ofclient().I think it is better to use packetdrill to do such validation, similar
to what was done with other socket options. No?Quoted 25 lines
Signed-off-by Geliang Tang <[email protected]>---
.../selftests/net/mptcp/mptcp_sockopt.c | 22
+++++++++++++++++++1 file changed, 22 insertions(+)tools/testing/selftests/net/mptcp/mptcp_sockopt.c +0
-0@@ -689,6 +689,26 @@ static int xaccept(int s) return fd; }tools/testing/selftests/net/mptcp/mptcp_sockopt.c +10
-0+static void test_tcp_maxseg_sockopt (int fd) +{ +int maxseg =1000 ; +socklen_t s; +int r; + + s =sizeof (maxseg); + r =setsockopt (fd,IPPROTO_TCP ,TCP_MAXSEG , &maxseg, s); +if (r !=0 ) +die_perror ("setsockopt TCP_MAXSEG" );tools/testing/selftests/net/mptcp/mptcp_sockopt.c static int xaccept(int s) · line 710
Quoted 10 lines
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +9
-1+ + maxseg =0 ; + r =getsockopt (fd,IPPROTO_TCP ,TCP_MAXSEG , &maxseg, &s); +if (r !=-1 && errno !=EINVAL ) + die_perror("getsockopt TCP_MAXSEG did not indicate -EINVAL"); + + if (maxseg != 1000) + xerror("maxseg=%d", maxseg); +}Here, you set and get the value, but you don't really check the behaviour is the one we expect.
Quoted 2 lines
It is important to check the behaviour. It would be easier to do that with packetdrill I think.
I totally agree, but I want to verify the set and get values in this set first, I will add packetdrill tests for it later (once I learn how to modify packetdrill).
Thanks,
-Geliang
Quoted 17 lines
Quoted 11 lines
+
static int server(int pipefd)
{
int fd = -1, r;tools/testing/selftests/net/mptcp/mptcp_sockopt.c +0
-0@@ -713,6 +733,8 @@ static int server(int pipefd)
process_one_client(r, pipefd);tools/testing/selftests/net/mptcp/mptcp_sockopt.c +2
-0+test_tcp_maxseg_sockopt (fd); +Quoted 3 lines
return 0;
}Cheers,
Matt
Hi Geliang,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal: Success! ✅
- KVM Validation: debug: Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/14591855995
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/a917e8ca4810
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=955617
If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:
$ cd [kernel source code]
$ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
--pull always mptcp/mptcp-upstream-virtme-docker:latest \
auto-normalFor more details:
https://github.com/multipath-tcp/mptcp-upstream-virtme-docker
Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)
Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)