From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6DF29436DC for ; Wed, 13 Dec 2023 08:36:45 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5E54142EB2; Wed, 13 Dec 2023 08:36:45 +0100 (CET) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id D069142E55; Wed, 13 Dec 2023 08:36:43 +0100 (CET) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id A86F5206C2; Wed, 13 Dec 2023 08:36:41 +0100 (CET) Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Subject: RE: [PATCH v4] lib/net: fix tcp/udp cksum with padding data X-MimeOLE: Produced By Microsoft Exchange V6.5 Date: Wed, 13 Dec 2023 08:36:38 +0100 Message-ID: <98CBD80474FA8B44BF855DF32C47DC35E9F0C3@smartserver.smartshare.dk> In-Reply-To: <20231213043732.2113867-1-kaiwenx.deng@intel.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PATCH v4] lib/net: fix tcp/udp cksum with padding data Thread-Index: AdothHMIaNQnW9jXRDWoTcc5kBrOmgAEL0CA References: <20231212021619.2038881-1-kaiwenx.deng@intel.com> <20231213043732.2113867-1-kaiwenx.deng@intel.com> From: =?iso-8859-1?Q?Morten_Br=F8rup?= To: "Kaiwen Deng" , Cc: , , , "Xiaoyun Li" , "Ferruh Yigit" , "Aman Singh" X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org > From: Kaiwen Deng [mailto:kaiwenx.deng@intel.com] > Sent: Wednesday, 13 December 2023 05.38 >=20 > 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. >=20 > 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. >=20 > This patch will use IP header to get the payload size to calculate > tcp/udp checksum. >=20 > Fixes: d178f693bbfe ("net: add UDP/TCP checksum in mbuf segments") > Cc: stable@dpdk.org >=20 > Signed-off-by: Kaiwen Deng Please fix indentation, refer to the Coding Style: https://doc.dpdk.org/guides/contributing/coding_style.html#c-indentation Note that line length up to 100 characters is acceptable: https://doc.dpdk.org/guides/contributing/coding_style.html#general-guidel= ines To some degree, indentation is a matter of taste. Just stay within the = boundaries of the Coding Style. > --- > lib/net/rte_ip.h | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) >=20 > diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h > index 6fa98a5a0f..bcdce723a5 100644 > --- a/lib/net/rte_ip.h > +++ b/lib/net/rte_ip.h > @@ -419,11 +419,15 @@ __rte_ipv4_udptcp_cksum_mbuf(const struct > rte_mbuf *m, > { > uint16_t raw_cksum; > uint32_t cksum; > + uint16_t len; >=20 > - if (l4_off > m->pkt_len) > - return 0; > + if (unlikely(l4_off > m->pkt_len)) > + return 0; /* invalid params, return a dummy value */ > + > + len =3D rte_be_to_cpu_16(ipv4_hdr->total_length) - > + (uint16_t)rte_ipv4_hdr_len(ipv4_hdr); Please fix indentation of this continuation line. >=20 > - if (rte_raw_cksum_mbuf(m, l4_off, m->pkt_len - l4_off, > &raw_cksum)) > + if (rte_raw_cksum_mbuf(m, l4_off, len, &raw_cksum)) > return 0; >=20 > cksum =3D raw_cksum + rte_ipv4_phdr_cksum(ipv4_hdr, 0); > @@ -663,10 +667,11 @@ __rte_ipv6_udptcp_cksum_mbuf(const struct > rte_mbuf *m, > uint16_t raw_cksum; > uint32_t cksum; >=20 > - if (l4_off > m->pkt_len) > - return 0; > + if (unlikely(l4_off > m->pkt_len)) > + return 0; /* invalid params, return a dummy value */ >=20 > - 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)) Please fix indentation of this continuation line. > return 0; >=20 > cksum =3D raw_cksum + rte_ipv6_phdr_cksum(ipv6_hdr, 0); > -- > 2.34.1 With indentation fixed, Reviewed-by: Morten Br=F8rup