* [PATCH] net: support VLAN stacking packet type parsing
@ 2025-07-03 9:30 Dengdui Huang
0 siblings, 0 replies; only message in thread
From: Dengdui Huang @ 2025-07-03 9:30 UTC (permalink / raw)
To: dev
Cc: stephen, jasvinder.singh, thomas, aman.deep.singh, lihuisong,
fengchengwen, liuyonglong
The current rte_net_get_ptype() only supports parsing packets with
one 0x8100 VLAN tag or two 0x88a8 VLAN tags. This patch extends it
to support parsing packets with two 0x8100 VLAN tags.
Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
---
lib/net/rte_net.c | 34 ++++++++++++++++++++++------------
lib/net/rte_net.h | 2 ++
2 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/lib/net/rte_net.c b/lib/net/rte_net.c
index 44fb6c0f51..fa8d023ca7 100644
--- a/lib/net/rte_net.c
+++ b/lib/net/rte_net.c
@@ -352,14 +352,19 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
if (proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN)) {
const struct rte_vlan_hdr *vh;
struct rte_vlan_hdr vh_copy;
+ uint8_t vlan_num = 1;
pkt_type = RTE_PTYPE_L2_ETHER_VLAN;
- vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
- if (unlikely(vh == NULL))
- return pkt_type;
- off += sizeof(*vh);
- hdr_lens->l2_len += sizeof(*vh);
- proto = vh->eth_proto;
+ while (proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN) &&
+ vlan_num <= MAX_VLAN_STACKING_TAGS) {
+ vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
+ if (unlikely(vh == NULL))
+ return pkt_type;
+ off += sizeof(*vh);
+ hdr_lens->l2_len += sizeof(*vh);
+ proto = vh->eth_proto;
+ vlan_num++;
+ }
} else if (proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_QINQ)) {
const struct rte_vlan_hdr *vh;
struct rte_vlan_hdr vh_copy;
@@ -504,15 +509,20 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
if (proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN)) {
const struct rte_vlan_hdr *vh;
struct rte_vlan_hdr vh_copy;
+ uint8_t vlan_num = 1;
pkt_type &= ~RTE_PTYPE_INNER_L2_MASK;
pkt_type |= RTE_PTYPE_INNER_L2_ETHER_VLAN;
- vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
- if (unlikely(vh == NULL))
- return pkt_type;
- off += sizeof(*vh);
- hdr_lens->inner_l2_len += sizeof(*vh);
- proto = vh->eth_proto;
+ while (proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN) &&
+ vlan_num <= MAX_VLAN_STACKING_TAGS) {
+ vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
+ if (unlikely(vh == NULL))
+ return pkt_type;
+ off += sizeof(*vh);
+ hdr_lens->inner_l2_len += sizeof(*vh);
+ proto = vh->eth_proto;
+ vlan_num++;
+ }
} else if (proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_QINQ)) {
const struct rte_vlan_hdr *vh;
struct rte_vlan_hdr vh_copy;
diff --git a/lib/net/rte_net.h b/lib/net/rte_net.h
index 65d724b84b..fdd55d57c8 100644
--- a/lib/net/rte_net.h
+++ b/lib/net/rte_net.h
@@ -13,6 +13,8 @@
extern "C" {
#endif
+#define MAX_VLAN_STACKING_TAGS 2
+
/**
* Structure containing header lengths associated to a packet, filled
* by rte_net_get_ptype().
--
2.33.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-07-03 9:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-03 9:30 [PATCH] net: support VLAN stacking packet type parsing Dengdui Huang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).