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 4BAAA436EE; Thu, 14 Dec 2023 11:13:15 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 39CA142FCB; Thu, 14 Dec 2023 11:13:15 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mails.dpdk.org (Postfix) with ESMTP id 3608C402E6; Thu, 14 Dec 2023 11:13:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702548793; x=1734084793; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=q/N76S2NYuB3zqarW8L+qzyqYq+c+OFWM9y31cpVbSg=; b=MaUoMwoB7KU90ZAy6ahP+Xl251dEWNVpV+i3na0JgOSQQ0NIP7zB4rju L7zpIQ6iqUfEsaKaXi4NOKasCFSv24bLA5fE0yIPIdlgxj10/EFCufeJe 6oOlxDZu5fau1wCoZWAgz/xTJo7bELUPaT9TA27sx0DDnoc3iIq4UB9Jw G9DK7NjtFO0q0Z3K/F/28BcQnAJxIakAjB1lAD5UViCgO7jTny3PYF/YM qRAs27zka7cufzLPEcF9gGbiXQxaXbrYTlbMJhyEJIXLQK8cEANov8bJv 2shXleaCU2kNtLlHK+NSJKtPkfkmMMBlhkycOHOErB8nK1cEzqMjx5R9Y Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10923"; a="380085049" X-IronPort-AV: E=Sophos;i="6.04,275,1695711600"; d="scan'208";a="380085049" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 02:08:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,275,1695711600"; d="scan'208";a="17712669" Received: from shwdenpg561.ccr.corp.intel.com (HELO dpdk..) ([10.239.252.3]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Dec 2023 02:08:15 -0800 From: Kaiwen Deng To: dev@dpdk.org Cc: stable@dpdk.org, qiming.yang@intel.com, yidingx.zhou@intel.com, Kaiwen Deng , Aman Singh , Ferruh Yigit , Xiaoyun Li Subject: [PATCH v5] lib/net: fix tcp/udp cksum with padding data Date: Thu, 14 Dec 2023 17:22:59 +0800 Message-Id: <20231214092259.2126634-1-kaiwenx.deng@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231213043732.2113867-1-kaiwenx.deng@intel.com> References: <20231213043732.2113867-1-kaiwenx.deng@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- lib/net/rte_ip.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/net/rte_ip.h b/lib/net/rte_ip.h index 6fa98a5a0f..0d103d4127 100644 --- a/lib/net/rte_ip.h +++ b/lib/net/rte_ip.h @@ -419,11 +419,14 @@ __rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, { uint16_t raw_cksum; uint32_t cksum; + uint16_t len; - if (l4_off > m->pkt_len) - return 0; + if (unlikely(l4_off > m->pkt_len)) + return 0; /* invalid params, return a dummy value */ + + 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, m->pkt_len - l4_off, &raw_cksum)) + if (rte_raw_cksum_mbuf(m, l4_off, len, &raw_cksum)) return 0; cksum = raw_cksum + rte_ipv4_phdr_cksum(ipv4_hdr, 0); @@ -663,10 +666,10 @@ __rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m, uint16_t raw_cksum; uint32_t cksum; - 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)) + 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