[{xenial, disco}:linux-azure PATCH 1/1] SAUCE: af_packet: Fix skb protocol value in tpacket_fill_skb()

Marcelo Henrique Cerri marcelo.cerri at canonical.com
Thu Dec 12 14:00:44 UTC 2019


From: Raghav Kempanna <kraghav at vmware.com>

BugLink: https://bugs.launchpad.net/bugs/1855461

Adapted from upstream patches for 4.15:
75c65772c3d1 ("net/packet: Ask driver for protocol if not provided by user")
18bed89107a4 ("af_packet: fix the tx skb protocol in raw sockets with ETH_P_ALL")

Signed-off-by: Raghav Kempanna <kraghav at vmware.com>
Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com>
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri at canonical.com>
---
 net/packet/af_packet.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 1e25e06df2db..ea74f2ffe41d 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2550,6 +2550,15 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
 		len = ((to_write > len_max) ? len_max : to_write);
 	}
 
+	if ((!skb->protocol || skb->protocol == htons(ETH_P_ALL)) &&
+	    sock->type == SOCK_RAW) {
+		const struct ethhdr *eth;
+
+		skb_reset_mac_header(skb);
+		eth = eth_hdr(skb);
+		skb->protocol = eth->h_proto;
+	}
+
 	skb_probe_transport_header(skb, 0);
 
 	return tp_len;
-- 
2.20.1




More information about the kernel-team mailing list