Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: net: run reuseport in an isolated netns

The reuseport_* tests (bpf, bpf_cpu, bpf_numa, dualstack) currently use
a fixed port range. This can cause intermittent test failures when the
ports are already in use by other services:

failed to bind receive socket: Address already in use

To avoid conflicts, run these tests in separate network namespaces using
unshare. Each test now has its own isolated network stack, preventing
port collisions with the host services.

Signed-off-by: Aleksei Oladko <aleksey.oladko@virtuozzo.com>
Link: https://patch.msgid.link/20260321215908.175465-2-aleksey.oladko@virtuozzo.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Aleksei Oladko and committed by
Jakub Kicinski
a897e194 ef94e96e

+42
+11
tools/testing/selftests/net/reuseport_bpf.c
··· 23 23 #include <sys/socket.h> 24 24 #include <sys/resource.h> 25 25 #include <unistd.h> 26 + #include <sched.h> 26 27 27 28 #include "kselftest.h" 28 29 ··· 456 455 setrlimit(RLIMIT_MEMLOCK, &rlim_old); 457 456 } 458 457 458 + static void setup_netns(void) 459 + { 460 + if (unshare(CLONE_NEWNET)) 461 + error(1, errno, "failed to unshare netns"); 462 + if (system("ip link set lo up")) 463 + error(1, 0, "failed to bring up lo interface in netns"); 464 + } 465 + 459 466 int main(void) 460 467 { 468 + setup_netns(); 469 + 461 470 fprintf(stderr, "---- IPv4 UDP ----\n"); 462 471 /* NOTE: UDP socket lookups traverse a different code path when there 463 472 * are > 10 sockets in a group. Run the bpf test through both paths.
+10
tools/testing/selftests/net/reuseport_bpf_cpu.c
··· 228 228 close(rcv_fd[cpu]); 229 229 } 230 230 231 + static void setup_netns(void) 232 + { 233 + if (unshare(CLONE_NEWNET)) 234 + error(1, errno, "failed to unshare netns"); 235 + if (system("ip link set lo up")) 236 + error(1, 0, "failed to bring up lo interface in netns"); 237 + } 238 + 231 239 int main(void) 232 240 { 233 241 int *rcv_fd, cpus; 242 + 243 + setup_netns(); 234 244 235 245 cpus = sysconf(_SC_NPROCESSORS_ONLN); 236 246 if (cpus <= 0)
+10
tools/testing/selftests/net/reuseport_bpf_numa.c
··· 230 230 close(rcv_fd[node]); 231 231 } 232 232 233 + static void setup_netns(void) 234 + { 235 + if (unshare(CLONE_NEWNET)) 236 + error(1, errno, "failed to unshare netns"); 237 + if (system("ip link set lo up")) 238 + error(1, 0, "failed to bring up lo interface in netns"); 239 + } 240 + 233 241 int main(void) 234 242 { 235 243 int *rcv_fd, nodes; 244 + 245 + setup_netns(); 236 246 237 247 if (numa_available() < 0) 238 248 ksft_exit_skip("no numa api support\n");
+11
tools/testing/selftests/net/reuseport_dualstack.c
··· 25 25 #include <sys/types.h> 26 26 #include <sys/socket.h> 27 27 #include <unistd.h> 28 + #include <sched.h> 28 29 29 30 static const int PORT = 8888; 30 31 ··· 157 156 close(epfd); 158 157 } 159 158 159 + static void setup_netns(void) 160 + { 161 + if (unshare(CLONE_NEWNET)) 162 + error(1, errno, "failed to unshare netns"); 163 + if (system("ip link set lo up")) 164 + error(1, 0, "failed to bring up lo interface in netns"); 165 + } 166 + 160 167 int main(void) 161 168 { 162 169 int rcv_fds[32], i; 170 + 171 + setup_netns(); 163 172 164 173 fprintf(stderr, "---- UDP IPv4 created before IPv6 ----\n"); 165 174 build_rcv_fd(AF_INET, SOCK_DGRAM, rcv_fds, 5);