Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # End-to-end eBPF tunnel test suite
0005 #   The script tests BPF network tunnel implementation.
0006 #
0007 # Topology:
0008 # ---------
0009 #     root namespace   |     at_ns0 namespace
0010 #                      |
0011 #      -----------     |     -----------
0012 #      | tnl dev |     |     | tnl dev |  (overlay network)
0013 #      -----------     |     -----------
0014 #      metadata-mode   |     native-mode
0015 #       with bpf       |
0016 #                      |
0017 #      ----------      |     ----------
0018 #      |  veth1  | --------- |  veth0  |  (underlay network)
0019 #      ----------    peer    ----------
0020 #
0021 #
0022 # Device Configuration
0023 # --------------------
0024 # Root namespace with metadata-mode tunnel + BPF
0025 # Device names and addresses:
0026 #       veth1 IP: 172.16.1.200, IPv6: 00::22 (underlay)
0027 #       tunnel dev <type>11, ex: gre11, IPv4: 10.1.1.200, IPv6: 1::22 (overlay)
0028 #
0029 # Namespace at_ns0 with native tunnel
0030 # Device names and addresses:
0031 #       veth0 IPv4: 172.16.1.100, IPv6: 00::11 (underlay)
0032 #       tunnel dev <type>00, ex: gre00, IPv4: 10.1.1.100, IPv6: 1::11 (overlay)
0033 #
0034 #
0035 # End-to-end ping packet flow
0036 # ---------------------------
0037 # Most of the tests start by namespace creation, device configuration,
0038 # then ping the underlay and overlay network.  When doing 'ping 10.1.1.100'
0039 # from root namespace, the following operations happen:
0040 # 1) Route lookup shows 10.1.1.100/24 belongs to tnl dev, fwd to tnl dev.
0041 # 2) Tnl device's egress BPF program is triggered and set the tunnel metadata,
0042 #    with remote_ip=172.16.1.100 and others.
0043 # 3) Outer tunnel header is prepended and route the packet to veth1's egress
0044 # 4) veth0's ingress queue receive the tunneled packet at namespace at_ns0
0045 # 5) Tunnel protocol handler, ex: vxlan_rcv, decap the packet
0046 # 6) Forward the packet to the overlay tnl dev
0047 
0048 BPF_PIN_TUNNEL_DIR="/sys/fs/bpf/tc/tunnel"
0049 PING_ARG="-c 3 -w 10 -q"
0050 ret=0
0051 GREEN='\033[0;92m'
0052 RED='\033[0;31m'
0053 NC='\033[0m' # No Color
0054 
0055 config_device()
0056 {
0057         ip netns add at_ns0
0058         ip link add veth0 type veth peer name veth1
0059         ip link set veth0 netns at_ns0
0060         ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0
0061         ip netns exec at_ns0 ip link set dev veth0 up
0062         ip link set dev veth1 up mtu 1500
0063         ip addr add dev veth1 172.16.1.200/24
0064 }
0065 
0066 add_gre_tunnel()
0067 {
0068         # at_ns0 namespace
0069         ip netns exec at_ns0 \
0070         ip link add dev $DEV_NS type $TYPE seq key 2 \
0071                 local 172.16.1.100 remote 172.16.1.200
0072         ip netns exec at_ns0 ip link set dev $DEV_NS up
0073         ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
0074 
0075         # root namespace
0076         ip link add dev $DEV type $TYPE key 2 external
0077         ip link set dev $DEV up
0078         ip addr add dev $DEV 10.1.1.200/24
0079 }
0080 
0081 add_ip6gretap_tunnel()
0082 {
0083 
0084         # assign ipv6 address
0085         ip netns exec at_ns0 ip addr add ::11/96 dev veth0
0086         ip netns exec at_ns0 ip link set dev veth0 up
0087         ip addr add dev veth1 ::22/96
0088         ip link set dev veth1 up
0089 
0090         # at_ns0 namespace
0091         ip netns exec at_ns0 \
0092                 ip link add dev $DEV_NS type $TYPE seq flowlabel 0xbcdef key 2 \
0093                 local ::11 remote ::22
0094 
0095         ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
0096         ip netns exec at_ns0 ip addr add dev $DEV_NS fc80::100/96
0097         ip netns exec at_ns0 ip link set dev $DEV_NS up
0098 
0099         # root namespace
0100         ip link add dev $DEV type $TYPE external
0101         ip addr add dev $DEV 10.1.1.200/24
0102         ip addr add dev $DEV fc80::200/24
0103         ip link set dev $DEV up
0104 }
0105 
0106 add_erspan_tunnel()
0107 {
0108         # at_ns0 namespace
0109         if [ "$1" == "v1" ]; then
0110                 ip netns exec at_ns0 \
0111                 ip link add dev $DEV_NS type $TYPE seq key 2 \
0112                 local 172.16.1.100 remote 172.16.1.200 \
0113                 erspan_ver 1 erspan 123
0114         else
0115                 ip netns exec at_ns0 \
0116                 ip link add dev $DEV_NS type $TYPE seq key 2 \
0117                 local 172.16.1.100 remote 172.16.1.200 \
0118                 erspan_ver 2 erspan_dir egress erspan_hwid 3
0119         fi
0120         ip netns exec at_ns0 ip link set dev $DEV_NS up
0121         ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
0122 
0123         # root namespace
0124         ip link add dev $DEV type $TYPE external
0125         ip link set dev $DEV up
0126         ip addr add dev $DEV 10.1.1.200/24
0127 }
0128 
0129 add_ip6erspan_tunnel()
0130 {
0131 
0132         # assign ipv6 address
0133         ip netns exec at_ns0 ip addr add ::11/96 dev veth0
0134         ip netns exec at_ns0 ip link set dev veth0 up
0135         ip addr add dev veth1 ::22/96
0136         ip link set dev veth1 up
0137 
0138         # at_ns0 namespace
0139         if [ "$1" == "v1" ]; then
0140                 ip netns exec at_ns0 \
0141                 ip link add dev $DEV_NS type $TYPE seq key 2 \
0142                 local ::11 remote ::22 \
0143                 erspan_ver 1 erspan 123
0144         else
0145                 ip netns exec at_ns0 \
0146                 ip link add dev $DEV_NS type $TYPE seq key 2 \
0147                 local ::11 remote ::22 \
0148                 erspan_ver 2 erspan_dir egress erspan_hwid 7
0149         fi
0150         ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
0151         ip netns exec at_ns0 ip link set dev $DEV_NS up
0152 
0153         # root namespace
0154         ip link add dev $DEV type $TYPE external
0155         ip addr add dev $DEV 10.1.1.200/24
0156         ip link set dev $DEV up
0157 }
0158 
0159 add_geneve_tunnel()
0160 {
0161         # at_ns0 namespace
0162         ip netns exec at_ns0 \
0163                 ip link add dev $DEV_NS type $TYPE \
0164                 id 2 dstport 6081 remote 172.16.1.200
0165         ip netns exec at_ns0 ip link set dev $DEV_NS up
0166         ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
0167 
0168         # root namespace
0169         ip link add dev $DEV type $TYPE dstport 6081 external
0170         ip link set dev $DEV up
0171         ip addr add dev $DEV 10.1.1.200/24
0172 }
0173 
0174 add_ip6geneve_tunnel()
0175 {
0176         ip netns exec at_ns0 ip addr add ::11/96 dev veth0
0177         ip netns exec at_ns0 ip link set dev veth0 up
0178         ip addr add dev veth1 ::22/96
0179         ip link set dev veth1 up
0180 
0181         # at_ns0 namespace
0182         ip netns exec at_ns0 \
0183                 ip link add dev $DEV_NS type $TYPE id 22 \
0184                 remote ::22     # geneve has no local option
0185         ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
0186         ip netns exec at_ns0 ip link set dev $DEV_NS up
0187 
0188         # root namespace
0189         ip link add dev $DEV type $TYPE external
0190         ip addr add dev $DEV 10.1.1.200/24
0191         ip link set dev $DEV up
0192 }
0193 
0194 add_ipip_tunnel()
0195 {
0196         # at_ns0 namespace
0197         ip netns exec at_ns0 \
0198                 ip link add dev $DEV_NS type $TYPE \
0199                 local 172.16.1.100 remote 172.16.1.200
0200         ip netns exec at_ns0 ip link set dev $DEV_NS up
0201         ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
0202 
0203         # root namespace
0204         ip link add dev $DEV type $TYPE external
0205         ip link set dev $DEV up
0206         ip addr add dev $DEV 10.1.1.200/24
0207 }
0208 
0209 add_ip6tnl_tunnel()
0210 {
0211         ip netns exec at_ns0 ip addr add ::11/96 dev veth0
0212         ip netns exec at_ns0 ip link set dev veth0 up
0213         ip addr add dev veth1 ::22/96
0214         ip link set dev veth1 up
0215 
0216         # at_ns0 namespace
0217         ip netns exec at_ns0 \
0218                 ip link add dev $DEV_NS type $TYPE \
0219                 local ::11 remote ::22
0220         ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
0221         ip netns exec at_ns0 ip addr add dev $DEV_NS 1::11/96
0222         ip netns exec at_ns0 ip link set dev $DEV_NS up
0223 
0224         # root namespace
0225         ip link add dev $DEV type $TYPE external
0226         ip addr add dev $DEV 10.1.1.200/24
0227         ip addr add dev $DEV 1::22/96
0228         ip link set dev $DEV up
0229 }
0230 
0231 test_gre()
0232 {
0233         TYPE=gretap
0234         DEV_NS=gretap00
0235         DEV=gretap11
0236         ret=0
0237 
0238         check $TYPE
0239         config_device
0240         add_gre_tunnel
0241         attach_bpf $DEV gre_set_tunnel gre_get_tunnel
0242         ping $PING_ARG 10.1.1.100
0243         check_err $?
0244         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0245         check_err $?
0246         cleanup
0247 
0248         if [ $ret -ne 0 ]; then
0249                 echo -e ${RED}"FAIL: $TYPE"${NC}
0250                 return 1
0251         fi
0252         echo -e ${GREEN}"PASS: $TYPE"${NC}
0253 }
0254 
0255 test_ip6gre()
0256 {
0257         TYPE=ip6gre
0258         DEV_NS=ip6gre00
0259         DEV=ip6gre11
0260         ret=0
0261 
0262         check $TYPE
0263         config_device
0264         # reuse the ip6gretap function
0265         add_ip6gretap_tunnel
0266         attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
0267         # underlay
0268         ping6 $PING_ARG ::11
0269         # overlay: ipv4 over ipv6
0270         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0271         ping $PING_ARG 10.1.1.100
0272         check_err $?
0273         # overlay: ipv6 over ipv6
0274         ip netns exec at_ns0 ping6 $PING_ARG fc80::200
0275         check_err $?
0276         cleanup
0277 
0278         if [ $ret -ne 0 ]; then
0279                 echo -e ${RED}"FAIL: $TYPE"${NC}
0280                 return 1
0281         fi
0282         echo -e ${GREEN}"PASS: $TYPE"${NC}
0283 }
0284 
0285 test_ip6gretap()
0286 {
0287         TYPE=ip6gretap
0288         DEV_NS=ip6gretap00
0289         DEV=ip6gretap11
0290         ret=0
0291 
0292         check $TYPE
0293         config_device
0294         add_ip6gretap_tunnel
0295         attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
0296         # underlay
0297         ping6 $PING_ARG ::11
0298         # overlay: ipv4 over ipv6
0299         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0300         ping $PING_ARG 10.1.1.100
0301         check_err $?
0302         # overlay: ipv6 over ipv6
0303         ip netns exec at_ns0 ping6 $PING_ARG fc80::200
0304         check_err $?
0305         cleanup
0306 
0307         if [ $ret -ne 0 ]; then
0308                 echo -e ${RED}"FAIL: $TYPE"${NC}
0309                 return 1
0310         fi
0311         echo -e ${GREEN}"PASS: $TYPE"${NC}
0312 }
0313 
0314 test_erspan()
0315 {
0316         TYPE=erspan
0317         DEV_NS=erspan00
0318         DEV=erspan11
0319         ret=0
0320 
0321         check $TYPE
0322         config_device
0323         add_erspan_tunnel $1
0324         attach_bpf $DEV erspan_set_tunnel erspan_get_tunnel
0325         ping $PING_ARG 10.1.1.100
0326         check_err $?
0327         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0328         check_err $?
0329         cleanup
0330 
0331         if [ $ret -ne 0 ]; then
0332                 echo -e ${RED}"FAIL: $TYPE"${NC}
0333                 return 1
0334         fi
0335         echo -e ${GREEN}"PASS: $TYPE"${NC}
0336 }
0337 
0338 test_ip6erspan()
0339 {
0340         TYPE=ip6erspan
0341         DEV_NS=ip6erspan00
0342         DEV=ip6erspan11
0343         ret=0
0344 
0345         check $TYPE
0346         config_device
0347         add_ip6erspan_tunnel $1
0348         attach_bpf $DEV ip4ip6erspan_set_tunnel ip4ip6erspan_get_tunnel
0349         ping6 $PING_ARG ::11
0350         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0351         check_err $?
0352         cleanup
0353 
0354         if [ $ret -ne 0 ]; then
0355                 echo -e ${RED}"FAIL: $TYPE"${NC}
0356                 return 1
0357         fi
0358         echo -e ${GREEN}"PASS: $TYPE"${NC}
0359 }
0360 
0361 test_geneve()
0362 {
0363         TYPE=geneve
0364         DEV_NS=geneve00
0365         DEV=geneve11
0366         ret=0
0367 
0368         check $TYPE
0369         config_device
0370         add_geneve_tunnel
0371         attach_bpf $DEV geneve_set_tunnel geneve_get_tunnel
0372         ping $PING_ARG 10.1.1.100
0373         check_err $?
0374         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0375         check_err $?
0376         cleanup
0377 
0378         if [ $ret -ne 0 ]; then
0379                 echo -e ${RED}"FAIL: $TYPE"${NC}
0380                 return 1
0381         fi
0382         echo -e ${GREEN}"PASS: $TYPE"${NC}
0383 }
0384 
0385 test_ip6geneve()
0386 {
0387         TYPE=geneve
0388         DEV_NS=ip6geneve00
0389         DEV=ip6geneve11
0390         ret=0
0391 
0392         check $TYPE
0393         config_device
0394         add_ip6geneve_tunnel
0395         attach_bpf $DEV ip6geneve_set_tunnel ip6geneve_get_tunnel
0396         ping $PING_ARG 10.1.1.100
0397         check_err $?
0398         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0399         check_err $?
0400         cleanup
0401 
0402         if [ $ret -ne 0 ]; then
0403                 echo -e ${RED}"FAIL: ip6$TYPE"${NC}
0404                 return 1
0405         fi
0406         echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
0407 }
0408 
0409 test_ipip()
0410 {
0411         TYPE=ipip
0412         DEV_NS=ipip00
0413         DEV=ipip11
0414         ret=0
0415 
0416         check $TYPE
0417         config_device
0418         add_ipip_tunnel
0419         ip link set dev veth1 mtu 1500
0420         attach_bpf $DEV ipip_set_tunnel ipip_get_tunnel
0421         ping $PING_ARG 10.1.1.100
0422         check_err $?
0423         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0424         check_err $?
0425         cleanup
0426 
0427         if [ $ret -ne 0 ]; then
0428                 echo -e ${RED}"FAIL: $TYPE"${NC}
0429                 return 1
0430         fi
0431         echo -e ${GREEN}"PASS: $TYPE"${NC}
0432 }
0433 
0434 test_ipip6()
0435 {
0436         TYPE=ip6tnl
0437         DEV_NS=ipip6tnl00
0438         DEV=ipip6tnl11
0439         ret=0
0440 
0441         check $TYPE
0442         config_device
0443         add_ip6tnl_tunnel
0444         ip link set dev veth1 mtu 1500
0445         attach_bpf $DEV ipip6_set_tunnel ipip6_get_tunnel
0446         # underlay
0447         ping6 $PING_ARG ::11
0448         # ip4 over ip6
0449         ping $PING_ARG 10.1.1.100
0450         check_err $?
0451         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0452         check_err $?
0453         cleanup
0454 
0455         if [ $ret -ne 0 ]; then
0456                 echo -e ${RED}"FAIL: $TYPE"${NC}
0457                 return 1
0458         fi
0459         echo -e ${GREEN}"PASS: $TYPE"${NC}
0460 }
0461 
0462 test_ip6ip6()
0463 {
0464         TYPE=ip6tnl
0465         DEV_NS=ip6ip6tnl00
0466         DEV=ip6ip6tnl11
0467         ret=0
0468 
0469         check $TYPE
0470         config_device
0471         add_ip6tnl_tunnel
0472         ip link set dev veth1 mtu 1500
0473         attach_bpf $DEV ip6ip6_set_tunnel ip6ip6_get_tunnel
0474         # underlay
0475         ping6 $PING_ARG ::11
0476         # ip6 over ip6
0477         ping6 $PING_ARG 1::11
0478         check_err $?
0479         ip netns exec at_ns0 ping6 $PING_ARG 1::22
0480         check_err $?
0481         cleanup
0482 
0483         if [ $ret -ne 0 ]; then
0484                 echo -e ${RED}"FAIL: ip6$TYPE"${NC}
0485                 return 1
0486         fi
0487         echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
0488 }
0489 
0490 setup_xfrm_tunnel()
0491 {
0492         auth=0x$(printf '1%.0s' {1..40})
0493         enc=0x$(printf '2%.0s' {1..32})
0494         spi_in_to_out=0x1
0495         spi_out_to_in=0x2
0496         # at_ns0 namespace
0497         # at_ns0 -> root
0498         ip netns exec at_ns0 \
0499                 ip xfrm state add src 172.16.1.100 dst 172.16.1.200 proto esp \
0500                         spi $spi_in_to_out reqid 1 mode tunnel \
0501                         auth-trunc 'hmac(sha1)' $auth 96 enc 'cbc(aes)' $enc
0502         ip netns exec at_ns0 \
0503                 ip xfrm policy add src 10.1.1.100/32 dst 10.1.1.200/32 dir out \
0504                 tmpl src 172.16.1.100 dst 172.16.1.200 proto esp reqid 1 \
0505                 mode tunnel
0506         # root -> at_ns0
0507         ip netns exec at_ns0 \
0508                 ip xfrm state add src 172.16.1.200 dst 172.16.1.100 proto esp \
0509                         spi $spi_out_to_in reqid 2 mode tunnel \
0510                         auth-trunc 'hmac(sha1)' $auth 96 enc 'cbc(aes)' $enc
0511         ip netns exec at_ns0 \
0512                 ip xfrm policy add src 10.1.1.200/32 dst 10.1.1.100/32 dir in \
0513                 tmpl src 172.16.1.200 dst 172.16.1.100 proto esp reqid 2 \
0514                 mode tunnel
0515         # address & route
0516         ip netns exec at_ns0 \
0517                 ip addr add dev veth0 10.1.1.100/32
0518         ip netns exec at_ns0 \
0519                 ip route add 10.1.1.200 dev veth0 via 172.16.1.200 \
0520                         src 10.1.1.100
0521 
0522         # root namespace
0523         # at_ns0 -> root
0524         ip xfrm state add src 172.16.1.100 dst 172.16.1.200 proto esp \
0525                 spi $spi_in_to_out reqid 1 mode tunnel \
0526                 auth-trunc 'hmac(sha1)' $auth 96  enc 'cbc(aes)' $enc
0527         ip xfrm policy add src 10.1.1.100/32 dst 10.1.1.200/32 dir in \
0528                 tmpl src 172.16.1.100 dst 172.16.1.200 proto esp reqid 1 \
0529                 mode tunnel
0530         # root -> at_ns0
0531         ip xfrm state add src 172.16.1.200 dst 172.16.1.100 proto esp \
0532                 spi $spi_out_to_in reqid 2 mode tunnel \
0533                 auth-trunc 'hmac(sha1)' $auth 96  enc 'cbc(aes)' $enc
0534         ip xfrm policy add src 10.1.1.200/32 dst 10.1.1.100/32 dir out \
0535                 tmpl src 172.16.1.200 dst 172.16.1.100 proto esp reqid 2 \
0536                 mode tunnel
0537         # address & route
0538         ip addr add dev veth1 10.1.1.200/32
0539         ip route add 10.1.1.100 dev veth1 via 172.16.1.100 src 10.1.1.200
0540 }
0541 
0542 test_xfrm_tunnel()
0543 {
0544         config_device
0545         > /sys/kernel/debug/tracing/trace
0546         setup_xfrm_tunnel
0547         mkdir -p ${BPF_PIN_TUNNEL_DIR}
0548         bpftool prog loadall ./test_tunnel_kern.o ${BPF_PIN_TUNNEL_DIR}
0549         tc qdisc add dev veth1 clsact
0550         tc filter add dev veth1 proto ip ingress bpf da object-pinned \
0551                 ${BPF_PIN_TUNNEL_DIR}/xfrm_get_state
0552         ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
0553         sleep 1
0554         grep "reqid 1" /sys/kernel/debug/tracing/trace
0555         check_err $?
0556         grep "spi 0x1" /sys/kernel/debug/tracing/trace
0557         check_err $?
0558         grep "remote ip 0xac100164" /sys/kernel/debug/tracing/trace
0559         check_err $?
0560         cleanup
0561 
0562         if [ $ret -ne 0 ]; then
0563                 echo -e ${RED}"FAIL: xfrm tunnel"${NC}
0564                 return 1
0565         fi
0566         echo -e ${GREEN}"PASS: xfrm tunnel"${NC}
0567 }
0568 
0569 attach_bpf()
0570 {
0571         DEV=$1
0572         SET=$2
0573         GET=$3
0574         mkdir -p ${BPF_PIN_TUNNEL_DIR}
0575         bpftool prog loadall ./test_tunnel_kern.o ${BPF_PIN_TUNNEL_DIR}/
0576         tc qdisc add dev $DEV clsact
0577         tc filter add dev $DEV egress bpf da object-pinned ${BPF_PIN_TUNNEL_DIR}/$SET
0578         tc filter add dev $DEV ingress bpf da object-pinned ${BPF_PIN_TUNNEL_DIR}/$GET
0579 }
0580 
0581 cleanup()
0582 {
0583         rm -rf ${BPF_PIN_TUNNEL_DIR}
0584 
0585         ip netns delete at_ns0 2> /dev/null
0586         ip link del veth1 2> /dev/null
0587         ip link del ipip11 2> /dev/null
0588         ip link del ipip6tnl11 2> /dev/null
0589         ip link del ip6ip6tnl11 2> /dev/null
0590         ip link del gretap11 2> /dev/null
0591         ip link del ip6gre11 2> /dev/null
0592         ip link del ip6gretap11 2> /dev/null
0593         ip link del geneve11 2> /dev/null
0594         ip link del ip6geneve11 2> /dev/null
0595         ip link del erspan11 2> /dev/null
0596         ip link del ip6erspan11 2> /dev/null
0597         ip xfrm policy delete dir out src 10.1.1.200/32 dst 10.1.1.100/32 2> /dev/null
0598         ip xfrm policy delete dir in src 10.1.1.100/32 dst 10.1.1.200/32 2> /dev/null
0599         ip xfrm state delete src 172.16.1.100 dst 172.16.1.200 proto esp spi 0x1 2> /dev/null
0600         ip xfrm state delete src 172.16.1.200 dst 172.16.1.100 proto esp spi 0x2 2> /dev/null
0601 }
0602 
0603 cleanup_exit()
0604 {
0605         echo "CATCH SIGKILL or SIGINT, cleanup and exit"
0606         cleanup
0607         exit 0
0608 }
0609 
0610 check()
0611 {
0612         ip link help 2>&1 | grep -q "\s$1\s"
0613         if [ $? -ne 0 ];then
0614                 echo "SKIP $1: iproute2 not support"
0615         cleanup
0616         return 1
0617         fi
0618 }
0619 
0620 enable_debug()
0621 {
0622         echo 'file ip_gre.c +p' > /sys/kernel/debug/dynamic_debug/control
0623         echo 'file ip6_gre.c +p' > /sys/kernel/debug/dynamic_debug/control
0624         echo 'file geneve.c +p' > /sys/kernel/debug/dynamic_debug/control
0625         echo 'file ipip.c +p' > /sys/kernel/debug/dynamic_debug/control
0626 }
0627 
0628 check_err()
0629 {
0630         if [ $ret -eq 0 ]; then
0631                 ret=$1
0632         fi
0633 }
0634 
0635 bpf_tunnel_test()
0636 {
0637         local errors=0
0638 
0639         echo "Testing GRE tunnel..."
0640         test_gre
0641         errors=$(( $errors + $? ))
0642 
0643         echo "Testing IP6GRE tunnel..."
0644         test_ip6gre
0645         errors=$(( $errors + $? ))
0646 
0647         echo "Testing IP6GRETAP tunnel..."
0648         test_ip6gretap
0649         errors=$(( $errors + $? ))
0650 
0651         echo "Testing ERSPAN tunnel..."
0652         test_erspan v2
0653         errors=$(( $errors + $? ))
0654 
0655         echo "Testing IP6ERSPAN tunnel..."
0656         test_ip6erspan v2
0657         errors=$(( $errors + $? ))
0658 
0659         echo "Testing GENEVE tunnel..."
0660         test_geneve
0661         errors=$(( $errors + $? ))
0662 
0663         echo "Testing IP6GENEVE tunnel..."
0664         test_ip6geneve
0665         errors=$(( $errors + $? ))
0666 
0667         echo "Testing IPIP tunnel..."
0668         test_ipip
0669         errors=$(( $errors + $? ))
0670 
0671         echo "Testing IPIP6 tunnel..."
0672         test_ipip6
0673         errors=$(( $errors + $? ))
0674 
0675         echo "Testing IP6IP6 tunnel..."
0676         test_ip6ip6
0677         errors=$(( $errors + $? ))
0678 
0679         echo "Testing IPSec tunnel..."
0680         test_xfrm_tunnel
0681         errors=$(( $errors + $? ))
0682 
0683         return $errors
0684 }
0685 
0686 trap cleanup 0 3 6
0687 trap cleanup_exit 2 9
0688 
0689 cleanup
0690 bpf_tunnel_test
0691 
0692 if [ $? -ne 0 ]; then
0693         echo -e "$(basename $0): ${RED}FAIL${NC}"
0694         exit 1
0695 fi
0696 echo -e "$(basename $0): ${GREEN}PASS${NC}"
0697 exit 0