]>
Commit | Line | Data |
---|---|---|
996139e8 WT |
1 | #!/bin/sh |
2 | # Create 2 namespaces with two veth peers, and | |
3 | # forward packets in-between using generic XDP | |
4 | # | |
5 | # NS1(veth11) NS2(veth22) | |
6 | # | | | |
7 | # | | | |
8 | # (veth1, ------ (veth2, | |
9 | # id:111) id:222) | |
10 | # | xdp forwarding | | |
11 | # ------------------ | |
12 | ||
13 | cleanup() | |
14 | { | |
15 | if [ "$?" = "0" ]; then | |
16 | echo "selftests: test_xdp_redirect [PASS]"; | |
17 | else | |
18 | echo "selftests: test_xdp_redirect [FAILED]"; | |
19 | fi | |
20 | ||
21 | set +e | |
7b4eb53d YS |
22 | ip link del veth1 2> /dev/null |
23 | ip link del veth2 2> /dev/null | |
996139e8 WT |
24 | ip netns del ns1 2> /dev/null |
25 | ip netns del ns2 2> /dev/null | |
26 | } | |
27 | ||
047dbb27 WT |
28 | ip link set dev lo xdpgeneric off 2>/dev/null > /dev/null |
29 | if [ $? -ne 0 ];then | |
30 | echo "selftests: [SKIP] Could not run test without the ip xdpgeneric support" | |
31 | exit 0 | |
32 | fi | |
996139e8 WT |
33 | set -e |
34 | ||
35 | ip netns add ns1 | |
36 | ip netns add ns2 | |
37 | ||
38 | trap cleanup 0 2 3 6 9 | |
39 | ||
40 | ip link add veth1 index 111 type veth peer name veth11 | |
41 | ip link add veth2 index 222 type veth peer name veth22 | |
42 | ||
43 | ip link set veth11 netns ns1 | |
44 | ip link set veth22 netns ns2 | |
45 | ||
46 | ip link set veth1 up | |
47 | ip link set veth2 up | |
48 | ||
49 | ip netns exec ns1 ip addr add 10.1.1.11/24 dev veth11 | |
50 | ip netns exec ns2 ip addr add 10.1.1.22/24 dev veth22 | |
51 | ||
52 | ip netns exec ns1 ip link set dev veth11 up | |
53 | ip netns exec ns2 ip link set dev veth22 up | |
54 | ||
55 | ip link set dev veth1 xdpgeneric obj test_xdp_redirect.o sec redirect_to_222 | |
56 | ip link set dev veth2 xdpgeneric obj test_xdp_redirect.o sec redirect_to_111 | |
57 | ||
58 | ip netns exec ns1 ping -c 1 10.1.1.22 | |
59 | ip netns exec ns2 ping -c 1 10.1.1.11 | |
60 | ||
61 | exit 0 |