2017-09-25 02:25:53 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-10-20 11:05:34 +08:00
|
|
|
BPF_FILE="test_xdp_meta.bpf.o"
|
2021-09-29 13:12:50 +08:00
|
|
|
# Kselftest framework requirement - SKIP code is 4.
|
|
|
|
readonly KSFT_SKIP=4
|
2022-01-25 16:17:16 +08:00
|
|
|
readonly NS1="ns1-$(mktemp -u XXXXXX)"
|
|
|
|
readonly NS2="ns2-$(mktemp -u XXXXXX)"
|
2021-09-29 13:12:50 +08:00
|
|
|
|
2017-09-25 02:25:53 +02:00
|
|
|
cleanup()
|
|
|
|
{
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
echo "selftests: test_xdp_meta [PASS]";
|
|
|
|
else
|
|
|
|
echo "selftests: test_xdp_meta [FAILED]";
|
|
|
|
fi
|
|
|
|
|
|
|
|
set +e
|
tools/bpf: fix batch-mode test failure of test_xdp_redirect.sh
The tests at tools/testing/selftests/bpf can run in patch mode, e.g.,
make -C tools/testing/selftests/bpf run_tests
With the batch mode, I experimented intermittent test failure of
test_xdp_redirect.sh.
....
selftests: test_xdp_redirect [PASS]
selftests: test_xdp_redirect.sh [PASS]
RTNETLINK answers: File exists
selftests: test_xdp_meta [FAILED]
selftests: test_xdp_meta.sh [FAIL]
....
The following illustrates what caused the failure:
(1). test_xdp_redirect creates veth pairs (veth1,veth11) and
(veth2,veth22), and assign veth11 and veth22 to namespace
ns1 and ns2 respectively.
(2). at the end of test_xdp_redirect test, ns1 and ns2 are
deleted. During this process, the deletion of actual
namespace resources, including deletion of veth1{1} and veth2{2},
is put into a workqueue to be processed asynchronously.
(3). test_xdp_meta tries to create veth pair (veth1, veth2).
The previous veth deletions in step (2) have not finished yet,
and veth1 or veth2 may be still valid in the kernel, thus
causing the failure.
The fix is to explicitly delete the veth pair before test_xdp_redirect
exits. Only one end of veth needs deletion as the kernel will delete
the other end automatically. Also test_xdp_meta is also fixed in
similar manner to avoid future potential issues.
Fixes: 996139e801fd ("selftests: bpf: add a test for XDP redirect")
Fixes: 22c8852624fc ("bpf: improve selftests and add tests for meta pointer")
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-02-05 16:25:24 -08:00
|
|
|
ip link del veth1 2> /dev/null
|
2022-01-25 16:17:16 +08:00
|
|
|
ip netns del ${NS1} 2> /dev/null
|
|
|
|
ip netns del ${NS2} 2> /dev/null
|
2017-09-25 02:25:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ip link set dev lo xdp off 2>/dev/null > /dev/null
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
echo "selftests: [SKIP] Could not run test without the ip xdp support"
|
2021-09-29 13:12:50 +08:00
|
|
|
exit $KSFT_SKIP
|
2017-09-25 02:25:53 +02:00
|
|
|
fi
|
|
|
|
set -e
|
|
|
|
|
2022-01-25 16:17:16 +08:00
|
|
|
ip netns add ${NS1}
|
|
|
|
ip netns add ${NS2}
|
2017-09-25 02:25:53 +02:00
|
|
|
|
|
|
|
trap cleanup 0 2 3 6 9
|
|
|
|
|
|
|
|
ip link add veth1 type veth peer name veth2
|
|
|
|
|
2022-01-25 16:17:16 +08:00
|
|
|
ip link set veth1 netns ${NS1}
|
|
|
|
ip link set veth2 netns ${NS2}
|
2017-09-25 02:25:53 +02:00
|
|
|
|
2022-01-25 16:17:16 +08:00
|
|
|
ip netns exec ${NS1} ip addr add 10.1.1.11/24 dev veth1
|
|
|
|
ip netns exec ${NS2} ip addr add 10.1.1.22/24 dev veth2
|
2017-09-25 02:25:53 +02:00
|
|
|
|
2022-01-25 16:17:16 +08:00
|
|
|
ip netns exec ${NS1} tc qdisc add dev veth1 clsact
|
|
|
|
ip netns exec ${NS2} tc qdisc add dev veth2 clsact
|
2017-09-25 02:25:53 +02:00
|
|
|
|
2022-10-20 11:05:34 +08:00
|
|
|
ip netns exec ${NS1} tc filter add dev veth1 ingress bpf da obj ${BPF_FILE} sec t
|
|
|
|
ip netns exec ${NS2} tc filter add dev veth2 ingress bpf da obj ${BPF_FILE} sec t
|
2017-09-25 02:25:53 +02:00
|
|
|
|
2022-10-20 11:05:34 +08:00
|
|
|
ip netns exec ${NS1} ip link set dev veth1 xdp obj ${BPF_FILE} sec x
|
|
|
|
ip netns exec ${NS2} ip link set dev veth2 xdp obj ${BPF_FILE} sec x
|
2017-09-25 02:25:53 +02:00
|
|
|
|
2022-01-25 16:17:16 +08:00
|
|
|
ip netns exec ${NS1} ip link set dev veth1 up
|
|
|
|
ip netns exec ${NS2} ip link set dev veth2 up
|
2017-09-25 02:25:53 +02:00
|
|
|
|
2022-01-25 16:17:16 +08:00
|
|
|
ip netns exec ${NS1} ping -c 1 10.1.1.22
|
|
|
|
ip netns exec ${NS2} ping -c 1 10.1.1.11
|
2017-09-25 02:25:53 +02:00
|
|
|
|
|
|
|
exit 0
|