Skip to contentSkip to conversation

selftests: consolidate TCP_INQ testing into sockopt

PATCH Superseded Geliang Tang 2 participants 14 messages Jul 9

Subsystems (3)

v5 of 14 Superseded Latest is v14 →

lore
Share & tools
lore

Geliang Tang

author reviewer
#0 lore raw

v5 cover selftests: consolidate TCP_INQ testing into sockopt

From: Geliang Tang <[email protected]>

v5:
- Continue using the approach from v3 and fix the instability issues. This version has undergone extensive loop testing.
- The new two separate functions, server_huge_transfer() and client_huge_transfer(), improve code structure.

v4:
- v3 changed the behavior of process_one_client and connect_one_server,
causing intermittent failures during loop testing. Revert to using the
v2 approach, along with some cleanups.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v3:
- No longer using process_one_client_inq() and connect_one_server_inq()
for switching; instead, the inq-related code has been merged into process_one_client() and connect_one_server().
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v2:
- patch 4, a new patch, add do_setsockopt_inq helper.
- cleanups.
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

v1:
- https://patchwork.kernel.org/project/mptcp/cover/[email protected]/

This series consolidates the TCP_INQ test functionality from mptcp_inq into mptcp_sockopt, simplifying the test suite while maintaining full test coverage.

Geliang Tang (12):
selftests: mptcp: sockopt: add tx/rx protocol options
selftests: mptcp: sockopt: add TCP_INQ test option
selftests: mptcp: sockopt: set TCP_INQ on accepted sockets
selftests: mptcp: sockopt: use unix socket instead of pipe
selftests: mptcp: sockopt: pass echo length over unixfd
selftests: mptcp: sockopt: set FIONREAD ioctl
selftests: mptcp: sockopt: add huge data transfer tests
selftests: mptcp: sockopt: add wait_for_ack helper
selftests: mptcp: sockopt: add get_tcp_inq helper
selftests: mptcp: sockopt: skip MPTCP opts for TCP tests
selftests: mptcp: sockopt: replace mptcp_inq with sockopt
selftests: mptcp: sockopt: remove obsolete mptcp_inq

 tools/testing/selftests/net/mptcp/.gitignore  |   1 -
 tools/testing/selftests/net/mptcp/Makefile    |   1 -
 tools/testing/selftests/net/mptcp/mptcp_inq.c | 614 ------------------
 .../selftests/net/mptcp/mptcp_sockopt.c       | 297 ++++++++-
 .../selftests/net/mptcp/mptcp_sockopt.sh      |   8 +-
 5 files changed, 274 insertions(+), 647 deletions(-)
 delete mode 100644 tools/testing/selftests/net/mptcp/mptcp_inq.c
Signature · 1 line
2.53.0
author reviewer
#1 lore raw

PATCH v5 1/12 selftests: mptcp: sockopt: add tx/rx protocol options

From: Geliang Tang <[email protected]>

Add -t and -r options to specify tx/rx protocols (TCP/MPTCP). This increases testing flexibility by allowing explicit protocol selection for both transmission and reception paths.

These codes are from mptcp_inq.c.

---
 .../selftests/net/mptcp/mptcp_sockopt.c       | 28 ++++++++++++++++---
 1 file changed, 24 insertions(+), 4 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +24 -4
index b6e58d936ebe..1d516779929a 100644
@@ -28,6 +28,8 @@
 #include <linux/compiler.h>
 
 static int pf = AF_INET;
+static int proto_tx = IPPROTO_MPTCP;
+static int proto_rx = IPPROTO_MPTCP;
 
 #ifndef IPPROTO_MPTCP
 #define IPPROTO_MPTCP 262
@@ -137,6 +139,7 @@ static void __noreturn die_perror(const char *msg)
 static void die_usage(int r)
 {
 	fprintf(stderr, "Usage: mptcp_sockopt [-6]\n");
+	fprintf(stderr, "                     [-t tcp|mptcp] [-r tcp|mptcp]\n");
 	exit(r);
 }
 
