staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / bpf / test_xdp_veth.sh
blobba8ffcdaac3028e5e947b93aa88b74ff1af0b747
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
4 # Create 3 namespaces with 3 veth peers, and
5 # forward packets in-between using native XDP
7 # XDP_TX
8 # NS1(veth11) NS2(veth22) NS3(veth33)
9 # | | |
10 # | | |
11 # (veth1, (veth2, (veth3,
12 # id:111) id:122) id:133)
13 # ^ | ^ | ^ |
14 # | | XDP_REDIRECT | | XDP_REDIRECT | |
15 # | ------------------ ------------------ |
16 # -----------------------------------------
17 # XDP_REDIRECT
19 # Kselftest framework requirement - SKIP code is 4.
20 ksft_skip=4
22 TESTNAME=xdp_veth
23 BPF_FS=$(awk '$3 == "bpf" {print $2; exit}' /proc/mounts)
24 BPF_DIR=$BPF_FS/test_$TESTNAME
26 _cleanup()
28 set +e
29 ip link del veth1 2> /dev/null
30 ip link del veth2 2> /dev/null
31 ip link del veth3 2> /dev/null
32 ip netns del ns1 2> /dev/null
33 ip netns del ns2 2> /dev/null
34 ip netns del ns3 2> /dev/null
35 rm -rf $BPF_DIR 2> /dev/null
38 cleanup_skip()
40 echo "selftests: $TESTNAME [SKIP]"
41 _cleanup
43 exit $ksft_skip
46 cleanup()
48 if [ "$?" = 0 ]; then
49 echo "selftests: $TESTNAME [PASS]"
50 else
51 echo "selftests: $TESTNAME [FAILED]"
53 _cleanup
56 if [ $(id -u) -ne 0 ]; then
57 echo "selftests: $TESTNAME [SKIP] Need root privileges"
58 exit $ksft_skip
61 if ! ip link set dev lo xdp off > /dev/null 2>&1; then
62 echo "selftests: $TESTNAME [SKIP] Could not run test without the ip xdp support"
63 exit $ksft_skip
66 if [ -z "$BPF_FS" ]; then
67 echo "selftests: $TESTNAME [SKIP] Could not run test without bpffs mounted"
68 exit $ksft_skip
71 if ! bpftool version > /dev/null 2>&1; then
72 echo "selftests: $TESTNAME [SKIP] Could not run test without bpftool"
73 exit $ksft_skip
76 set -e
78 trap cleanup_skip EXIT
80 ip netns add ns1
81 ip netns add ns2
82 ip netns add ns3
84 ip link add veth1 index 111 type veth peer name veth11 netns ns1
85 ip link add veth2 index 122 type veth peer name veth22 netns ns2
86 ip link add veth3 index 133 type veth peer name veth33 netns ns3
88 ip link set veth1 up
89 ip link set veth2 up
90 ip link set veth3 up
92 ip -n ns1 addr add 10.1.1.11/24 dev veth11
93 ip -n ns3 addr add 10.1.1.33/24 dev veth33
95 ip -n ns1 link set dev veth11 up
96 ip -n ns2 link set dev veth22 up
97 ip -n ns3 link set dev veth33 up
99 mkdir $BPF_DIR
100 bpftool prog loadall \
101 xdp_redirect_map.o $BPF_DIR/progs type xdp \
102 pinmaps $BPF_DIR/maps
103 bpftool map update pinned $BPF_DIR/maps/tx_port key 0 0 0 0 value 122 0 0 0
104 bpftool map update pinned $BPF_DIR/maps/tx_port key 1 0 0 0 value 133 0 0 0
105 bpftool map update pinned $BPF_DIR/maps/tx_port key 2 0 0 0 value 111 0 0 0
106 ip link set dev veth1 xdp pinned $BPF_DIR/progs/redirect_map_0
107 ip link set dev veth2 xdp pinned $BPF_DIR/progs/redirect_map_1
108 ip link set dev veth3 xdp pinned $BPF_DIR/progs/redirect_map_2
110 ip -n ns1 link set dev veth11 xdp obj xdp_dummy.o sec xdp_dummy
111 ip -n ns2 link set dev veth22 xdp obj xdp_tx.o sec tx
112 ip -n ns3 link set dev veth33 xdp obj xdp_dummy.o sec xdp_dummy
114 trap cleanup EXIT
116 ip netns exec ns1 ping -c 1 -W 1 10.1.1.33
118 exit 0