app/testpmd: perform SW IP checksum for GRO packets

Message ID 20220511013705.24602-1-wenwux.ma@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Andrew Rybchenko
Headers
Series app/testpmd: perform SW IP checksum for GRO packets |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Ma, WenwuX May 11, 2022, 1:37 a.m. UTC
  The GRO library doesn't re-calculate checksums for
merged packets. If users want the merged packets to
have correct IP checksums, they should select HW IP
checksum calculation for the port which the merged
packets are transmitted to. But if the port doesn't
support HW IP checksum, users may perform a SW IP
checksum. This patch add the code about it.

Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
---
 app/test-pmd/csumonly.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Comments

David Marchand May 11, 2022, 7:27 a.m. UTC | #1
On Wed, May 11, 2022 at 3:40 AM Wenwu Ma <wenwux.ma@intel.com> wrote:
>
> The GRO library doesn't re-calculate checksums for
> merged packets. If users want the merged packets to
> have correct IP checksums, they should select HW IP
> checksum calculation for the port which the merged
> packets are transmitted to. But if the port doesn't
> support HW IP checksum, users may perform a SW IP
> checksum. This patch add the code about it.

It looks like a fix, please add a Fixes: line.
Out of curiosity, would there be an issue too when using the gso library?

>
> Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
  
Ma, WenwuX May 11, 2022, 9 a.m. UTC | #2
> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: 2022年5月11日 15:28
> To: Ma, WenwuX <wenwux.ma@intel.com>
> Cc: Li, Xiaoyun <xiaoyun.li@intel.com>; Singh, Aman Deep
> <aman.deep.singh@intel.com>; Zhang, Yuying <yuying.zhang@intel.com>;
> dev <dev@dpdk.org>; Hu, Jiayu <jiayu.hu@intel.com>; Wang, Yinan
> <yinan.wang@intel.com>; He, Xingguang <xingguang.he@intel.com>
> Subject: Re: [PATCH] app/testpmd: perform SW IP checksum for GRO
> packets
> 
> On Wed, May 11, 2022 at 3:40 AM Wenwu Ma <wenwux.ma@intel.com>
> wrote:
> >
> > The GRO library doesn't re-calculate checksums for merged packets. If
> > users want the merged packets to have correct IP checksums, they
> > should select HW IP checksum calculation for the port which the merged
> > packets are transmitted to. But if the port doesn't support HW IP
> > checksum, users may perform a SW IP checksum. This patch add the code
> > about it.
> 
> It looks like a fix, please add a Fixes: line.
ok

> Out of curiosity, would there be an issue too when using the gso library?
> 
yes, gso library has the same issue. IP checksum need  to be re-calculated for fragmented packets

> >
> > Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
> 
> 
> --
> David Marchand
  

Patch

diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c
index 8b6665d6f3..76ce58f6d0 100644
--- a/app/test-pmd/csumonly.c
+++ b/app/test-pmd/csumonly.c
@@ -824,6 +824,7 @@  pkt_burst_checksum_forward(struct fwd_stream *fs)
 	void **gro_ctx;
 	uint16_t gro_pkts_num;
 	uint8_t gro_enable;
+	struct rte_ipv4_hdr *ipv4_hdr;
 #endif
 	uint16_t nb_rx;
 	uint16_t nb_tx;
@@ -1098,6 +1099,17 @@  pkt_burst_checksum_forward(struct fwd_stream *fs)
 				fs->gro_times = 0;
 			}
 		}
+
+		for (i = 0; i < nb_rx; i++) {
+			if ((pkts_burst[i]->ol_flags & RTE_MBUF_F_TX_IPV4) &&
+				(tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
+				ipv4_hdr = rte_pktmbuf_mtod_offset(pkts_burst[i],
+							struct rte_ipv4_hdr *,
+							pkts_burst[i]->l2_len);
+				ipv4_hdr->hdr_checksum = 0;
+				ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
+			}
+		}
 	}
 #endif