[RFC mptcp-next v4 09/10] selftests: mptcp: connect: update sock_test_tcpulp

Geliang Tang
2025-12-12T02:27:44Z

Update sock_test_tcpulp() to ensure the mptcp_connect.c tests are not
broken.

fallback() helper has been implemented to verify fallback scenarios,
ensuring that MPTCP fallback-to-TCP tests continue to pass.

Co-developed-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
.../selftests/net/mptcp/mptcp_connect.c | 20 ++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/testing/selftests/net/mptcp/mptcp_connect.c
index b82df82e0594..e5c394ea4e11 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_connect.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c
@@ -266,6 +266,18 @@ static void set_mptfo(int fd, int pf)
perror("TCP_FASTOPEN");
}

+static int fallback(int fd)
+{
+ int is_mptcp = 0;
+ socklen_t optlen;
+
+ optlen = sizeof(is_mptcp);
+ if (getsockopt(fd, IPPROTO_TCP, TCP_IS_MPTCP, &is_mptcp, &optlen) == -1)
+ perror("TCP_IS_MPTCP");
+
+ return !is_mptcp;
+}
+
static int do_ulp_so(int sock, const char *name)
{
return setsockopt(sock, IPPROTO_TCP, TCP_ULP, name, strlen(name));
@@ -282,7 +294,7 @@ static void sock_test_tcpulp(int sock, int proto, unsigned int line)
X("getsockopt");

if (buflen > 0) {
- if (strcmp(buf, "mptcp") != 0)
+ if (strcmp(buf, fallback(sock) ? "mptcp" : "tls") != 0)
xerror("unexpected ULP '%s' for proto %d at line %u", buf, proto, line);
ret = do_ulp_so(sock, "tls");
if (ret == 0)
@@ -424,8 +436,6 @@ static int sock_connect_mptcp(const char * const remoteaddr,
}

freeaddrinfo(addr);
- if (sock != -1)
- SOCK_TEST_TCPULP(sock, proto);
return sock;
}

@@ -1197,8 +1207,6 @@ int main_loop_s(int listensock)
xerror("can't open %s: %d", cfg_input, errno);
}

- SOCK_TEST_TCPULP(remotesock, 0);
-
memset(&winfo, 0, sizeof(winfo));
err = copyfd_io(fd, remotesock, 1, true, &winfo);
} else {
@@ -1371,8 +1379,6 @@ int main_loop(void)
again:
check_getpeername_connect(fd);

- SOCK_TEST_TCPULP(fd, cfg_sock_proto);
-
if (cfg_rcvbuf)
set_rcvbuf(fd, cfg_rcvbuf);
if (cfg_sndbuf)
--
2.51.0