[PATCH 3/5] selftests: net: run reuseport tests in netns to avoid port conflicts

Aleksei Oladko
2026-01-20T23:06:18Z

From: Konstantin Khorenko <khorenko@virtuozzo.com>

Some net kselftests use fixed ports which overlap with process-exporter
service already running on the host. When such a conflict happens,
the test fail with:

failed to bind receive socket: Address already in use

Instead of changing port numbers, run the affected tests in isolated
network namespace to avoid conflicts with running daemons.

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
tools/testing/selftests/net/Makefile | 12 ++++++++----
tools/testing/selftests/net/reuseport_bpf.sh | 4 ++++
tools/testing/selftests/net/reuseport_bpf_cpu.sh | 4 ++++
tools/testing/selftests/net/reuseport_bpf_numa.sh | 4 ++++
tools/testing/selftests/net/reuseport_dualstack.sh | 4 ++++
5 files changed, 24 insertions(+), 4 deletions(-)
create mode 100755 tools/testing/selftests/net/reuseport_bpf.sh
create mode 100755 tools/testing/selftests/net/reuseport_bpf_cpu.sh
create mode 100755 tools/testing/selftests/net/reuseport_bpf_numa.sh
create mode 100755 tools/testing/selftests/net/reuseport_dualstack.sh

diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index b66ba04f19d9..a160e0d816d9 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -64,6 +64,10 @@ TEST_PROGS := \
psock_snd.sh \
reuseaddr_ports_exhausted.sh \
reuseport_addr_any.sh \
+ reuseport_bpf.sh \
+ reuseport_bpf_cpu.sh \
+ reuseport_bpf_numa.sh \
+ reuseport_dualstack.sh
route_hint.sh \
route_localnet.sh \
rps_default_mask.sh \
@@ -142,6 +146,10 @@ TEST_GEN_FILES := \
psock_tpacket \
reuseaddr_ports_exhausted \
reuseport_addr_any \
+ reuseport_bpf \
+ reuseport_bpf_cpu \
+ reuseport_bpf_numa \
+ reuseport_dualstack \
rxtimestamp \
sctp_hello \
skf_net_off \
@@ -169,10 +177,6 @@ TEST_GEN_PROGS := \
ipv6_fragmentation \
proc_net_pktgen \
reuseaddr_conflict \
- reuseport_bpf \
- reuseport_bpf_cpu \
- reuseport_bpf_numa \
- reuseport_dualstack \
sk_bind_sendto_listen \
sk_connect_zero_addr \
sk_so_peek_off \
diff --git a/tools/testing/selftests/net/reuseport_bpf.sh b/tools/testing/selftests/net/reuseport_bpf.sh
new file mode 100755
index 000000000000..75014a5462a1
--- /dev/null
+++ b/tools/testing/selftests/net/reuseport_bpf.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+./in_netns.sh ./reuseport_bpf
diff --git a/tools/testing/selftests/net/reuseport_bpf_cpu.sh b/tools/testing/selftests/net/reuseport_bpf_cpu.sh
new file mode 100755
index 000000000000..243dc5bee014
--- /dev/null
+++ b/tools/testing/selftests/net/reuseport_bpf_cpu.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+./in_netns.sh ./reuseport_bpf_cpu
diff --git a/tools/testing/selftests/net/reuseport_bpf_numa.sh b/tools/testing/selftests/net/reuseport_bpf_numa.sh
new file mode 100755
index 000000000000..eccab95a3202
--- /dev/null
+++ b/tools/testing/selftests/net/reuseport_bpf_numa.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+./in_netns.sh ./reuseport_bpf_numa
diff --git a/tools/testing/selftests/net/reuseport_dualstack.sh b/tools/testing/selftests/net/reuseport_dualstack.sh
new file mode 100755
index 000000000000..82cc8e345a83
--- /dev/null
+++ b/tools/testing/selftests/net/reuseport_dualstack.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+./in_netns.sh ./reuseport_dualstack
--
2.43.0