gre_offload: simplify GRE header length calculation in gre_gso_segment()
[firefly-linux-kernel-4.4.55.git] / net / ipv4 / gre_offload.c
index 746a7b10d434e9270db2ef35ed5a0cb2f925982c..29512e3e7e7c6f598854d4d3eafd4e4047fc6440 100644 (file)
@@ -26,7 +26,7 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
 {
        struct sk_buff *segs = ERR_PTR(-EINVAL);
        netdev_features_t enc_features;
-       int ghl = GRE_HEADER_SECTION;
+       int ghl;
        struct gre_base_hdr *greh;
        u16 mac_offset = skb->mac_header;
        int mac_len = skb->mac_len;
@@ -49,15 +49,11 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
 
        greh = (struct gre_base_hdr *)skb_transport_header(skb);
 
-       if (greh->flags & GRE_KEY)
-               ghl += GRE_HEADER_SECTION;
-       if (greh->flags & GRE_SEQ)
-               ghl += GRE_HEADER_SECTION;
-       if (greh->flags & GRE_CSUM) {
-               ghl += GRE_HEADER_SECTION;
-               csum = true;
-       } else
-               csum = false;
+       ghl = skb_inner_network_header(skb) - skb_transport_header(skb);
+       if (unlikely(ghl < sizeof(*greh)))
+               goto out;
+
+       csum = !!(greh->flags & GRE_CSUM);
 
        if (unlikely(!pskb_may_pull(skb, ghl)))
                goto out;
@@ -250,7 +246,7 @@ out:
        return pp;
 }
 
-int gre_gro_complete(struct sk_buff *skb, int nhoff)
+static int gre_gro_complete(struct sk_buff *skb, int nhoff)
 {
        struct gre_base_hdr *greh = (struct gre_base_hdr *)(skb->data + nhoff);
        struct packet_offload *ptype;