All of lore.kernel.org
 help / color / mirror / Atom feed
From: zibuyu <zibuyu423@gmail.com>
To: mptcp@lists.linux.dev
Subject: [PATCH mptcp-next v2] selftests: mptcp: cover mixed accepts on one listener
Date: Thu,  3 Dec 2026 21:51:51 +0800	[thread overview]
Message-ID: <179630585724.2.6064655453761563853@gmail.com> (raw)

The socket option test handles one MPTCP connection per listener. It
leaves the passive TCP fallback path untested when other children of
the same listener negotiate MPTCP.

Connect an MPTCP client, a TCP client and another MPTCP client to the
same listener. Keep all three connections open, check SO_PROTOCOL on
each accepted socket and verify that it reads its own client's byte.
The existing socket option test runs this sequence for IPv4 and IPv6.

OpenAI Codex generated the test and ran the socket option selftests.

Link: https://github.com/multipath-tcp/mptcp_net-next/issues/426
Signed-off-by: zibuyu <zibuyu423@gmail.com>
---
Changes in v2:
- Include kselftest.h for ARRAY_SIZE(). With the UAPI headers installed,
  <linux/kernel.h> resolves to the exported header and the build fails.

Built the MPTCP selftests with the installed UAPI headers. All 11
mptcp_sockopt.sh subtests passed, including IPv4 and IPv6. The host
kernel skipped the optional IP_RECVERR and IPV6_RECVERR checks.

v1: https://lore.kernel.org/mptcp/20261203094509.3382752-1-zibuyu423@gmail.com/

 tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 54 ++++++++++++++++++-----
 1 file changed, 42 insertions(+), 12 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
index b8158a1..aa90fe5 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
@@ -27,6 +27,8 @@
 #include <linux/tcp.h>
 #include <linux/compiler.h>
 
+#include "../../kselftest.h"
+
 static int pf = AF_INET;
 
 #ifndef IPPROTO_MPTCP
@@ -705,22 +707,49 @@ static int xaccept(int s)
 	return fd;
 }
 
-static int server(int pipefd)
+static void test_mixed_accept(int listener, const char *addr, const char *port)
 {
-	int fd = -1, r;
+	static const int protos[] = { IPPROTO_MPTCP, IPPROTO_TCP, IPPROTO_MPTCP };
+	int clients[ARRAY_SIZE(protos)], accepted[ARRAY_SIZE(protos)];
+	size_t i;
 
-	switch (pf) {
-	case AF_INET:
-		fd = sock_listen_mptcp("127.0.0.1", "15432");
-		break;
-	case AF_INET6:
-		fd = sock_listen_mptcp("::1", "15432");
-		break;
-	default:
-		xerror("Unknown pf %d\n", pf);
-		break;
+	for (i = 0; i < ARRAY_SIZE(protos); i++) {
+		char tag = 'A' + i;
+
+		clients[i] = sock_connect_mptcp(addr, port, protos[i]);
+		accepted[i] = xaccept(listener);
+		if (write(clients[i], &tag, 1) != 1)
+			die_perror("write client tag");
 	}
 
+	/* Check each child while the negotiated and fallback sockets coexist. */
+	for (i = 0; i < ARRAY_SIZE(protos); i++) {
+		int proto;
+		socklen_t len = sizeof(proto);
+		char tag;
+
+		if (getsockopt(accepted[i], SOL_SOCKET, SO_PROTOCOL, &proto, &len))
+			die_perror("getsockopt SO_PROTOCOL");
+		if (proto != protos[i])
+			xerror("accept %zu: got protocol %d, expected %d", i, proto, protos[i]);
+
+		if (read(accepted[i], &tag, 1) != 1 || tag != 'A' + i)
+			xerror("accept %zu: did not receive its client tag", i);
+	}
+
+	for (i = 0; i < ARRAY_SIZE(protos); i++) {
+		close(accepted[i]);
+		close(clients[i]);
+	}
+}
+
+static int server(int pipefd)
+{
+	const char *addr = pf == AF_INET6 ? "::1" : "127.0.0.1";
+	const char *port = "15432";
+	int fd, r;
+
+	fd = sock_listen_mptcp(addr, port);
 	r = write(pipefd, "conn", 4);
 	assert(r == 4);
 
@@ -728,6 +757,7 @@ static int server(int pipefd)
 	r = xaccept(fd);
 
 	process_one_client(r, pipefd);
+	test_mixed_accept(fd, addr, port);
 
 	close(fd);
 	return 0;

             reply	other threads:[~2026-12-03 13:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 13:51 zibuyu [this message]
2026-12-03 17:37 ` [PATCH mptcp-next v2] selftests: mptcp: cover mixed accepts on one listener Matthieu Baerts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179630585724.2.6064655453761563853@gmail.com \
    --to=zibuyu423@gmail.com \
    --cc=mptcp@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.