Skip to contentSkip to conversation

Set skb->protocol properly before calling dst_output()

PATCH In review Eli Cooper 2 participants 3 messages Nov 29, 2016 – Nov 30, 2016

Subsystems (3)
lore
Share & tools
lore

Eli Cooper

author
#0 lore raw

PATCH 1/2 Set skb->protocol properly before calling dst_output()

When xfrm is applied to TSO/GSO packets, it follows this path:

    xfrm_output() -> xfrm_output_gso() -> skb_gso_segment()

where skb_gso_segment() relies on skb->protocol to function properly.

This patch sets skb->protocol properly before dst_output() is called, fixing a bug where GSO packets sent through a sit or ipip6 tunnel are dropped when xfrm is involved.

---
 net/ipv4/ip_output.c   | 4 +++-
 net/ipv6/output_core.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
net/ipv4/ip_output.c +3 -1
index 105908d..0180e44 100644
@@ -117,8 +117,10 @@ int ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb)
 	int err;
 
 	err = __ip_local_out(net, sk, skb);
-	if (likely(err == 1))
+	if (likely(err == 1)) {
+		skb->protocol = htons(ETH_P_IP);
 		err = dst_output(net, sk, skb);
+	}
 
 	return err;
 }
net/ipv6/output_core.c +3 -1
index 7cca8ac..d6e850d 100644
@@ -166,8 +166,10 @@ int ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb)
 	int err;
 
 	err = __ip6_local_out(net, sk, skb);
-	if (likely(err == 1))
+	if (likely(err == 1)) {
+		skb->protocol = htons(ETH_P_IPV6);
 		err = dst_output(net, sk, skb);
+	}
 
 	return err;
 }
Signature · 1 line
2.10.2
author
#1 lore raw

PATCH 2/2 Revert: "ip6_tunnel: Update skb->protocol to ETH_P_IPV6 in ip6_tnl_xmit()"

This reverts commit ae148b085876fa771d9ef2c05f85d4b4bf09ce0d ("ip6_tunnel: Update skb->protocol to ETH_P_IPV6 in ip6_tnl_xmit()").

skb->protocol is now set in ip_local_out() and ip6_local_out() right before dst_output() is called. It is no longer necessary to do it in each tunnel.

---
 net/ipv6/ip6_tunnel.c | 1 -
 1 file changed, 1 deletion(-)
net/ipv6/ip6_tunnel.c +0 -1
index 0a4759b..d76674e 100644
@@ -1181,7 +1181,6 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
 	if (err)
 		return err;
 
-	skb->protocol = htons(ETH_P_IPV6);
 	skb_push(skb, sizeof(struct ipv6hdr));
 	skb_reset_network_header(skb);
 	ipv6h = ipv6_hdr(skb);
Signature · 1 line
2.10.2
maintainer
#2 lore raw
In reply to Eli Cooper

From: Eli Cooper <[email protected]>
Date: Tue, 29 Nov 2016 10:35:28 +0800

Quoted 22 lines

When xfrm is applied to TSO/GSO packets, it follows this path:

    xfrm_output() -> xfrm_output_gso() -> skb_gso_segment()

where skb_gso_segment() relies on skb->protocol to function properly.

This patch sets skb->protocol properly before dst_output() is called, fixing a bug where GSO packets sent through a sit or ipip6 tunnel are dropped when xfrm is involved.

---
 net/ipv4/ip_output.c   | 4 +++-
 net/ipv6/output_core.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
net/ipv4/ip_output.c +0 -0
index 105908d..0180e44 100644

net/ipv4/ip_output.c int ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb) · line 124

Quoted 9 lines
net/ipv4/ip_output.c +3 -1
@@ -117,8 +117,10 @@ int ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb)
 	int err;
 
 	err = __ip_local_out(net, sk, skb);
-	if (likely(err == 1))
+	if (likely(err == 1)) {
+		skb->protocol = htons(ETH_P_IP);
 		err = dst_output(net, sk, skb);
+	}
 

__ip_local_out() potentially does a dst_output() call too via the netfilter hook, so you definitely need to place the skb->protocol assignment before that netfilter hook.