Skip to content

Commit 9600d62

Browse files
author
Alexei Starovoitov
committed
Merge branch 'Remove unused test_ipip.sh test and add missed'
Hangbin Liu says: ==================== In comment 173ca26 ("samples/bpf: add comprehensive ipip, ipip6, ip6ip6 test") we added some bpf tunnel tests. In commit 933a741 ("selftests/bpf: bpf tunnel test.") when we moved it to the current folder, we missed some points: 1. ip6ip6 test is not added 2. forgot to remove test_ipip.sh in sample folder 3. TCP test code is not removed in test_tunnel_kern.c In this patch set I add back ip6ip6 test and remove unused code. I'm not sure if this should be net or net-next, so just set to net. Here is the test result: ``` Testing IP6IP6 tunnel... PING ::11(::11) 56 data bytes --- ::11 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 63ms rtt min/avg/max/mdev = 0.014/1028.308/2060.906/841.361 ms, pipe 2 PING 1::11(1::11) 56 data bytes --- 1::11 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 48ms rtt min/avg/max/mdev = 0.026/0.029/0.036/0.006 ms PING 1::22(1::22) 56 data bytes --- 1::22 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 47ms rtt min/avg/max/mdev = 0.030/0.048/0.067/0.016 ms PASS: ip6ip6tnl ``` v3: Add back ICMP check as Martin suggested. v2: Keep ip6ip6 section in test_tunnel_kern.c. ==================== Acked-by: Martin KaFai Lau <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents 0e6f601 + e2215b0 commit 9600d62

File tree

3 files changed

+46
-218
lines changed

3 files changed

+46
-218
lines changed

samples/bpf/test_ipip.sh

Lines changed: 0 additions & 179 deletions
This file was deleted.

tools/testing/selftests/bpf/progs/test_tunnel_kern.c

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <linux/ip.h>
1616
#include <linux/ipv6.h>
1717
#include <linux/types.h>
18-
#include <linux/tcp.h>
1918
#include <linux/socket.h>
2019
#include <linux/pkt_cls.h>
2120
#include <linux/erspan.h>
@@ -528,29 +527,18 @@ int _ipip_set_tunnel(struct __sk_buff *skb)
528527
struct bpf_tunnel_key key = {};
529528
void *data = (void *)(long)skb->data;
530529
struct iphdr *iph = data;
531-
struct tcphdr *tcp = data + sizeof(*iph);
532530
void *data_end = (void *)(long)skb->data_end;
533531
int ret;
534532

535533
/* single length check */
536-
if (data + sizeof(*iph) + sizeof(*tcp) > data_end) {
534+
if (data + sizeof(*iph) > data_end) {
537535
ERROR(1);
538536
return TC_ACT_SHOT;
539537
}
540538

541539
key.tunnel_ttl = 64;
542540
if (iph->protocol == IPPROTO_ICMP) {
543541
key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */
544-
} else {
545-
if (iph->protocol != IPPROTO_TCP || iph->ihl != 5)
546-
return TC_ACT_SHOT;
547-
548-
if (tcp->dest == bpf_htons(5200))
549-
key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */
550-
else if (tcp->dest == bpf_htons(5201))
551-
key.remote_ipv4 = 0xac100165; /* 172.16.1.101 */
552-
else
553-
return TC_ACT_SHOT;
554542
}
555543

556544
ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
@@ -585,19 +573,20 @@ int _ipip6_set_tunnel(struct __sk_buff *skb)
585573
struct bpf_tunnel_key key = {};
586574
void *data = (void *)(long)skb->data;
587575
struct iphdr *iph = data;
588-
struct tcphdr *tcp = data + sizeof(*iph);
589576
void *data_end = (void *)(long)skb->data_end;
590577
int ret;
591578

592579
/* single length check */
593-
if (data + sizeof(*iph) + sizeof(*tcp) > data_end) {
580+
if (data + sizeof(*iph) > data_end) {
594581
ERROR(1);
595582
return TC_ACT_SHOT;
596583
}
597584

598585
__builtin_memset(&key, 0x0, sizeof(key));
599-
key.remote_ipv6[3] = bpf_htonl(0x11); /* ::11 */
600586
key.tunnel_ttl = 64;
587+
if (iph->protocol == IPPROTO_ICMP) {
588+
key.remote_ipv6[3] = bpf_htonl(0x11); /* ::11 */
589+
}
601590

602591
ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key),
603592
BPF_F_TUNINFO_IPV6);
@@ -634,35 +623,18 @@ int _ip6ip6_set_tunnel(struct __sk_buff *skb)
634623
struct bpf_tunnel_key key = {};
635624
void *data = (void *)(long)skb->data;
636625
struct ipv6hdr *iph = data;
637-
struct tcphdr *tcp = data + sizeof(*iph);
638626
void *data_end = (void *)(long)skb->data_end;
639627
int ret;
640628

