All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemb@google.com>
To: netdev@vger.kernel.org
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	 kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	elder@kernel.org,  Willem de Bruijn <willemb@google.com>
Subject: [PATCH net-next v2 3/5] packet: reset network header on all headerless devices
Date: Sun, 29 Nov 2026 11:30:38 -0500	[thread overview]
Message-ID: <20261129163327.893403-4-willemb@google.com> (raw)
In-Reply-To: <20261129163327.893403-1-willemb@google.com>

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 <willemb@google.com>
---
 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


  parent reply	other threads:[~2026-11-29 16:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 16:30 [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 1/5] net: ipa: remove ethernet-specific artifacts from modem netdev setup Willem de Bruijn
2026-11-29 16:30 ` [PATCH net-next v2 2/5] net: remove header_ops->validate and dev_validate_header() Willem de Bruijn
2026-11-30 17:36   ` netdev-bot+sashiko
2026-11-29 16:30 ` Willem de Bruijn [this message]
2026-11-30 17:36   ` [PATCH net-next v2 3/5] packet: reset network header on all headerless devices netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 4/5] packet: use Ethernet header length in vlan_get_tci() Willem de Bruijn
2026-11-30 17:36   ` netdev-bot+sashiko
2026-11-29 16:30 ` [PATCH net-next v2 5/5] net: remove unused net_device::min_header_len Willem de Bruijn
2026-12-02  1:46 ` [PATCH net-next v2 0/5] net: remove dev_validate_header() and net_device::min_header_len willemb

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129163327.893403-4-willemb@google.com \
    --to=willemb@google.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=elder@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.