Commit 9d66c9dd authored by Hangbin Liu's avatar Hangbin Liu Committed by Alexei Starovoitov

selftests/bpf/test_xdp_veth: 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>
Link: https://lore.kernel.org/r/20220125081717.1260849-3-liuhangbin@gmail.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent cec74489
......@@ -22,6 +22,9 @@ ksft_skip=4
TESTNAME=xdp_veth
BPF_FS=$(awk '$3 == "bpf" {print $2; exit}' /proc/mounts)
BPF_DIR=$BPF_FS/test_$TESTNAME
readonly NS1="ns1-$(mktemp -u XXXXXX)"
readonly NS2="ns2-$(mktemp -u XXXXXX)"
readonly NS3="ns3-$(mktemp -u XXXXXX)"
_cleanup()
{
......@@ -29,9 +32,9 @@ _cleanup()
ip link del veth1 2> /dev/null
ip link del veth2 2> /dev/null
ip link del veth3 2> /dev/null
ip netns del ns1 2> /dev/null
ip netns del ns2 2> /dev/null
ip netns del ns3 2> /dev/null
ip netns del ${NS1} 2> /dev/null
ip netns del ${NS2} 2> /dev/null
ip netns del ${NS3} 2> /dev/null
rm -rf $BPF_DIR 2> /dev/null
}
......@@ -77,24 +80,24 @@ set -e
trap cleanup_skip EXIT
ip netns add ns1
ip netns add ns2
ip netns add ns3
ip netns add ${NS1}
ip netns add ${NS2}
ip netns add ${NS3}
ip link add veth1 index 111 type veth peer name veth11 netns ns1
ip link add veth2 index 122 type veth peer name veth22 netns ns2
ip link add veth3 index 133 type veth peer name veth33 netns ns3
ip link add veth1 index 111 type veth peer name veth11 netns ${NS1}
ip link add veth2 index 122 type veth peer name veth22 netns ${NS2}
ip link add veth3 index 133 type veth peer name veth33 netns ${NS3}
ip link set veth1 up
ip link set veth2 up
ip link set veth3 up
ip -n ns1 addr add 10.1.1.11/24 dev veth11
ip -n ns3 addr add 10.1.1.33/24 dev veth33
ip -n ${NS1} addr add 10.1.1.11/24 dev veth11
ip -n ${NS3} addr add 10.1.1.33/24 dev veth33
ip -n ns1 link set dev veth11 up
ip -n ns2 link set dev veth22 up
ip -n ns3 link set dev veth33 up
ip -n ${NS1} link set dev veth11 up
ip -n ${NS2} link set dev veth22 up
ip -n ${NS3} link set dev veth33 up
mkdir $BPF_DIR
bpftool prog loadall \
......@@ -107,12 +110,12 @@ ip link set dev veth1 xdp pinned $BPF_DIR/progs/redirect_map_0
ip link set dev veth2 xdp pinned $BPF_DIR/progs/redirect_map_1
ip link set dev veth3 xdp pinned $BPF_DIR/progs/redirect_map_2
ip -n ns1 link set dev veth11 xdp obj xdp_dummy.o sec xdp
ip -n ns2 link set dev veth22 xdp obj xdp_tx.o sec xdp
ip -n ns3 link set dev veth33 xdp obj xdp_dummy.o sec xdp
ip -n ${NS1} link set dev veth11 xdp obj xdp_dummy.o sec xdp
ip -n ${NS2} link set dev veth22 xdp obj xdp_tx.o sec xdp
ip -n ${NS3} link set dev veth33 xdp obj xdp_dummy.o sec xdp
trap cleanup EXIT
ip netns exec ns1 ping -c 1 -W 1 10.1.1.33
ip netns exec ${NS1} ping -c 1 -W 1 10.1.1.33
exit 0
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