All of lore.kernel.org
 help / color / mirror / Atom feed
From: William Bland <blandwwa@gmail.com>
Cc: dev@dpdk.org, William Bland <blandwwa@gmail.com>
Subject: [PATCH 2/3] net: add VLAN insert function with a TPID argument
Date: Mon, 24 Aug 2026 15:22:26 -0400	[thread overview]
Message-ID: <20260824192228.1197189-2-blandwwa@gmail.com> (raw)
In-Reply-To: <20260824192228.1197189-1-blandwwa@gmail.com>

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.

Signed-off-by: William Bland <blandwwa@gmail.com>
---
 lib/net/rte_ether.h | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/lib/net/rte_ether.h b/lib/net/rte_ether.h
index cb10d8fb06..1410ec1968 100644
--- a/lib/net/rte_ether.h
+++ b/lib/net/rte_ether.h
@@ -379,19 +379,21 @@ static inline int rte_vlan_strip(struct rte_mbuf *m)
 }
 
 /**
- * Insert VLAN tag into mbuf.
+ * Insert VLAN tag with the given TPID into mbuf.
  *
- * Software version of VLAN unstripping
+ * Software version of VLAN unstripping.
  *
  * @param m
  *   The packet mbuf.
+ * @param tpid
+ *   Tag Protocol Identifier to insert (host order).
  * @return
  *   - 0: On success
  *   -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)
+static inline int rte_vlan_insert_tpid(struct rte_mbuf **m, uint16_t tpid)
 {
 	struct rte_ether_hdr *oh, *nh;
 	struct rte_vlan_hdr *vh;
@@ -411,7 +413,7 @@ static inline int rte_vlan_insert(struct rte_mbuf **m)
 		return -ENOSPC;
 
 	memmove(nh, oh, 2 * RTE_ETHER_ADDR_LEN);
-	nh->ether_type = rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN);
+	nh->ether_type = rte_cpu_to_be_16(tpid);
 
 	vh = (struct rte_vlan_hdr *) (nh + 1);
 	vh->vlan_tci = rte_cpu_to_be_16((*m)->vlan_tci);
@@ -426,6 +428,26 @@ static inline int rte_vlan_insert(struct rte_mbuf **m)
 	return 0;
 }
 
+/**
+ * Insert VLAN tag into mbuf.
+ *
+ * Software version of VLAN unstripping. Always inserts an 802.1Q tag
+ * (TPID 0x8100). Use rte_vlan_insert_tpid() when the original TPID may
+ * differ (e.g. 802.1ad QinQ outer tags).
+ *
+ * @param m
+ *   The packet mbuf.
+ * @return
+ *   - 0: On success
+ *   -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)
+{
+	return rte_vlan_insert_tpid(m, RTE_ETHER_TYPE_VLAN);
+}
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.43.0


  reply	other threads:[~2026-08-24 19:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 19:22 [PATCH 1/3] net: fix VLAN insert doc comment for shared-mbuf error code William Bland
2026-08-24 19:22 ` William Bland [this message]
2026-08-24 19:22 ` [PATCH 3/3] net/af_packet: fix QinQ outer TPID on VLAN reinsertion William Bland
2026-08-24 20:59 ` [PATCH 1/3] net: fix VLAN insert doc comment for shared-mbuf error code Stephen Hemminger

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=20260824192228.1197189-2-blandwwa@gmail.com \
    --to=blandwwa@gmail.com \
    --cc=dev@dpdk.org \
    /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.