selftests/bpf: convert bpf tunnel test to BPF_F_ADJ_ROOM_FIXED_GSO
authorWillem de Bruijn <willemb@google.com>
Fri, 22 Mar 2019 18:32:59 +0000 (14:32 -0400)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 22 Mar 2019 20:52:45 +0000 (13:52 -0700)
Lower route MTU to ensure packets fit in device MTU after encap, then
skip the gso_size changes.

Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/test_tc_tunnel.c
tools/testing/selftests/bpf/test_tc_tunnel.sh

index f6a16fd..3b79dff 100644 (file)
@@ -52,6 +52,7 @@ static __always_inline int encap_ipv4(struct __sk_buff *skb, bool with_gre)
        struct grev4hdr h_outer;
        struct iphdr iph_inner;
        struct tcphdr tcph;
+       __u64 flags;
        int olen;
 
        if (bpf_skb_load_bytes(skb, ETH_HLEN, &iph_inner,
@@ -69,10 +70,11 @@ static __always_inline int encap_ipv4(struct __sk_buff *skb, bool with_gre)
        if (tcph.dest != __bpf_constant_htons(cfg_port))
                return TC_ACT_OK;
 
+       flags = BPF_F_ADJ_ROOM_FIXED_GSO;
        olen = with_gre ? sizeof(h_outer) : sizeof(h_outer.ip);
 
        /* add room between mac and network header */
-       if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_MAC, 0))
+       if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_MAC, flags))
                return TC_ACT_SHOT;
 
        /* prepare new outer network header */
@@ -102,6 +104,7 @@ static __always_inline int encap_ipv6(struct __sk_buff *skb, bool with_gre)
        struct ipv6hdr iph_inner;
        struct grev6hdr h_outer;
        struct tcphdr tcph;
+       __u64 flags;
        int olen;
 
        if (bpf_skb_load_bytes(skb, ETH_HLEN, &iph_inner,
@@ -116,10 +119,11 @@ static __always_inline int encap_ipv6(struct __sk_buff *skb, bool with_gre)
        if (tcph.dest != __bpf_constant_htons(cfg_port))
                return TC_ACT_OK;
 
+       flags = BPF_F_ADJ_ROOM_FIXED_GSO;
        olen = with_gre ? sizeof(h_outer) : sizeof(h_outer.ip);
 
        /* add room between mac and network header */
-       if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_MAC, 0))
+       if (bpf_skb_adjust_room(skb, olen, BPF_ADJ_ROOM_MAC, flags))
                return TC_ACT_SHOT;
 
        /* prepare new outer network header */
@@ -195,7 +199,8 @@ static int decap_internal(struct __sk_buff *skb, int off, int len, char proto)
                return TC_ACT_OK;
        }
 
-       if (bpf_skb_adjust_room(skb, -olen, BPF_ADJ_ROOM_MAC, 0))
+       if (bpf_skb_adjust_room(skb, -olen, BPF_ADJ_ROOM_MAC,
+                               BPF_F_ADJ_ROOM_FIXED_GSO))
                return TC_ACT_SHOT;
 
        return TC_ACT_OK;
index 9e18754..cda5317 100755 (executable)
@@ -35,6 +35,12 @@ setup() {
        ip -netns "${ns1}" -6 addr add "${ns1_v6}/64" dev veth1 nodad
        ip -netns "${ns2}" -6 addr add "${ns2_v6}/64" dev veth2 nodad
 
+       # clamp route to reserve room for tunnel headers
+       ip -netns "${ns1}" -4 route flush table main
+       ip -netns "${ns1}" -6 route flush table main
+       ip -netns "${ns1}" -4 route add "${ns2_v4}" mtu 1476 dev veth1
+       ip -netns "${ns1}" -6 route add "${ns2_v6}" mtu 1456 dev veth1
+
        sleep 1
 
        dd if=/dev/urandom of="${infile}" bs="${datalen}" count=1 status=none