Devices without a userspace-visible link layer header (!dev_has_header()) should leave hard_header_len at 0 and use needed_headroom for headers prepended in ndo_start_xmit(), but some still set hard_header_len > 0 instead (e.g., PPP, mctp-usb, routed br2684, and previously sit). On SOCK_RAW sends, af_packet reserves hard_header_len and leaves skb->network_header pointing that many bytes into the L3 header. Commit 88a8121dc1d3 ("af_packet: fix raw sockets over 6in4 tunnel") added a workaround in packet_snd() only for short IPv6 packets on 6in4 tunnels, explicitly noting that it was temporary and left to be cleaned up in net-next. That heuristic misses longer packets and misfires on non-Ethernet devices with a link layer header where min_header_len is 0. Replace it with !dev_has_header(dev) in packet_snd(). Apply the same in tpacket_fill_skb(), which has the same problem but never had the workaround, so that SOCK_RAW sends behave the same with and without a TX ring. For consistency, also switch packet_sendmsg_spkt() from dev->header_ops to dev_has_header(dev). This has no effect today: the only header_ops without ->create are ip_tunnel_header_ops and hdlc_null_ops, and all devices using them have hard_header_len 0. Signed-off-by: Willem de Bruijn --- net/packet/af_packet.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 0ea3036bee24..4ff7a2cc11e5 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2054,7 +2054,7 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg, if (!skb) { size_t reserved = LL_RESERVED_SPACE_EX(dev, hard_header_len); int tlen = dev->needed_tailroom; - unsigned int hhlen = dev->header_ops ? hard_header_len : 0; + unsigned int hhlen = dev_has_header(dev) ? hard_header_len : 0; rcu_read_unlock(); skb = sock_wmalloc(sk, len + reserved + tlen, 0, GFP_KERNEL); @@ -2661,6 +2661,8 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, skb_push(skb, hard_header_len); skb_put(skb, copylen - hard_header_len); + if (!dev_has_header(dev)) + skb_reset_network_header(skb); err = skb_store_bits(skb, 0, data, hdrlen); if (unlikely(err)) return err; @@ -3125,8 +3127,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len) goto out_free; } else if (reserve) { skb_reserve(skb, -reserve); - if (len < reserve + sizeof(struct ipv6hdr) && - dev->min_header_len != hard_header_len) + if (!dev_has_header(dev)) skb_reset_network_header(skb); } -- 2.56.1.839.g22a8290db9-goog