From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 773F643698;
	Thu,  7 Dec 2023 10:37:28 +0100 (CET)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id EA80742ED1;
	Thu,  7 Dec 2023 10:37:27 +0100 (CET)
Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65])
 by mails.dpdk.org (Postfix) with ESMTP id ABB1542E7A;
 Thu,  7 Dec 2023 10:37:26 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1701941847; x=1733477847;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=etHLzBztMaD+omNEgtDcSVLvQzYh5LDwB8Mn32s64Z8=;
 b=TWr3M+eZRfGHzEs9pxBCy7TbH9d8B8ld+qJCgSvgZPZ0DDBE7teM9MIO
 cN2GVmeByG09z9xH3tS+BjCLt6RX40BY2wzRvOi9vU4vZICmUr8cBcqAP
 mQJQ4sqtP3uLzC6g/rw+Ao/bO6a5P8EeaU5LlXjNEyptM2WC1DczQkDaw
 Pi22eHPd5TfbCy22ml9D8rEo15zJD0v3/3piRlc56wPLi6i3OTPxamTBe
 2O2O4nggpZZUAxTYD/cgFixJ3MA2fB26KMyuwmwp17hvEeHlaV4C9FsHY
 Rx4DPPokxqqHH/h2VwfGjspwGlaraQdKD0+iB3Y1t1Lprm4wT45TPKHHK A==;
X-IronPort-AV: E=McAfee;i="6600,9927,10916"; a="398087750"
X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="398087750"
Received: from orsmga006.jf.intel.com ([10.7.209.51])
 by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 07 Dec 2023 01:37:25 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=McAfee;i="6600,9927,10916"; a="747911698"
X-IronPort-AV: E=Sophos;i="6.04,256,1695711600"; d="scan'208";a="747911698"
Received: from shwdenpg561.ccr.corp.intel.com (HELO dpdk..) ([10.239.252.3])
 by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 07 Dec 2023 01:37:22 -0800
From: Kaiwen Deng <kaiwenx.deng@intel.com>
To: dev@dpdk.org
Cc: stable@dpdk.org, qiming.yang@intel.com, yidingx.zhou@intel.com,
 Kaiwen Deng <kaiwenx.deng@intel.com>,
 Aman Singh <aman.deep.singh@intel.com>,
 Yuying Zhang <yuying.zhang@intel.com>,
 Olivier Matz <olivier.matz@6wind.com>,
 Pablo de Lara <pablo.de.lara.guarch@intel.com>
Subject: [PATCH v2] app/test-pmd: fix tcp/udp cksum with padding data
Date: Thu,  7 Dec 2023 16:53:03 +0800
Message-Id: <20231207085303.1924630-1-kaiwenx.deng@intel.com>
X-Mailer: git-send-email 2.34.1
In-Reply-To: <20230804082849.533059-1-kaiwenx.deng@intel.com>
References: <20230804082849.533059-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 <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=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. Testpmd does not trim these IP packets to the true
length of the frame, so errors will occur when calculating TCP
or UDP checksum.

This commit fixes this issue by triming IP packets to the true
length of the frame in testpmd.

Fixes: 03d17e4d0179 ("app/testpmd: do not change IP addrs in checksum engine")
Cc: stable@dpdk.org

Signed-off-by: Kaiwen Deng <kaiwenx.deng@intel.com>
---
 app/test-pmd/csumonly.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 21210aff43..f7c8af96d7 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -860,12 +860,14 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	uint16_t nb_rx;
 	uint16_t nb_prep;
 	uint16_t i;
+	uint16_t pad_len;
 	uint64_t rx_ol_flags, tx_ol_flags;
 	uint64_t tx_offloads;
 	uint32_t rx_bad_ip_csum;
 	uint32_t rx_bad_l4_csum;
 	uint32_t rx_bad_outer_l4_csum;
 	uint32_t rx_bad_outer_ip_csum;
+	uint32_t l3_off;
 	struct testpmd_offload_info info;
 
 	/* receive a burst of packet */
@@ -987,6 +989,36 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 			l3_hdr = (char *)l3_hdr + info.outer_l3_len + info.l2_len;
 		}
 
+		if (info.is_tunnel) {
+			l3_off = info.outer_l2_len +
+					info.outer_l3_len +
+					info.l2_len;
+		} else {
+			l3_off = info.l2_len;
+		}
+		switch (info.ethertype) {
+		case _htons(RTE_ETHER_TYPE_IPV4):
+			pad_len = rte_pktmbuf_data_len(m) -
+					(l3_off +
+					rte_be_to_cpu_16(
+					((struct rte_ipv4_hdr *)l3_hdr)->total_length));
+			break;
+		case _htons(RTE_ETHER_TYPE_IPV6):
+			pad_len = rte_pktmbuf_data_len(m) -
+					(l3_off + info.l3_len +
+					rte_be_to_cpu_16(
+					((struct rte_ipv6_hdr *)l3_hdr)->payload_len));
+			break;
+		default:
+			pad_len = 0;
+			break;
+		}
+
+		if (pad_len) {
+			rte_pktmbuf_data_len(m) = rte_pktmbuf_data_len(m) - pad_len;
+			rte_pktmbuf_pkt_len(m) = rte_pktmbuf_data_len(m);
+		}
+
 		/* step 2: depending on user command line configuration,
 		 * recompute checksum either in software or flag the
 		 * mbuf to offload the calculation to the NIC. If TSO
-- 
2.34.1