[PATCH dpdk v5 5/5] net: add truncated packet tests for rte_net_get_ptype
Robin Jarry
rjarry at redhat.com
Mon May 18 15:27:19 CEST 2026
Ensure rte_net_get_ptype handles truncated packets gracefully by
stopping at the last layer it can fully parse.
Signed-off-by: Robin Jarry <rjarry at redhat.com>
---
app/test/test_net_ptype.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/app/test/test_net_ptype.c b/app/test/test_net_ptype.c
index cc7026077191..332ace5dd929 100644
--- a/app/test/test_net_ptype.c
+++ b/app/test/test_net_ptype.c
@@ -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);
--
2.54.0
More information about the dev
mailing list