xref: /linux/tools/testing/selftests/bpf/test_xdp_meta.sh (revision dec1c62e91ba268ab2a6e339d4d7a59287d5eba1)
1#!/bin/sh
2
3# Kselftest framework requirement - SKIP code is 4.
4readonly KSFT_SKIP=4
5readonly NS1="ns1-$(mktemp -u XXXXXX)"
6readonly NS2="ns2-$(mktemp -u XXXXXX)"
7
8cleanup()
9{
10	if [ "$?" = "0" ]; then
11		echo "selftests: test_xdp_meta [PASS]";
12	else
13		echo "selftests: test_xdp_meta [FAILED]";
14	fi
15
16	set +e
17	ip link del veth1 2> /dev/null
18	ip netns del ${NS1} 2> /dev/null
19	ip netns del ${NS2} 2> /dev/null
20}
21
22ip link set dev lo xdp off 2>/dev/null > /dev/null
23if [ $? -ne 0 ];then
24	echo "selftests: [SKIP] Could not run test without the ip xdp support"
25	exit $KSFT_SKIP
26fi
27set -e
28
29ip netns add ${NS1}
30ip netns add ${NS2}
31
32trap cleanup 0 2 3 6 9
33
34ip link add veth1 type veth peer name veth2
35
36ip link set veth1 netns ${NS1}
37ip link set veth2 netns ${NS2}
38
39ip netns exec ${NS1} ip addr add 10.1.1.11/24 dev veth1
40ip netns exec ${NS2} ip addr add 10.1.1.22/24 dev veth2
41
42ip netns exec ${NS1} tc qdisc add dev veth1 clsact
43ip netns exec ${NS2} tc qdisc add dev veth2 clsact
44
45ip netns exec ${NS1} tc filter add dev veth1 ingress bpf da obj test_xdp_meta.o sec t
46ip netns exec ${NS2} tc filter add dev veth2 ingress bpf da obj test_xdp_meta.o sec t
47
48ip netns exec ${NS1} ip link set dev veth1 xdp obj test_xdp_meta.o sec x
49ip netns exec ${NS2} ip link set dev veth2 xdp obj test_xdp_meta.o sec x
50
51ip netns exec ${NS1} ip link set dev veth1 up
52ip netns exec ${NS2} ip link set dev veth2 up
53
54ip netns exec ${NS1} ping -c 1 10.1.1.22
55ip netns exec ${NS2} ping -c 1 10.1.1.11
56
57exit 0
58