• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
13cleanup()
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
22	ip link del veth1 2> /dev/null
23	ip link del veth2 2> /dev/null
24	ip netns del ns1 2> /dev/null
25	ip netns del ns2 2> /dev/null
26}
27
28ip link set dev lo xdpgeneric off 2>/dev/null > /dev/null
29if [ $? -ne 0 ];then
30	echo "selftests: [SKIP] Could not run test without the ip xdpgeneric support"
31	exit 0
32fi
33set -e
34
35ip netns add ns1
36ip netns add ns2
37
38trap cleanup 0 2 3 6 9
39
40ip link add veth1 index 111 type veth peer name veth11
41ip link add veth2 index 222 type veth peer name veth22
42
43ip link set veth11 netns ns1
44ip link set veth22 netns ns2
45
46ip link set veth1 up
47ip link set veth2 up
48
49ip netns exec ns1 ip addr add 10.1.1.11/24 dev veth11
50ip netns exec ns2 ip addr add 10.1.1.22/24 dev veth22
51
52ip netns exec ns1 ip link set dev veth11 up
53ip netns exec ns2 ip link set dev veth22 up
54
55ip link set dev veth1 xdpgeneric obj test_xdp_redirect.o sec redirect_to_222
56ip link set dev veth2 xdpgeneric obj test_xdp_redirect.o sec redirect_to_111
57
58ip netns exec ns1 ping -c 1 10.1.1.22
59ip netns exec ns2 ping -c 1 10.1.1.11
60
61exit 0
62