Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftest/bpf: Add missed ip6ip6 test back

In comment 173ca26e9b51 ("samples/bpf: add comprehensive ipip, ipip6,
ip6ip6 test") we added ip6ip6 test for bpf tunnel testing. But in commit
933a741e3b82 ("selftests/bpf: bpf tunnel test.") when we moved it to
the current folder, we didn't add it.

This patch add the ip6ip6 test back to bpf tunnel test. Update the ipip6's
topology for both IPv4 and IPv6 testing. Since iperf test is removed as
currect framework simplified it in purpose, I also removed unused tcp
checkings in test_tunnel_kern.c.

Fixes: 933a741e3b82 ("selftests/bpf: bpf tunnel test.")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20201110015013.1570716-2-liuhangbin@gmail.com

authored by

Hangbin Liu and committed by
Alexei Starovoitov
58cfa49c 0e6f601e

+46 -39
+7 -35
tools/testing/selftests/bpf/progs/test_tunnel_kern.c
··· 15 15 #include <linux/ip.h> 16 16 #include <linux/ipv6.h> 17 17 #include <linux/types.h> 18 - #include <linux/tcp.h> 19 18 #include <linux/socket.h> 20 19 #include <linux/pkt_cls.h> 21 20 #include <linux/erspan.h> ··· 527 528 struct bpf_tunnel_key key = {}; 528 529 void *data = (void *)(long)skb->data; 529 530 struct iphdr *iph = data; 530 - struct tcphdr *tcp = data + sizeof(*iph); 531 531 void *data_end = (void *)(long)skb->data_end; 532 532 int ret; 533 533 534 534 /* single length check */ 535 - if (data + sizeof(*iph) + sizeof(*tcp) > data_end) { 535 + if (data + sizeof(*iph) > data_end) { 536 536 ERROR(1); 537 537 return TC_ACT_SHOT; 538 538 } ··· 539 541 key.tunnel_ttl = 64; 540 542 if (iph->protocol == IPPROTO_ICMP) { 541 543 key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */ 542 - } else { 543 - if (iph->protocol != IPPROTO_TCP || iph->ihl != 5) 544 - return TC_ACT_SHOT; 545 - 546 - if (tcp->dest == bpf_htons(5200)) 547 - key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */ 548 - else if (tcp->dest == bpf_htons(5201)) 549 - key.remote_ipv4 = 0xac100165; /* 172.16.1.101 */ 550 - else 551 - return TC_ACT_SHOT; 552 544 } 553 545 554 546 ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0); ··· 573 585 struct bpf_tunnel_key key = {}; 574 586 void *data = (void *)(long)skb->data; 575 587 struct iphdr *iph = data; 576 - struct tcphdr *tcp = data + sizeof(*iph); 577 588 void *data_end = (void *)(long)skb->data_end; 578 589 int ret; 579 590 580 591 /* single length check */ 581 - if (data + sizeof(*iph) + sizeof(*tcp) > data_end) { 592 + if (data + sizeof(*iph) > data_end) { 582 593 ERROR(1); 583 594 return TC_ACT_SHOT; 584 595 } 585 596 586 597 __builtin_memset(&key, 0x0, sizeof(key)); 587 - key.remote_ipv6[3] = bpf_htonl(0x11); /* ::11 */ 588 598 key.tunnel_ttl = 64; 599 + if (iph->protocol == IPPROTO_ICMP) { 600 + key.remote_ipv6[3] = bpf_htonl(0x11); /* ::11 */ 601 + } 589 602 590 603 ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 591 604 BPF_F_TUNINFO_IPV6); ··· 623 634 struct bpf_tunnel_key key = {}; 624 635 void *data = (void *)(long)skb->data; 625 636 struct ipv6hdr *iph = data; 626 - struct tcphdr *tcp = data + sizeof(*iph); 627 637 void *data_end = (void *)(long)skb->data_end; 628 638 int ret; 629 639 630 640 /* single length check */ 631 - if (data + sizeof(*iph) + sizeof(*tcp) > data_end) { 641 + if (data + sizeof(*iph) > data_end) { 632 642 ERROR(1); 633 643 return TC_ACT_SHOT; 634 644 } 635 645 636 - key.remote_ipv6[0] = bpf_htonl(0x2401db00); 637 646 key.tunnel_ttl = 64; 638 - 639 647 if (iph->nexthdr == 58 /* NEXTHDR_ICMP */) { 640 - key.remote_ipv6[3] = bpf_htonl(1); 641 - } else { 642 - if (iph->nexthdr != 6 /* NEXTHDR_TCP */) { 643 - ERROR(iph->nexthdr); 644 - return TC_ACT_SHOT; 645 - } 646 - 647 - if (tcp->dest == bpf_htons(5200)) { 648 - key.remote_ipv6[3] = bpf_htonl(1); 649 - } else if (tcp->dest == bpf_htons(5201)) { 650 - key.remote_ipv6[3] = bpf_htonl(2); 651 - } else { 652 - ERROR(tcp->dest); 653 - return TC_ACT_SHOT; 654 - } 648 + key.remote_ipv6[3] = bpf_htonl(0x11); /* ::11 */ 655 649 } 656 650 657 651 ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key),
+39 -4
tools/testing/selftests/bpf/test_tunnel.sh
··· 24 24 # Root namespace with metadata-mode tunnel + BPF 25 25 # Device names and addresses: 26 26 # veth1 IP: 172.16.1.200, IPv6: 00::22 (underlay) 27 - # tunnel dev <type>11, ex: gre11, IPv4: 10.1.1.200 (overlay) 27 + # tunnel dev <type>11, ex: gre11, IPv4: 10.1.1.200, IPv6: 1::22 (overlay) 28 28 # 29 29 # Namespace at_ns0 with native tunnel 30 30 # Device names and addresses: 31 31 # veth0 IPv4: 172.16.1.100, IPv6: 00::11 (underlay) 32 - # tunnel dev <type>00, ex: gre00, IPv4: 10.1.1.100 (overlay) 32 + # tunnel dev <type>00, ex: gre00, IPv4: 10.1.1.100, IPv6: 1::11 (overlay) 33 33 # 34 34 # 35 35 # End-to-end ping packet flow ··· 250 250 ip addr add dev $DEV 10.1.1.200/24 251 251 } 252 252 253 - add_ipip6tnl_tunnel() 253 + add_ip6tnl_tunnel() 254 254 { 255 255 ip netns exec at_ns0 ip addr add ::11/96 dev veth0 256 256 ip netns exec at_ns0 ip link set dev veth0 up ··· 262 262 ip link add dev $DEV_NS type $TYPE \ 263 263 local ::11 remote ::22 264 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 265 266 ip netns exec at_ns0 ip link set dev $DEV_NS up 266 267 267 268 # root namespace 268 269 ip link add dev $DEV type $TYPE external 269 270 ip addr add dev $DEV 10.1.1.200/24 271 + ip addr add dev $DEV 1::22/96 270 272 ip link set dev $DEV up 271 273 } 272 274 ··· 536 534 537 535 check $TYPE 538 536 config_device 539 - add_ipip6tnl_tunnel 537 + add_ip6tnl_tunnel 540 538 ip link set dev veth1 mtu 1500 541 539 attach_bpf $DEV ipip6_set_tunnel ipip6_get_tunnel 542 540 # underlay ··· 553 551 return 1 554 552 fi 555 553 echo -e ${GREEN}"PASS: $TYPE"${NC} 554 + } 555 + 556 + test_ip6ip6() 557 + { 558 + TYPE=ip6tnl 559 + DEV_NS=ip6ip6tnl00 560 + DEV=ip6ip6tnl11 561 + ret=0 562 + 563 + check $TYPE 564 + config_device 565 + add_ip6tnl_tunnel 566 + ip link set dev veth1 mtu 1500 567 + attach_bpf $DEV ip6ip6_set_tunnel ip6ip6_get_tunnel 568 + # underlay 569 + ping6 $PING_ARG ::11 570 + # ip6 over ip6 571 + ping6 $PING_ARG 1::11 572 + check_err $? 573 + ip netns exec at_ns0 ping6 $PING_ARG 1::22 574 + check_err $? 575 + cleanup 576 + 577 + if [ $ret -ne 0 ]; then 578 + echo -e ${RED}"FAIL: ip6$TYPE"${NC} 579 + return 1 580 + fi 581 + echo -e ${GREEN}"PASS: ip6$TYPE"${NC} 556 582 } 557 583 558 584 setup_xfrm_tunnel() ··· 676 646 ip link del veth1 2> /dev/null 677 647 ip link del ipip11 2> /dev/null 678 648 ip link del ipip6tnl11 2> /dev/null 649 + ip link del ip6ip6tnl11 2> /dev/null 679 650 ip link del gretap11 2> /dev/null 680 651 ip link del ip6gre11 2> /dev/null 681 652 ip link del ip6gretap11 2> /dev/null ··· 771 740 772 741 echo "Testing IPIP6 tunnel..." 773 742 test_ipip6 743 + errors=$(( $errors + $? )) 744 + 745 + echo "Testing IP6IP6 tunnel..." 746 + test_ip6ip6 774 747 errors=$(( $errors + $? )) 775 748 776 749 echo "Testing IPSec tunnel..."