[Devel] [PATCH hci-8.1 v4 3/3] selftests/bpf: run the xsk veth tests in a network namespace of their own
Konstantin Khorenko
khorenko at virtuozzo.com
Tue Oct 27 21:15:21 MSK 2026
From: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
test_xsk.sh makes its veth pair in the namespace it runs in, and the
host treats it as any new interface: address configuration, neighbour
discovery and the like happen on that pair. The AF_XDP sockets under
test receive the host's packets among their own. The tests count and
inspect what they receive, so they fail on a configured host and pass
on a bare one.
Re-run the veth part in an unnamed network namespace with a sysfs of its
own, which the busy poll setup writes to. The namespace goes away with
its last process however the run ends, and takes the pair with it.
With -d the pair has to outlive the run, so the namespace gets a name,
and the script prints how to enter and delete it.
If no network namespace can be created, the tests are skipped, as
without veth or ip. A failure after that, mounting sysfs in the
namespace included, fails the run.
https://virtuozzo.atlassian.net/browse/VSTOR-150731
Feature: fix selftests
Signed-off-by: Eva Kurchatova <eva.kurchatova at virtuozzo.com>
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
tools/testing/selftests/bpf/test_xsk.sh | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/test_xsk.sh b/tools/testing/selftests/bpf/test_xsk.sh
index 65aafe0003db0..1554d1ec02b12 100755
--- a/tools/testing/selftests/bpf/test_xsk.sh
+++ b/tools/testing/selftests/bpf/test_xsk.sh
@@ -68,7 +68,8 @@
# Run with verbose output:
# sudo ./test_xsk.sh -v
#
-# Set up veth interfaces and leave them up so xskxceiver can be launched in a debugger:
+# Set up veth interfaces in a network namespace and leave them up so
+# xskxceiver can be launched in a debugger there:
# sudo ./test_xsk.sh -d
#
# Run test suite for physical device in loopback mode
@@ -162,8 +163,33 @@ if [ ! -z $ETH ]; then
VETH1=${ETH}
else
validate_root_exec
- validate_veth_support ${VETH0}
validate_ip_utility
+ # The host configures and talks on any new interface in its namespace
+ if [ -z "$XSK_NETNS" ]; then
+ if ! unshare --net true; then
+ echo "skip all tests: cannot create a network namespace" >&2
+ test_exit $ksft_skip
+ fi
+ if [[ $debug -ne 1 ]]; then
+ # Unnamed, it goes with its last process; its own sysfs shows its interfaces
+ XSK_NETNS=1 exec unshare --net --mount sh -c \
+ 'mount -t sysfs sysfs /sys && exec bash "$0" "$@"' \
+ "$0" "$@"
+ fi
+ # The pair of a run by hand outlives it, in a namespace with a name
+ XSK_NETNS=xsk${VETH0_POSTFIX}
+ ip netns add ${XSK_NETNS} || exit 1
+ trap "ip netns del ${XSK_NETNS}" EXIT
+ # This run's veth names were never created; the pair is in the namespace
+ trap "exit 1" INT
+ XSK_NETNS=${XSK_NETNS} ip netns exec ${XSK_NETNS} bash "$0" "$@" || exit
+ trap - EXIT
+ echo "The pair is up in network namespace ${XSK_NETNS}," \
+ "use ip netns exec ${XSK_NETNS};" \
+ "ip netns del ${XSK_NETNS} removes it"
+ exit 0
+ fi
+ validate_veth_support ${VETH0}
setup_vethPairs
retval=$?
--
2.43.0
More information about the Devel
mailing list