From: Willem de Bruijn <willemdebruijn.kernel@gmail.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 5/6] packet: use Ethernet header length in vlan_get_tci()
Date: Tue, 24 Nov 2026 12:05:43 -0500 [thread overview]
Message-ID: <20261124170551.1874487-6-willemdebruijn.kernel@gmail.com> (raw)
In-Reply-To: <20261124170551.1874487-1-willemdebruijn.kernel@gmail.com>
From: Willem de Bruijn <willemb@google.com>
vlan_get_tci() uses dev->min_header_len to locate the outer 802.1Q/AD
header on SOCK_DGRAM captures, with an is_vlan_dev() fallback that has
been obsolete since commit 447cbe95ebb9 ("vlan: fix skb_under_panic and
races when toggling HW VLAN offload") stopped adding VLAN_HLEN to
vlandev->hard_header_len.
Only Ethernet and loopback devices set min_header_len (to ETH_HLEN).
Check ARPHRD_ETHER / ARPHRD_LOOPBACK and read at ETH_HLEN directly
instead, removing the last min_header_len reader and letting
packet_recvmsg() use sll->sll_hatype without an RCU device lookup.
This changes the reported TCI in three cases:
- Ethernet devices with hard_header_len > ETH_HLEN (e.g., smsc95xx,
rndis_host) previously failed the min_header_len == hard_header_len
test and reported TCI 0. They now report the TCI.
- Non-Ethernet devices with hard_header_len 0 (e.g., tun, rmnet)
previously read a VLAN header at the MAC offset. They now report
TCI 0.
- packet_recvmsg() previously omitted the VLAN fields if the device
had been unregistered since the packet was queued. It now fills
them from the queued skb.
Signed-off-by: Willem de Bruijn <willemb@google.com>
---
net/packet/af_packet.c | 38 +++++++++-----------------------------
1 file changed, 9 insertions(+), 29 deletions(-)
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index bf0ad6d5c1e3..b169d3e11b17 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -547,29 +547,18 @@ static void *packet_current_frame(struct packet_sock *po,
return packet_lookup_frame(po, rb, rb->head, status);
}
-static u16 vlan_get_tci(const struct sk_buff *skb, struct net_device *dev)
+static u16 vlan_get_tci(const struct sk_buff *skb, unsigned short type)
{
struct vlan_hdr vhdr, *vh;
- unsigned int header_len;
- if (!dev)
+ if (type != ARPHRD_ETHER && type != ARPHRD_LOOPBACK)
return 0;
/* In the SOCK_DGRAM scenario, skb data starts at the network
* protocol, which is after the VLAN headers. The outer VLAN
- * header is at the hard_header_len offset in non-variable
- * length link layer headers. If it's a VLAN device, the
- * min_header_len should be used to exclude the VLAN header
- * size.
+ * header is at the ETH_HLEN offset from the MAC header.
*/
- if (dev->min_header_len == dev->hard_header_len)
- header_len = dev->hard_header_len;
- else if (is_vlan_dev(dev))
- header_len = dev->min_header_len;
- else
- return 0;
-
- vh = skb_header_pointer(skb, skb_mac_offset(skb) + header_len,
+ vh = skb_header_pointer(skb, skb_mac_offset(skb) + ETH_HLEN,
sizeof(vhdr), &vhdr);
if (unlikely(!vh))
return 0;
@@ -1012,7 +1001,7 @@ static void prb_fill_vlan_info(struct tpacket_kbdq_core *pkc,
ppd->hv1.tp_vlan_tpid = ntohs(pkc->skb->vlan_proto);
ppd->tp_status = TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
} else if (unlikely(po->sk.sk_type == SOCK_DGRAM && eth_type_vlan(pkc->skb->protocol))) {
- ppd->hv1.tp_vlan_tci = vlan_get_tci(pkc->skb, pkc->skb->dev);
+ ppd->hv1.tp_vlan_tci = vlan_get_tci(pkc->skb, pkc->skb->dev->type);
ppd->hv1.tp_vlan_tpid = ntohs(pkc->skb->protocol);
ppd->tp_status = TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
} else {
@@ -2454,7 +2443,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
h.h2->tp_vlan_tpid = ntohs(skb->vlan_proto);
status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
} else if (unlikely(sk->sk_type == SOCK_DGRAM && eth_type_vlan(skb->protocol))) {
- h.h2->tp_vlan_tci = vlan_get_tci(skb, skb->dev);
+ h.h2->tp_vlan_tci = vlan_get_tci(skb, dev->type);
h.h2->tp_vlan_tpid = ntohs(skb->protocol);
status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
} else {
@@ -3626,19 +3615,10 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
} else if (unlikely(sock->type == SOCK_DGRAM && eth_type_vlan(skb->protocol))) {
struct sockaddr_ll *sll = &PACKET_SKB_CB(skb)->sa.ll;
- struct net_device *dev;
- rcu_read_lock();
- dev = dev_get_by_index_rcu(sock_net(sk), sll->sll_ifindex);
- if (dev) {
- aux.tp_vlan_tci = vlan_get_tci(skb, dev);
- aux.tp_vlan_tpid = ntohs(skb->protocol);
- aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
- } else {
- aux.tp_vlan_tci = 0;
- aux.tp_vlan_tpid = 0;
- }
- rcu_read_unlock();
+ aux.tp_vlan_tci = vlan_get_tci(skb, sll->sll_hatype);
+ aux.tp_vlan_tpid = ntohs(skb->protocol);
+ aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
} else {
aux.tp_vlan_tci = 0;
aux.tp_vlan_tpid = 0;
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-24 17:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 17:05 [PATCH net-next 0/6] net: remove dev_validate_header() and net_device::min_header_len Willem de Bruijn
2026-11-24 17:05 ` [PATCH net-next 1/6] net: ipa: remove ethernet-specific artifacts from modem netdev setup Willem de Bruijn
2026-11-24 17:57 ` Alex Elder
2026-11-26 17:49 ` willemb
2026-11-24 17:05 ` [PATCH net-next 2/6] net: remove header_ops->validate and dev_validate_header() Willem de Bruijn
2026-11-25 20:06 ` netdev-bot+sashiko
2026-11-24 17:05 ` [PATCH net-next 3/6] packet: validate TX header length before skb allocation Willem de Bruijn
2026-11-25 20:06 ` netdev-bot+sashiko
2026-11-24 17:05 ` [PATCH net-next 4/6] packet: reset network header on all headerless devices Willem de Bruijn
2026-11-24 17:05 ` Willem de Bruijn [this message]
2026-11-25 20:06 ` [PATCH net-next 5/6] packet: use Ethernet header length in vlan_get_tci() netdev-bot+sashiko
2026-11-24 17:05 ` [PATCH net-next 6/6] net: remove unused net_device::min_header_len Willem de Bruijn
2026-11-26 17:46 ` [PATCH net-next 0/6] 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=20261124170551.1874487-6-willemdebruijn.kernel@gmail.com \
--to=willemdebruijn.kernel@gmail.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 \
--cc=willemb@google.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.