Skip to contentSkip to conversation

gre_offload: simplify GRE header length calculation in gre_gso_segment()

PATCH Applied Neal Cardwell 3 participants 3 messages Jan 10, 2014 – Jan 13, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gre_offload: simplify GRE header length calculation in gre_gso_segment()

Simplify the GRE header length calculation in gre_gso_segment(). Switch to an approach that is simpler, faster, and more general. The new approach will continue to be correct even if we add support for the optional variable-length routing info that may be present in a GRE header.

Cc Eric Dumazet <[email protected]>
Cc H.K. Jerry Chu <[email protected]>
Cc Pravin B Shelar <[email protected]>
---
 net/ipv4/gre_offload.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
net/ipv4/gre_offload.c +6 -10
index 746a7b1..f6604b6 100644
@@ -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;
Signature · 1 line
1.8.5.1
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Neal Cardwell

Simplify the GRE header length calculation in gre_gso_segment(). Switch to an approach that is simpler, faster, and more general. The new approach will continue to be correct even if we add support for the optional variable-length routing info that may be present in a GRE header.

Cc Eric Dumazet <[email protected]>
Cc H.K. Jerry Chu <[email protected]>
Cc Pravin B Shelar <[email protected]>

---

maintainer Applied
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Thu, 09 Jan 2014 18:09:18 -0800

Quoted 7 lines · Neal Cardwell
Quoted 6 lines

Simplify the GRE header length calculation in gre_gso_segment(). Switch to an approach that is simpler, faster, and more general. The new approach will continue to be correct even if we add support for the optional variable-length routing info that may be present in a GRE header.

Quoted 7 lines
Quoted 5 lines
Cc Eric Dumazet <[email protected]>
Cc H.K. Jerry Chu <[email protected]>
Cc Pravin B Shelar <[email protected]>

---

Applied, thank you.