641629
/* single length check */
642-
if (data + sizeof(*iph) + sizeof(*tcp) > data_end) {
630+
if (data + sizeof(*iph) > data_end) {
643631
ERROR(1);
644632
return TC_ACT_SHOT;
645633
}
646634

647-
key.remote_ipv6[0] = bpf_htonl(0x2401db00);
648635
key.tunnel_ttl = 64;
649-
650636
if (iph->nexthdr == 58 /* NEXTHDR_ICMP */) {
651-
key.remote_ipv6[3] = bpf_htonl(1);
652-
} else {
653-
if (iph->nexthdr != 6 /* NEXTHDR_TCP */) {
654-
ERROR(iph->nexthdr);
655-
return TC_ACT_SHOT;
656-
}
657-
658-
if (tcp->dest == bpf_htons(5200)) {
659-
key.remote_ipv6[3] = bpf_htonl(1);
660-
} else if (tcp->dest == bpf_htons(5201)) {
661-
key.remote_ipv6[3] = bpf_htonl(2);
662-
} else {
663-
ERROR(tcp->dest);
664-
return TC_ACT_SHOT;
665-
}
637+
key.remote_ipv6[3] = bpf_htonl(0x11); /* ::11 */
666638
}
667639

668640
ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key),

tools/testing/selftests/bpf/test_tunnel.sh

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
# Root namespace with metadata-mode tunnel + BPF
2525
# Device names and addresses:
2626
# 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)
2828
#
2929
# Namespace at_ns0 with native tunnel
3030
# Device names and addresses:
3131
# 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)
3333
#
3434
#
3535
# End-to-end ping packet flow
@@ -250,7 +250,7 @@ add_ipip_tunnel()
250250
ip addr add dev $DEV 10.1.1.200/24
251251
}
252252

253-
add_ipip6tnl_tunnel()
253+
add_ip6tnl_tunnel()
254254
{
255255
ip netns exec at_ns0 ip addr add ::11/96 dev veth0
256256
ip netns exec at_ns0 ip link set dev veth0 up
@@ -262,11 +262,13 @@ add_ipip6tnl_tunnel()
262262
ip link add dev $DEV_NS type $TYPE \
263263
local ::11 remote ::22
264264
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
265266
ip netns exec at_ns0 ip link set dev $DEV_NS up
266267

267268
# root namespace
268269
ip link add dev $DEV type $TYPE external
269270
ip addr add dev $DEV 10.1.1.200/24
271+
ip addr add dev $DEV 1::22/96
270272
ip link set dev $DEV up
271273
}
272274

@@ -534,7 +536,7 @@ test_ipip6()
534536

535537
check $TYPE
536538
config_device
537-
add_ipip6tnl_tunnel
539+
add_ip6tnl_tunnel
538540
ip link set dev veth1 mtu 1500
539541
attach_bpf $DEV ipip6_set_tunnel ipip6_get_tunnel
540542
# underlay
@@ -553,6 +555,34 @@ test_ipip6()
553555
echo -e ${GREEN}"PASS: $TYPE"${NC}
554556
}
555557

558+
test_ip6ip6()
559+
{
560+
TYPE=ip6tnl
561+
DEV_NS=ip6ip6tnl00
562+
DEV=ip6ip6tnl11
563+
ret=0
564+
565+
check $TYPE
566+
config_device
567+
add_ip6tnl_tunnel
568+
ip link set dev veth1 mtu 1500
569+
attach_bpf $DEV ip6ip6_set_tunnel ip6ip6_get_tunnel
570+
# underlay
571+
ping6 $PING_ARG ::11
572+
# ip6 over ip6
573+
ping6 $PING_ARG 1::11
574+
check_err $?
575+
ip netns exec at_ns0 ping6 $PING_ARG 1::22
576+
check_err $?
577+
cleanup
578+
579+
if [ $ret -ne 0 ]; then
580+
echo -e ${RED}"FAIL: ip6$TYPE"${NC}
581+
return 1
582+
fi
583+
echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
584+
}
585+
556586
setup_xfrm_tunnel()
557587
{
558588
auth=0x$(printf '1%.0s' {1..40})
@@ -646,6 +676,7 @@ cleanup()
646676
ip link del veth1 2> /dev/null
647677
ip link del ipip11 2> /dev/null
648678
ip link del ipip6tnl11 2> /dev/null
679+
ip link del ip6ip6tnl11 2> /dev/null
649680
ip link del gretap11 2> /dev/null
650681
ip link del ip6gre11 2> /dev/null
651682
ip link del ip6gretap11 2> /dev/null
@@ -742,6 +773,10 @@ bpf_tunnel_test()
742773
test_ipip6
743774
errors=$(( $errors + $? ))
744775

776+
echo "Testing IP6IP6 tunnel..."
777+
test_ip6ip6
778+
errors=$(( $errors + $? ))
779+
745780
echo "Testing IPSec tunnel..."
746781
test_xfrm_tunnel
747782
errors=$(( $errors + $? ))

0 commit comments

Comments
 (0)