From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Raslan Darawsheh" <rasland@nvidia.com>,
"NBU-Contact-Thomas Monjalon (EXTERNAL)" <thomas@monjalon.net>,
"Stephen Hemminger" <stephen@networkplumber.org>
Cc: <dev@dpdk.org>, <haijie1@huawei.com>
Subject: RE: [PATCH] app/testpmd: fix VLAN header parsing
Date: Mon, 24 Mar 2025 09:45:00 +0100 [thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35E9FB49@smartserver.smartshare.dk> (raw)
In-Reply-To: <CH3PR12MB84608270E82932227FEF61E5CFA42@CH3PR12MB8460.namprd12.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 3718 bytes --]
Answer inline below.
From: Raslan Darawsheh [mailto:rasland@nvidia.com]
Sent: Monday, 24 March 2025 09.32
Comment inline below.
From: Raslan Darawsheh [mailto:rasland@nvidia.com]
Sent: Monday, 24 March 2025 08.35
>> From: Raslan Darawsheh [mailto:rasland@nvidia.com]
>> Sent: Sunday, 23 March 2025 13.28
>>
>> Updated the `get_ethertype_by_ptype` function to correctly parse VLAN
>> headers.
>>
>> Fixes: 76730c7b9b5a ("app/testpmd: use packet type parsing API")
>> Cc: haijie1@huawei.com
>>
>>> Signed-off-by: Raslan Darawsheh <rasland@nvidia.com>
>> ---
>> app/test-pmd/csumonly.c | 8 +++++---
>> 1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
>> index 5b906eaa53..302cc4cc66 100644
>> --- a/app/test-pmd/csumonly.c
>> +++ b/app/test-pmd/csumonly.c
>> @@ -468,6 +468,7 @@ get_ethertype_by_ptype(struct rte_ether_hdr
>> *eth_hdr, uint32_t ptype)
>> {
>> struct rte_vlan_hdr *vlan_hdr;
>> uint16_t ethertype;
>> + uint32_t i = 0;
>>
>> switch (ptype) {
>> case RTE_PTYPE_L3_IPV4:
>> @@ -486,10 +487,11 @@ get_ethertype_by_ptype(struct rte_ether_hdr
>> *eth_hdr, uint32_t ptype)
>> return _htons(RTE_ETHER_TYPE_IPV6);
>> default:
>> ethertype = eth_hdr->ether_type;
>> - while (eth_hdr->ether_type == _htons(RTE_ETHER_TYPE_VLAN)
>> ||
>> - eth_hdr->ether_type == _htons(RTE_ETHER_TYPE_QINQ)) {
>> + while (ethertype == _htons(RTE_ETHER_TYPE_VLAN) ||
>> + ethertype == _htons(RTE_ETHER_TYPE_QINQ)) {
>> vlan_hdr = (struct rte_vlan_hdr *)
>> - ((char *)eth_hdr + sizeof(*eth_hdr));
>> + ((char *)eth_hdr + sizeof(*eth_hdr) +
>> + (i * sizeof(struct rte_vlan_hdr)));
>Doesn't work; "i" is not incremented, and remains 0.
>Instead do this: Initialize (struct rte_vlan_hdr *)vlan_hdr=RTE_PTR_ADD(eth_hdr, offsetof(rte_ether_hdr, ether_type)) before the loop, and move vlan_hdr+=RTE_VLAN_HLEN inside the loop.
Yes you are correct I had a (i++ *) but must have slipped while rebasing will handle your way in v2
MB: Noticed a bug in my suggestion: Due to the type of vlan_hdr, moving it should be vlan_hdr++, not vlan_hdr+=RTE_VLAN_HLEN.
Yes sure will handle,
MB: And you might want to impose a maximum boundary to the loop, as suggested by Stephen. E.g. break out of the loop if vlan_hdr>RTE_PTR_ADD(eth_hdr, offsetof(rte_ether_hdr, ether_type)+4*sizeof(struct rte_vlan_hdr)). Supporting up to 4 stacked VLAN tags should suffice.
I'm not sure this should be added to this patch, as I tend to believe it's less critical to handle for this release, and also, this might cause inconsistent results, think of the case if we send five stacked vlan tags, then we'll return ethertype as VLAN as we skipped the last one.
MB:
It should go in this patch, to prevent code analysis tools from warning about unbounded loop causing potential buffer overrun - the bug described by Stephen.
IMO, a stack of 4 VLAN tags should suffice, but you can make it 8 to give it some extra margin. More than 8 VLAN tags is never going to happen with real traffic.
In reality, most NICs can only strip 1 or 2 VLAN tags, and would return ethertype as VLAN. But this can be ignored for this patch.
>> ethertype = vlan_hdr->eth_proto;
>> }
>> return ethertype;
>> --
>> 2.39.5 (Apple Git-154)
Kindest regards
Raslan Darawsheh
[-- Attachment #2: Type: text/html, Size: 11164 bytes --]
next prev parent reply other threads:[~2025-03-24 8:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-23 12:28 Raslan Darawsheh
2025-03-23 13:14 ` Morten Brørup
2025-03-24 7:34 ` Raslan Darawsheh
2025-03-24 7:43 ` Morten Brørup
2025-03-24 7:44 ` Morten Brørup
2025-03-24 8:32 ` Raslan Darawsheh
2025-03-24 8:45 ` Morten Brørup [this message]
2025-03-23 16:00 ` Stephen Hemminger
2025-03-24 7:37 ` Raslan Darawsheh
2025-03-23 16:39 ` Thomas Monjalon
2025-03-24 7:38 ` Raslan Darawsheh
2025-03-24 8:50 ` [PATCH v2] " Raslan Darawsheh
2025-03-24 9:04 ` Morten Brørup
2025-03-24 9:40 ` Raslan Darawsheh
2025-03-24 9:33 ` [PATCH v3] " Raslan Darawsheh
2025-03-24 13:18 ` Morten Brørup
2025-03-24 16:59 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=98CBD80474FA8B44BF855DF32C47DC35E9FB49@smartserver.smartshare.dk \
--to=mb@smartsharesystems.com \
--cc=dev@dpdk.org \
--cc=haijie1@huawei.com \
--cc=rasland@nvidia.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).