patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH] app/test-pmd: fix L4 checksum with padding data
@ 2023-08-04  8:28 Kaiwen Deng
  2023-11-02 19:20 ` Ferruh Yigit
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Kaiwen Deng @ 2023-08-04  8:28 UTC (permalink / raw)
  To: dev
  Cc: stable, qiming.yang, yidingx.zhou, Kaiwen Deng, Aman Singh,
	Yuying Zhang, Olivier Matz, Pablo de Lara

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 7af635e3f7..58b72b714a 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -853,12 +853,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 */
@@ -980,6 +982,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 +
+					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


^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2024-02-19  1:10 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-04  8:28 [PATCH] app/test-pmd: fix L4 checksum with padding data 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
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

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).