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

selftests/bpf/test_xdp_redirect: use temp netns for testing

Use temp netns instead of hard code name for testing in case the
netns already exists.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Acked-by: William Tu <u9012063@gmail.com>
Link: https://lore.kernel.org/r/20220125081717.1260849-8-liuhangbin@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Hangbin Liu and committed by
Alexei Starovoitov
4ec25b49 36d9970e

+16 -14
+16 -14
tools/testing/selftests/bpf/test_xdp_redirect.sh
··· 10 10 # | xdp forwarding | 11 11 # ------------------ 12 12 13 + readonly NS1="ns1-$(mktemp -u XXXXXX)" 14 + readonly NS2="ns2-$(mktemp -u XXXXXX)" 13 15 ret=0 14 16 15 17 setup() ··· 19 17 20 18 local xdpmode=$1 21 19 22 - ip netns add ns1 23 - ip netns add ns2 20 + ip netns add ${NS1} 21 + ip netns add ${NS2} 24 22 25 - ip link add veth1 index 111 type veth peer name veth11 netns ns1 26 - ip link add veth2 index 222 type veth peer name veth22 netns ns2 23 + ip link add veth1 index 111 type veth peer name veth11 netns ${NS1} 24 + ip link add veth2 index 222 type veth peer name veth22 netns ${NS2} 27 25 28 26 ip link set veth1 up 29 27 ip link set veth2 up 30 - ip -n ns1 link set dev veth11 up 31 - ip -n ns2 link set dev veth22 up 28 + ip -n ${NS1} link set dev veth11 up 29 + ip -n ${NS2} link set dev veth22 up 32 30 33 - ip -n ns1 addr add 10.1.1.11/24 dev veth11 34 - ip -n ns2 addr add 10.1.1.22/24 dev veth22 31 + ip -n ${NS1} addr add 10.1.1.11/24 dev veth11 32 + ip -n ${NS2} addr add 10.1.1.22/24 dev veth22 35 33 } 36 34 37 35 cleanup() 38 36 { 39 37 ip link del veth1 2> /dev/null 40 38 ip link del veth2 2> /dev/null 41 - ip netns del ns1 2> /dev/null 42 - ip netns del ns2 2> /dev/null 39 + ip netns del ${NS1} 2> /dev/null 40 + ip netns del ${NS2} 2> /dev/null 43 41 } 44 42 45 43 test_xdp_redirect() ··· 54 52 return 0 55 53 fi 56 54 57 - ip -n ns1 link set veth11 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null 58 - ip -n ns2 link set veth22 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null 55 + ip -n ${NS1} link set veth11 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null 56 + ip -n ${NS2} link set veth22 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null 59 57 ip link set dev veth1 $xdpmode obj test_xdp_redirect.o sec redirect_to_222 &> /dev/null 60 58 ip link set dev veth2 $xdpmode obj test_xdp_redirect.o sec redirect_to_111 &> /dev/null 61 59 62 - if ip netns exec ns1 ping -c 1 10.1.1.22 &> /dev/null && 63 - ip netns exec ns2 ping -c 1 10.1.1.11 &> /dev/null; then 60 + if ip netns exec ${NS1} ping -c 1 10.1.1.22 &> /dev/null && 61 + ip netns exec ${NS2} ping -c 1 10.1.1.11 &> /dev/null; then 64 62 echo "selftests: test_xdp_redirect $xdpmode [PASS]"; 65 63 else 66 64 ret=1