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 8B899436CC for ; Tue, 12 Dec 2023 04:01:26 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 80B0A42DC7; Tue, 12 Dec 2023 04:01:26 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 7C905402B9; Tue, 12 Dec 2023 04:01:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702350083; x=1733886083; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Jgtg7DZv0j16I9rSceasxm5ouIl4ufWEqrQuYthBiqU=; b=VHsTks2L30n0llSUwJGu6ipSivCo27XH34jP411r6/oeAab6KucAb8mG XleH6PFF1HJV87IPGEkf0vWxcrvVkVp6Su+q7suLB9C6Vocrq//gnzIjO rHb3mZBj+z5F47KsCX66FALabpjzS2iNupsUilK4sPn6rgkKi0xVqU6wJ NeJzdfNofspk8t1oVd2scc7CwnOzY36dh9pfB61feWlIWPnb/x9UmaSzq 0aejJ8UQF8N5Ltz+0u5Yp3Z+0ym1WDyVS9IiSvpGvXL9k8u1v89PeCAJ1 RZAaAOf/DNNRxPaauRaYGeoPWG+PX8ClkE1RVLSArEK2tifU+B8Dotw74 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="425870258" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="425870258" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 19:01:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10921"; a="946597827" X-IronPort-AV: E=Sophos;i="6.04,269,1695711600"; d="scan'208";a="946597827" Received: from shwdenpg561.ccr.corp.intel.com (HELO dpdk..) ([10.239.252.3]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Dec 2023 19:01:17 -0800 From: Kaiwen Deng To: dev@dpdk.org Cc: stable@dpdk.org, qiming.yang@intel.com, yidingx.zhou@intel.com, Kaiwen Deng , Xiaoyun Li , Aman Singh , Ferruh Yigit Subject: [PATCH v3] lib/net: fix tcp/udp cksum with padding data Date: Tue, 12 Dec 2023 10:16:19 +0800 Message-Id: <20231212021619.2038881-1-kaiwenx.deng@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231207085303.1924630-1-kaiwenx.deng@intel.com> References: <20231207085303.1924630-1-kaiwenx.deng@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 | 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; - 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)) 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; - 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)) return 0; cksum = raw_cksum + rte_ipv6_phdr_cksum(ipv6_hdr, 0); -- 2.34.1