blob: 226f45381b7690acfb16a3fc3d662f710cc5e436 [file] [log] [blame]
William Tu6afb1e22016-08-19 11:55:44 -07001#!/bin/bash
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01002# SPDX-License-Identifier: GPL-2.0
William Tu6afb1e22016-08-19 11:55:44 -07003# 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
7
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
12
William Tu6afb1e22016-08-19 11:55:44 -070013function config_device {
14 ip netns add at_ns0
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
Alexei Starovoitova1c82702016-09-15 13:00:31 -070019 ip link set dev veth1 up mtu 1500
William Tu6afb1e22016-08-19 11:55:44 -070020 ip addr add dev veth1 172.16.1.200/24
21}
22
23function add_gre_tunnel {
24 # in namespace
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
29
30 # out of namespace
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
34}
35
William Tu56ddd302017-12-01 15:26:10 -080036function add_ip6gretap_tunnel {
37
38 # assign ipv6 address
39 ip netns exec at_ns0 ip addr add ::11/96 dev veth0
40 ip netns exec at_ns0 ip link set dev veth0 up
41 ip addr add dev veth1 ::22/96
42 ip link set dev veth1 up
43
44 # in namespace
45 ip netns exec at_ns0 \
46 ip link add dev $DEV_NS type $TYPE flowlabel 0xbcdef key 2 \
47 local ::11 remote ::22
48
49 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
50 ip netns exec at_ns0 ip addr add dev $DEV_NS fc80::100/96
51 ip netns exec at_ns0 ip link set dev $DEV_NS up
52
53 # out of namespace
54 ip link add dev $DEV type $TYPE external
55 ip addr add dev $DEV 10.1.1.200/24
56 ip addr add dev $DEV fc80::200/24
57 ip link set dev $DEV up
58}
59
William Tuef88f892017-08-25 09:21:29 -070060function add_erspan_tunnel {
61 # in namespace
62 ip netns exec at_ns0 \
63 ip link add dev $DEV_NS type $TYPE seq key 2 local 172.16.1.100 remote 172.16.1.200 erspan 123
64 ip netns exec at_ns0 ip link set dev $DEV_NS up
65 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
66
67 # out of namespace
68 ip link add dev $DEV type $TYPE external
69 ip link set dev $DEV up
70 ip addr add dev $DEV 10.1.1.200/24
71}
72
William Tu6afb1e22016-08-19 11:55:44 -070073function add_vxlan_tunnel {
74 # Set static ARP entry here because iptables set-mark works
75 # on L3 packet, as a result not applying to ARP packets,
76 # causing errors at get_tunnel_{key/opt}.
77
78 # in namespace
79 ip netns exec at_ns0 \
80 ip link add dev $DEV_NS type $TYPE id 2 dstport 4789 gbp remote 172.16.1.200
81 ip netns exec at_ns0 ip link set dev $DEV_NS address 52:54:00:d9:01:00 up
82 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
83 ip netns exec at_ns0 arp -s 10.1.1.200 52:54:00:d9:02:00
84 ip netns exec at_ns0 iptables -A OUTPUT -j MARK --set-mark 0x800FF
85
86 # out of namespace
87 ip link add dev $DEV type $TYPE external gbp dstport 4789
88 ip link set dev $DEV address 52:54:00:d9:02:00 up
89 ip addr add dev $DEV 10.1.1.200/24
90 arp -s 10.1.1.100 52:54:00:d9:01:00
91}
92
93function add_geneve_tunnel {
94 # in namespace
95 ip netns exec at_ns0 \
96 ip link add dev $DEV_NS type $TYPE id 2 dstport 6081 remote 172.16.1.200
97 ip netns exec at_ns0 ip link set dev $DEV_NS up
98 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
99
100 # out of namespace
101 ip link add dev $DEV type $TYPE dstport 6081 external
102 ip link set dev $DEV up
103 ip addr add dev $DEV 10.1.1.200/24
104}
105
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700106function add_ipip_tunnel {
107 # in namespace
108 ip netns exec at_ns0 \
109 ip link add dev $DEV_NS type $TYPE local 172.16.1.100 remote 172.16.1.200
110 ip netns exec at_ns0 ip link set dev $DEV_NS up
111 ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
112
113 # out of namespace
114 ip link add dev $DEV type $TYPE external
115 ip link set dev $DEV up
116 ip addr add dev $DEV 10.1.1.200/24
117}
118
William Tu6afb1e22016-08-19 11:55:44 -0700119function attach_bpf {
120 DEV=$1
121 SET_TUNNEL=$2
122 GET_TUNNEL=$3
123 tc qdisc add dev $DEV clsact
124 tc filter add dev $DEV egress bpf da obj tcbpf2_kern.o sec $SET_TUNNEL
125 tc filter add dev $DEV ingress bpf da obj tcbpf2_kern.o sec $GET_TUNNEL
126}
127
128function test_gre {
129 TYPE=gretap
130 DEV_NS=gretap00
131 DEV=gretap11
132 config_device
133 add_gre_tunnel
134 attach_bpf $DEV gre_set_tunnel gre_get_tunnel
135 ping -c 1 10.1.1.100
136 ip netns exec at_ns0 ping -c 1 10.1.1.200
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700137 cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700138}
139
William Tu56ddd302017-12-01 15:26:10 -0800140function test_ip6gre {
141 TYPE=ip6gre
142 DEV_NS=ip6gre00
143 DEV=ip6gre11
144 config_device
145 # reuse the ip6gretap function
146 add_ip6gretap_tunnel
147 attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
148 # underlay
149 ping6 -c 4 ::11
150 # overlay: ipv4 over ipv6
151 ip netns exec at_ns0 ping -c 1 10.1.1.200
152 ping -c 1 10.1.1.100
153 # overlay: ipv6 over ipv6
154 ip netns exec at_ns0 ping6 -c 1 fc80::200
155 cleanup
156}
157
158function test_ip6gretap {
159 TYPE=ip6gretap
160 DEV_NS=ip6gretap00
161 DEV=ip6gretap11
162 config_device
163 add_ip6gretap_tunnel
164 attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
165 # underlay
166 ping6 -c 4 ::11
167 # overlay: ipv4 over ipv6
168 ip netns exec at_ns0 ping -i .2 -c 1 10.1.1.200
169 ping -c 1 10.1.1.100
170 # overlay: ipv6 over ipv6
171 ip netns exec at_ns0 ping6 -c 1 fc80::200
172 cleanup
173}
174
William Tuef88f892017-08-25 09:21:29 -0700175function test_erspan {
176 TYPE=erspan
177 DEV_NS=erspan00
178 DEV=erspan11
179 config_device
180 add_erspan_tunnel
181 attach_bpf $DEV erspan_set_tunnel erspan_get_tunnel
182 ping -c 1 10.1.1.100
183 ip netns exec at_ns0 ping -c 1 10.1.1.200
184 cleanup
185}
186
William Tu6afb1e22016-08-19 11:55:44 -0700187function test_vxlan {
188 TYPE=vxlan
189 DEV_NS=vxlan00
190 DEV=vxlan11
191 config_device
192 add_vxlan_tunnel
193 attach_bpf $DEV vxlan_set_tunnel vxlan_get_tunnel
194 ping -c 1 10.1.1.100
195 ip netns exec at_ns0 ping -c 1 10.1.1.200
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700196 cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700197}
198
199function test_geneve {
200 TYPE=geneve
201 DEV_NS=geneve00
202 DEV=geneve11
203 config_device
204 add_geneve_tunnel
205 attach_bpf $DEV geneve_set_tunnel geneve_get_tunnel
206 ping -c 1 10.1.1.100
207 ip netns exec at_ns0 ping -c 1 10.1.1.200
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700208 cleanup
209}
210
211function test_ipip {
212 TYPE=ipip
213 DEV_NS=ipip00
214 DEV=ipip11
215 config_device
216 tcpdump -nei veth1 &
217 cat /sys/kernel/debug/tracing/trace_pipe &
218 add_ipip_tunnel
219 ethtool -K veth1 gso off gro off rx off tx off
220 ip link set dev veth1 mtu 1500
221 attach_bpf $DEV ipip_set_tunnel ipip_get_tunnel
222 ping -c 1 10.1.1.100
223 ip netns exec at_ns0 ping -c 1 10.1.1.200
224 ip netns exec at_ns0 iperf -sD -p 5200 > /dev/null
225 sleep 0.2
226 iperf -c 10.1.1.100 -n 5k -p 5200
227 cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700228}
229
230function cleanup {
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700231 set +ex
232 pkill iperf
William Tu6afb1e22016-08-19 11:55:44 -0700233 ip netns delete at_ns0
234 ip link del veth1
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700235 ip link del ipip11
236 ip link del gretap11
William Tu56ddd302017-12-01 15:26:10 -0800237 ip link del ip6gre11
238 ip link del ip6gretap11
William Tucc75f852017-07-31 14:40:50 -0700239 ip link del vxlan11
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700240 ip link del geneve11
William Tuef88f892017-08-25 09:21:29 -0700241 ip link del erspan11
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700242 pkill tcpdump
243 pkill cat
244 set -ex
William Tu6afb1e22016-08-19 11:55:44 -0700245}
246
William Tuef88f892017-08-25 09:21:29 -0700247trap cleanup 0 2 3 6 9
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700248cleanup
William Tu6afb1e22016-08-19 11:55:44 -0700249echo "Testing GRE tunnel..."
250test_gre
William Tu56ddd302017-12-01 15:26:10 -0800251echo "Testing IP6GRE tunnel..."
252test_ip6gre
253echo "Testing IP6GRETAP tunnel..."
254test_ip6gretap
William Tuef88f892017-08-25 09:21:29 -0700255echo "Testing ERSPAN tunnel..."
256test_erspan
William Tu6afb1e22016-08-19 11:55:44 -0700257echo "Testing VXLAN tunnel..."
258test_vxlan
William Tu6afb1e22016-08-19 11:55:44 -0700259echo "Testing GENEVE tunnel..."
260test_geneve
Alexei Starovoitova1c82702016-09-15 13:00:31 -0700261echo "Testing IPIP tunnel..."
262test_ipip
263echo "*** PASS ***"