@@ -202,7 +205,7 @@ static int sock_listen_mptcp(const char * const listenaddr,
 	hints.ai_family = pf;
 
 	for (a = addr; a; a = a->ai_next) {
-		sock = socket(a->ai_family, a->ai_socktype, IPPROTO_MPTCP);
+		sock = socket(a->ai_family, a->ai_socktype, proto_rx);
 		if (sock < 0)
 			continue;
 
@@ -260,11 +263,22 @@ static int sock_connect_mptcp(const char * const remoteaddr,
 	return sock;
 }
 
+static int protostr_to_num(const char *s)
+{
+	if (strcasecmp(s, "tcp") == 0)
+		return IPPROTO_TCP;
+	if (strcasecmp(s, "mptcp") == 0)
+		return IPPROTO_MPTCP;
+
+	die_usage(1);
+	return 0;
+}
+
 static void parse_opts(int argc, char **argv)
 {
 	int c;
 
-	while ((c = getopt(argc, argv, "h6")) != -1) {
+	while ((c = getopt(argc, argv, "h6t:r:")) != -1) {
 		switch (c) {
 		case 'h':
 			die_usage(0);
@@ -272,6 +286,12 @@ static void parse_opts(int argc, char **argv)
 		case '6':
 			pf = AF_INET6;
 			break;
+		case 't':
+			proto_tx = protostr_to_num(optarg);
+			break;
+		case 'r':
+			proto_rx = protostr_to_num(optarg);
+			break;
 		default:
 			die_usage(1);
 			break;
@@ -777,10 +797,10 @@ static int client(int pipefd)
 
 	switch (pf) {
 	case AF_INET:
-		fd = sock_connect_mptcp("127.0.0.1", "15432", IPPROTO_MPTCP);
+		fd = sock_connect_mptcp("127.0.0.1", "15432", proto_tx);
 		break;
 	case AF_INET6:
-		fd = sock_connect_mptcp("::1", "15432", IPPROTO_MPTCP);
+		fd = sock_connect_mptcp("::1", "15432", proto_tx);
 		break;
 	default:
 		xerror("Unknown pf %d\n", pf);
Signature · 1 line
2.53.0
author reviewer
#2 lore raw

PATCH v5 2/12 selftests: mptcp: sockopt: add TCP_INQ test option

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Add -i option to enable TCP_INQ testing. This prepares for consolidating TCP_INQ tests into a single binary by adding the necessary command-line interface.

---
 tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +6 -1
index 1d516779929a..45dc85d10519 100644
@@ -30,6 +30,7 @@
 static int pf = AF_INET;
 static int proto_tx = IPPROTO_MPTCP;
 static int proto_rx = IPPROTO_MPTCP;
+static bool inq;
 
 #ifndef IPPROTO_MPTCP
 #define IPPROTO_MPTCP 262
@@ -140,6 +141,7 @@ static void die_usage(int r)
 {
 	fprintf(stderr, "Usage: mptcp_sockopt [-6]\n");
 	fprintf(stderr, "                     [-t tcp|mptcp] [-r tcp|mptcp]\n");
+	fprintf(stderr, "                     [-i]\n");
 	exit(r);
 }
 
@@ -278,7 +280,7 @@ static void parse_opts(int argc, char **argv)
 {
 	int c;
 
-	while ((c = getopt(argc, argv, "h6t:r:")) != -1) {
+	while ((c = getopt(argc, argv, "h6t:r:i")) != -1) {
 		switch (c) {
 		case 'h':
 			die_usage(0);
@@ -292,6 +294,9 @@ static void parse_opts(int argc, char **argv)
 		case 'r':
 			proto_rx = protostr_to_num(optarg);
 			break;
+		case 'i':
+			inq = true;
+			break;
 		default:
 			die_usage(1);
 			break;
Signature · 1 line
2.53.0
author reviewer
#3 lore raw

PATCH v5 3/12 selftests: mptcp: sockopt: set TCP_INQ on accepted sockets

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Add helper functions to conditionally set TCP_INQ sockopt on accepted sockets when running in inq mode. This ensures proper testing of TCP_CM_INQ functionality by enabling the required socket option on both ends of the connection.

These codes are from mptcp_inq.c.

---
 tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +11 -0
index 45dc85d10519..c6ced79e5814 100644
@@ -718,6 +718,14 @@ static void process_one_client(int fd, int pipefd)
 	close(fd);
 }
 
+static void do_setsockopt_inq(int fd)
+{
+	int on = 1;
+
+	if (setsockopt(fd, IPPROTO_TCP, TCP_INQ, &on, sizeof(on)))
+		die_perror("setsockopt(TCP_INQ)");
+}
+
 static int xaccept(int s)
 {
 	int fd = accept(s, NULL, 0);
@@ -725,6 +733,9 @@ static int xaccept(int s)
 	if (fd < 0)
 		die_perror("accept");
 
+	if (inq)
+		do_setsockopt_inq(fd);
+
 	return fd;
 }
 
Signature · 1 line
2.53.0
author reviewer
#4 lore raw

PATCH v5 4/12 selftests: mptcp: sockopt: use unix socket instead of pipe

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Replace pipe-based synchronization with Unix domain socket pairs (SOCK_DGRAM) for better bidirectional communication reliability between server and client processes.

These codes are from mptcp_inq.c.

---
 .../selftests/net/mptcp/mptcp_sockopt.c       | 40 +++++++++----------
 1 file changed, 20 insertions(+), 20 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +20 -20
index c6ced79e5814..6738ad45b9eb 100644
@@ -592,7 +592,7 @@ static void do_getsockopts(struct so_state *s, int fd, size_t r, size_t w)
 		do_getsockopt_mptcp_full_info(s, fd);
 }
 
-static void connect_one_server(int fd, int pipefd)
+static void connect_one_server(int fd, int unixfd)
 {
 	char buf[4096], buf2[4096];
 	size_t len, i, total;
@@ -617,9 +617,9 @@ static void connect_one_server(int fd, int pipefd)
 	do_getsockopts(&s, fd, 0, 0);
 
 	/* un-block server */
-	ret = read(pipefd, buf2, 4);
+	ret = read(unixfd, buf2, 4);
 	assert(ret == 4);
-	close(pipefd);
+	close(unixfd);
 
 	assert(strncmp(buf2, "xmit", 4) == 0);
 
@@ -661,7 +661,7 @@ static void connect_one_server(int fd, int pipefd)
 	close(fd);
 }
 
-static void process_one_client(int fd, int pipefd)
+static void process_one_client(int fd, int unixfd)
 {
 	ssize_t ret, ret2, ret3;
 	struct so_state s;
@@ -670,7 +670,7 @@ static void process_one_client(int fd, int pipefd)
 	memset(&s, 0, sizeof(s));
 	do_getsockopts(&s, fd, 0, 0);
 
-	ret = write(pipefd, "xmit", 4);
+	ret = write(unixfd, "xmit", 4);
 	assert(ret == 4);
 
 	ret = read(fd, buf, sizeof(buf));
@@ -739,7 +739,7 @@ static int xaccept(int s)
 	return fd;
 }
 
-static int server(int pipefd)
+static int server(int unixfd)
 {
 	int fd = -1, r;
 
@@ -755,13 +755,13 @@ static int server(int pipefd)
 		break;
 	}
 
-	r = write(pipefd, "conn", 4);
+	r = write(unixfd, "conn", 4);
 	assert(r == 4);
 
 	alarm(15);
 	r = xaccept(fd);
 
-	process_one_client(r, pipefd);
+	process_one_client(r, unixfd);
 
 	close(fd);
 	return 0;
@@ -805,7 +805,7 @@ static void test_ip_tos_sockopt(int fd)
 		xerror("expect socklen_t == -1");
 }
 
-static int client(int pipefd)
+static int client(int unixfd)
 {
 	int fd = -1;
 
@@ -824,7 +824,7 @@ static int client(int pipefd)
 
 	test_ip_tos_sockopt(fd);
 
-	connect_one_server(fd, pipefd);
+	connect_one_server(fd, unixfd);
 
 	return 0;
 }
@@ -878,35 +878,35 @@ int main(int argc, char *argv[])
 {
 	int e1, e2, wstatus;
 	pid_t s, c, ret;
-	int pipefds[2];
+	int unixfds[2];
 
 	parse_opts(argc, argv);
 
 	init_rng();
 
-	e1 = pipe(pipefds);
+	e1 = socketpair(AF_UNIX, SOCK_DGRAM, 0, unixfds);
 	if (e1 < 0)
-		die_perror("pipe");
+		die_perror("socketpair");
 
 	s = xfork();
 	if (s == 0) {
-		close(pipefds[0]);
-		ret = server(pipefds[1]);
-		close(pipefds[1]);
+		close(unixfds[0]);
+		ret = server(unixfds[1]);
+		close(unixfds[1]);
 		return ret;
 	}
 
-	close(pipefds[1]);
+	close(unixfds[1]);
 
 	/* wait until server bound a socket */
-	e1 = read(pipefds[0], &e1, 4);
+	e1 = read(unixfds[0], &e1, 4);
 	assert(e1 == 4);
 
 	c = xfork();
 	if (c == 0)
-		return client(pipefds[0]);
+		return client(unixfds[0]);
 
-	close(pipefds[0]);
+	close(unixfds[0]);
 
 	ret = waitpid(s, &wstatus, 0);
 	if (ret == -1)
Signature · 1 line
2.53.0
author reviewer
#5 lore raw

PATCH v5 5/12 selftests: mptcp: sockopt: pass echo length over unixfd

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Pass 'len' from the server to the client over the unixfd control channel so that the client knows the server's payload size in advance for the FIONREAD loop and TCP_CM_INQ validation. Also keep the unixfd open for the second write by moving 'close(unixfd)' to the end of connect_one_server().

These codes are from mptcp_inq.c.

Note: Additionally, silence a -Wstringop-overflow false positive by using 'len - total' as the read size, which lets GCC prove the destination is large enough.

---
 tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +12 -2
index 6738ad45b9eb..15c9f8dbae47 100644
@@ -619,10 +619,12 @@ static void connect_one_server(int fd, int unixfd)
 	/* un-block server */
 	ret = read(unixfd, buf2, 4);
 	assert(ret == 4);
-	close(unixfd);
 
 	assert(strncmp(buf2, "xmit", 4) == 0);
 
+	ret = write(unixfd, &len, sizeof(len));
+	assert(ret == (ssize_t)sizeof(len));
+
 	ret = write(fd, buf, len);
 	if (ret < 0)
 		die_perror("write");
@@ -632,7 +634,7 @@ static void connect_one_server(int fd, int unixfd)
 
 	total = 0;
 	do {
-		ret = read(fd, buf2 + total, sizeof(buf2) - total);
+		ret = read(fd, buf2 + total, len - total);
 		if (ret < 0)
 			die_perror("read");
 		if (ret == 0) {
@@ -659,12 +661,14 @@ static void connect_one_server(int fd, int unixfd)
 
 	assert(s.mptcpi_rcv_delta == (uint64_t)total);
 	close(fd);
+	close(unixfd);
 }
 
 static void process_one_client(int fd, int unixfd)
 {
 	ssize_t ret, ret2, ret3;
 	struct so_state s;
+	size_t expect_len;
 	char buf[4096];
 
 	memset(&s, 0, sizeof(s));
@@ -673,6 +677,12 @@ static void process_one_client(int fd, int unixfd)
 	ret = write(unixfd, "xmit", 4);
 	assert(ret == 4);
 
+	ret = read(unixfd, &expect_len, sizeof(expect_len));
+	assert(ret == (ssize_t)sizeof(expect_len));
+
+	if (expect_len > sizeof(buf))
+		xerror("expect len %zu exceeds buffer size", expect_len);
+
 	ret = read(fd, buf, sizeof(buf));
 	if (ret < 0)
 		die_perror("read");
Signature · 1 line
2.53.0
author reviewer
#6 lore raw

PATCH v5 6/12 selftests: mptcp: sockopt: set FIONREAD ioctl

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Implement FIONREAD ioctl checks to validate available data size, ensuring synchronization between write and read operations with non-blocking waits.

These codes are from mptcp_inq.c.

---
 .../selftests/net/mptcp/mptcp_sockopt.c       | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +19 -0
index 15c9f8dbae47..1b4d94abb1c6 100644
@@ -20,6 +20,7 @@
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/ioctl.h>
 
 #include <netdb.h>
 #include <netinet/in.h>
@@ -683,6 +684,24 @@ static void process_one_client(int fd, int unixfd)
 	if (expect_len > sizeof(buf))
 		xerror("expect len %zu exceeds buffer size", expect_len);
 
+	for (;;) {
+		struct timespec req;
+		unsigned int queued;
+
+		ret = ioctl(fd, FIONREAD, &queued);
+		if (ret < 0)
+			die_perror("FIONREAD");
+		if (queued > expect_len)
+			xerror("FIONREAD returned %u, but only %zu expected\n",
+			       queued, expect_len);
+		if (queued == expect_len)
+			break;
+
+		req.tv_sec = 0;
+		req.tv_nsec = 1000 * 1000ul;
+		nanosleep(&req, NULL);
+	}
+
 	ret = read(fd, buf, sizeof(buf));
 	if (ret < 0)
 		die_perror("read");
Signature · 1 line
2.53.0
author reviewer
#7 lore raw

PATCH v5 7/12 selftests: mptcp: sockopt: add huge data transfer tests

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Introduce huge data transfer tests (1-17 MB) to validate MPTCP socket options under high-volume conditions, including proper EOF handling, preparing for TCP_INQ support in subsequent patches.

These codes are from mptcp_inq.c, but here they have been placed into two separate functions.

---
 .../selftests/net/mptcp/mptcp_sockopt.c       | 104 ++++++++++++++++++
 1 file changed, 104 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +104 -0
index 1b4d94abb1c6..b4da3aa9713b 100644
@@ -593,6 +593,47 @@ static void do_getsockopts(struct so_state *s, int fd, size_t r, size_t w)
 		do_getsockopt_mptcp_full_info(s, fd);
 }
 
+static void server_huge_transfer(int fd, int unixfd, size_t len)
+{
+	char buf[4096], buf2[4];
+	size_t total;
+	ssize_t ret;
+
+	ret = read(unixfd, buf2, 4);
+	assert(strncmp(buf2, "huge", 4) == 0);
+
+	total = rand() % (16 * 1024 * 1024);
+	total += (1 * 1024 * 1024);
+
+	ret = write(unixfd, &total, sizeof(total));
+	assert(ret == (ssize_t)sizeof(total));
+
+	while (total > 0) {
+		if (total > sizeof(buf))
+			len = sizeof(buf);
+		else
+			len = total;
+
+		ret = write(fd, buf, len);
+		if (ret < 0)
+			die_perror("write");
+		total -= ret;
+
+		/* we don't have to care about buf content, only
+		 * number of total bytes sent
+		 */
+	}
+
+	ret = read(unixfd, buf2, 4);
+	assert(ret == 4);
+	assert(strncmp(buf2, "shut", 4) == 0);
+
+	ret = write(fd, buf, 1);
+	assert(ret == 1);
+	ret = write(unixfd, "closed", 6);
+	assert(ret == 6);
+}
+
 static void connect_one_server(int fd, int unixfd)
 {
 	char buf[4096], buf2[4096];
@@ -661,10 +702,70 @@ static void connect_one_server(int fd, int unixfd)
 		total += 1; /* sequence advances due to FIN */
 
 	assert(s.mptcpi_rcv_delta == (uint64_t)total);
+
+	if (inq)
+		server_huge_transfer(fd, unixfd, len);
+
 	close(fd);
 	close(unixfd);
 }
 
+static void client_huge_transfer(int fd, int unixfd)
+{
+	char msg_buf[4096];
+	size_t expect_len;
+	ssize_t ret, tot;
+	char buf[4096];
+	char tmp[16];
+	struct iovec iov = {
+		.iov_base = buf,
+		.iov_len = 1,
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+		.msg_control = msg_buf,
+		.msg_controllen = sizeof(msg_buf),
+	};
+
+	/* request a large swath of data. */
+	ret = write(unixfd, "huge", 4);
+	assert(ret == 4);
+
+	ret = read(unixfd, &expect_len, sizeof(expect_len));
+	assert(ret == (ssize_t)sizeof(expect_len));
+
+	/* peer should send us a few mb of data */
+	if (expect_len <= sizeof(buf))
+		xerror("expect len %zu too small\n", expect_len);
+
+	tot = 0;
+	do {
+		iov.iov_len = sizeof(buf);
+		ret = recvmsg(fd, &msg, 0);
+		if (ret < 0)
+			die_perror("recvmsg");
+
+		tot += ret;
+	} while ((size_t)tot < expect_len);
+
+	ret = write(unixfd, "shut", 4);
+	assert(ret == 4);
+
+	/* wait for hangup. Should have received one more byte of data. */
+	ret = read(unixfd, tmp, sizeof(tmp));
+	assert(ret == 6);
+	assert(strncmp(tmp, "closed", 6) == 0);
+
+	sleep(1);
+
+	iov.iov_len = 1;
+	ret = recvmsg(fd, &msg, 0);
+	if (ret < 0)
+		die_perror("recvmsg");
+	assert(ret == 1);
+}
+
 static void process_one_client(int fd, int unixfd)
 {
 	ssize_t ret, ret2, ret3;
@@ -715,6 +816,9 @@ static void process_one_client(int fd, int unixfd)
 	if (ret2 < 0)
 		die_perror("write");
 
+	if (inq)
+		client_huge_transfer(fd, unixfd);
+
 	/* wait for hangup */
 	ret3 = read(fd, buf, 1);
 	if (ret3 != 0)
Signature · 1 line
2.53.0
author reviewer
#8 lore raw

PATCH v5 8/12 selftests: mptcp: sockopt: add wait_for_ack helper

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Add wait_for_ack() helper using TIOCOUTQ/SIOCOUTQNSD ioctls to synchronize tests by waiting for data acknowledgment before proceeding.

These codes are from mptcp_inq.c.

---
 .../selftests/net/mptcp/mptcp_sockopt.c       | 42 ++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +41 -1
index b4da3aa9713b..393c863f3762 100644
@@ -26,6 +26,7 @@
 #include <netinet/in.h>
 
 #include <linux/tcp.h>
+#include <linux/sockios.h>
 #include <linux/compiler.h>
 
 static int pf = AF_INET;
@@ -593,10 +594,44 @@ static void do_getsockopts(struct so_state *s, int fd, size_t r, size_t w)
 		do_getsockopt_mptcp_full_info(s, fd);
 }
 
+/* wait up to timeout milliseconds */
+static void wait_for_ack(int fd, int timeout, size_t total)
+{
+	int i;
+
+	for (i = 0; i < timeout; i++) {
+		int nsd, ret, queued = -1;
+		struct timespec req;
+
+		ret = ioctl(fd, TIOCOUTQ, &queued);
+		if (ret < 0)
+			die_perror("TIOCOUTQ");
+
+		ret = ioctl(fd, SIOCOUTQNSD, &nsd);
+		if (ret < 0)
+			die_perror("SIOCOUTQNSD");
+
+		if ((size_t)queued > total)
+			xerror("TIOCOUTQ %u, but only %zu expected\n",
+			       queued, total);
+		assert(nsd <= queued);
+
+		if (queued == 0)
+			return;
+
+		/* wait for peer to ack rx of all data */
+		req.tv_sec = 0;
+		req.tv_nsec = 1 * 1000 * 1000ul; /* 1ms */
+		nanosleep(&req, NULL);
+	}
+
+	xerror("still tx data queued after %u ms\n", timeout);
+}
+
 static void server_huge_transfer(int fd, int unixfd, size_t len)
 {
 	char buf[4096], buf2[4];
-	size_t total;
+	size_t total, sent;
 	ssize_t ret;
 
 	ret = read(unixfd, buf2, 4);
@@ -604,10 +639,13 @@ static void server_huge_transfer(int fd, int unixfd, size_t len)
 
 	total = rand() % (16 * 1024 * 1024);
 	total += (1 * 1024 * 1024);
+	sent = total;
 
 	ret = write(unixfd, &total, sizeof(total));
 	assert(ret == (ssize_t)sizeof(total));
 
+	wait_for_ack(fd, 5000, len);
+
 	while (total > 0) {
 		if (total > sizeof(buf))
 			len = sizeof(buf);
@@ -628,6 +666,8 @@ static void server_huge_transfer(int fd, int unixfd, size_t len)
 	assert(ret == 4);
 	assert(strncmp(buf2, "shut", 4) == 0);
 
+	wait_for_ack(fd, 5000, sent);
+
 	ret = write(fd, buf, 1);
 	assert(ret == 1);
 	ret = write(unixfd, "closed", 6);
Signature · 1 line
2.53.0
author reviewer
#9 lore raw

PATCH v5 9/12 selftests: mptcp: sockopt: add get_tcp_inq helper

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Add check_tcp_inq() helper to extract and verify TCP_CM_INQ values from control messages, ensuring correct in-queue data tracking during transfers.

These codes are from mptcp_inq.c.

---
 .../selftests/net/mptcp/mptcp_sockopt.c       | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +30 -0
index 393c863f3762..1674b660848d 100644
@@ -750,8 +750,25 @@ static void connect_one_server(int fd, int unixfd)
 	close(unixfd);
 }
 
+static void get_tcp_inq(struct msghdr *msgh, unsigned int *inqv)
+{
+	struct cmsghdr *cmsg;
+
+	for (cmsg = CMSG_FIRSTHDR(msgh); cmsg;
+	     cmsg = CMSG_NXTHDR(msgh, cmsg)) {
+		if (cmsg->cmsg_level == IPPROTO_TCP &&
+		    cmsg->cmsg_type == TCP_CM_INQ) {
+			memcpy(inqv, CMSG_DATA(cmsg), sizeof(*inqv));
+			return;
+		}
+	}
+
+	xerror("could not find TCP_CM_INQ cmsg type");
+}
+
 static void client_huge_transfer(int fd, int unixfd)
 {
+	unsigned int tcp_inq;
 	char msg_buf[4096];
 	size_t expect_len;
 	ssize_t ret, tot;
@@ -787,6 +804,14 @@ static void client_huge_transfer(int fd, int unixfd)
 			die_perror("recvmsg");
 
 		tot += ret;
+
+		get_tcp_inq(&msg, &tcp_inq);
+
+		if (tcp_inq > expect_len - tot)
+			xerror("inq %d, remaining %d total_len %d\n",
+			       tcp_inq, expect_len - tot, (int)expect_len);
+
+		assert(tcp_inq <= expect_len - tot);
 	} while ((size_t)tot < expect_len);
 
 	ret = write(unixfd, "shut", 4);
@@ -804,6 +829,11 @@ static void client_huge_transfer(int fd, int unixfd)
 	if (ret < 0)
 		die_perror("recvmsg");
 	assert(ret == 1);
+
+	get_tcp_inq(&msg, &tcp_inq);
+
+	/* tcp_inq should be 1 due to received fin. */
+	assert(tcp_inq == 1);
 }
 
 static void process_one_client(int fd, int unixfd)
Signature · 1 line
2.53.0
author reviewer
#10 lore raw

PATCH v5 10/12 selftests: mptcp: sockopt: skip MPTCP opts for TCP tests

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Enhance compatibility with TCP tests in mptcp_sockopt.c by skipping MPTCP getsockopt checks during TCP tests since MPTCP socket options are not available.

---
 tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.c +6 -2
index 1674b660848d..13d10a606501 100644
@@ -584,6 +584,9 @@ static void do_getsockopt_mptcp_full_info(struct so_state *s, int fd)
 
 static void do_getsockopts(struct so_state *s, int fd, size_t r, size_t w)
 {
+	if (proto_tx != IPPROTO_MPTCP || proto_rx != IPPROTO_MPTCP)
+		return;
+
 	do_getsockopt_mptcp_info(s, fd, w);
 
 	do_getsockopt_tcp_info(s, fd, r, w);
@@ -741,7 +744,8 @@ static void connect_one_server(int fd, int unixfd)
 	if (eof)
 		total += 1; /* sequence advances due to FIN */
 
-	assert(s.mptcpi_rcv_delta == (uint64_t)total);
+	assert(!s.mptcpi_rcv_delta ||
+	       s.mptcpi_rcv_delta == (uint64_t)total);
 
 	if (inq)
 		server_huge_transfer(fd, unixfd, len);
@@ -895,7 +899,7 @@ static void process_one_client(int fd, int unixfd)
 		xerror("expected EOF, got %lu", ret3);
 
 	do_getsockopts(&s, fd, ret, ret2);
-	if (s.mptcpi_rcv_delta != (uint64_t)ret + 1)
+	if (s.mptcpi_rcv_delta && s.mptcpi_rcv_delta != (uint64_t)ret + 1)
 		xerror("mptcpi_rcv_delta %" PRIu64 ", expect %" PRIu64 ", diff %" PRId64,
 		       s.mptcpi_rcv_delta, ret + 1, s.mptcpi_rcv_delta - (ret + 1));
 
Signature · 1 line
2.53.0
author reviewer
#11 lore raw

PATCH v5 11/12 selftests: mptcp: sockopt: replace mptcp_inq with sockopt

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Update mptcp_sockopt.sh to use mptcp_sockopt binary instead of mptcp_inq. This consolidates TCP_INQ testing into a single test binary while maintaining equivalent test coverage.

---
 tools/testing/selftests/net/mptcp/mptcp_sockopt.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tools/testing/selftests/net/mptcp/mptcp_sockopt.sh +4 -4
index e850a87429b6..a39265555438 100755
@@ -308,7 +308,7 @@ run_tests()
 do_tcpinq_test()
 {
 	print_title "TCP_INQ cmsg/ioctl $*"
-	ip netns exec "$ns_sbox" ./mptcp_inq "$@"
+	ip netns exec "$ns_sbox" ./mptcp_sockopt "$@"
 	local lret=$?
 	if [ $lret -ne 0 ];then
 		ret=$lret
@@ -334,19 +334,19 @@ do_tcpinq_tests()
 
 	local args
 	for args in "-t tcp" "-r tcp"; do
-		do_tcpinq_test $args
+		do_tcpinq_test $args -i
 		lret=$?
 		if [ $lret -ne 0 ] ; then
 			return $lret
 		fi
-		do_tcpinq_test -6 $args
+		do_tcpinq_test -6 $args -i
 		lret=$?
 		if [ $lret -ne 0 ] ; then
 			return $lret
 		fi
 	done
 
-	do_tcpinq_test -r tcp -t tcp
+	do_tcpinq_test -r tcp -t tcp -i
 
 	return $?
 }
Signature · 1 line
2.53.0
author reviewer
#12 lore raw

PATCH v5 12/12 selftests: mptcp: sockopt: remove obsolete mptcp_inq

In reply to Geliang Tang

From: Geliang Tang <[email protected]>

Delete mptcp_inq binary and references since its functionality has been fully integrated into mptcp_sockopt. This simplifies the test suite structure and reduces maintenance overhead.

---
 tools/testing/selftests/net/mptcp/.gitignore  |   1 -
 tools/testing/selftests/net/mptcp/Makefile    |   1 -
 tools/testing/selftests/net/mptcp/mptcp_inq.c | 614 ------------------
 3 files changed, 616 deletions(-)
 delete mode 100644 tools/testing/selftests/net/mptcp/mptcp_inq.c
tools/testing/selftests/net/mptcp/.gitignore +0 -1
index 833279fb34e2..c62e91ce385d 100644
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 mptcp_connect
 mptcp_diag
-mptcp_inq
 mptcp_sockopt
 pm_nl_ctl
 *.pcap
tools/testing/selftests/net/mptcp/Makefile +0 -1
index 22ba0da2adb8..fa80e6448728 100644
@@ -22,7 +22,6 @@ TEST_PROGS := \
 TEST_GEN_FILES := \
 	mptcp_connect \
 	mptcp_diag \
-	mptcp_inq \
 	mptcp_sockopt \
 	pm_nl_ctl \
 # end of TEST_GEN_FILES
tools/testing/selftests/net/mptcp/mptcp_inq.c deleted +0 -614

614 lines not on this page · raw message

Signature · 1 line
2.53.0
#13 lore raw
In reply to Geliang Tang

Hi Geliang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Success! ✅
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Success! ✅
- KVM Validation: debug (only selftest_mptcp_join): 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/29001832658

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/c950e4c1806b
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1124363

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-normal

For 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)