udp: properly complete L4 GRO over UDP tunnel packet
authorPaolo Abeni <pabeni@redhat.com>
Tue, 30 Mar 2021 10:28:51 +0000 (12:28 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 31 Mar 2021 00:06:49 +0000 (17:06 -0700)
After the previous patch, the stack can do L4 UDP aggregation
on top of a UDP tunnel.

In such scenario, udp{4,6}_gro_complete will be called twice. This function
will enter its is_flist branch immediately, even though that is only
correct on the second call, as GSO_FRAGLIST is only relevant for the
inner packet.

Instead, we need to try first UDP tunnel-based aggregation, if the GRO
packet requires that.

This patch changes udp{4,6}_gro_complete to skip the frag list processing
when while encap_mark == 1, identifying processing of the outer tunnel
header.
Additionally, clears the field in udp_gro_complete() so that we can enter
the frag list path on the next round, for the inner header.

v1 -> v2:
 - hopefully clarified the commit message

Reviewed-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/udp_offload.c
net/ipv6/udp_offload.c

index 25134a3..54e06b8 100644 (file)
@@ -642,6 +642,11 @@ int udp_gro_complete(struct sk_buff *skb, int nhoff,
                skb_shinfo(skb)->gso_type = uh->check ? SKB_GSO_UDP_TUNNEL_CSUM
                                        : SKB_GSO_UDP_TUNNEL;
 
+               /* clear the encap mark, so that inner frag_list gro_complete
+                * can take place
+                */
+               NAPI_GRO_CB(skb)->encap_mark = 0;
+
                /* Set encapsulation before calling into inner gro_complete()
                 * functions to make them set up the inner offsets.
                 */
@@ -665,7 +670,8 @@ INDIRECT_CALLABLE_SCOPE int udp4_gro_complete(struct sk_buff *skb, int nhoff)
        const struct iphdr *iph = ip_hdr(skb);
        struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
 
-       if (NAPI_GRO_CB(skb)->is_flist) {
+       /* do fraglist only if there is no outer UDP encap (or we already processed it) */
+       if (NAPI_GRO_CB(skb)->is_flist && !NAPI_GRO_CB(skb)->encap_mark) {
                uh->len = htons(skb->len - nhoff);
 
                skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4);
index faa823c..b3d9ed9 100644 (file)
@@ -163,7 +163,8 @@ INDIRECT_CALLABLE_SCOPE int udp6_gro_complete(struct sk_buff *skb, int nhoff)
        const struct ipv6hdr *ipv6h = ipv6_hdr(skb);
        struct udphdr *uh = (struct udphdr *)(skb->data + nhoff);
 
-       if (NAPI_GRO_CB(skb)->is_flist) {
+       /* do fraglist only if there is no outer UDP encap (or we already processed it) */
+       if (NAPI_GRO_CB(skb)->is_flist && !NAPI_GRO_CB(skb)->encap_mark) {
                uh->len = htons(skb->len - nhoff);
 
                skb_shinfo(skb)->gso_type |= (SKB_GSO_FRAGLIST|SKB_GSO_UDP_L4);