|SUCCESS| [v4] net: fix VLAN packet type

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Thu Apr 23 14:44:03 CEST 2026


Test-Label: ai-code-review
Test-Status: SUCCESS
https://dpdk.org/patch/163262

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-04-23

I'll review this DPDK patch for correctness, coding style, and guideline compliance.

```
commit <sha from patchwork>
Author: Robin Jarry <rjarry at redhat.com>
Subject: [PATCH dpdk v4] net: fix VLAN packet type

This patch fixes a bug where single VLAN frames are misidentified as QinQ
due to incorrect bitwise OR operations when setting L2 packet types in
rte_net_get_ptype().

> diff --git a/lib/net/rte_net.c b/lib/net/rte_net.c
> index 458b4814a9c9..a871318b21c2 100644
> --- a/lib/net/rte_net.c
> +++ b/lib/net/rte_net.c
> @@ -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;
> +		}

Does this code handle the pkt_type initialization correctly? The variable
pkt_type is initialized to RTE_PTYPE_L2_ETHER before entering the VLAN
loop. When this code overwrites pkt_type with the assignment operator,
does it properly preserve any L3/L4 type information that might have been
set before entering this case block?

Looking at the function flow, pkt_type is set to RTE_PTYPE_L2_ETHER early
in the function, then the code enters a loop based on proto (the ethertype).
If a VLAN ethertype is encountered, this new code will overwrite pkt_type
completely. Can this cause issues if any bits other than the L2 field were
already set in pkt_type?

The ternary operator spans multiple lines. According to the coding style
guide section on operators, when breaking lines within ternary operators,
the question mark and colon should align. The current indentation has the
colon indented one extra space compared to the condition line. Can this
indentation be adjusted to match the style where the '?' and ':' align?

>  		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;

The removed code used '|=' which caused the bug. Does the fix ensure that
subsequent VLAN tags in stacked configurations don't overwrite the L2 type
set for the first tag?

> diff --git a/app/test/test_net_ptype.c b/app/test/test_net_ptype.c
> new file mode 100644
> index 000000000000..bfe85da13543
> --- /dev/null
> +++ b/app/test/test_net_ptype.c

[ ... ]

> +static int
> +test_get_ptype(struct rte_mempool *pool, const char *name,
> +	       const uint8_t *pktdata, size_t len, uint32_t expected_ptype,
> +	       uint8_t expected_l2_len, uint16_t expected_l3_len,
> +	       uint8_t expected_l4_len)
> +{
> +	struct rte_net_hdr_lens hdr_lens;
> +	struct rte_mbuf *m;
> +	uint32_t ptype;
> +	char *data;
> +
> +	RTE_LOG(INFO, EAL, "%s: %s\n", __func__, name);
> +
> +	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");
> +	}

Does this code check for the rte_pktmbuf_append failure correctly? After
calling rte_pktmbuf_free(m), the RTE_TEST_ASSERT_NOT_NULL macro will cause
the function to return an error. However, does the macro guarantee that no
further code executes? If execution continues past the assertion, does the
code safely handle the freed mbuf?

> +
> +	memcpy(data, pktdata, len);
> +
> +	memset(&hdr_lens, 0, sizeof(hdr_lens));
> +	ptype = rte_net_get_ptype(m, &hdr_lens, RTE_PTYPE_ALL_MASK);
> +
> +	rte_pktmbuf_free(m);
> +
> +	RTE_TEST_ASSERT_EQUAL(ptype, expected_ptype,
> +		"unexpected ptype: got 0x%x, expected 0x%x",
> +		ptype, expected_ptype);
> +	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);
> +	RTE_TEST_ASSERT_EQUAL(hdr_lens.l3_len, expected_l3_len,
> +		"unexpected l3_len: got %u, expected %u",
> +		hdr_lens.l3_len, expected_l3_len);
> +	RTE_TEST_ASSERT_EQUAL(hdr_lens.l4_len, expected_l4_len,
> +		"unexpected l4_len: got %u, expected %u",
> +		hdr_lens.l4_len, expected_l4_len);

[ ... ]

```


More information about the test-report mailing list