Commit 4ec25b49 authored by Hangbin Liu's avatar Hangbin Liu Committed by Alexei Starovoitov

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: default avatarHangbin Liu <liuhangbin@gmail.com>
Acked-by: default avatarWilliam Tu <u9012063@gmail.com>
Link: https://lore.kernel.org/r/20220125081717.1260849-8-liuhangbin@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 36d9970e
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
# | xdp forwarding | # | xdp forwarding |
# ------------------ # ------------------
readonly NS1="ns1-$(mktemp -u XXXXXX)"
readonly NS2="ns2-$(mktemp -u XXXXXX)"
ret=0 ret=0
setup() setup()
...@@ -17,27 +19,27 @@ setup() ...@@ -17,27 +19,27 @@ setup()
local xdpmode=$1 local xdpmode=$1
ip netns add ns1 ip netns add ${NS1}
ip netns add ns2 ip netns add ${NS2}
ip link add veth1 index 111 type veth peer name veth11 netns ns1 ip link add veth1 index 111 type veth peer name veth11 netns ${NS1}
ip link add veth2 index 222 type veth peer name veth22 netns ns2 ip link add veth2 index 222 type veth peer name veth22 netns ${NS2}
ip link set veth1 up ip link set veth1 up
ip link set veth2 up ip link set veth2 up
ip -n ns1 link set dev veth11 up ip -n ${NS1} link set dev veth11 up
ip -n ns2 link set dev veth22 up ip -n ${NS2} link set dev veth22 up
ip -n ns1 addr add 10.1.1.11/24 dev veth11 ip -n ${NS1} addr add 10.1.1.11/24 dev veth11
ip -n ns2 addr add 10.1.1.22/24 dev veth22 ip -n ${NS2} addr add 10.1.1.22/24 dev veth22
} }
cleanup() cleanup()
{ {
ip link del veth1 2> /dev/null ip link del veth1 2> /dev/null
ip link del veth2 2> /dev/null ip link del veth2 2> /dev/null
ip netns del ns1 2> /dev/null ip netns del ${NS1} 2> /dev/null
ip netns del ns2 2> /dev/null ip netns del ${NS2} 2> /dev/null
} }
test_xdp_redirect() test_xdp_redirect()
...@@ -52,13 +54,13 @@ test_xdp_redirect() ...@@ -52,13 +54,13 @@ test_xdp_redirect()
return 0 return 0
fi fi
ip -n ns1 link set veth11 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null ip -n ${NS1} link set veth11 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null
ip -n ns2 link set veth22 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null ip -n ${NS2} link set veth22 $xdpmode obj xdp_dummy.o sec xdp &> /dev/null
ip link set dev veth1 $xdpmode obj test_xdp_redirect.o sec redirect_to_222 &> /dev/null ip link set dev veth1 $xdpmode obj test_xdp_redirect.o sec redirect_to_222 &> /dev/null
ip link set dev veth2 $xdpmode obj test_xdp_redirect.o sec redirect_to_111 &> /dev/null ip link set dev veth2 $xdpmode obj test_xdp_redirect.o sec redirect_to_111 &> /dev/null
if ip netns exec ns1 ping -c 1 10.1.1.22 &> /dev/null && if ip netns exec ${NS1} ping -c 1 10.1.1.22 &> /dev/null &&
ip netns exec ns2 ping -c 1 10.1.1.11 &> /dev/null; then ip netns exec ${NS2} ping -c 1 10.1.1.11 &> /dev/null; then
echo "selftests: test_xdp_redirect $xdpmode [PASS]"; echo "selftests: test_xdp_redirect $xdpmode [PASS]";
else else
ret=1 ret=1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment