patches for DPDK stable branches
 help / color / mirror / Atom feed
From: "Morten Brørup" <mb@smartsharesystems.com>
To: "Kaiwen Deng" <kaiwenx.deng@intel.com>, <dev@dpdk.org>
Cc: <stable@dpdk.org>, <qiming.yang@intel.com>,
	<yidingx.zhou@intel.com>, "Xiaoyun Li" <xiaoyun.li@intel.com>,
	"Aman Singh" <aman.deep.singh@intel.com>,
	"Ferruh Yigit" <ferruh.yigit@intel.com>
Subject: RE: [PATCH v3] lib/net: fix tcp/udp cksum with padding data
Date: Tue, 12 Dec 2023 09:10:04 +0100	[thread overview]
Message-ID: <98CBD80474FA8B44BF855DF32C47DC35E9F0B0@smartserver.smartshare.dk> (raw)
In-Reply-To: <20231212021619.2038881-1-kaiwenx.deng@intel.com>

> From: Kaiwen Deng [mailto:kaiwenx.deng@intel.com]
> Sent: Tuesday, 12 December 2023 03.16
> 
> IEEE 802 packets may have a minimum size limit. The data fields
> should be padded when necessary. In some cases, the padding data
> is not zero.
> 
> In 'rte_ipv4_udptcp_cksum_mbuf()', as payload length
> "mbuf->pkt_len - l4_off" is used, which includes padding and if
> padding is not zero it will end up producing wrong checksum.
> 
> This patch will use IP header to get the payload size to calculate
> tcp/udp checksum.
> 
> Fixes: d178f693bbfe ("net: add UDP/TCP checksum in mbuf segments")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Kaiwen Deng <kaiwenx.deng@intel.com>
> ---
>  lib/net/rte_ip.h | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h
> index 6fa98a5a0f..c503a2b57f 100644
> --- a/lib/net/rte_ip.h
> +++ b/lib/net/rte_ip.h
> @@ -423,7 +423,10 @@ __rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf
> *m,
>  	if (l4_off > m->pkt_len)
>  		return 0;

It's not directly related, but while you are at it, please also add unlikely to the above check:

-	if (l4_off > m->pkt_len)
-		return 0;
+	if (unlikely(l4_off > m->pkt_len))
+		return 0; /* invalid params, return a dummy value */

> 
> -	if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off,
> &raw_cksum))
> +	uint16_t len = rte_be_to_cpu_16(ipv4_hdr->total_length) -
> +				(uint16_t)rte_ipv4_hdr_len(ipv4_hdr);
> +
> +	if (rte_raw_cksum_mbuf(m, l4_off, len, &raw_cksum))

Please declare "uint16_t len;" with the other variables at the top of the function, and only set its value here. (It's allowed to declare here, but please follow this function's existing convention of where variables are declared.)

>  		return 0;
> 
>  	cksum = raw_cksum + rte_ipv4_phdr_cksum(ipv4_hdr, 0);
> @@ -666,7 +669,9 @@ __rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf
> *m,
>  	if (l4_off > m->pkt_len)
>  		return 0;

Again not directly related, but please also add unlikely to this comparison:

-	if (l4_off > m->pkt_len)
-		return 0;
+	if (unlikely(l4_off > m->pkt_len))
+		return 0; /* invalid params, return a dummy value */

> 
> -	if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off,
> &raw_cksum))
> +	uint16_t len = rte_be_to_cpu_16(ipv6_hdr->payload_len);
> +
> +	if (rte_raw_cksum_mbuf(m, l4_off, len, &raw_cksum))

No need for "len" variable here, just use rte_be_to_cpu_16(ipv6_hdr->payload_len) directly:

-	if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, &raw_cksum))
+	if (rte_raw_cksum_mbuf(m, l4_off, rte_be_to_cpu_16(ipv6_hdr->payload_len), &raw_cksum))

>  		return 0;
> 
>  	cksum = raw_cksum + rte_ipv6_phdr_cksum(ipv6_hdr, 0);
> --
> 2.34.1


  reply	other threads:[~2023-12-12  8:10 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-04  8:28 [PATCH] app/test-pmd: fix L4 checksum " Kaiwen Deng
2023-11-02 19:20 ` Ferruh Yigit
2023-11-03  2:49   ` Deng, KaiwenX
2023-11-03  4:03     ` Ferruh Yigit
2023-11-14  2:19       ` Deng, KaiwenX
2023-11-14 19:09         ` Ferruh Yigit
2023-11-16  7:02           ` Deng, KaiwenX
2023-11-16 22:58   ` Stephen Hemminger
2023-11-17  0:50     ` Ferruh Yigit
2023-11-17  3:28       ` Stephen Hemminger
2023-11-17  9:29         ` Ferruh Yigit
2023-11-17 12:11           ` Morten Brørup
2023-11-17 16:23             ` Stephen Hemminger
2023-11-17 16:22           ` Stephen Hemminger
2023-11-20 10:47             ` Ferruh Yigit
2023-11-20  9:21       ` Deng, KaiwenX
2023-11-20 10:46         ` Ferruh Yigit
2023-11-22  3:04           ` Deng, KaiwenX
2023-11-17  1:13 ` Ferruh Yigit
2023-11-20  9:52   ` Deng, KaiwenX
2023-12-07  8:53 ` [PATCH v2] app/test-pmd: fix tcp/udp cksum " Kaiwen Deng
2023-12-07 14:35   ` Ferruh Yigit
2023-12-12  2:16   ` [PATCH v3] lib/net: " Kaiwen Deng
2023-12-12  8:10     ` Morten Brørup [this message]
2023-12-13  4:37     ` [PATCH v4] " Kaiwen Deng
2023-12-13  7:36       ` Morten Brørup
2023-12-14  9:22       ` [PATCH v5] " Kaiwen Deng
2023-12-14 11:20         ` Morten Brørup
2024-02-19  1:10           ` 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=98CBD80474FA8B44BF855DF32C47DC35E9F0B0@smartserver.smartshare.dk \
    --to=mb@smartsharesystems.com \
    --cc=aman.deep.singh@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=kaiwenx.deng@intel.com \
    --cc=qiming.yang@intel.com \
    --cc=stable@dpdk.org \
    --cc=xiaoyun.li@intel.com \
    --cc=yidingx.zhou@intel.com \
    /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).