[PATCH net-next 4/4] selftests: mptcp: cover IP_RECVERR sockopt propagation
From: "Matthieu Baerts (NGI0)" <matttbe@kernel.org>
Date: 2026-09-18 18:38:49
Also in:
linux-kselftest, lkml, mptcp
Subsystem:
kernel selftest framework, networking [general], networking [mptcp], the rest · Maintainers:
Shuah Khan, Shuah Khan, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Matthieu Baerts, Mat Martineau, Linus Torvalds
From: David Carlier <redacted> Exercise setsockopt/getsockopt of IP_RECVERR and IPV6_RECVERR on the MPTCP parent socket, including the empty-errqueue EAGAIN contract on MSG_ERRQUEUE|MSG_DONTWAIT. End-to-end errqueue delivery (ICMP, TX timestamps, zerocopy) depends on subflow-side producers that are out of scope for this series and will be covered by follow-up work. Assisted-by: Codex:gpt-5 Signed-off-by: David Carlier <redacted> Acked-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> --- To: Shuah Khan <shuah@kernel.org> Cc: linux-kselftest@vger.kernel.org --- tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 70 +++++++++++++++++++++++ 1 file changed, 70 insertions(+)
diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
index b6e58d936ebe..d68515b7903b 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c
+++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c@@ -183,6 +183,13 @@ static void xgetaddrinfo(const char *node, const char *service, } } +static bool expect_all_features(void) +{ + char *env = getenv("SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES"); + + return env && strcmp(env, "1") == 0; +} + static int sock_listen_mptcp(const char * const listenaddr, const char * const port) {
@@ -769,6 +776,68 @@ static void test_ip_tos_sockopt(int fd) xerror("expect socklen_t == -1"); } +static void test_ip_recverr_sockopt(int fd) +{ + struct iovec iov = { + .iov_base = &(char){ 0 }, + .iov_len = 1, + }; + struct msghdr msg = { + .msg_iov = &iov, + .msg_iovlen = 1, + }; + int one = 1, zero = 0, val = -1; + socklen_t s = sizeof(val); + int level, optname, r; + + switch (pf) { + case AF_INET: + level = SOL_IP; + optname = IP_RECVERR; + break; + case AF_INET6: + level = SOL_IPV6; + optname = IPV6_RECVERR; + break; + default: + xerror("Unknown pf %d\n", pf); + } + + r = setsockopt(fd, level, optname, &one, sizeof(one)); + if (r) { + /* For older kernels not supporting IP(V6)_RECVERR yet */ + if (errno == EOPNOTSUPP && !expect_all_features()) { + fprintf(stderr, "IP(V6)_RECVERR not supported, SKIP\n"); + return; + } + + die_perror("setsockopt IP(V6)_RECVERR on"); + } + + r = getsockopt(fd, level, optname, &val, &s); + if (r) + die_perror("getsockopt IP(V6)_RECVERR on"); + if (s != sizeof(val) || val != one) + xerror("IP(V6)_RECVERR on mismatch val=%d len=%u", val, s); + + r = recvmsg(fd, &msg, MSG_ERRQUEUE | MSG_DONTWAIT); + if (r != -1 || errno != EAGAIN) + xerror("expected empty errqueue to return EAGAIN, r=%d err=%d", + r, errno); + + r = setsockopt(fd, level, optname, &zero, sizeof(zero)); + if (r) + die_perror("setsockopt IP(V6)_RECVERR off"); + + val = -1; + s = sizeof(val); + r = getsockopt(fd, level, optname, &val, &s); + if (r) + die_perror("getsockopt IP(V6)_RECVERR off"); + if (s != sizeof(val) || val != zero) + xerror("IP(V6)_RECVERR off mismatch val=%d len=%u", val, s); +} + static int client(int pipefd) { int fd = -1;
@@ -787,6 +856,7 @@ static int client(int pipefd) } test_ip_tos_sockopt(fd); + test_ip_recverr_sockopt(fd); connect_one_server(fd, pipefd);
--
2.55.0