2 # SPDX-License-Identifier: GPL-2.0
4 # Create 3 namespaces with 3 veth peers, and
5 # forward packets in-between using native XDP
8 # NS1(veth11) NS2(veth22) NS3(veth33)
11 # (veth1, (veth2, (veth3,
12 # id:111) id:122) id:133)
14 # | | XDP_REDIRECT | | XDP_REDIRECT | |
15 # | ------------------ ------------------ |
16 # -----------------------------------------
19 # Kselftest framework requirement - SKIP code is 4.
23 BPF_FS
=$
(awk '$3 == "bpf" {print $2; exit}' /proc
/mounts
)
24 BPF_DIR
=$BPF_FS/test_
$TESTNAME
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
40 echo "selftests: $TESTNAME [SKIP]"
49 echo "selftests: $TESTNAME [PASS]"
51 echo "selftests: $TESTNAME [FAILED]"
56 if [ $
(id
-u) -ne 0 ]; then
57 echo "selftests: $TESTNAME [SKIP] Need root privileges"
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"
66 if [ -z "$BPF_FS" ]; then
67 echo "selftests: $TESTNAME [SKIP] Could not run test without bpffs mounted"
71 if ! bpftool version
> /dev
/null
2>&1; then
72 echo "selftests: $TESTNAME [SKIP] Could not run test without bpftool"
78 trap cleanup_skip EXIT
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
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
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
116 ip netns
exec ns1
ping -c 1 -W 1 10.1.1.33