[PATCH mptcp-next v2 3/3] selftests: mptcp: sockopt: add TCP_MAXSEG sockopt tests

Geliang Tang posted 3 patches 7 months, 3 weeks ago
There is a newer version of this series
[PATCH mptcp-next v2 3/3] selftests: mptcp: sockopt: add TCP_MAXSEG sockopt tests
Posted by Geliang Tang 7 months, 3 weeks ago
From: Geliang Tang <tanggeliang@kylinos.cn>

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().

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 .../selftests/net/mptcp/mptcp_sockopt.c       | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
index 9934a68df237..5ad1e9ed2fe6 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
@@ -697,6 +697,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;
@@ -721,6 +741,8 @@ static int server(int pipefd)
 
 	process_one_client(r, pipefd);
 
+	test_tcp_maxseg_sockopt(fd);
+
 	return 0;
 }
 
-- 
2.43.0
Re: [PATCH mptcp-next v2 3/3] selftests: mptcp: sockopt: add TCP_MAXSEG sockopt tests
Posted by Matthieu Baerts 7 months, 2 weeks ago
Hi Geliang

On 23/04/2025 11:40, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> 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().

I understand you wanted a way to test it, but the set/get is not enough,
and it looks "useless". I'm OK to apply the two other patches with the
small suggested modifications, but I will only send them when there will
be a packetdrill test.

Do not hesitate to imitate other packetdrill test, e.g.
mptcp/sockopts/sockopt_keepalive.pkt. In this case, you could set MAXSEG
(e.g. 1000), then send data (e.g. write(5000)) and check 4 packets are
sent, and the MSS is set to 1000. It might be good to change the value
again later, and see if the behaviour is the expected one
(setsockopt(MAXSEG, 1250) + write(2500)). If possible, after that, in
the same test, also create another subflow, and only check the MSS to
see if it has the expected value. To test that, feel free to look at:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker?tab=readme-ov-file#packetdrill

Note that the behaviour should be as closed as possible to TCP. Don't
hesitate to run the same kind of test with "plain" TCP.

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.