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 seq key
2 \
27 local 172.16.1.100 remote
172.16.1.200
28 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
29 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
32 ip link add dev
$DEV type $TYPE key
2 external
33 ip link
set dev
$DEV up
34 ip addr add dev
$DEV 10.1.1.200/24
37 function add_ip6gretap_tunnel
{
40 ip netns
exec at_ns0 ip addr add
::11/96 dev veth0
41 ip netns
exec at_ns0 ip link
set dev veth0 up
42 ip addr add dev veth1
::22/96
43 ip link
set dev veth1 up
46 ip netns
exec at_ns0 \
47 ip link add dev
$DEV_NS type $TYPE seq flowlabel
0xbcdef key
2 \
48 local ::11 remote
::22
50 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
51 ip netns
exec at_ns0 ip addr add dev
$DEV_NS fc80
::100/96
52 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
55 ip link add dev
$DEV type $TYPE external
56 ip addr add dev
$DEV 10.1.1.200/24
57 ip addr add dev
$DEV fc80
::200/24
58 ip link
set dev
$DEV up
61 function add_erspan_tunnel
{
63 if [ "$1" == "v1" ]; then
64 ip netns
exec at_ns0 \
65 ip link add dev
$DEV_NS type $TYPE seq key
2 \
66 local 172.16.1.100 remote
172.16.1.200 \
67 erspan_ver
1 erspan
123
69 ip netns
exec at_ns0 \
70 ip link add dev
$DEV_NS type $TYPE seq key
2 \
71 local 172.16.1.100 remote
172.16.1.200 \
72 erspan_ver
2 erspan_dir egress erspan_hwid
3
74 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
75 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
78 ip link add dev
$DEV type $TYPE external
79 ip link
set dev
$DEV up
80 ip addr add dev
$DEV 10.1.1.200/24
83 function add_ip6erspan_tunnel
{
86 ip netns
exec at_ns0 ip addr add
::11/96 dev veth0
87 ip netns
exec at_ns0 ip link
set dev veth0 up
88 ip addr add dev veth1
::22/96
89 ip link
set dev veth1 up
92 if [ "$1" == "v1" ]; then
93 ip netns
exec at_ns0 \
94 ip link add dev
$DEV_NS type $TYPE seq key
2 \
95 local ::11 remote
::22 \
96 erspan_ver
1 erspan
123
98 ip netns
exec at_ns0 \
99 ip link add dev
$DEV_NS type $TYPE seq key
2 \
100 local ::11 remote
::22 \
101 erspan_ver
2 erspan_dir egress erspan_hwid
7
103 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
104 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
107 ip link add dev
$DEV type $TYPE external
108 ip addr add dev
$DEV 10.1.1.200/24
109 ip link
set dev
$DEV up
112 function add_vxlan_tunnel
{
113 # Set static ARP entry here because iptables set-mark works
114 # on L3 packet, as a result not applying to ARP packets,
115 # causing errors at get_tunnel_{key/opt}.
118 ip netns
exec at_ns0 \
119 ip link add dev
$DEV_NS type $TYPE id
2 dstport
4789 gbp remote
172.16.1.200
120 ip netns
exec at_ns0 ip link
set dev
$DEV_NS address
52:54:00:d9
:01:00 up
121 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
122 ip netns
exec at_ns0 arp
-s 10.1.1.200 52:54:00:d9
:02:00
123 ip netns
exec at_ns0 iptables
-A OUTPUT
-j MARK
--set-mark 0x800FF
126 ip link add dev
$DEV type $TYPE external gbp dstport
4789
127 ip link
set dev
$DEV address
52:54:00:d9
:02:00 up
128 ip addr add dev
$DEV 10.1.1.200/24
129 arp
-s 10.1.1.100 52:54:00:d9
:01:00
132 function add_geneve_tunnel
{
134 ip netns
exec at_ns0 \
135 ip link add dev
$DEV_NS type $TYPE id
2 dstport
6081 remote
172.16.1.200
136 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
137 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
140 ip link add dev
$DEV type $TYPE dstport
6081 external
141 ip link
set dev
$DEV up
142 ip addr add dev
$DEV 10.1.1.200/24
145 function add_ipip_tunnel
{
147 ip netns
exec at_ns0 \
148 ip link add dev
$DEV_NS type $TYPE local 172.16.1.100 remote
172.16.1.200
149 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
150 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
153 ip link add dev
$DEV type $TYPE external
154 ip link
set dev
$DEV up
155 ip addr add dev
$DEV 10.1.1.200/24
158 function attach_bpf
{
162 tc qdisc add dev
$DEV clsact
163 tc filter add dev
$DEV egress bpf da obj tcbpf2_kern.o sec
$SET_TUNNEL
164 tc filter add dev
$DEV ingress bpf da obj tcbpf2_kern.o sec
$GET_TUNNEL
173 attach_bpf
$DEV gre_set_tunnel gre_get_tunnel
175 ip netns
exec at_ns0
ping -c 1 10.1.1.200
179 function test_ip6gre
{
184 # reuse the ip6gretap function
186 attach_bpf
$DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
189 # overlay: ipv4 over ipv6
190 ip netns
exec at_ns0
ping -c 1 10.1.1.200
192 # overlay: ipv6 over ipv6
193 ip netns
exec at_ns0 ping6
-c 1 fc80
::200
197 function test_ip6gretap
{
203 attach_bpf
$DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
206 # overlay: ipv4 over ipv6
207 ip netns
exec at_ns0
ping -i .2 -c 1 10.1.1.200
209 # overlay: ipv6 over ipv6
210 ip netns
exec at_ns0 ping6
-c 1 fc80
::200
214 function test_erspan
{
220 attach_bpf
$DEV erspan_set_tunnel erspan_get_tunnel
222 ip netns
exec at_ns0
ping -c 1 10.1.1.200
226 function test_ip6erspan
{
231 add_ip6erspan_tunnel
$1
232 attach_bpf
$DEV ip4ip6erspan_set_tunnel ip4ip6erspan_get_tunnel
234 ip netns
exec at_ns0
ping -c 1 10.1.1.200
238 function test_vxlan
{
244 attach_bpf
$DEV vxlan_set_tunnel vxlan_get_tunnel
246 ip netns
exec at_ns0
ping -c 1 10.1.1.200
250 function test_geneve
{
256 attach_bpf
$DEV geneve_set_tunnel geneve_get_tunnel
258 ip netns
exec at_ns0
ping -c 1 10.1.1.200
268 cat /sys
/kernel
/debug
/tracing
/trace_pipe
&
270 ethtool
-K veth1 gso off gro off rx off tx off
271 ip link
set dev veth1 mtu
1500
272 attach_bpf
$DEV ipip_set_tunnel ipip_get_tunnel
274 ip netns
exec at_ns0
ping -c 1 10.1.1.200
275 ip netns
exec at_ns0 iperf
-sD -p 5200 > /dev
/null
277 iperf
-c 10.1.1.100 -n 5k
-p 5200
284 ip netns delete at_ns0
289 ip link del ip6gretap11
293 ip link del ip6erspan11
299 trap cleanup
0 2 3 6 9
301 echo "Testing GRE tunnel..."
303 echo "Testing IP6GRE tunnel..."
305 echo "Testing IP6GRETAP tunnel..."
307 echo "Testing ERSPAN tunnel..."
310 echo "Testing IP6ERSPAN tunnel..."
313 echo "Testing VXLAN tunnel..."
315 echo "Testing GENEVE tunnel..."
317 echo "Testing IPIP tunnel..."