[PATCH] net: support VLAN stacking packet type parsing
Bruce Richardson
bruce.richardson at intel.com
Fri Jul 4 13:32:11 CEST 2025
On Fri, Jul 04, 2025 at 12:18:45PM +0200, Morten Brørup wrote:
> > From: Dengdui Huang [mailto:huangdengdui at huawei.com]
> > Sent: Thursday, 3 July 2025 11.30
> >
> > 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 at 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++;
> > + }
>
> It's not that simple.
>
> VLAN tags are not like MPLS labels.
> With the MPLS packet type, we expect a stack of labels.
> But with VLAN tagged packets, we expect exactly one VLAN tag at each outer/inner layer of headers. (Or no VLAN tag at the inner layer.)
>
> This function already supports packets with 2 VLAN tags:
> A stack of 2 VLAN tags is currently detected as 1 outer VLAN tag, adjusting hdr_lens->l2_len accordingly, and 1 inner VLAN tag, adjusting hdr_lens->inner_l2_len accordingly.
> This behavior should not be changed.
>
> I don't have a firm idea about how to better represent packets with a stack of 3+ VLAN tags than what we do today, so suggestions are welcome.
>
> Which use case is this patch addressing?
> Maybe information about the use case could guide us in some direction.
>
Hi all,
this email discussion comes at a bit of a fortunate time for me, as I'm
currently looking at our vlan tag/qinq stripping behaviour in our Intel NIC
drivers, and there is some discussion internally as to what our driver
behaviour should be compared to what it has historically been. :-)
The documentation - both in the NIC guide [1] and the testpmd guide [2] -
is rather short on detail as to what exactly the behaviour should be when
vlan strip or qinq strip is implemented. Therefore, I'd hope that those
more familiar with networking than me would be able to help clarify things
so we can document the correct behaviour precisely - and hopefully test our
drivers against it in future!
The simple cases are obvious (looking only at stripping behaviour here):
* no vlan stripping - nothing done to packet
* no vlan tag in pkg - nothing to do, irrespective of offload
* Vlan strip enabled and single vlan tag present - HW should strip the tag and
place it in descriptor for placing in mbuf.
Now the questions I have:
* To handle questions with 2 vlan tags, the QinQ case - do we need to
enable both vlan-strip and QinQ strip, or does QinQ strip imply stripping
both?
- one suggested interpretation here, was that QinQ implies stripping the
tag with id EtherType 0x88a8, and vlan stripping implies taking off the
tag with 0x8100
- another interpretation is vlan strip means just to take off one tag (if
present), and qinq strip means to take off both tags (if present).
The question above leads to other consequences:
* if we enable qinq strip, but get a single-vlan tagged frame, what is the
behaviour?
* if we get a qinq packet, but regular vlan strip is enabled, which tag, if
any, is stripped?
* should it be an error to enable both qinq strip and vlan strip at the
same time? Should it be an error to enable qinq strip without vlan strip?
* in the mbuf, we have a "vlan_tci" field, and an "vlan_tci_outer" field.
For single vlan strip, presumably only the vlan_tci field should be used,
and for qinq traffic stripped, it's obvious which field goes where.
However, what if we have QinQ strip and we only receive a single vlan
tag, where should that be put? Should it go in inner or outer?
Feedback welcome, and suggested doc updates welcome too.
Thanks,
/Bruce
[1] https://doc.dpdk.org/guides/nics/features.html#vlan-offload
[2] https://doc.dpdk.org/guides/testpmd_app_ug/run_app.html
More information about the dev
mailing list