2 # SPDX-License-Identifier: GPL-2.0
3 # In Namespace 0 (at_ns0) using native tunnel
4 # Overlay IP: 10.1.1.100
5 # local 192.16.1.100 remote 192.16.1.200
6 # veth0 IP: 172.16.1.100, tunnel dev <type>00
8 # Out of Namespace using BPF set/get on lwtunnel
9 # Overlay IP: 10.1.1.200
10 # local 172.16.1.200 remote 172.16.1.100
11 # veth1 IP: 172.16.1.200, tunnel dev <type>11
13 function config_device {
15 ip link add veth0 type veth peer name veth1
16 ip link set veth0 netns at_ns0
17 ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0
18 ip netns exec at_ns0 ip link set dev veth0 up
19 ip link set dev veth1 up mtu 1500
20 ip addr add dev veth1 172.16.1.200/24
23 function add_gre_tunnel {
25 ip netns exec at_ns0 \
26 ip link add dev $DEV_NS type $TYPE key 2 local 172.16.1.100 remote 172.16.1.200
27 ip netns exec at_ns0 ip link set dev $DEV_NS up
28 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
31 ip link add dev $DEV type $TYPE key 2 external
32 ip link set dev $DEV up
33 ip addr add dev $DEV 10.1.1.200/24
36 function add_erspan_tunnel {
38 ip netns exec at_ns0 \
39 ip link add dev $DEV_NS type $TYPE seq key 2 local 172.16.1.100 remote 172.16.1.200 erspan 123
40 ip netns exec at_ns0 ip link set dev $DEV_NS up
41 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
44 ip link add dev $DEV type $TYPE external
45 ip link set dev $DEV up
46 ip addr add dev $DEV 10.1.1.200/24
49 function add_vxlan_tunnel {
50 # Set static ARP entry here because iptables set-mark works
51 # on L3 packet, as a result not applying to ARP packets,
52 # causing errors at get_tunnel_{key/opt}.
55 ip netns exec at_ns0 \
56 ip link add dev $DEV_NS type $TYPE id 2 dstport 4789 gbp remote 172.16.1.200
57 ip netns exec at_ns0 ip link set dev $DEV_NS address 52:54:00:d9:01:00 up
58 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
59 ip netns exec at_ns0 arp -s 10.1.1.200 52:54:00:d9:02:00
60 ip netns exec at_ns0 iptables -A OUTPUT -j MARK --set-mark 0x800FF
63 ip link add dev $DEV type $TYPE external gbp dstport 4789
64 ip link set dev $DEV address 52:54:00:d9:02:00 up
65 ip addr add dev $DEV 10.1.1.200/24
66 arp -s 10.1.1.100 52:54:00:d9:01:00
69 function add_geneve_tunnel {
71 ip netns exec at_ns0 \
72 ip link add dev $DEV_NS type $TYPE id 2 dstport 6081 remote 172.16.1.200
73 ip netns exec at_ns0 ip link set dev $DEV_NS up
74 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
77 ip link add dev $DEV type $TYPE dstport 6081 external
78 ip link set dev $DEV up
79 ip addr add dev $DEV 10.1.1.200/24
82 function add_ipip_tunnel {
84 ip netns exec at_ns0 \
85 ip link add dev $DEV_NS type $TYPE local 172.16.1.100 remote 172.16.1.200
86 ip netns exec at_ns0 ip link set dev $DEV_NS up
87 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
90 ip link add dev $DEV type $TYPE external
91 ip link set dev $DEV up
92 ip addr add dev $DEV 10.1.1.200/24
99 tc qdisc add dev $DEV clsact
100 tc filter add dev $DEV egress bpf da obj tcbpf2_kern.o sec $SET_TUNNEL
101 tc filter add dev $DEV ingress bpf da obj tcbpf2_kern.o sec $GET_TUNNEL
110 attach_bpf $DEV gre_set_tunnel gre_get_tunnel
112 ip netns exec at_ns0 ping -c 1 10.1.1.200
116 function test_erspan {
122 attach_bpf $DEV erspan_set_tunnel erspan_get_tunnel
124 ip netns exec at_ns0 ping -c 1 10.1.1.200
128 function test_vxlan {
134 attach_bpf $DEV vxlan_set_tunnel vxlan_get_tunnel
136 ip netns exec at_ns0 ping -c 1 10.1.1.200
140 function test_geneve {
146 attach_bpf $DEV geneve_set_tunnel geneve_get_tunnel
148 ip netns exec at_ns0 ping -c 1 10.1.1.200
158 cat /sys/kernel/debug/tracing/trace_pipe &
160 ethtool -K veth1 gso off gro off rx off tx off
161 ip link set dev veth1 mtu 1500
162 attach_bpf $DEV ipip_set_tunnel ipip_get_tunnel
164 ip netns exec at_ns0 ping -c 1 10.1.1.200
165 ip netns exec at_ns0 iperf -sD -p 5200 > /dev/null
167 iperf -c 10.1.1.100 -n 5k -p 5200
174 ip netns delete at_ns0
186 trap cleanup 0 2 3 6 9
188 echo "Testing GRE tunnel..."
190 echo "Testing ERSPAN tunnel..."
192 echo "Testing VXLAN tunnel..."
194 echo "Testing GENEVE tunnel..."
196 echo "Testing IPIP tunnel..."