Skip to contentSkip to conversation

net: fix VLAN insert doc comment for shared-mbuf error code

PATCH Applied William Bland 2 participants 7 messages Aug 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 net: fix VLAN insert doc comment for shared-mbuf error code

The implementation returns -EINVAL when the mbuf is shared or indirect, but the doc comment inaccurately stated -EPERM.

Fixes c974021a5949 ("ether: add soft vlan encap/decap")
---
 lib/net/rte_ether.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
lib/net/rte_ether.h +2 -1
index c9a0b536c3..cb10d8fb06 100644
@@ -387,7 +387,8 @@ static inline int rte_vlan_strip(struct rte_mbuf *m)
  *   The packet mbuf.
  * @return
  *   - 0: On success
- *   -EPERM: mbuf is shared overwriting would be unsafe
+ *   -EINVAL: overwriting would be unsafe because mbuf is shared or
+ *            indirect, or mbuf's first segment is too short
  *   -ENOSPC: not enough headroom in mbuf
  */
 static inline int rte_vlan_insert(struct rte_mbuf **m)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 2/4 net/af_packet: make Rx VLAN stripped flag handling explicit

Rx VLAN handling set RTE_MBUF_F_RX_VLAN_STRIPPED unconditionally, relying on rte_vlan_insert() to clear it again. This produced correct flags, but in a way that was not readily apparent from the driver.

Make the flag handling explicit in the driver itself: only set RTE_MBUF_F_RX_VLAN_STRIPPED when vlan_strip is requested, or when reinsertion fails. No behavioral change.

---
 drivers/net/af_packet/rte_eth_af_packet.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/af_packet/rte_eth_af_packet.c +6 -2
index b0ff22ea55..d95d045a37 100644
@@ -223,10 +223,14 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 		/* check for vlan info */
 		if (ppd->tp_status & TP_STATUS_VLAN_VALID) {
 			mbuf->vlan_tci = ppd->tp_vlan_tci;
-			mbuf->ol_flags |= (RTE_MBUF_F_RX_VLAN | RTE_MBUF_F_RX_VLAN_STRIPPED);
+			mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN;
 
-			if (!pkt_q->vlan_strip && rte_vlan_insert(&mbuf))
+			if (pkt_q->vlan_strip) {
+				mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
+			} else if (rte_vlan_insert(&mbuf) != 0) {
 				PMD_LOG(ERR, "Failed to reinsert VLAN tag");
+				mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
+			}
 		}
 
 		/* add kernel provided timestamp when offloading is enabled */
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 2/4] net/af_packet: make Rx VLAN stripped flag handling explicit

Quoted 10 lines · On Wed, 26 Aug 2026 13:38:39 -0400 William Bland <[email protected]> wrote:

Rx VLAN handling set RTE_MBUF_F_RX_VLAN_STRIPPED unconditionally, relying on rte_vlan_insert() to clear it again. This produced correct flags, but in a way that was not readily apparent from the driver.

Make the flag handling explicit in the driver itself: only set RTE_MBUF_F_RX_VLAN_STRIPPED when vlan_strip is requested, or when reinsertion fails. No behavioral change.

---

Applied to next-net.

#3 lore raw

PATCH v2 3/4 net: add VLAN insert function with a TPID argument

In reply to William Bland

rte_vlan_insert() hardcodes EtherType 0x8100 (802.1Q). This is wrong when reinserting a stripped tag whose original TPID was 0x88a8 (802.1ad QinQ).

Add rte_vlan_insert_tpid() which takes an explicit tpid parameter, and rewrite rte_vlan_insert() as a wrapper that passes RTE_ETHER_TYPE_VLAN.

---
 app/test/meson.build                   |   2 +-
 app/test/test_net_ether.c              | 149 +++++++++++++++++++++++--
 doc/guides/rel_notes/release_26_11.rst |   7 ++
 lib/net/rte_ether.h                    |  61 +++++++---
 4 files changed, 193 insertions(+), 26 deletions(-)
