[PATCH mptcp-next v11 05/11] selftests: mptcp: sockopt: add tx/rx protocol options
Geliang Tang <[email protected]> Wed, 15 Jul 2026 10:48:51 +0800
| Newsgroups | dev.linux.lists.mptcp |
|---|---|
| Message-ID | <0f8e8149460e792998d9648c2f8e9842e126e44e.1784082850.git.tanggeliang@kylinos.cn> |
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. Enhance compatibility with TCP tests by skipping MPTCP getsockopt checks during TCP tests since MPTCP socket options are not available. Signed-off-by: Geliang Tang <[email protected]> --- .../selftests/net/mptcp/mptcp_sockopt.c | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c index 9e1d84af5268..71db07913d14 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c @@ -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 @@ -139,6 +141,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); } @@ -204,7 +207,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; @@ -262,11 +265,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); @@ -274,6 +288,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; @@ -559,6 +579,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); @@ -634,7 +657,8 @@ static void connect_one_server(int fd, int pipefd) if (eof) total += 1; /* sequence advances due to FIN */ - assert(s.mptcpi_rcv_delta == (uint64_t)total); + if (proto_tx == IPPROTO_MPTCP && proto_rx == IPPROTO_MPTCP) + assert(s.mptcpi_rcv_delta == (uint64_t)total); close(fd); } @@ -683,8 +707,9 @@ static void process_one_client(int fd, int pipefd) r += ret; do_getsockopts(&s, fd, r, w); - check_stat_equal("mptcpi_rcv_delta", s.mptcpi_rcv_delta, - (uint64_t)r + 1); /* +1 for FIN */ + if (proto_tx == IPPROTO_MPTCP && proto_rx == IPPROTO_MPTCP) + check_stat_equal("mptcpi_rcv_delta", s.mptcpi_rcv_delta, + (uint64_t)r + 1); /* +1 for FIN */ /* be nice when running on top of older kernel */ if (s.pkt_stats_avail) { @@ -786,10 +811,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); -- 2.53.0