net: fix L2 ptype assignment in VLAN loop
PATCH 1/1 net: fix L2 ptype assignment in VLAN loop
Since commit 1f250674085a ("net: fix packet type for stacked VLAN"), rte_net_get_ptype() uses |= to set the L2 ptype inside the VLAN parsing loop. Since pkt_type is already initialized with RTE_PTYPE_L2_ETHER (0x1), or-ing it with RTE_PTYPE_L2_ETHER_VLAN (0x6) results in RTE_PTYPE_L2_ETHER_QINQ (0x7). This causes single VLAN frames to be misidentified as QinQ.
This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls rte_net_get_ptype() in tap_verify_csum() to determine the L2 header length. With the wrong ptype, l2_len is set to 22 (ether + QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.
Use a simple assignment to replace the L2 ptype instead. Add VLAN and QinQ test packets in cksum_autotest to prevent regressions.
--- app/test/test_cksum.c | 29 +++++++++++++++++++++++++++++ lib/net/rte_net.c | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-)
app/test/test_cksum.c +29 -0
@@ -75,6 +75,27 @@ static const char test_cksum_ipv6_udp[] = { 0x00, 0x35, 0x00, 0x09, 0x87, 0x70, 0x78, }; +/* generated in scapy with Ether()/Dot1Q(vlan=42)/IP()/UDP()/Raw('x') */ +static const char test_cksum_vlan_ipv4_udp[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x81 ,0x00 ,0x00 ,0x2a , +0x08 ,0x00 ,0x45 ,0x00 ,0x00 ,0x1d ,0x00 ,0x01 , +0x00 ,0x00 ,0x40 ,0x11 ,0x7c ,0xcd ,0x7f ,0x00 , +0x00 ,0x01 ,0x7f ,0x00 ,0x00 ,0x01 ,0x00 ,0x35 , +0x00 ,0x35 ,0x00 ,0x09 ,0x89 ,0x6f ,0x78 , +}; + +/* generated in scapy with Ether()/Dot1AD(vlan=42)/Dot1Q(vlan=43)/IP()/UDP()/Raw('x') */ +static const char test_cksum_qinq_ipv4_udp[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x88 ,0xa8 ,0x00 ,0x2a , +0x81 ,0x00 ,0x00 ,0x2b ,0x08 ,0x00 ,0x45 ,0x00 , +0x00 ,0x1d ,0x00 ,0x01 ,0x00 ,0x00 ,0x40 ,0x11 , +0x7c ,0xcd ,0x7f ,0x00 ,0x00 ,0x01 ,0x7f ,0x00 , +0x00 ,0x01 ,0x00 ,0x35 ,0x00 ,0x35 ,0x00 ,0x09 , +0x89 ,0x6f ,0x78 , +}; +/* generated in scapy with Ether()/IP(options='\x00')/UDP()/Raw('x')) */ static const char test_cksum_ipv4_opts_udp[] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 ,
@@ -252,6 +273,14 @@ test_cksum(void) sizeof(test_cksum_ipv6_udp)) < 0)GOTO_FAIL ("checksum error on ipv6_udp" ); +if (test_l4_cksum (pktmbuf_pool, test_cksum_vlan_ipv4_udp, +sizeof (test_cksum_vlan_ipv4_udp)) <0 ) +GOTO_FAIL ("checksum error on vlan_ipv4_udp" ); + +if (test_l4_cksum (pktmbuf_pool, test_cksum_qinq_ipv4_udp, +sizeof (test_cksum_qinq_ipv4_udp)) <0 ) +GOTO_FAIL ("checksum error on qinq_ipv4_udp" ); +if (test_l4_cksum (pktmbuf_pool, test_cksum_ipv4_opts_udp,sizeof (test_cksum_ipv4_opts_udp)) <0 )GOTO_FAIL ("checksum error on ipv4_opts_udp" );
lib/net/rte_net.c +1 -1
@@ -359,7 +359,7 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (++vlan_depth >RTE_NET_VLAN_MAX_DEPTH )return 0 ; - pkt_type |= + pkt_type = proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) ?RTE_PTYPE_L2_ETHER_VLAN :RTE_PTYPE_L2_ETHER_QINQ ;
Signature · 1 line
2.53.0
Robin Jarry, Apr 22, 2026 at 12:28:
Quoted 59 lines
Since commit
1f250674085a("net: fix packet type for stacked VLAN"),rte_net_get_ptype()uses |= to set the L2 ptype inside the VLAN parsing loop. Sincepkt_typeis already initialized withRTE_PTYPE_L2_ETHER(0x1), or-ing it withRTE_PTYPE_L2_ETHER_VLAN(0x6) results inRTE_PTYPE_L2_ETHER_QINQ(0x7). This causes single VLAN frames to be misidentified as QinQ.This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls
rte_net_get_ptype()intap_verify_csum()to determine the L2 header length. With the wrong ptype,l2_lenis set to 22 (ether + QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.Use a simple assignment to replace the L2 ptype instead. Add VLAN and QinQ test packets in
cksum_autotestto prevent regressions.Fixes 1f250674085a ("net: fix packet type for stacked VLAN")Signed-off-by Robin Jarry <[email protected]>--- app/test/test_cksum.c | 29 +++++++++++++++++++++++++++++ lib/net/rte_net.c | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-)app/test/test_cksum.c +21
-0@@ -75,6 +75,27 @@ static const char test_cksum_ipv6_udp[] = { 0x00, 0x35, 0x00, 0x09, 0x87, 0x70, 0x78, }; +/* generated in scapy with Ether()/Dot1Q(vlan=42)/IP()/UDP()/Raw('x') */ +static const char test_cksum_vlan_ipv4_udp[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x81 ,0x00 ,0x00 ,0x2a , +0x08 ,0x00 ,0x45 ,0x00 ,0x00 ,0x1d ,0x00 ,0x01 , +0x00 ,0x00 ,0x40 ,0x11 ,0x7c ,0xcd ,0x7f ,0x00 , +0x00 ,0x01 ,0x7f ,0x00 ,0x00 ,0x01 ,0x00 ,0x35 , +0x00 ,0x35 ,0x00 ,0x09 ,0x89 ,0x6f ,0x78 , +}; + +/* generated in scapy with Ether()/Dot1AD(vlan=42)/Dot1Q(vlan=43)/IP()/UDP()/Raw('x') */ +static const char test_cksum_qinq_ipv4_udp[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x88 ,0xa8 ,0x00 ,0x2a , +0x81 ,0x00 ,0x00 ,0x2b ,0x08 ,0x00 ,0x45 ,0x00 , +0x00 ,0x1d ,0x00 ,0x01 ,0x00 ,0x00 ,0x40 ,0x11 , +0x7c ,0xcd ,0x7f ,0x00 ,0x00 ,0x01 ,0x7f ,0x00 , +0x00 ,0x01 ,0x00 ,0x35 ,0x00 ,0x35 ,0x00 ,0x09 , +0x89 ,0x6f ,0x78 , +}; +/* generated in scapy with Ether()/IP(options='\x00')/UDP()/Raw('x')) */ static const char test_cksum_ipv4_opts_udp[] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 ,
app/test/test_cksum.c test_cksum(void) · line 282
Quoted 10 lines
app/test/test_cksum.c +7
-0@@ -252,6 +273,14 @@ test_cksum(void) sizeof(test_cksum_ipv6_udp)) < 0)GOTO_FAIL ("checksum error on ipv6_udp" ); +if (test_l4_cksum (pktmbuf_pool, test_cksum_vlan_ipv4_udp, +sizeof (test_cksum_vlan_ipv4_udp)) <0 ) +GOTO_FAIL ("checksum error on vlan_ipv4_udp" ); + +if (test_l4_cksum (pktmbuf_pool, test_cksum_qinq_ipv4_udp, +sizeof (test_cksum_qinq_ipv4_udp)) <0 ) +GOTO_FAIL ("checksum error on qinq_ipv4_udp" );
The tests are useless, they don't check that the L2 ptype is correct. I'll send a v2 with proper ptype tests.
PATCH v2 1/1 net: fix L2 ptype assignment in VLAN loop
In reply to Robin JarrySince commit 1f250674085a ("net: fix packet type for stacked VLAN"), rte_net_get_ptype() uses |= to set the L2 ptype inside the VLAN parsing loop. Since pkt_type is already initialized with RTE_PTYPE_L2_ETHER (0x1), or-ing it with RTE_PTYPE_L2_ETHER_VLAN (0x6) results in RTE_PTYPE_L2_ETHER_QINQ (0x7). This causes single VLAN frames to be misidentified as QinQ.
This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls rte_net_get_ptype() in tap_verify_csum() to determine the L2 header length. With the wrong ptype, l2_len is set to 22 (ether + QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.
Use a simple assignment to replace the L2 ptype instead. Add a ptype unit test covering plain Ethernet, VLAN and QinQ L2 detection to prevent regressions.
---
Notes:
v2: added new ptype tests
app/test/meson.build | 1 + app/test/test_net_ptype.c | 117 ++++++++++++++++++++++++++++++++++++++ lib/net/rte_net.c | 2 +- 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 app/test/test_net_ptype.c
app/test/meson.build +1 -0
@@ -135,6 +135,7 @@ source_file_deps = { 'test_mp_secondary.c': ['hash'], 'test_net_ether.c': ['net'], 'test_net_ip6.c': ['net'], + 'test_net_ptype.c': ['net'], 'test_pcapng.c': ['net_null', 'net', 'ethdev', 'pcapng', 'bus_vdev'], 'test_pdcp.c': ['eventdev', 'pdcp', 'net', 'timer', 'security'], 'test_pdump.c': ['pdump'] + sample_packet_forward_deps,
app/test/test_net_ptype.c new file +117 -0
117 lines not on this page · raw message
lib/net/rte_net.c +1 -1
@@ -359,7 +359,7 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (++vlan_depth >RTE_NET_VLAN_MAX_DEPTH )return 0 ; - pkt_type |= + pkt_type = proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) ?RTE_PTYPE_L2_ETHER_VLAN :RTE_PTYPE_L2_ETHER_QINQ ;
Signature · 1 line
2.53.0
22/04/2026 12:38, Robin Jarry:
Quoted 6 lines
Since commit
1f250674085a("net: fix packet type for stacked VLAN"),rte_net_get_ptype()uses |= to set the L2 ptype inside the VLAN parsing loop. Sincepkt_typeis already initialized withRTE_PTYPE_L2_ETHER(0x1), or-ing it withRTE_PTYPE_L2_ETHER_VLAN(0x6) results inRTE_PTYPE_L2_ETHER_QINQ(0x7). This causes single VLAN frames to be misidentified as QinQ.
Thanks for finding this major regression.
Minor nit about the title (for whoever will merge it):
we don't really care the problem is in a loop. I think this title is easier to read:
net: fix VLAN packet type
Thomas Monjalon, Apr 22, 2026 at 15:16:
Quoted 8 lines
22/04/2026 12:38, Robin Jarry:
Quoted 6 lines
Since commit
1f250674085a("net: fix packet type for stacked VLAN"),rte_net_get_ptype()uses |= to set the L2 ptype inside the VLAN parsing loop. Sincepkt_typeis already initialized withRTE_PTYPE_L2_ETHER(0x1), or-ing it withRTE_PTYPE_L2_ETHER_VLAN(0x6) results inRTE_PTYPE_L2_ETHER_QINQ(0x7). This causes single VLAN frames to be misidentified as QinQ.
Quoted 6 lines
Thanks for finding this major regression.
Minor nit about the title (for whoever will merge it):
we don't really care the problem is in a loop. I think this title is easier to read:
net: fix VLAN packet type
I will send a v3 with a different approach. Currently my fix breaks the detection of QinQ if it is followed by a plain vlan header.
I'll adjust the title.
Quoted 22 lines · Robin Jarry
app/test/test_net_ptype.c new file +22
-0+static int +test_get_ptype (struct rte_mempool *pool,const char *pktdata,size_t len, +uint32_t expected_l2,uint8_t expected_l2_len) +{ +struct rte_net_hdr_lens hdr_lens; +struct rte_mbuf *m; +uint32_t ptype; +uint32_t l2; +char *data; + + m =rte_pktmbuf_alloc (pool); +RTE_TEST_ASSERT_NOT_NULL (m,"cannot allocate mbuf" ); + + data =rte_pktmbuf_append (m, len); +if (data ==NULL ) { +rte_pktmbuf_free (m); +RTE_TEST_ASSERT_NOT_NULL (data,"cannot append data" ); + } + +memcpy (data, pktdata, len); + + ptype =rte_net_get_ptype (m, &hdr_lens,RTE_PTYPE_ALL_MASK );
app/test/test_net_ptype.c line 79
Quoted 10 lines
app/test/test_net_ptype.c new file +10
-0+ l2 = ptype &RTE_PTYPE_L2_MASK ; + +rte_pktmbuf_free (m); + +RTE_TEST_ASSERT_EQUAL (l2, expected_l2, +"unexpected L2 ptype: got 0x%x, expected 0x%x" , + l2, expected_l2); +RTE_TEST_ASSERT_EQUAL (hdr_lens.l2_len, expected_l2_len, +"unexpected l2_len: got %u, expected %u" , + hdr_lens.l2_len, expected_l2_len);
Since this test asks for RTE_PTYPE_ALL_MASK, let's validate the full returned ptype, and the returned offsets.
Quoted 2 lines
(quoted diff) +2
-0+ + return 0;
Signature · 1 line
David Marchand
PATCH v3 1/1 net: fix VLAN packet type
In reply to Robin JarrySince commit 1f250674085a ("net: fix packet type for stacked VLAN"), rte_net_get_ptype() uses |= to set the L2 ptype inside the VLAN parsing loop. Since pkt_type is already initialized with RTE_PTYPE_L2_ETHER (0x1), or-ing it with RTE_PTYPE_L2_ETHER_VLAN (0x6) results in RTE_PTYPE_L2_ETHER_QINQ (0x7). This causes single VLAN frames to be misidentified as QinQ.
This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls rte_net_get_ptype() in tap_verify_csum() to determine the L2 header length. With the wrong ptype, l2_len is set to 22 (ether
+ QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.
Initialize pkt_type to 0 and defer the RTE_PTYPE_L2_ETHER assignment to the l3 label, only if no VLAN/QinQ type was set in the loop. This avoids the bitwise-or conflict between the L2 ptype constants entirely.
Add a new net_ptype_autotest unit test that verifies the ptype and header lengths (l2_len, l3_len, l4_len) returned by rte_net_get_ptype() for plain Ethernet, single VLAN, stacked VLAN (two 802.1Q tags), and QinQ (802.1ad + 802.1Q) frames, with both IPv4/IPv6 and UDP/TCP combinations.
---
Notes:
v3:
* changed the approach: initialize pkt_type=0 and only set it to RTE_PTYPE_L2_ETHER if neither of VLAN nor QINQ matched.
* extended the unit tests to check for header lengths and added ipv6 / tcp cases.
v2: added new ptype tests
app/test/meson.build | 1 + app/test/test_net_ptype.c | 231 ++++++++++++++++++++++++++++++++++++++ lib/net/rte_net.c | 4 +- 3 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 app/test/test_net_ptype.c
app/test/meson.build +1 -0
@@ -135,6 +135,7 @@ source_file_deps = { 'test_mp_secondary.c': ['hash'], 'test_net_ether.c': ['net'], 'test_net_ip6.c': ['net'], + 'test_net_ptype.c': ['net'], 'test_pcapng.c': ['net_null', 'net', 'ethdev', 'pcapng', 'bus_vdev'], 'test_pdcp.c': ['eventdev', 'pdcp', 'net', 'timer', 'security'], 'test_pdump.c': ['pdump'] + sample_packet_forward_deps,
app/test/test_net_ptype.c new file +231 -0
231 lines not on this page · raw message
lib/net/rte_net.c +3 -1
@@ -331,8 +331,8 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,struct rte_net_hdr_lens local_hdr_lens;const struct rte_ether_hdr *eh;struct rte_ether_hdr eh_copy; -uint32_t pkt_type =RTE_PTYPE_L2_ETHER ;uint32_t off =0 , vlan_depth =0 ; +uint32_t pkt_type =0 ;uint16_t proto;int ret;
@@ -392,6 +392,8 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m, } l3: +if (pkt_type ==0 ) + pkt_type =RTE_PTYPE_L2_ETHER ;if ((layers &RTE_PTYPE_L3_MASK ) ==0 )return pkt_type;
Signature · 1 line
2.53.0
Re: [PATCH dpdk v3] net: fix VLAN packet type
Quoted 24 lines · Robin Jarry
Since commit
1f250674085a("net: fix packet type for stacked VLAN"),rte_net_get_ptype()uses |= to set the L2 ptype inside the VLAN parsing loop. Sincepkt_typeis already initialized withRTE_PTYPE_L2_ETHER(0x1), or-ing it withRTE_PTYPE_L2_ETHER_VLAN(0x6) results inRTE_PTYPE_L2_ETHER_QINQ(0x7). This causes single VLAN frames to be misidentified as QinQ.This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls
rte_net_get_ptype()intap_verify_csum()to determine the L2 header length. With the wrong ptype,l2_lenis set to 22 (ether
+ QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.Initialize
pkt_typeto 0 and defer theRTE_PTYPE_L2_ETHERassignment to the l3 label, only if no VLAN/QinQ type was set in the loop. This avoids the bitwise-or conflict between the L2 ptype constants entirely.Add a new
net_ptype_autotestunit test that verifies the ptype and header lengths (l2_len,l3_len,l4_len) returned byrte_net_get_ptype()for plain Ethernet, single VLAN, stacked VLAN (two 802.1Q tags), and QinQ (802.1ad + 802.1Q) frames, with both IPv4/IPv6 and UDP/TCP combinations.
Quoted 4 lines
Fixes 1f250674085a ("net: fix packet type for stacked VLAN")Signed-off-by Robin Jarry <[email protected]>
Hi Robin,
Thanks for reporting this.
Quoted 18 lines
---
Notes:
v3:* changed the approach: initialize pkt_type=0 and only set it to
RTE_PTYPE_L2_ETHERif neither of VLAN nor QINQ matched.
* extended the unit tests to check for header lengths and added ipv6 / tcp cases.v2: added new ptype tests
app/test/meson.build | 1 + app/test/test_net_ptype.c | 231 ++++++++++++++++++++++++++++++++++++++ lib/net/rte_net.c | 4 +- 3 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 app/test/test_net_ptype.c
<snip>
Quoted 15 lines
lib/net/rte_net.c +1
-1@@ -331,8 +331,8 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,struct rte_net_hdr_lens local_hdr_lens;const struct rte_ether_hdr *eh;struct rte_ether_hdr eh_copy; -uint32_t pkt_type =RTE_PTYPE_L2_ETHER ;uint32_t off =0 , vlan_depth =0 ; +uint32_t pkt_type =0 ;uint16_t proto;int ret;
lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 393
Quoted 2 lines
lib/net/rte_net.c +0
-0@@ -392,6 +392,8 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m, }
Not shown in diff, but for:
pkt_type |= proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN) ? RTE_PTYPE_L2_ETHER_VLAN : RTE_PTYPE_L2_ETHER_QINQ;
It seems to be produce the right result, but I'm not sure we should be treating the ptype L2 defines as bitmasks. Maybe I'm wrong and it was planned, but it looks like a coincidence it works now because QINQ (0x7) happens to be a superset of VLAN (0x6) for the OR.
Perhaps you could check vlan_depth and assign VLAN or QINQ based on that?
thanks,
Kevin.
Quoted 6 lines
lib/net/rte_net.c +2
-0l3: +if (pkt_type ==0 ) + pkt_type =RTE_PTYPE_L2_ETHER ;if ((layers &RTE_PTYPE_L3_MASK ) ==0 )return pkt_type;
Re: [PATCH dpdk v3] net: fix VLAN packet type
Kevin Traynor, Apr 23, 2026 at 11:19:
Quoted 7 lines
Not shown in diff, but for:
pkt_type |= proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN) ? RTE_PTYPE_L2_ETHER_VLAN : RTE_PTYPE_L2_ETHER_QINQ;
Quoted 6 lines
It seems to be produce the right result, but I'm not sure we should be treating the ptype L2 defines as bitmasks. Maybe I'm wrong and it was planned, but it looks like a coincidence it works now because QINQ (
0x7) happens to be a superset of VLAN (0x6) for the OR.Perhaps you could check
vlan_depthand assign VLAN or QINQ based on that?
I hadn't considered this. It would make sense to have something like:
l3:
switch (vlan_depth) {
case 0:
pkt_type = RTE_PTYPE_L2_ETHER;
break;
case 1:
pkt_type = RTE_PTYPE_L2_ETHER_VLAN;
break;
default:
pkt_type = RTE_PTYPE_L2_ETHER_QINQ;
break;
}Mind that this will report RTE_PTYPE_L2_ETHER_QINQ even if we have double stacked 802.1Q tags (ether type 0x8100) and no 802.1ad S-tag (QinQ 0x88A8). I don't think this is an issue, but I'll let you judge.
I can send a v4 with this if that suits you.
Re: [PATCH dpdk v3] net: fix VLAN packet type
Quoted 30 lines · Robin Jarry
Kevin Traynor, Apr 23, 2026 at 11:19:
Quoted 7 lines
Not shown in diff, but for:
pkt_type |= proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN) ? RTE_PTYPE_L2_ETHER_VLAN : RTE_PTYPE_L2_ETHER_QINQ;Quoted 6 lines
It seems to be produce the right result, but I'm not sure we should be treating the ptype L2 defines as bitmasks. Maybe I'm wrong and it was planned, but it looks like a coincidence it works now because QINQ (
0x7) happens to be a superset of VLAN (0x6) for the OR.Perhaps you could check
vlan_depthand assign VLAN or QINQ based on that?I hadn't considered this. It would make sense to have something like:
l3:
switch (vlan_depth) { case 0: pkt_type = RTE_PTYPE_L2_ETHER; break; case 1: pkt_type = RTE_PTYPE_L2_ETHER_VLAN; break; default: pkt_type = RTE_PTYPE_L2_ETHER_QINQ; break; }
Quoted 4 lines
Mind that this will report
RTE_PTYPE_L2_ETHER_QINQeven if we have double stacked 802.1Q tags (ether type0x8100) and no 802.1ad S-tag (QinQ0x88A8). I don't think this is an issue, but I'll let you judge.
I'm not sure about this.
Quoted 2 lines
I can send a v4 with this if that suits you.
Setting pkt_type later has some implications for early returns (now i notice that's present in v3 too)
Would this work ?
@@ -358,10 +358,12 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
struct rte_vlan_hdr vh_copy;
+ if (vlan_depth == 0) {
+ pkt_type =
+ proto ==rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN) ?
+ RTE_PTYPE_L2_ETHER_VLAN :
+ RTE_PTYPE_L2_ETHER_QINQ;
+ }
if (++vlan_depth > RTE_NET_VLAN_MAX_DEPTH)
return 0;
- pkt_type |=
- proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN) ?
- RTE_PTYPE_L2_ETHER_VLAN :
- RTE_PTYPE_L2_ETHER_QINQ;
vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
if (unlikely(vh == NULL))Re: [PATCH dpdk v3] net: fix VLAN packet type
Kevin Traynor, Apr 23, 2026 at 12:59:
Quoted 13 lines
Setting
pkt_typelater has some implications for early returns (now i notice that's present in v3 too)Would this work ?
(quoted diff) +3
-0@@ -358,10 +358,12 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m, struct rte_vlan_hdr vh_copy; + if (vlan_depth == 0) { + pkt_type = + proto ==
rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN)?(quoted diff) +1
-0+ RTE_PTYPE_L2_ETHER_VLAN :
Review
Quoted 10 lines
(quoted diff) +2
-4+ RTE_PTYPE_L2_ETHER_QINQ; + } if (++vlan_depth > RTE_NET_VLAN_MAX_DEPTH) return 0; - pkt_type |= - proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_VLAN) ? - RTE_PTYPE_L2_ETHER_VLAN : - RTE_PTYPE_L2_ETHER_QINQ; vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy); if (unlikely(vh == NULL))
Yes, that works. I'll send a v4.
PATCH v4 1/1 net: fix VLAN packet type
In reply to Robin JarrySince commit 1f250674085a ("net: fix packet type for stacked VLAN"), rte_net_get_ptype() uses |= to set the L2 ptype inside the VLAN parsing loop. Since pkt_type is already initialized with RTE_PTYPE_L2_ETHER (0x1), or-ing it with RTE_PTYPE_L2_ETHER_VLAN (0x6) results in RTE_PTYPE_L2_ETHER_QINQ (0x7). This causes single VLAN frames to be misidentified as QinQ.
This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls rte_net_get_ptype() in tap_verify_csum() to determine the L2 header length. With the wrong ptype, l2_len is set to 22 (ether
+ QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.
Set pkt_type to RTE_PTYPE_L2_ETHER_VLAN or RTE_PTYPE_L2_ETHER_QINQ only for the first level of "VLAN" tag seen. This avoids the bitwise-or conflict between the L2 ptype constants entirely.
Add a new net_ptype_autotest unit test that verifies the ptype and header lengths (l2_len, l3_len, l4_len) returned by rte_net_get_ptype() for plain Ethernet, single VLAN, stacked VLAN (two 802.1Q tags), and QinQ (802.1ad + 802.1Q) frames, with both IPv4/IPv6 and UDP/TCP combinations.
---
Notes:
v4:
* changed the approach again. Only set VLAN or QINQ ptype for the first encountered vlan/qinq ether type.
* unit tests not changed
v3:
* changed the approach: initialize pkt_type=0 and only set it to RTE_PTYPE_L2_ETHER if neither of VLAN nor QINQ matched.
* extended the unit tests to check for header lengths and added ipv6 / tcp cases.
v2: added new ptype tests
v3:
* changed the approach: initialize pkt_type=0 and only set it to RTE_PTYPE_L2_ETHER if neither of VLAN nor QINQ matched.
* extended the unit tests to check for header lengths and added ipv6 / tcp cases.
v2: added new ptype tests
app/test/meson.build | 1 + app/test/test_net_ptype.c | 231 ++++++++++++++++++++++++++++++++++++++ lib/net/rte_net.c | 10 +- 3 files changed, 238 insertions(+), 4 deletions(-) create mode 100644 app/test/test_net_ptype.c
app/test/meson.build +1 -0
@@ -135,6 +135,7 @@ source_file_deps = { 'test_mp_secondary.c': ['hash'], 'test_net_ether.c': ['net'], 'test_net_ip6.c': ['net'], + 'test_net_ptype.c': ['net'], 'test_pcapng.c': ['net_null', 'net', 'ethdev', 'pcapng', 'bus_vdev'], 'test_pdcp.c': ['eventdev', 'pdcp', 'net', 'timer', 'security'], 'test_pdump.c': ['pdump'] + sample_packet_forward_deps,
app/test/test_net_ptype.c new file +231 -0
231 lines not on this page · raw message
lib/net/rte_net.c +6 -4
@@ -357,12 +357,14 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; +if (vlan_depth ==0 ) { + pkt_type = + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) ? +RTE_PTYPE_L2_ETHER_VLAN : +RTE_PTYPE_L2_ETHER_QINQ ; + }if (++vlan_depth >RTE_NET_VLAN_MAX_DEPTH )return 0 ; - pkt_type |= - proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) ? -RTE_PTYPE_L2_ETHER_VLAN : -RTE_PTYPE_L2_ETHER_QINQ ; vh =rte_pktmbuf_read (m, off,sizeof (*vh), &vh_copy);if (unlikely (vh ==NULL ))return pkt_type;
Signature · 1 line
2.53.0
Re: [PATCH dpdk v4] net: fix VLAN packet type
Quoted 24 lines · Robin Jarry
Since commit
1f250674085a("net: fix packet type for stacked VLAN"),rte_net_get_ptype()uses |= to set the L2 ptype inside the VLAN parsing loop. Sincepkt_typeis already initialized withRTE_PTYPE_L2_ETHER(0x1), or-ing it withRTE_PTYPE_L2_ETHER_VLAN(0x6) results inRTE_PTYPE_L2_ETHER_QINQ(0x7). This causes single VLAN frames to be misidentified as QinQ.This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls
rte_net_get_ptype()intap_verify_csum()to determine the L2 header length. With the wrong ptype,l2_lenis set to 22 (ether
+ QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.Set
pkt_typetoRTE_PTYPE_L2_ETHER_VLANorRTE_PTYPE_L2_ETHER_QINQonly for the first level of "VLAN" tag seen. This avoids the bitwise-or conflict between the L2 ptype constants entirely.Add a new
net_ptype_autotestunit test that verifies the ptype and header lengths (l2_len,l3_len,l4_len) returned byrte_net_get_ptype()for plain Ethernet, single VLAN, stacked VLAN (two 802.1Q tags), and QinQ (802.1ad + 802.1Q) frames, with both IPv4/IPv6 and UDP/TCP combinations.
Quoted 6 lines
Fixes 1f250674085a ("net: fix packet type for stacked VLAN")Signed-off-by Robin Jarry <[email protected]>---
Thanks Robin, LGTM.
Re: [PATCH dpdk v4] net: fix VLAN packet type
In reply to Robin JarryQuoted 5 lines · Robin Jarry
lib/net/rte_net.c +0
-0
lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 365
Quoted 9 lines
lib/net/rte_net.c +6
-0@@ -357,12 +357,14 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; +if (vlan_depth ==0 ) { + pkt_type = + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) ? +RTE_PTYPE_L2_ETHER_VLAN : +RTE_PTYPE_L2_ETHER_QINQ ; + }
This code is becoming too complex.
The original usecase with more than 2 stacked vlan is a bit strange, but the max depth limit seems just arbitrary (why 8?).
We have clear boundaries, with the size of the packet (see below, check on vh == NULL).
The offending commit also allows stacking mpls on top of vlan, without mentioning it.
I think we want this behavior, but still was it intended?
In the end, reverting the previous fix then just advancing off and breaking once proto is not a vlan/qinq type gives a much simpler fix when compared to v25.11.
(ignoring indent changes with -w)
$ git diff -w v25.11 lib/net/rte_net.c
lib/net/rte_net.c +11 -13
@@ -349,30 +349,28 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_IPV4 )) goto l3;/* fast path if packet is IPv4 */ -if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) { +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) {const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) pkt_type =RTE_PTYPE_L2_ETHER_VLAN ; +else + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + +do { 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; - }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; + }while (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )); + } - pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; - vh =rte_pktmbuf_read (m, off +sizeof (*vh),sizeof (*vh), - &vh_copy); -if (unlikely (vh ==NULL )) -return pkt_type; - off +=2 *sizeof (*vh); - hdr_lens->l2_len +=2 *sizeof (*vh); - proto = vh->eth_proto; - }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || +if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {unsigned int i;const struct rte_mpls_hdr *mh;
This is untested, but what do you think?
Signature · 1 line
David Marchand
Re: [PATCH dpdk v4] net: fix VLAN packet type
David Marchand, Apr 25, 2026 at 10:40:
Quoted 81 lines · Robin Jarry
Quoted 5 lines
lib/net/rte_net.c +0
-0lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 365
Quoted 9 lines
lib/net/rte_net.c +6
-0@@ -357,12 +357,14 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; +if (vlan_depth ==0 ) { + pkt_type = + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) ? +RTE_PTYPE_L2_ETHER_VLAN : +RTE_PTYPE_L2_ETHER_QINQ ; + }This code is becoming too complex.
The original usecase with more than 2 stacked vlan is a bit strange, but the max depth limit seems just arbitrary (why 8?).
We have clear boundaries, with the size of the packet (see below, check on vh == NULL).The offending commit also allows stacking mpls on top of vlan, without mentioning it.
I think we want this behavior, but still was it intended?In the end, reverting the previous fix then just advancing off and breaking once proto is not a vlan/qinq type gives a much simpler fix when compared to v25.11.
(ignoring indent changes with -w)
$ git diff -w v25.11 lib/net/rte_net.clib/net/rte_net.c +11
-13@@ -349,30 +349,28 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_IPV4 )) goto l3;/* fast path if packet is IPv4 */ -if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) { +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) {const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) pkt_type =RTE_PTYPE_L2_ETHER_VLAN ; +else + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + +do { 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; - }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; + }while (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )); + } - pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; - vh =rte_pktmbuf_read (m, off +sizeof (*vh),sizeof (*vh), - &vh_copy); -if (unlikely (vh ==NULL )) -return pkt_type; - off +=2 *sizeof (*vh); - hdr_lens->l2_len +=2 *sizeof (*vh); - proto = vh->eth_proto; - }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || +if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {unsigned int i;const struct rte_mpls_hdr *mh;
Quoted 1 line
This is untested, but what do you think?
That looks correct. But you don't impose a limit in the number of VLANs?
I don't see any good reason to support more than 2 stacked tags.
Re: [PATCH dpdk v4] net: fix VLAN packet type
27/04/2026 12:47, Robin Jarry:
Quoted 7 lines
David Marchand, Apr 25, 2026 at 10:40:
Quoted 2 lines · Robin Jarry
This is untested, but what do you think?
That looks correct. But you don't impose a limit in the number of VLANs?
I don't see any good reason to support more than 2 stacked tags.
Look in the mailing list.
I remember it was to limit a risk of infinite loop.
Re: [PATCH dpdk v4] net: fix VLAN packet type
Quoted 6 lines · Thomas Monjalon
27/04/2026 12:47, Robin Jarry:
Quoted 4 lines
David Marchand, Apr 25, 2026 at 10:40:
Quoted 2 lines · Robin Jarry
This is untested, but what do you think?
Quoted 6 lines
Quoted 3 lines
That looks correct. But you don't impose a limit in the number of VLANs?
I don't see any good reason to support more than 2 stacked tags.
Look in the mailing list.
I remember it was to limit a risk of infinite loop.
Defensive programming (iiuc why it was introduced) seems a bad idea. It imposes a restriction for no good reason.
The same can be achieved by checking the offset vs packet length (rte_pktmbuf_read), and no arbitrary limit needed.
I am for simply reverting the patch in LTS releases.
We can come up with a new change in main for Gregory usecase, but it does not seem like something we want to backport in LTS.
Signature · 1 line
David Marchand
RE: [PATCH dpdk v4] net: fix VLAN packet type
Quoted 20 lines
From: David Marchand [mailto:[email protected]]
Sent: Thursday, 30 April 2026 12.12Quoted 4 lines · Thomas Monjalon
27/04/2026 12:47, Robin Jarry:
Quoted 2 lines
David Marchand, Apr 25, 2026 at 10:40:
Quoted 1 line
On Thu, 23 Apr 2026 at 13:25, Robin Jarry <[email protected]>
Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 1 line
This is untested, but what do you think?
That looks correct. But you don't impose a limit in the number of
VLANs?
Quoted 5 lines
Quoted 2 lines
I don't see any good reason to support more than 2 stacked tags.
Look in the mailing list.
I remember it was to limit a risk of infinite loop.
Quoted 9 lines
Defensive programming (iiuc why it was introduced) seems a bad idea. It imposes a restriction for no good reason.
The same can be achieved by checking the offset vs packet length (rte_pktmbuf_read), and no arbitrary limit needed.I am for simply reverting the patch in LTS releases.
We can come up with a new change in main for Gregory usecase, but it does not seem like something we want to backport in LTS.
I just took a look at rte_net_get_ptype().
The MPLS parser is also broken.
It simply skips 5 MPLS labels without checking if they are MPLS labels at all.
And there's no PPPoE parser.
Re: [PATCH dpdk v4] net: fix VLAN packet type
In reply to David MarchandQuoted 81 lines · David Marchand
Quoted 5 lines · Robin Jarry
lib/net/rte_net.c +0
-0lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 365
Quoted 9 lines
lib/net/rte_net.c +6
-0@@ -357,12 +357,14 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; +if (vlan_depth ==0 ) { + pkt_type = + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) ? +RTE_PTYPE_L2_ETHER_VLAN : +RTE_PTYPE_L2_ETHER_QINQ ; + }This code is becoming too complex.
The original usecase with more than 2 stacked vlan is a bit strange, but the max depth limit seems just arbitrary (why 8?).
We have clear boundaries, with the size of the packet (see below, check on vh == NULL).The offending commit also allows stacking mpls on top of vlan, without mentioning it.
I think we want this behavior, but still was it intended?In the end, reverting the previous fix then just advancing off and breaking once proto is not a vlan/qinq type gives a much simpler fix when compared to v25.11.
(ignoring indent changes with -w)
$ git diff -w v25.11 lib/net/rte_net.clib/net/rte_net.c +11
-13@@ -349,30 +349,28 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_IPV4 )) goto l3;/* fast path if packet is IPv4 */ -if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) { +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) {const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) pkt_type =RTE_PTYPE_L2_ETHER_VLAN ; +else + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + +do { 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; - }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; + }while (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )); + } - pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; - vh =rte_pktmbuf_read (m, off +sizeof (*vh),sizeof (*vh), - &vh_copy); -if (unlikely (vh ==NULL )) -return pkt_type; - off +=2 *sizeof (*vh); - hdr_lens->l2_len +=2 *sizeof (*vh); - proto = vh->eth_proto; - }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || +if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {unsigned int i;const struct rte_mpls_hdr *mh;
Quoted 3 lines
This is untested, but what do you think?
This version LGTM. Maybe we should consider returning NULL on invalid packets
v5 cover Fix and improve VLAN/MPLS parsing in rte_net_get_ptype
In reply to Robin JarryRevert commit 1f250674085a ("net: fix packet type for stacked VLAN") which introduced a regression causing single VLAN frames to be misidentified as QinQ due to incorrect use of |= on the ptype.
Replace the separate VLAN and QinQ code paths with a single loop that handles arbitrarily stacked VLAN tags. Fix the MPLS path to use the bottom of stack bit instead of a hardcoded label limit, and parse the L3 protocol of the MPLS payload by inspecting the first nibble.
Add unit tests for rte_net_get_ptype covering Ethernet, VLAN, QinQ, MPLS, IPv4/IPv6, and truncated packet scenarios.
v5:
* Split the series in multiple patches.
* Revert the commit that introduced the bug.
* Add support for stacked VLAN/QINQ as suggested by David.
* Fix MPLS bottom of stack detection. Try to guess MPLS payload.
* Add more test cases.
v4:
* changed the approach again. Only set VLAN or QINQ ptype for the first encountered vlan/qinq ether type.
* unit tests not changed
v3:
* changed the approach: initialize pkt_type=0 and only set it to RTE_PTYPE_L2_ETHER if neither of VLAN nor QINQ matched.
* extended the unit tests to check for header lengths and added ipv6 / tcp cases.
v2: added new ptype tests
v3:
* changed the approach: initialize pkt_type=0 and only set it to RTE_PTYPE_L2_ETHER if neither of VLAN nor QINQ matched.
* extended the unit tests to check for header lengths and added ipv6 / tcp cases.
v2: added new ptype tests
Robin Jarry (5):
Revert "net: fix packet type for stacked VLAN"
net: support multiple stacked VLAN tags
net: add unit tests for rte_net_get_ptype
net: parse L3 protocol after MPLS labels
net: add truncated packet tests for rte_net_get_ptype
app/test/meson.build | 1 + app/test/test_net_ptype.c | 326 ++++++++++++++++++++++++++++++++++++++ lib/net/rte_net.c | 72 +++++---- 3 files changed, 369 insertions(+), 30 deletions(-) create mode 100644 app/test/test_net_ptype.c
Signature · 1 line
2.54.0
PATCH v5 1/5 Revert "net: fix packet type for stacked VLAN"
This reverts commit 1f250674085aeb4ffd15ac2519a68efc04faf7ac.
rte_net_get_ptype() now uses |= to set the L2 ptype inside the VLAN parsing loop. Since pkt_type is already initialized with RTE_PTYPE_L2_ETHER (0x1), or-ing it with RTE_PTYPE_L2_ETHER_VLAN (0x6) results in RTE_PTYPE_L2_ETHER_QINQ (0x7). This causes single VLAN frames to be misidentified as QinQ.
This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls rte_net_get_ptype() in tap_verify_csum() to determine the L2 header length. With the wrong ptype, l2_len is set to 22 (ether
+ QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.
Bugzilla ID: 1941
--- lib/net/rte_net.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
lib/net/rte_net.c +15 -14
@@ -320,9 +320,6 @@ rte_net_skip_ip6_ext(uint16_t proto, const struct rte_mbuf *m, uint32_t *off,return -1 ; } -/* limit number of supported VLAN headers */ -#define RTE_NET_VLAN_MAX_DEPTH 8 -/* parse mbuf data to get packet type */ RTE_EXPORT_SYMBOL(rte_net_get_ptype) uint32_t rte_net_get_ptype(const struct rte_mbuf *m,
@@ -332,7 +329,7 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,const struct rte_ether_hdr *eh;struct rte_ether_hdr eh_copy;uint32_t pkt_type =RTE_PTYPE_L2_ETHER ; -uint32_t off =0 , vlan_depth =0 ; +uint32_t off =0 ;uint16_t proto;int ret;
@@ -352,26 +349,30 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_IPV4 )) goto l3;/* fast path if packet is IPv4 */ -while (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) || - proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) {const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; -if (++vlan_depth >RTE_NET_VLAN_MAX_DEPTH ) -return 0 ; - pkt_type |= - proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) ? -RTE_PTYPE_L2_ETHER_VLAN : -RTE_PTYPE_L2_ETHER_QINQ ; + 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; - } + }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { +const struct rte_vlan_hdr *vh; +struct rte_vlan_hdr vh_copy; -if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + vh =rte_pktmbuf_read (m, off +sizeof (*vh),sizeof (*vh), + &vh_copy); +if (unlikely (vh ==NULL )) +return pkt_type; + off +=2 *sizeof (*vh); + hdr_lens->l2_len +=2 *sizeof (*vh); + proto = vh->eth_proto; + }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {unsigned int i;const struct rte_mpls_hdr *mh;
Signature · 1 line
2.54.0
Re: [PATCH dpdk v5 1/5] Revert "net: fix packet type for stacked VLAN"
Quoted 16 lines · Robin Jarry
This reverts commit
1f250674085aeb4ffd15ac2519a68efc04faf7ac.
rte_net_get_ptype()now uses |= to set the L2 ptype inside the VLAN parsing loop. Sincepkt_typeis already initialized withRTE_PTYPE_L2_ETHER(0x1), or-ing it withRTE_PTYPE_L2_ETHER_VLAN(0x6) results inRTE_PTYPE_L2_ETHER_QINQ(0x7). This causes single VLAN frames to be misidentified as QinQ.This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls
rte_net_get_ptype()intap_verify_csum()to determine the L2 header length. With the wrong ptype,l2_lenis set to 22 (ether
+ QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.
Quoted 5 lines
Bugzilla ID: 1941
Fixes 1f250674085a ("net: fix packet type for stacked VLAN")Signed-off-by Robin Jarry <[email protected]>
Just a note that this commit is already present in all latest LTS releases.
Signature · 1 line
David Marchand
Re: [PATCH dpdk v5 1/5] Revert "net: fix packet type for stacked VLAN"
In reply to Robin JarryQuoted 15 lines · Robin Jarry
This reverts commit
1f250674085aeb4ffd15ac2519a68efc04faf7ac.
rte_net_get_ptype()now uses |= to set the L2 ptype inside the VLAN parsing loop. Sincepkt_typeis already initialized withRTE_PTYPE_L2_ETHER(0x1), or-ing it withRTE_PTYPE_L2_ETHER_VLAN(0x6) results inRTE_PTYPE_L2_ETHER_QINQ(0x7). This causes single VLAN frames to be misidentified as QinQ.This was detected while testing DPDK 25.11.1 in grout. The net/tap driver calls
rte_net_get_ptype()intap_verify_csum()to determine the L2 header length. With the wrong ptype,l2_lenis set to 22 (ether
+ QinQ = 14 + 8) instead of 18 (ether + VLAN = 14 + 4), shifting the IP header pointer by 4 bytes. The checksum is then computed on garbage data, causing valid packets to be dropped.
Quoted 8 lines
Bugzilla ID: 1941
Fixes 1f250674085a ("net: fix packet type for stacked VLAN")Signed-off-by Robin Jarry <[email protected]>--- lib/net/rte_net.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
PATCH v5 2/5 net: support multiple stacked VLAN tags
In reply to Robin JarryThe VLAN and QinQ code paths in rte_net_get_ptype handle at most two tags with duplicated logic. Replace them with a single loop that consumes all consecutive VLAN/QinQ headers regardless of depth.
Bugzilla ID: 1941
--- lib/net/rte_net.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)
lib/net/rte_net.c +16 -19
@@ -349,29 +349,26 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_IPV4 )) goto l3;/* fast path if packet is IPv4 */ -if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) { +if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) || + (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ ))) {const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; - 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; - }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) + pkt_type =RTE_PTYPE_L2_ETHER_VLAN ; +else + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + +do { + 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 ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )); - pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; - vh =rte_pktmbuf_read (m, off +sizeof (*vh),sizeof (*vh), - &vh_copy); -if (unlikely (vh ==NULL )) -return pkt_type; - off +=2 *sizeof (*vh); - hdr_lens->l2_len +=2 *sizeof (*vh); - proto = vh->eth_proto; }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {unsigned int i;
Signature · 1 line
2.54.0
Re: [PATCH dpdk v5 2/5] net: support multiple stacked VLAN tags
Quoted 8 lines · Robin Jarry
The VLAN and QinQ code paths in
rte_net_get_ptypehandle at most two tags with duplicated logic. Replace them with a single loop that consumes all consecutive VLAN/QinQ headers regardless of depth.Bugzilla ID: 1941
Suggested-by David Marchand <[email protected]>Signed-off-by Robin Jarry <[email protected]>
For the record, I am still skeptical about the usecase behind this change.
Quoted 27 lines
--- lib/net/rte_net.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)lib/net/rte_net.c +2
-10@@ -349,29 +349,26 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_IPV4 )) goto l3;/* fast path if packet is IPv4 */ -if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) { +if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) || + (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ ))) {const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; - 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; - }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { -const struct rte_vlan_hdr *vh;
lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 365
Quoted 10 lines
lib/net/rte_net.c +9
-1-struct rte_vlan_hdr vh_copy; +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) + pkt_type =RTE_PTYPE_L2_ETHER_VLAN ; +else + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + + do { + vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy); + if (unlikely(vh == NULL)) + return pkt_type;
Kevin noted that it is weird to report back some packet type when the packet is malformed.
Maybe return RTE_PTYPE_UNKNOWN here so that the application is forced to validate the packet? (it should already be doing it, in any case..).
Quoted 17 lines
lib/net/rte_net.c +5
-8+ off +=sizeof (*vh); + hdr_lens->l2_len +=sizeof (*vh); + proto = vh->eth_proto; + }while (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )); - pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; - vh =rte_pktmbuf_read (m, off +sizeof (*vh),sizeof (*vh), - &vh_copy); -if (unlikely (vh ==NULL )) -return pkt_type; - off +=2 *sizeof (*vh); - hdr_lens->l2_len +=2 *sizeof (*vh); - proto = vh->eth_proto; }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {unsigned int i;
Signature · 1 line
David Marchand
Re: [PATCH dpdk v5 2/5] net: support multiple stacked VLAN tags
David Marchand, May 20, 2026 at 11:56:
Quoted 48 lines · Robin Jarry
Quoted 8 lines
The VLAN and QinQ code paths in
rte_net_get_ptypehandle at most two tags with duplicated logic. Replace them with a single loop that consumes all consecutive VLAN/QinQ headers regardless of depth.Bugzilla ID: 1941
Suggested-by David Marchand <[email protected]>Signed-off-by Robin Jarry <[email protected]>For the record, I am still skeptical about the usecase behind this change.
Quoted 35 lines
--- lib/net/rte_net.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)lib/net/rte_net.c +9
-11@@ -349,29 +349,26 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_IPV4 )) goto l3;/* fast path if packet is IPv4 */ -if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) { +if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) || + (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ ))) {const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; - 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; - }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) + pkt_type =RTE_PTYPE_L2_ETHER_VLAN ; +else + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + + do { + vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy);
Quoted 8 lines
lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 365
Quoted 2 lines
lib/net/rte_net.c +2
-0+if (unlikely (vh ==NULL )) +return pkt_type;Kevin noted that it is weird to report back some packet type when the packet is malformed.
Maybe returnRTE_PTYPE_UNKNOWNhere so that the application is forced to validate the packet? (it should already be doing it, in any case..).
If we do this, we need to fix it in the entire function. There are several other places where the "current" value of pkt_type is returned on error.
Quoted 19 lines
Quoted 19 lines
lib/net/rte_net.c +5
-8+ off +=sizeof (*vh); + hdr_lens->l2_len +=sizeof (*vh); + proto = vh->eth_proto; + }while (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )); - pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; - vh =rte_pktmbuf_read (m, off +sizeof (*vh),sizeof (*vh), - &vh_copy); -if (unlikely (vh ==NULL )) -return pkt_type; - off +=2 *sizeof (*vh); - hdr_lens->l2_len +=2 *sizeof (*vh); - proto = vh->eth_proto; }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {unsigned int i;
Signature · 1 line
Robin
Quoted 1 line
Avoid contact with skin.
Re: [PATCH dpdk v5 2/5] net: support multiple stacked VLAN tags
Quoted 19 lines · Robin Jarry
Quoted 13 lines
lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 365
Quoted 12 lines
lib/net/rte_net.c +9
-3- }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) + pkt_type =RTE_PTYPE_L2_ETHER_VLAN ; +else + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + + do { + vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy); + if (unlikely(vh == NULL)) + return pkt_type;Quoted 5 lines
Kevin noted that it is weird to report back some packet type when the packet is malformed.
Maybe returnRTE_PTYPE_UNKNOWNhere so that the application is forced to validate the packet? (it should already be doing it, in any case..).
Quoted 3 lines
If we do this, we need to fix it in the entire function. There are several other places where the "current" value of
pkt_typeis returned on error.
There is this point and the code has been behaving like this for years, so some applications may have been relying on this behavior. I don't mind leaving as is.
Signature · 1 line
David Marchand
Re: [PATCH dpdk v5 2/5] net: support multiple stacked VLAN tags
Quoted 20 lines · David Marchand
Quoted 19 lines · Robin Jarry
Quoted 18 lines
lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 365
Quoted 12 lines
lib/net/rte_net.c +9
-3- }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) + pkt_type =RTE_PTYPE_L2_ETHER_VLAN ; +else + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + + do { + vh = rte_pktmbuf_read(m, off, sizeof(*vh), &vh_copy); + if (unlikely(vh == NULL)) + return pkt_type;Kevin noted that it is weird to report back some packet type when the packet is malformed.
Maybe returnRTE_PTYPE_UNKNOWNhere so that the application is forced to validate the packet? (it should already be doing it, in any case..).
Quoted 9 lines
Quoted 3 lines
If we do this, we need to fix it in the entire function. There are several other places where the "current" value of
pkt_typeis returned on error.There is this point and the code has been behaving like this for years, so some applications may have been relying on this behavior. I don't mind leaving as is.
I can agree with Hyrum's law :-) https://xkcd.com/1172/
Re: [PATCH dpdk v5 2/5] net: support multiple stacked VLAN tags
In reply to Robin JarryQuoted 50 lines · Robin Jarry
The VLAN and QinQ code paths in
rte_net_get_ptypehandle at most two tags with duplicated logic. Replace them with a single loop that consumes all consecutive VLAN/QinQ headers regardless of depth.Bugzilla ID: 1941
Suggested-by David Marchand <[email protected]>Signed-off-by Robin Jarry <[email protected]>--- lib/net/rte_net.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-)lib/net/rte_net.c +16
-11@@ -349,29 +349,26 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m,if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_IPV4 )) goto l3;/* fast path if packet is IPv4 */ -if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) { +if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) || + (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ ))) {const struct rte_vlan_hdr *vh;struct rte_vlan_hdr vh_copy; - 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; - }else if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ )) { -const struct rte_vlan_hdr *vh; -struct rte_vlan_hdr vh_copy; +if (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_VLAN )) + pkt_type =RTE_PTYPE_L2_ETHER_VLAN ; +else + pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; + +do { + 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 ) || + proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_QINQ ));
lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 373
Quoted 10 lines
lib/net/rte_net.c +0
-8- pkt_type =RTE_PTYPE_L2_ETHER_QINQ ; - vh =rte_pktmbuf_read (m, off +sizeof (*vh),sizeof (*vh), - &vh_copy); -if (unlikely (vh ==NULL )) -return pkt_type; - off +=2 *sizeof (*vh); - hdr_lens->l2_len +=2 *sizeof (*vh); - proto = vh->eth_proto; }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {
David's code snipped earlier in the thread suggested that this should be change from an 'else if' to an 'if'. It seems to make sense to have it as an 'if', not sure if it was deliberate to remove. Though it might not be really part of this patch.
- } else if ((proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS)) ||
+ if ((proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLS)) ||
(proto == rte_cpu_to_be_16(RTE_ETHER_TYPE_MPLSM))) {
unsigned int i;Quoted 1 line
lib/net/rte_net.c +0
-0unsigned int i;
Re: [PATCH dpdk v5 2/5] net: support multiple stacked VLAN tags
Kevin Traynor, May 21, 2026 at 15:38:
lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 374
Quoted 12 lines
lib/net/rte_net.c uint32_t rte_net_get_ptype(const struct rte_mbuf *m, · line 373
Quoted 2 lines
lib/net/rte_net.c +0
-0}else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {David's code snipped earlier in the thread suggested that this should be change from an 'else if' to an 'if'. It seems to make sense to have it as an 'if', not sure if it was deliberate to remove. Though it might not be really part of this patch.
lib/net/rte_net.c +1
-1- }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || +if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) {unsigned int i;
Yes, I deliberately kept this as it was. I can add another patch to change to a simple if. It makes sense to support MPLS in VLAN.
Signature · 1 line
Robin
Quoted 1 line
Place stamp here.
Re: [PATCH dpdk v5 2/5] net: support multiple stacked VLAN tags
In reply to Robin JarryQuoted 7 lines · On Mon, 18 May 2026 15:27:16 +0200 Robin Jarry <[email protected]> wrote:
The VLAN and QinQ code paths in
rte_net_get_ptypehandle at most two tags with duplicated logic. Replace them with a single loop that consumes all consecutive VLAN/QinQ headers regardless of depth.Bugzilla ID: 1941
Suggested-by David Marchand <[email protected]>Signed-off-by Robin Jarry <[email protected]>
Another issue discovered by AI is that hdr_lens->l2_len is too small.
Patch 2/5: net: support multiple stacked VLAN tags
Warning: hdr_lens->l2_len is uint8_t. The previous code capped the tag count at RTE_NET_VLAN_MAX_DEPTH (8), bounding l2_len to 14 + 8*4 = 46. The new do/while consumes tags until rte_pktmbuf_read() fails, so the only bound is packet length. A frame carrying >=61 stacked VLAN/QINQ tags (>=244 bytes of L2 headers) wraps l2_len around 256. There is no infinite loop or OOB read (off advances monotonically and the read terminates at end of data), but the wrapped l2_len is exactly the kind of bad header-length value this series set out to fix in tap_verify_csum. Consider keeping a depth cap, or widening/saturating l2_len.
PATCH v5 3/5 net: add unit tests for rte_net_get_ptype
In reply to Robin JarryThere is no test coverage for rte_net_get_ptype. Add a test suite that exercises plain Ethernet, single VLAN, QinQ, double VLAN, IPv4 with options, IPv6, TCP and UDP combinations.
--- app/test/meson.build | 1 + app/test/test_net_ptype.c | 231 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+) create mode 100644 app/test/test_net_ptype.c
app/test/meson.build +1 -0
@@ -135,6 +135,7 @@ source_file_deps = { 'test_mp_secondary.c': ['hash'], 'test_net_ether.c': ['net'], 'test_net_ip6.c': ['net'], + 'test_net_ptype.c': ['net'], 'test_pcapng.c': ['net_null', 'net', 'ethdev', 'pcapng', 'bus_vdev'], 'test_pdcp.c': ['eventdev', 'pdcp', 'net', 'timer', 'security'], 'test_pdump.c': ['pdump'] + sample_packet_forward_deps,
app/test/test_net_ptype.c new file +231 -0
231 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v5 4/5 net: parse L3 protocol after MPLS labels
In reply to Robin Jarryrte_net_get_ptype stops at the MPLS layer and never identifies the L3 protocol of the payload. Also, the label parsing uses a fixed maximum of 5 headers instead of checking the bottom of stack bit.
Use the bottom of stack bit to consume all labels and inspect the first nibble of the payload to determine if it is IPv4 or IPv6.
Add test cases to verify this works. Ensure that an unknown protocol after MPLS (e.g. ARP) does not produce a bogus L3 type.
--- app/test/test_net_ptype.c | 57 +++++++++++++++++++++++++++++++++++++++ lib/net/rte_net.c | 34 ++++++++++++++++------- 2 files changed, 81 insertions(+), 10 deletions(-)
app/test/test_net_ptype.c +57 -0
@@ -118,6 +118,51 @@ static const uint8_t pkt_vlan_vlan_ipv4_udp[] = { 0x89, 0x6f, 0x78, }; +/* Ether(type=MPLS)/MPLS(label=42,s=1)/IP()/UDP()/Raw('x') */ +static const uint8_t pkt_mpls_ipv4_udp[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x88 ,0x47 ,0x00 ,0x02 , +0xa1 ,0x40 ,0x45 ,0x00 ,0x00 ,0x1d ,0x00 ,0x01 , +0x00 ,0x00 ,0x40 ,0x11 ,0x7c ,0xcd ,0x7f ,0x00 , +0x00 ,0x01 ,0x7f ,0x00 ,0x00 ,0x01 ,0x00 ,0x35 , +0x00 ,0x35 ,0x00 ,0x09 ,0x89 ,0x6f ,0x78 , +}; + +/* Ether(type=MPLS)/MPLS(label=42,s=0)/MPLS(label=43,s=1)/IPv6()/TCP() */ +static const uint8_t pkt_mpls2_ipv6_tcp[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x88 ,0x47 ,0x00 ,0x02 , +0xa0 ,0x40 ,0x00 ,0x02 ,0xb1 ,0x40 ,0x60 ,0x00 , +0x00 ,0x00 ,0x00 ,0x14 ,0x06 ,0x40 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x01 ,0x00 ,0x14 , +0x00 ,0x50 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x50 ,0x02 ,0x20 ,0x00 ,0x8f ,0x7d , +0x00 ,0x00 , +}; + +/* Ether(type=MPLSM)/MPLS(label=42,s=1)/IP()/UDP()/Raw('x') */ +static const uint8_t pkt_mplsm_ipv4_udp[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x88 ,0x48 ,0x00 ,0x02 , +0xa1 ,0x40 ,0x45 ,0x00 ,0x00 ,0x1d ,0x00 ,0x01 , +0x00 ,0x00 ,0x40 ,0x11 ,0x7c ,0xcd ,0x7f ,0x00 , +0x00 ,0x01 ,0x7f ,0x00 ,0x00 ,0x01 ,0x00 ,0x35 , +0x00 ,0x35 ,0x00 ,0x09 ,0x89 ,0x6f ,0x78 , +}; + +/* Ether(type=MPLS)/MPLS(label=42,s=1)/ARP() -- unknown L3 after MPLS */ +static const uint8_t pkt_mpls_arp[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x88 ,0x47 ,0x00 ,0x02 , +0xa1 ,0x40 ,0x00 ,0x01 ,0x08 ,0x00 ,0x06 ,0x04 , +0x00 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x7f ,0x00 ,0x00 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x7f ,0x00 ,0x00 ,0x02 , +}; +/* Ether()/Dot1AD(vlan=42)/Dot1Q(vlan=43)/IPv6()/TCP() */ static const uint8_t pkt_qinq_ipv6_tcp[] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 ,
@@ -222,6 +267,18 @@ test_net_ptype(void) ret |=test_case (pool, pkt_qinq_ipv6_tcp,RTE_PTYPE_L2_ETHER_QINQ |RTE_PTYPE_L3_IPV6 |RTE_PTYPE_L4_TCP ,22 ,40 ,20 ); + ret |=test_case (pool, pkt_mpls_ipv4_udp, +RTE_PTYPE_L2_ETHER_MPLS |RTE_PTYPE_L3_IPV4 |RTE_PTYPE_L4_UDP , +18 ,20 ,8 ); + ret |=test_case (pool, pkt_mpls2_ipv6_tcp, +RTE_PTYPE_L2_ETHER_MPLS |RTE_PTYPE_L3_IPV6 |RTE_PTYPE_L4_TCP , +22 ,40 ,20 ); + ret |=test_case (pool, pkt_mplsm_ipv4_udp, +RTE_PTYPE_L2_ETHER_MPLS |RTE_PTYPE_L3_IPV4 |RTE_PTYPE_L4_UDP , +18 ,20 ,8 ); + ret |=test_case (pool, pkt_mpls_arp, +RTE_PTYPE_L2_ETHER_MPLS , +18 ,0 ,0 );rte_mempool_free (pool);
lib/net/rte_net.c +24 -10
@@ -371,22 +371,36 @@ uint32_t rte_net_get_ptype(const struct rte_mbuf *m, }else if ((proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLS )) || (proto ==rte_cpu_to_be_16 (RTE_ETHER_TYPE_MPLSM ))) { -unsigned int i;const struct rte_mpls_hdr *mh;struct rte_mpls_hdr mh_copy; +const uint8_t *nimble; +uint8_t nimble_copy; -#define MAX_MPLS_HDR 5 -for (i =0 ; i <MAX_MPLS_HDR ; i++) { - mh =rte_pktmbuf_read (m, off + (i *sizeof (*mh)), -sizeof (*mh), &mh_copy); + pkt_type =RTE_PTYPE_L2_ETHER_MPLS ; + +/* consume all labels until bottom of stack is reached */ +do { + mh =rte_pktmbuf_read (m, off,sizeof (*mh), &mh_copy);if (unlikely (mh ==NULL ))return pkt_type; - } -if (i ==MAX_MPLS_HDR ) + off +=sizeof (*mh); + hdr_lens->l2_len +=sizeof (*mh); + }while (!mh->bs); + +/* try to guess what is the payload based on the first 4 bits */ + nimble =rte_pktmbuf_read (m, off,sizeof (*nimble), &nimble_copy); +if (nimble ==NULL )return pkt_type; - pkt_type =RTE_PTYPE_L2_ETHER_MPLS ; - hdr_lens->l2_len += (sizeof (*mh) * i); -return pkt_type; +switch (*nimble &0xf0 ) { +case 0x40 : + proto =RTE_BE16 (RTE_ETHER_TYPE_IPV4 ); +break ; +case 0x60 : + proto =RTE_BE16 (RTE_ETHER_TYPE_IPV6 ); +break ; +default : +return pkt_type; + } } l3:
Signature · 1 line
2.54.0
Re: [PATCH dpdk v5 4/5] net: parse L3 protocol after MPLS labels
Quoted 4 lines · On Mon, 18 May 2026 15:27:18 +0200 Robin Jarry <[email protected]> wrote:
rte_net_get_ptypestops at the MPLS layer and never identifies the L3 protocol of the payload. Also, the label parsing uses a fixed maximum of 5 headers instead of checking the bottom of stack bit.
Quoted 8 lines
Use the bottom of stack bit to consume all labels and inspect the first nibble of the payload to determine if it is IPv4 or IPv6.
Add test cases to verify this works. Ensure that an unknown protocol after MPLS (e.g. ARP) does not produce a bogus L3 type.
Signed-off-by Robin Jarry <[email protected]>---
Re: [PATCH dpdk v5 4/5] net: parse L3 protocol after MPLS labels
Info:
The local variable name nimble (and its companion nimble_copy) appears to be a typo for nibble. A nibble is the standard term for 4 bits, which is what the code reads and masks against 0xf0. The commit message itself uses the correct spelling ("inspect the first nibble of the payload"), so only the code is affected.
const uint8_t *nimble;
uint8_t nimble_copy;
...
nimble = rte_pktmbuf_read(m, off, sizeof(*nimble), &nimble_copy);
if (nimble == NULL)
return pkt_type;
switch (*nimble & 0xf0) {Suggest renaming to nibble/nibble_copy for clarity.
Re: [PATCH dpdk v5 4/5] net: parse L3 protocol after MPLS labels
In reply to Robin JarryQuoted 4 lines · On Mon, 18 May 2026 15:27:18 +0200 Robin Jarry <[email protected]> wrote:
rte_net_get_ptypestops at the MPLS layer and never identifies the L3 protocol of the payload. Also, the label parsing uses a fixed maximum of 5 headers instead of checking the bottom of stack bit.
Quoted 8 lines
Use the bottom of stack bit to consume all labels and inspect the first nibble of the payload to determine if it is IPv4 or IPv6.
Add test cases to verify this works. Ensure that an unknown protocol after MPLS (e.g. ARP) does not produce a bogus L3 type.
Signed-off-by Robin Jarry <[email protected]>---
AI spotted similar potential uint8_t overflow here.
Patch 4/5: net: parse L3 protocol after MPLS labels
Warning: same uint8_t l2_len concern as patch 2. The old loop was capped at MAX_MPLS_HDR (5); the new "do { } while (!mh->bs)" is bounded only by packet length, so a deep label stack wraps l2_len.
Info: the local is named "nimble" (and the read into nimble_copy); the comment says "first 4 bits", i.e. the nibble. Likely meant "nibble".
PATCH v5 5/5 net: add truncated packet tests for rte_net_get_ptype
In reply to Robin JarryEnsure rte_net_get_ptype handles truncated packets gracefully by stopping at the last layer it can fully parse.
--- app/test/test_net_ptype.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
app/test/test_net_ptype.c +38 -0
@@ -163,6 +163,32 @@ static const uint8_t pkt_mpls_arp[] = { 0x00, 0x00, 0x7f, 0x00, 0x00, 0x02, }; +/* Ether()/Dot1Q() -- VLAN header truncated */ +static const uint8_t pkt_vlan_trunc[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x81 ,0x00 ,0x00 ,0x2a , +}; + +/* Ether(type=MPLS) -- MPLS header truncated */ +static const uint8_t pkt_mpls_trunc[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x88 ,0x47 ,0x00 ,0x02 , +}; + +/* Ether(type=MPLS)/MPLS(label=42,s=1) -- no payload after label */ +static const uint8_t pkt_mpls_no_payload[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x88 ,0x47 ,0x00 ,0x02 , +0xa1 ,0x40 , +}; + +/* Ether()/IP() -- IPv4 header truncated */ +static const uint8_t pkt_ipv4_trunc[] = { +0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x08 ,0x00 ,0x45 ,0x00 , +0x00 ,0x1d ,0x00 ,0x01 ,0x00 ,0x00 ,0x40 ,0x11 , +}; +/* Ether()/Dot1AD(vlan=42)/Dot1Q(vlan=43)/IPv6()/TCP() */ static const uint8_t pkt_qinq_ipv6_tcp[] = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x00 ,
@@ -279,6 +305,18 @@ test_net_ptype(void) ret |=test_case (pool, pkt_mpls_arp,RTE_PTYPE_L2_ETHER_MPLS ,18 ,0 ,0 ); + ret |=test_case (pool, pkt_vlan_trunc, +RTE_PTYPE_L2_ETHER_VLAN , +14 ,0 ,0 ); + ret |=test_case (pool, pkt_mpls_trunc, +RTE_PTYPE_L2_ETHER_MPLS , +14 ,0 ,0 ); + ret |=test_case (pool, pkt_mpls_no_payload, +RTE_PTYPE_L2_ETHER_MPLS , +18 ,0 ,0 ); + ret |=test_case (pool, pkt_ipv4_trunc, +RTE_PTYPE_L2_ETHER , +14 ,0 ,0 );rte_mempool_free (pool);
Signature · 1 line
2.54.0
Re: [PATCH dpdk v5 0/5] Fix and improve VLAN/MPLS parsing in rte_net_get_ptype
In reply to Robin JarryQuoted 52 lines · On Mon, 18 May 2026 15:27:14 +0200 Robin Jarry <[email protected]> wrote:
Revert commit
1f250674085a("net: fix packet type for stacked VLAN") which introduced a regression causing single VLAN frames to be misidentified as QinQ due to incorrect use of |= on the ptype.Replace the separate VLAN and QinQ code paths with a single loop that handles arbitrarily stacked VLAN tags. Fix the MPLS path to use the bottom of stack bit instead of a hardcoded label limit, and parse the L3 protocol of the MPLS payload by inspecting the first nibble.
Add unit tests for
rte_net_get_ptypecovering Ethernet, VLAN, QinQ, MPLS, IPv4/IPv6, and truncated packet scenarios.v5:
* Split the series in multiple patches.
* Revert the commit that introduced the bug.
* Add support for stacked VLAN/QINQ as suggested by David.
* Fix MPLS bottom of stack detection. Try to guess MPLS payload.
* Add more test cases.v4:
* changed the approach again. Only set VLAN or QINQ ptype for the first encountered vlan/qinq ether type.
* unit tests not changedv3:
* changed the approach: initialize pkt_type=0 and only set it to
RTE_PTYPE_L2_ETHERif neither of VLAN nor QINQ matched.
* extended the unit tests to check for header lengths and added ipv6 / tcp cases.v2: added new ptype tests
v3:
* changed the approach: initialize pkt_type=0 and only set it to
RTE_PTYPE_L2_ETHERif neither of VLAN nor QINQ matched.
* extended the unit tests to check for header lengths and added ipv6 / tcp cases.v2: added new ptype tests
Robin Jarry (5):
Revert "net: fix packet type for stacked VLAN"
net: support multiple stacked VLAN tags
net: add unit tests forrte_net_get_ptype
net: parse L3 protocol after MPLS labels
net: add truncated packet tests forrte_net_get_ptype
Quoted 6 lines
app/test/meson.build | 1 + app/test/test_net_ptype.c | 326 ++++++++++++++++++++++++++++++++++++++ lib/net/rte_net.c | 72 +++++---- 3 files changed, 369 insertions(+), 30 deletions(-) create mode 100644 app/test/test_net_ptype.c
In addition to the other comments, would like a release note for this.
Warning: rte_net_get_ptype() is a public stable API and this changes its observable output (MPLS payload now resolves to L3 IPv4/IPv6 and falls through to l3 instead of returning at the MPLS layer). No release-notes entry accompanies the series. The VLAN misidentification fix (patch 1) is a bug fix with Cc: stable, but the MPLS L3-detection change is a behavior enhancement to an existing API and warrants a note in the current release notes.