app/test/meson.build +1 -1
index 51abeeb732..e927d4306a 100644
@@ -134,7 +134,7 @@ source_file_deps = {
     'test_meter.c': ['meter'],
     'test_metrics.c': ['metrics'],
     'test_mp_secondary.c': ['hash'],
-    'test_net_ether.c': ['net'],
+    'test_net_ether.c': ['net', 'mbuf'],
     'test_net_ip6.c': ['net'],
     'test_pcapng.c': ['net_null', 'net', 'ethdev', 'pcapng', 'bus_vdev'],
     'test_pdcp.c': ['eventdev', 'pdcp', 'net', 'timer', 'security'],
app/test/test_net_ether.c +139 -10

173 lines not on this page · raw message

doc/guides/rel_notes/release_26_11.rst +7 -0
index c8cc86295d..a7481b51ff 100644
@@ -55,6 +55,13 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added TPID support to VLAN tag insertion.**
+
+  Added ``rte_vlan_insert_tpid()`` to the net library, allowing the Tag
+  Protocol Identifier (TPID) of an inserted VLAN tag to be specified
+  explicitly, so that 802.1ad (QinQ) outer tags can be reinserted with
+  the correct EtherType.
+
 
 Removed Items
 -------------
lib/net/rte_ether.h +46 -15

79 lines not on this page · raw message

Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v2 3/4] net: add VLAN insert function with a TPID argument

Quoted 9 lines · On Wed, 26 Aug 2026 13:38:40 -0400 William Bland <[email protected]> wrote:

rte_vlan_insert() hardcodes EtherType 0x8100 (802.1Q). This is wrong when reinserting a stripped tag whose original TPID was 0x88a8 (802.1ad QinQ).

Add rte_vlan_insert_tpid() which takes an explicit tpid parameter, and rewrite rte_vlan_insert() as a wrapper that passes RTE_ETHER_TYPE_VLAN.

---

Applied to next-net.

#5 lore raw

PATCH v2 4/4 net/af_packet: fix QinQ outer TPID on VLAN reinsertion

In reply to William Bland

eth_af_packet_rx() called rte_vlan_insert(), which hardcodes EtherType 0x8100 (802.1Q). This was wrong when reinserting a stripped tag whose original TPID was 0x88a8 (802.1ad QinQ).

Fix by reading the actual TPID from tp_vlan_tpid (struct tpacket2_hdr), then passing it to rte_vlan_insert_tpid().

This depends on the rte_vlan_insert_tpid() function added by "net: add VLAN insert function with a TPID argument".

Fixes 23deeebfcfa8 ("net/af_packet: support 802.1Q VLAN")
---
 drivers/net/af_packet/rte_eth_af_packet.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/af_packet/rte_eth_af_packet.c +9 -3
index d95d045a37..e7fbb3c31d 100644
@@ -222,14 +222,20 @@ eth_af_packet_rx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts)
 
 		/* check for vlan info */
 		if (ppd->tp_status & TP_STATUS_VLAN_VALID) {
+			uint16_t tpid;
+
 			mbuf->vlan_tci = ppd->tp_vlan_tci;
 			mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN;
 
 			if (pkt_q->vlan_strip) {
 				mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
-			} else if (rte_vlan_insert(&mbuf) != 0) {
-				PMD_LOG(ERR, "Failed to reinsert VLAN tag");
-				mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
+			} else {
+				tpid = (ppd->tp_status & TP_STATUS_VLAN_TPID_VALID) ?
+					ppd->tp_vlan_tpid : RTE_ETHER_TYPE_VLAN;
+				if (rte_vlan_insert_tpid(&mbuf, tpid) != 0) {
+					PMD_LOG(ERR, "Failed to reinsert VLAN tag");
+					mbuf->ol_flags |= RTE_MBUF_F_RX_VLAN_STRIPPED;
+				}
 			}
 		}
 
Signature · 1 line
2.43.0
#6 lore raw
In reply to William Bland
Quoted 8 lines · On Wed, 26 Aug 2026 13:38:38 -0400 William Bland <[email protected]> wrote:

The implementation returns -EINVAL when the mbuf is shared or indirect, but the doc comment inaccurately stated -EPERM.

Fixes c974021a5949 ("ether: add soft vlan encap/decap")

---

Applied to net-next and I fixed the pre-existing error code formatting. Turns out you need two '-' to get it to be processed as bullet list with negative number.