2 # SPDX-License-Identifier: GPL-2.0
4 # End-to-end eBPF tunnel test suite
5 # The script tests BPF network tunnel implementation.
9 # root namespace | at_ns0 namespace
11 # ----------- | -----------
12 # | tnl dev | | | tnl dev | (overlay network)
13 # ----------- | -----------
14 # metadata-mode | native-mode
17 # ---------- | ----------
18 # | veth1 | --------- | veth0 | (underlay network)
19 # ---------- peer ----------
22 # Device Configuration
23 # --------------------
24 # Root namespace with metadata-mode tunnel + BPF
25 # Device names and addresses:
26 # veth1 IP: 172.16.1.200, IPv6: 00::22 (underlay)
27 # tunnel dev <type>11, ex: gre11, IPv4: 10.1.1.200, IPv6: 1::22 (overlay)
29 # Namespace at_ns0 with native tunnel
30 # Device names and addresses:
31 # veth0 IPv4: 172.16.1.100, IPv6: 00::11 (underlay)
32 # tunnel dev <type>00, ex: gre00, IPv4: 10.1.1.100, IPv6: 1::11 (overlay)
35 # End-to-end ping packet flow
36 # ---------------------------
37 # Most of the tests start by namespace creation, device configuration,
38 # then ping the underlay and overlay network. When doing 'ping 10.1.1.100'
39 # from root namespace, the following operations happen:
40 # 1) Route lookup shows 10.1.1.100/24 belongs to tnl dev, fwd to tnl dev.
41 # 2) Tnl device's egress BPF program is triggered and set the tunnel metadata,
42 # with remote_ip=172.16.1.200 and others.
43 # 3) Outer tunnel header is prepended and route the packet to veth1's egress
44 # 4) veth0's ingress queue receive the tunneled packet at namespace at_ns0
45 # 5) Tunnel protocol handler, ex: vxlan_rcv, decap the packet
46 # 6) Forward the packet to the overlay tnl dev
48 PING_ARG
="-c 3 -w 10 -q"
52 NC
='\033[0m' # No Color
57 ip link add veth0
type veth peer name veth1
58 ip link
set veth0 netns at_ns0
59 ip netns
exec at_ns0 ip addr add
172.16.1.100/24 dev veth0
60 ip netns
exec at_ns0 ip link
set dev veth0 up
61 ip link
set dev veth1 up mtu
1500
62 ip addr add dev veth1
172.16.1.200/24
68 ip netns
exec at_ns0 \
69 ip link add dev
$DEV_NS type $TYPE seq key
2 \
70 local 172.16.1.100 remote
172.16.1.200
71 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
72 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
75 ip link add dev
$DEV type $TYPE key
2 external
76 ip link
set dev
$DEV up
77 ip addr add dev
$DEV 10.1.1.200/24
80 add_ip6gretap_tunnel
()
84 ip netns
exec at_ns0 ip addr add
::11/96 dev veth0
85 ip netns
exec at_ns0 ip link
set dev veth0 up
86 ip addr add dev veth1
::22/96
87 ip link
set dev veth1 up
90 ip netns
exec at_ns0 \
91 ip link add dev
$DEV_NS type $TYPE seq flowlabel
0xbcdef key
2 \
92 local ::11 remote
::22
94 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
95 ip netns
exec at_ns0 ip addr add dev
$DEV_NS fc80
::100/96
96 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
99 ip link add dev
$DEV type $TYPE external
100 ip addr add dev
$DEV 10.1.1.200/24
101 ip addr add dev
$DEV fc80
::200/24
102 ip link
set dev
$DEV up
108 if [ "$1" == "v1" ]; then
109 ip netns
exec at_ns0 \
110 ip link add dev
$DEV_NS type $TYPE seq key
2 \
111 local 172.16.1.100 remote
172.16.1.200 \
112 erspan_ver
1 erspan
123
114 ip netns
exec at_ns0 \
115 ip link add dev
$DEV_NS type $TYPE seq key
2 \
116 local 172.16.1.100 remote
172.16.1.200 \
117 erspan_ver
2 erspan_dir egress erspan_hwid
3
119 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
120 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
123 ip link add dev
$DEV type $TYPE external
124 ip link
set dev
$DEV up
125 ip addr add dev
$DEV 10.1.1.200/24
128 add_ip6erspan_tunnel
()
131 # assign ipv6 address
132 ip netns
exec at_ns0 ip addr add
::11/96 dev veth0
133 ip netns
exec at_ns0 ip link
set dev veth0 up
134 ip addr add dev veth1
::22/96
135 ip link
set dev veth1 up
138 if [ "$1" == "v1" ]; then
139 ip netns
exec at_ns0 \
140 ip link add dev
$DEV_NS type $TYPE seq key
2 \
141 local ::11 remote
::22 \
142 erspan_ver
1 erspan
123
144 ip netns
exec at_ns0 \
145 ip link add dev
$DEV_NS type $TYPE seq key
2 \
146 local ::11 remote
::22 \
147 erspan_ver
2 erspan_dir egress erspan_hwid
7
149 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
150 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
153 ip link add dev
$DEV type $TYPE external
154 ip addr add dev
$DEV 10.1.1.200/24
155 ip link
set dev
$DEV up
160 # Set static ARP entry here because iptables set-mark works
161 # on L3 packet, as a result not applying to ARP packets,
162 # causing errors at get_tunnel_{key/opt}.
165 ip netns
exec at_ns0 \
166 ip link add dev
$DEV_NS type $TYPE \
167 id
2 dstport
4789 gbp remote
172.16.1.200
168 ip netns
exec at_ns0 \
169 ip link
set dev
$DEV_NS address
52:54:00:d9
:01:00 up
170 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
171 ip netns
exec at_ns0 arp
-s 10.1.1.200 52:54:00:d9
:02:00
172 ip netns
exec at_ns0 iptables
-A OUTPUT
-j MARK
--set-mark 0x800FF
175 ip link add dev
$DEV type $TYPE external gbp dstport
4789
176 ip link
set dev
$DEV address
52:54:00:d9
:02:00 up
177 ip addr add dev
$DEV 10.1.1.200/24
178 arp
-s 10.1.1.100 52:54:00:d9
:01:00
181 add_ip6vxlan_tunnel
()
183 #ip netns exec at_ns0 ip -4 addr del 172.16.1.100 dev veth0
184 ip netns
exec at_ns0 ip
-6 addr add
::11/96 dev veth0
185 ip netns
exec at_ns0 ip link
set dev veth0 up
186 #ip -4 addr del 172.16.1.200 dev veth1
187 ip
-6 addr add dev veth1
::22/96
188 ip link
set dev veth1 up
191 ip netns
exec at_ns0 \
192 ip link add dev
$DEV_NS type $TYPE id
22 dstport
4789 \
193 local ::11 remote
::22
194 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
195 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
198 ip link add dev
$DEV type $TYPE external dstport
4789
199 ip addr add dev
$DEV 10.1.1.200/24
200 ip link
set dev
$DEV up
206 ip netns
exec at_ns0 \
207 ip link add dev
$DEV_NS type $TYPE \
208 id
2 dstport
6081 remote
172.16.1.200
209 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
210 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
213 ip link add dev
$DEV type $TYPE dstport
6081 external
214 ip link
set dev
$DEV up
215 ip addr add dev
$DEV 10.1.1.200/24
218 add_ip6geneve_tunnel
()
220 ip netns
exec at_ns0 ip addr add
::11/96 dev veth0
221 ip netns
exec at_ns0 ip link
set dev veth0 up
222 ip addr add dev veth1
::22/96
223 ip link
set dev veth1 up
226 ip netns
exec at_ns0 \
227 ip link add dev
$DEV_NS type $TYPE id
22 \
228 remote
::22 # geneve has no local option
229 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
230 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
233 ip link add dev
$DEV type $TYPE external
234 ip addr add dev
$DEV 10.1.1.200/24
235 ip link
set dev
$DEV up
241 ip netns
exec at_ns0 \
242 ip link add dev
$DEV_NS type $TYPE \
243 local 172.16.1.100 remote
172.16.1.200
244 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
245 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
248 ip link add dev
$DEV type $TYPE external
249 ip link
set dev
$DEV up
250 ip addr add dev
$DEV 10.1.1.200/24
255 ip netns
exec at_ns0 ip addr add
::11/96 dev veth0
256 ip netns
exec at_ns0 ip link
set dev veth0 up
257 ip addr add dev veth1
::22/96
258 ip link
set dev veth1 up
261 ip netns
exec at_ns0 \
262 ip link add dev
$DEV_NS type $TYPE \
263 local ::11 remote
::22
264 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 10.1.1.100/24
265 ip netns
exec at_ns0 ip addr add dev
$DEV_NS 1::11/96
266 ip netns
exec at_ns0 ip link
set dev
$DEV_NS up
269 ip link add dev
$DEV type $TYPE external
270 ip addr add dev
$DEV 10.1.1.200/24
271 ip addr add dev
$DEV 1::22/96
272 ip link
set dev
$DEV up
285 attach_bpf
$DEV gre_set_tunnel gre_get_tunnel
286 ping $PING_ARG 10.1.1.100
288 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
292 if [ $ret -ne 0 ]; then
293 echo -e ${RED}"FAIL: $TYPE"${NC}
296 echo -e ${GREEN}"PASS: $TYPE"${NC}
308 # reuse the ip6gretap function
310 attach_bpf
$DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
313 # overlay: ipv4 over ipv6
314 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
315 ping $PING_ARG 10.1.1.100
317 # overlay: ipv6 over ipv6
318 ip netns
exec at_ns0 ping6
$PING_ARG fc80
::200
322 if [ $ret -ne 0 ]; then
323 echo -e ${RED}"FAIL: $TYPE"${NC}
326 echo -e ${GREEN}"PASS: $TYPE"${NC}
339 attach_bpf
$DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
342 # overlay: ipv4 over ipv6
343 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
344 ping $PING_ARG 10.1.1.100
346 # overlay: ipv6 over ipv6
347 ip netns
exec at_ns0 ping6
$PING_ARG fc80
::200
351 if [ $ret -ne 0 ]; then
352 echo -e ${RED}"FAIL: $TYPE"${NC}
355 echo -e ${GREEN}"PASS: $TYPE"${NC}
368 attach_bpf
$DEV erspan_set_tunnel erspan_get_tunnel
369 ping $PING_ARG 10.1.1.100
371 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
375 if [ $ret -ne 0 ]; then
376 echo -e ${RED}"FAIL: $TYPE"${NC}
379 echo -e ${GREEN}"PASS: $TYPE"${NC}
391 add_ip6erspan_tunnel
$1
392 attach_bpf
$DEV ip4ip6erspan_set_tunnel ip4ip6erspan_get_tunnel
394 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
398 if [ $ret -ne 0 ]; then
399 echo -e ${RED}"FAIL: $TYPE"${NC}
402 echo -e ${GREEN}"PASS: $TYPE"${NC}
415 attach_bpf
$DEV vxlan_set_tunnel vxlan_get_tunnel
416 ping $PING_ARG 10.1.1.100
418 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
422 if [ $ret -ne 0 ]; then
423 echo -e ${RED}"FAIL: $TYPE"${NC}
426 echo -e ${GREEN}"PASS: $TYPE"${NC}
439 ip link
set dev veth1 mtu
1500
440 attach_bpf
$DEV ip6vxlan_set_tunnel ip6vxlan_get_tunnel
444 ping $PING_ARG 10.1.1.100
446 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
450 if [ $ret -ne 0 ]; then
451 echo -e ${RED}"FAIL: ip6$TYPE"${NC}
454 echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
467 attach_bpf
$DEV geneve_set_tunnel geneve_get_tunnel
468 ping $PING_ARG 10.1.1.100
470 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
474 if [ $ret -ne 0 ]; then
475 echo -e ${RED}"FAIL: $TYPE"${NC}
478 echo -e ${GREEN}"PASS: $TYPE"${NC}
491 attach_bpf
$DEV ip6geneve_set_tunnel ip6geneve_get_tunnel
492 ping $PING_ARG 10.1.1.100
494 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
498 if [ $ret -ne 0 ]; then
499 echo -e ${RED}"FAIL: ip6$TYPE"${NC}
502 echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
515 ip link
set dev veth1 mtu
1500
516 attach_bpf
$DEV ipip_set_tunnel ipip_get_tunnel
517 ping $PING_ARG 10.1.1.100
519 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
523 if [ $ret -ne 0 ]; then
524 echo -e ${RED}"FAIL: $TYPE"${NC}
527 echo -e ${GREEN}"PASS: $TYPE"${NC}
540 ip link
set dev veth1 mtu
1500
541 attach_bpf
$DEV ipip6_set_tunnel ipip6_get_tunnel
545 ping $PING_ARG 10.1.1.100
547 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
551 if [ $ret -ne 0 ]; then
552 echo -e ${RED}"FAIL: $TYPE"${NC}
555 echo -e ${GREEN}"PASS: $TYPE"${NC}
568 ip link
set dev veth1 mtu
1500
569 attach_bpf
$DEV ip6ip6_set_tunnel ip6ip6_get_tunnel
573 ping6
$PING_ARG 1::11
575 ip netns
exec at_ns0 ping6
$PING_ARG 1::22
579 if [ $ret -ne 0 ]; then
580 echo -e ${RED}"FAIL: ip6$TYPE"${NC}
583 echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
588 auth
=0x$
(printf '1%.0s' {1.
.40})
589 enc
=0x$
(printf '2%.0s' {1.
.32})
594 ip netns
exec at_ns0 \
595 ip xfrm state add src
172.16.1.100 dst
172.16.1.200 proto esp \
596 spi
$spi_in_to_out reqid
1 mode tunnel \
597 auth-trunc
'hmac(sha1)' $auth 96 enc
'cbc(aes)' $enc
598 ip netns
exec at_ns0 \
599 ip xfrm policy add src
10.1.1.100/32 dst
10.1.1.200/32 dir out \
600 tmpl src
172.16.1.100 dst
172.16.1.200 proto esp reqid
1 \
603 ip netns
exec at_ns0 \
604 ip xfrm state add src
172.16.1.200 dst
172.16.1.100 proto esp \
605 spi
$spi_out_to_in reqid
2 mode tunnel \
606 auth-trunc
'hmac(sha1)' $auth 96 enc
'cbc(aes)' $enc
607 ip netns
exec at_ns0 \
608 ip xfrm policy add src
10.1.1.200/32 dst
10.1.1.100/32 dir
in \
609 tmpl src
172.16.1.200 dst
172.16.1.100 proto esp reqid
2 \
612 ip netns
exec at_ns0 \
613 ip addr add dev veth0
10.1.1.100/32
614 ip netns
exec at_ns0 \
615 ip route add
10.1.1.200 dev veth0 via
172.16.1.200 \
620 ip xfrm state add src
172.16.1.100 dst
172.16.1.200 proto esp \
621 spi
$spi_in_to_out reqid
1 mode tunnel \
622 auth-trunc
'hmac(sha1)' $auth 96 enc
'cbc(aes)' $enc
623 ip xfrm policy add src
10.1.1.100/32 dst
10.1.1.200/32 dir
in \
624 tmpl src
172.16.1.100 dst
172.16.1.200 proto esp reqid
1 \
627 ip xfrm state add src
172.16.1.200 dst
172.16.1.100 proto esp \
628 spi
$spi_out_to_in reqid
2 mode tunnel \
629 auth-trunc
'hmac(sha1)' $auth 96 enc
'cbc(aes)' $enc
630 ip xfrm policy add src
10.1.1.200/32 dst
10.1.1.100/32 dir out \
631 tmpl src
172.16.1.200 dst
172.16.1.100 proto esp reqid
2 \
634 ip addr add dev veth1
10.1.1.200/32
635 ip route add
10.1.1.100 dev veth1 via
172.16.1.100 src
10.1.1.200
641 > /sys
/kernel
/debug
/tracing
/trace
643 tc qdisc add dev veth1 clsact
644 tc filter add dev veth1 proto ip ingress bpf da obj test_tunnel_kern.o \
646 ip netns
exec at_ns0
ping $PING_ARG 10.1.1.200
648 grep "reqid 1" /sys
/kernel
/debug
/tracing
/trace
650 grep "spi 0x1" /sys
/kernel
/debug
/tracing
/trace
652 grep "remote ip 0xac100164" /sys
/kernel
/debug
/tracing
/trace
656 if [ $ret -ne 0 ]; then
657 echo -e ${RED}"FAIL: xfrm tunnel"${NC}
660 echo -e ${GREEN}"PASS: xfrm tunnel"${NC}
668 tc qdisc add dev
$DEV clsact
669 tc filter add dev
$DEV egress bpf da obj test_tunnel_kern.o sec
$SET
670 tc filter add dev
$DEV ingress bpf da obj test_tunnel_kern.o sec
$GET
675 ip netns delete at_ns0
2> /dev
/null
676 ip link del veth1
2> /dev
/null
677 ip link del ipip11
2> /dev
/null
678 ip link del ipip6tnl11
2> /dev
/null
679 ip link del ip6ip6tnl11
2> /dev
/null
680 ip link del gretap11
2> /dev
/null
681 ip link del ip6gre11
2> /dev
/null
682 ip link del ip6gretap11
2> /dev
/null
683 ip link del vxlan11
2> /dev
/null
684 ip link del ip6vxlan11
2> /dev
/null
685 ip link del geneve11
2> /dev
/null
686 ip link del ip6geneve11
2> /dev
/null
687 ip link del erspan11
2> /dev
/null
688 ip link del ip6erspan11
2> /dev
/null
689 ip xfrm policy delete dir out src
10.1.1.200/32 dst
10.1.1.100/32 2> /dev
/null
690 ip xfrm policy delete dir
in src
10.1.1.100/32 dst
10.1.1.200/32 2> /dev
/null
691 ip xfrm state delete src
172.16.1.100 dst
172.16.1.200 proto esp spi
0x1 2> /dev
/null
692 ip xfrm state delete src
172.16.1.200 dst
172.16.1.100 proto esp spi
0x2 2> /dev
/null
697 echo "CATCH SIGKILL or SIGINT, cleanup and exit"
704 ip link
help 2>&1 |
grep -q "\s$1\s"
706 echo "SKIP $1: iproute2 not support"
714 echo 'file ip_gre.c +p' > /sys
/kernel
/debug
/dynamic_debug
/control
715 echo 'file ip6_gre.c +p' > /sys
/kernel
/debug
/dynamic_debug
/control
716 echo 'file vxlan.c +p' > /sys
/kernel
/debug
/dynamic_debug
/control
717 echo 'file geneve.c +p' > /sys
/kernel
/debug
/dynamic_debug
/control
718 echo 'file ipip.c +p' > /sys
/kernel
/debug
/dynamic_debug
/control
723 if [ $ret -eq 0 ]; then
732 echo "Testing GRE tunnel..."
734 errors
=$
(( $errors + $?
))
736 echo "Testing IP6GRE tunnel..."
738 errors
=$
(( $errors + $?
))
740 echo "Testing IP6GRETAP tunnel..."
742 errors
=$
(( $errors + $?
))
744 echo "Testing ERSPAN tunnel..."
746 errors
=$
(( $errors + $?
))
748 echo "Testing IP6ERSPAN tunnel..."
750 errors
=$
(( $errors + $?
))
752 echo "Testing VXLAN tunnel..."
754 errors
=$
(( $errors + $?
))
756 echo "Testing IP6VXLAN tunnel..."
758 errors
=$
(( $errors + $?
))
760 echo "Testing GENEVE tunnel..."
762 errors
=$
(( $errors + $?
))
764 echo "Testing IP6GENEVE tunnel..."
766 errors
=$
(( $errors + $?
))
768 echo "Testing IPIP tunnel..."
770 errors
=$
(( $errors + $?
))
772 echo "Testing IPIP6 tunnel..."
774 errors
=$
(( $errors + $?
))
776 echo "Testing IP6IP6 tunnel..."
778 errors
=$
(( $errors + $?
))
780 echo "Testing IPSec tunnel..."
782 errors
=$
(( $errors + $?
))
788 trap cleanup_exit
2 9
793 if [ $?
-ne 0 ]; then
794 echo -e "$(basename $0): ${RED}FAIL${NC}"
797 echo -e "$(basename $0): ${GREEN}PASS${NC}"