app/test-pmd: fix L4 checksum with padding data
PATCH 1/1 app/test-pmd: fix L4 checksum with padding data
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.
--- app/test-pmd/csumonly.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
app/test-pmd/csumonly.c +32 -0
@@ -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
Signature · 1 line
2.34.1
Quoted 6 lines · Kaiwen Deng
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.
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Are the received mbuf data_len & pkt_len wrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?
Quoted 67 lines
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")Signed-off-by Kaiwen Deng <[email protected]>--- app/test-pmd/csumonly.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)app/test-pmd/csumonly.c +32
-0@@ -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
Quoted 20 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 3, 2023 3:20 AM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 5 lines · Kaiwen Deng
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.
Quoted 8 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?
Hi Ferruh,
In effect, the packet is padded by the switch.
IEEE 802 packets may have a minimum size limit. The data fields should be padded by switch when necessary. In some switches, the padding data is not zero.
Csumonly doesn't trim these packets to the true length of the frame.
In csumonly, the received mbuf data_len is the true length of the packet plus the padding data len. Therefore, padding data is included in the checksum calculation.
When the padding data is not zero, the checksum is wrong.
Quoted 74 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct
Quoted 17 lines
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 checksumengine")
Cc: [email protected]Signed-off-by Kaiwen Deng <[email protected]>--- app/test-pmd/csumonly.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)app/test-pmd/csumonly.c index renamed from app/test-pmd/csumonly.c +0
-0
7af635e3f7..58b72b714a100644app/test-pmd/csumonly.c +0
-0@@ -853,12 +853,14 @@ pkt_burst_checksum_forward(struct
fwd_stream*fs)app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream
Quoted 15 lines
app/test-pmd/csumonly.c +2
-0uint16_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)
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream · line 982
Quoted 1 line
app/test-pmd/csumonly.c +0
-0l3_hdr = (char *)l3_hdr + info.outer_l3_len +info.l2_len;
Quoted 21 lines
app/test-pmd/csumonly.c +18
-0} + 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(app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 10 lines
app/test-pmd/csumonly.c +9
-0+ ((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;Quoted 6 lines
app/test-pmd/csumonly.c +3
-0+rte_pktmbuf_pkt_len (m) =rte_pktmbuf_data_len (m); + } +/* step 2: depending on user command line configuration, app/test-pmd/csumonly.c +0
-0* recompute checksum either in software or flag the * mbuf to offload the calculation to the NIC. If TSO
Quoted 30 lines · KaiwenX
Quoted 20 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 3, 2023 3:20 AM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 5 lines · Kaiwen Deng
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.
Quoted 8 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?Hi Ferruh,
Quoted 9 lines
In effect, the packet is padded by the switch.
IEEE 802 packets may have a minimum size limit. The data fields should be padded by switch when necessary. In some switches, the padding data is not zero.Csumonly doesn't trim these packets to the true length of the frame.
In csumonly, the received mbufdata_lenis the true length of the packet plus the padding data len. Therefore, padding data is included in the checksum calculation.
When the padding data is not zero, the checksum is wrong.
Thanks for clarification.
Even some non-zero padding added, it will calculate the csum successfully, but I assume in this case csum becomes different than expected csum and test fails?
In this case why not fix the generated packets, and make them compatible to minimum size requirement? What is generating packets?
Quoted 75 lines
Quoted 74 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct
Quoted 17 lines
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 checksumengine")
Cc: [email protected]Signed-off-by Kaiwen Deng <[email protected]>--- app/test-pmd/csumonly.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)app/test-pmd/csumonly.c index renamed from app/test-pmd/csumonly.c +0
-0
7af635e3f7..58b72b714a100644app/test-pmd/csumonly.c +0
-0@@ -853,12 +853,14 @@ pkt_burst_checksum_forward(struct
fwd_stream*fs)app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream
Quoted 15 lines
app/test-pmd/csumonly.c +2
-0uint16_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)
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream · line 982
Quoted 1 line
app/test-pmd/csumonly.c +0
-0l3_hdr = (char *)l3_hdr + info.outer_l3_len +info.l2_len;
Quoted 21 lines
app/test-pmd/csumonly.c +18
-0} + 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(app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 10 lines
app/test-pmd/csumonly.c +9
-0+ ((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;Quoted 6 lines
app/test-pmd/csumonly.c +3
-0+rte_pktmbuf_pkt_len (m) =rte_pktmbuf_data_len (m); + } +/* step 2: depending on user command line configuration, app/test-pmd/csumonly.c +0
-0* recompute checksum either in software or flag the * mbuf to offload the calculation to the NIC. If TSO
Quoted 45 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 3, 2023 12:03 PM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 13 lines · KaiwenX
Quoted 13 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 3, 2023 3:20 AM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 3 lines
Quoted 3 lines · Kaiwen Deng
Quoted 2 lines
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.
Quoted 14 lines
Quoted 4 lines
Quoted 3 lines
Testpmd does not trim these IP packets to the true length of the frame, so errors will occur when calculating TCP or UDP checksum.
Quoted 8 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?Hi Ferruh,
Quoted 11 lines
Quoted 3 lines
In effect, the packet is padded by the switch.
IEEE 802 packets may have a minimum size limit. The data fields should be padded by switch when necessary. In some switches, the padding data isnot zero.
Quoted 3 lines
Csumonly doesn't trim these packets to the true length of the frame. In csumonly, the received mbuf
data_lenis the true length of the packet plusthe padding data len.
Quoted 3 lines
Therefore, padding data is included in the checksum calculation. When the padding data is not zero, the checksum is wrong.
Hi,
Sorry for late reply.
The minimum frame length specified by IEEE 802.3 is 64 bytes. In practice, there are many packets less than 64 bytes that are padding through the switch.
We found this issue because some customers found that their packets could not calculate checksum correctly, they would send some packets less than 64 bytes, but our app didn't strip the padding data for such packets.
Quoted 89 lines
Thanks for clarification.
Even some non-zero padding added, it will calculate the csum successfully, but I assume in this case csum becomes different than expected csum and test fails?
In this case why not fix the generated packets, and make them compatible to minimum size requirement? What is generating packets?
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
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 inchecksum
engine")
Cc: [email protected]Signed-off-by Kaiwen Deng <[email protected]>--- app/test-pmd/csumonly.c | 32++++++++++++++++++++++++++++++++
Quoted 21 lines
Quoted 21 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct
Quoted 7 lines
1 file changed, 32 insertions(+)app/test-pmd/csumonly.c index renamed from app/test-pmd/csumonly.c +0
-0
7af635e3f7..58b72b714a100644app/test-pmd/csumonly.c +0
-0@@ -853,12 +853,14 @@ pkt_burst_checksum_forward(struct
fwd_stream*fs)Quoted 13 lines
app/test-pmd/csumonly.c +2
-0uint16_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;Quoted 2 lines
Quoted 2 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct
Quoted 2 lines
app/test-pmd/csumonly.c +0
-0/* receive a burst of packet */ @@ -980,6 +982,36 @@ pkt_burst_checksum_forward(struct
fwd_streamQuoted 42 lines
Quoted 41 lines
*fs)
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct · line 982
Quoted 1 line
app/test-pmd/csumonly.c +0
-0l3_hdr = (char *)l3_hdr + info.outer_l3_len +info.l2_len;
Quoted 21 lines
app/test-pmd/csumonly.c +18
-0} + 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(app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 10 lines
app/test-pmd/csumonly.c +9
-0+ ((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;Quoted 6 lines
app/test-pmd/csumonly.c +3
-0+rte_pktmbuf_pkt_len (m) =rte_pktmbuf_data_len (m); + } +/* step 2: depending on user command line configuration, app/test-pmd/csumonly.c +0
-0* recompute checksum either in software or flag the * mbuf to offload the calculation to the NIC. If TSO
Quoted 56 lines · KaiwenX
Quoted 45 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 3, 2023 12:03 PM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 13 lines · KaiwenX
Quoted 13 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 3, 2023 3:20 AM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 3 lines
Quoted 3 lines · Kaiwen Deng
Quoted 2 lines
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.
Quoted 14 lines
Quoted 4 lines
Quoted 3 lines
Testpmd does not trim these IP packets to the true length of the frame, so errors will occur when calculating TCP or UDP checksum.
Quoted 8 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?Hi Ferruh,
Quoted 11 lines
Quoted 3 lines
In effect, the packet is padded by the switch.
IEEE 802 packets may have a minimum size limit. The data fields should be padded by switch when necessary. In some switches, the padding data isnot zero.
Quoted 3 lines
Csumonly doesn't trim these packets to the true length of the frame. In csumonly, the received mbuf
data_lenis the true length of the packet plusthe padding data len.
Quoted 3 lines
Therefore, padding data is included in the checksum calculation. When the padding data is not zero, the checksum is wrong.
Quoted 9 lines
Hi,
Sorry for late reply.
The minimum frame length specified by IEEE 802.3 is 64 bytes. In practice, there are many packets less than 64 bytes that are padding through the switch.We found this issue because some customers found that their packets could not calculate checksum correctly, they would send some packets less than 64 bytes, but our app didn't strip the padding data for such packets.
OK, so switch in between is padding packets to make them compatible with standard.
From DPDK application perspective received packet is 64 bytes, right? Problem happens because where verifies the checksum gets different checksum that expected, but this is because packet is modified in between by the networking setup.
I am not sure about trying to fix this in the testpmd.
Why not send packets that are >= 64 bytes from sender side, or configure switch to not add padding or maybe use different switch?
Quoted 90 lines
Quoted 89 lines
Thanks for clarification.
Even some non-zero padding added, it will calculate the csum successfully, but I assume in this case csum becomes different than expected csum and test fails?
In this case why not fix the generated packets, and make them compatible to minimum size requirement? What is generating packets?
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
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 inchecksum
engine")
Cc: [email protected]Signed-off-by Kaiwen Deng <[email protected]>--- app/test-pmd/csumonly.c | 32++++++++++++++++++++++++++++++++
Quoted 21 lines
Quoted 21 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct
Quoted 7 lines
1 file changed, 32 insertions(+)app/test-pmd/csumonly.c index renamed from app/test-pmd/csumonly.c +0
-0
7af635e3f7..58b72b714a100644app/test-pmd/csumonly.c +0
-0@@ -853,12 +853,14 @@ pkt_burst_checksum_forward(struct
fwd_stream*fs)Quoted 13 lines
app/test-pmd/csumonly.c +2
-0uint16_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;Quoted 2 lines
Quoted 2 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct
Quoted 2 lines
app/test-pmd/csumonly.c +0
-0/* receive a burst of packet */ @@ -980,6 +982,36 @@ pkt_burst_checksum_forward(struct
fwd_streamQuoted 42 lines
Quoted 41 lines
*fs)
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct · line 982
Quoted 1 line
app/test-pmd/csumonly.c +0
-0l3_hdr = (char *)l3_hdr + info.outer_l3_len +info.l2_len;
Quoted 21 lines
app/test-pmd/csumonly.c +18
-0} + 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(app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 10 lines
app/test-pmd/csumonly.c +9
-0+ ((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;Quoted 6 lines
app/test-pmd/csumonly.c +3
-0+rte_pktmbuf_pkt_len (m) =rte_pktmbuf_data_len (m); + } +/* step 2: depending on user command line configuration, app/test-pmd/csumonly.c +0
-0* recompute checksum either in software or flag the * mbuf to offload the calculation to the NIC. If TSO
Quoted 89 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Wednesday, November 15, 2023 3:10 AM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 56 lines · KaiwenX
Quoted 56 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 3, 2023 12:03 PM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 14 lines · KaiwenX
Quoted 14 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 3, 2023 3:20 AM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 4 lines
Quoted 4 lines · Kaiwen Deng
Quoted 3 lines
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.
Quoted 12 lines
Quoted 4 lines
Quoted 3 lines
Testpmd does not trim these IP packets to the true length of the frame, so errors will occur when calculating TCP or UDP checksum.
Quoted 8 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?Quoted 6 lines
Hi Ferruh,
In effect, the packet is padded by the switch.
IEEE 802 packets may have a minimum size limit. The data fields should be padded by switch when necessary. In some switches, the padding data isnot zero.
Quoted 4 lines
Csumonly doesn't trim these packets to the true length of the frame. In csumonly, the received mbuf
data_lenis the true length of the packet plusQuoted 8 lines
Quoted 4 lines
the padding data len.
Quoted 3 lines
Therefore, padding data is included in the checksum calculation. When the padding data is not zero, the checksum is wrong.
Hi,
Sorry for late reply.
The minimum frame length specified by IEEE 802.3 is 64 bytes. In practice, there are many packets less than 64 bytes that are padding throughthe switch.
Quoted 4 lines
We found this issue because some customers found that their packets could not calculate checksum correctly, they would send some packets less than 64 bytes, but our app didn't strip the padding data for such
packets.
Quoted 1 line
OK, so switch in between is padding packets to make them compatible with standard.
Quoted 9 lines
From DPDK application perspective received packet is 64 bytes, right? Problem happens because where verifies the checksum gets different checksum that expected, but this is because packet is modified in between by the networking setup.
I am not sure about trying to fix this in the testpmd.Why not send packets that are >= 64 bytes from sender side, or configure switch to not add padding or maybe use different switch?
If we send a 40 bytes UDP packet, it will be padded to 64 bytes as it passes through the switch, whereas the Linux kernel stack strips out the padding data as it receives the packet.
I think maybe DPDK applications should be aligned with the Linux kernel. Otherwise the csumonly application only supports packets above 64 bytes.
Quoted 91 lines
Quoted 91 lines
Quoted 90 lines
Thanks for clarification.
Even some non-zero padding added, it will calculate the csum successfully, but I assume in this case csum becomes different than expected csum and test fails?
In this case why not fix the generated packets, and make them compatible to minimum size requirement? What is generating packets?
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
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 inchecksum
engine")
Cc: [email protected]Signed-off-by Kaiwen Deng <[email protected]>--- app/test-pmd/csumonly.c | 32++++++++++++++++++++++++++++++++
Quoted 21 lines
Quoted 21 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct
Quoted 7 lines
1 file changed, 32 insertions(+)app/test-pmd/csumonly.c +0
-0@@ -853,12 +853,14 @@ pkt_burst_checksum_forward(struct
fwd_stream*fs)Quoted 13 lines
app/test-pmd/csumonly.c +2
-0uint16_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;Quoted 2 lines
Quoted 2 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct
Quoted 2 lines
app/test-pmd/csumonly.c +0
-0/* receive a burst of packet */ @@ -980,6 +982,36 @@ pkt_burst_checksum_forward(struct
fwd_streamQuoted 42 lines
Quoted 41 lines
*fs)
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct · line 982
Quoted 1 line
app/test-pmd/csumonly.c +0
-0l3_hdr = (char *)l3_hdr + info.outer_l3_len +info.l2_len;
Quoted 21 lines
app/test-pmd/csumonly.c +18
-0} + 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(app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 10 lines
app/test-pmd/csumonly.c +9
-0+ ((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;Quoted 6 lines
app/test-pmd/csumonly.c +3
-0+rte_pktmbuf_pkt_len (m) =rte_pktmbuf_data_len (m); + } +/* step 2: depending on user command line configuration, app/test-pmd/csumonly.c +0
-0* recompute checksum either in software or flag the * mbuf to offload the calculation to the NIC. If TSO
Quoted 8 lines · On Thu, 2 Nov 2023 19:20:07 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines · Kaiwen Deng
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.
Quoted 7 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?
The root cause is that get_udptcp_cksum_mbuf is using m->pkt_len which maybe larger than the actual data. The real issue is there and in rte_ip.h checksum code. The correct fix would be to use l3_len instead.
It also looks like test-pmd is not validating the IP header. Both parse_ipv4() and parse_ipv6() should check if packet was truncated. Same for both UDP and TCP lengths.
Quoted 16 lines · Stephen Hemminger
Quoted 13 lines · On Thu, 2 Nov 2023 19:20:07 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines · Kaiwen Deng
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.
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Quoted 7 lines
Quoted 2 lines
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?The root cause is that
get_udptcp_cksum_mbufis usingm->pkt_lenwhich maybe larger than the actual data. The real issue is there and inrte_ip.hchecksum code. The correct fix would be to usel3_leninstead.
I see, you are right.
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.
I agree using 'l3_len' instead is correct fix.
But this requires ABI/API change,
plus do we have any reason to keep the padding, discarding it as this patch does is also simpler alternative.
Other alternative can be to zero the padding bytes. I guess standard doesn't enforce them to be zero, but we can do this to remove its impact on checksum calculation.
@Kaiwen, did you able to test this with HW offload, what is the behavior of the HW, does is remove padding bytes?
Quoted 4 lines
It also looks like test-pmd is not validating the IP header. Both
parse_ipv4()andparse_ipv6()should check if packet was truncated. Same for both UDP and TCP lengths.
Quoted 20 lines · On Fri, 17 Nov 2023 00:50:16 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 5 lines
Quoted 5 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Quoted 7 lines
Quoted 2 lines
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?The root cause is that
get_udptcp_cksum_mbufis usingm->pkt_lenwhich maybe larger than the actual data. The real issue is there and inrte_ip.hchecksum code. The correct fix would be to usel3_leninstead.I see, you are right.
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.
Quoted 5 lines
I agree using '
l3_len' instead is correct fix.But this requires ABI/API change,
plus do we have any reason to keep the padding, discarding it as this patch does is also simpler alternative.
Possibly an API version to change the args would work to fix.
Quoted 23 lines · Stephen Hemminger
Quoted 20 lines · On Fri, 17 Nov 2023 00:50:16 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 5 lines
Quoted 5 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Quoted 7 lines
Quoted 2 lines
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?The root cause is that
get_udptcp_cksum_mbufis usingm->pkt_lenwhich maybe larger than the actual data. The real issue is there and inrte_ip.hchecksum code. The correct fix would be to usel3_leninstead.I see, you are right.
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.
Quoted 9 lines
Quoted 5 lines
I agree using '
l3_len' instead is correct fix.But this requires ABI/API change,
plus do we have any reason to keep the padding, discarding it as this patch does is also simpler alternative.Possibly an API version to change the args would work to fix.
rte_ipv4_udptcp_cksum_mbuf() and rte_ipv6_udptcp_cksum_mbuf() are inline functions, unfortunately we can't version them.
But those functions already gets IP header as parameter, can't we use IP header to get the payload size? If so this can be fixed without updating API.
Quoted 47 lines
From: Ferruh Yigit [mailto:[email protected]]
Sent: Friday, 17 November 2023 10.30Quoted 6 lines · Stephen Hemminger
Quoted 3 lines · On Fri, 17 Nov 2023 00:50:16 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that
has
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
checksum error?
Are the received mbuf
data_len&pkt_lenwrong? Instead of tryingto fix
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
the mbuf during forwarding, can we fix where packet generated?
The root cause is that
get_udptcp_cksum_mbufis usingm->pkt_lenwhich maybe larger than the actual data. The real issue is thereand
Quoted 1 line
Quoted 1 line
Quoted 1 line
in
rte_ip.hchecksum code. The correct fix would be to usel3_leninstead.
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
I see, you are right.
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 wrongchecksum.
Quoted 6 lines
Quoted 6 lines
I agree using '
l3_len' instead is correct fix.But this requires ABI/API change,
plus do we have any reason to keep the padding, discarding it asthis
Quoted 5 lines
Quoted 1 line
patch does is also simpler alternative.
Possibly an API version to change the args would work to fix.
rte_ipv4_udptcp_cksum_mbuf()andrte_ipv6_udptcp_cksum_mbuf()are inline
functions, unfortunately we can't version them.
Quoted 5 lines
But those functions already gets IP header as parameter, can't we use IP
header to get the payload size? If so this can be fixed without updating
API.
If rte_ipv4_udptcp_cksum_mbuf() - or any other function in the DPDK Network Headers library - includes Ethernet padding (which may be non-zero) when calculating the TCP/UDP checksum of an IPv4 packet, it is a bug, and must be fixed there.
Our test cases should use random padding to catch bugs like this.
And I just realized that Ethernet padding may be added to any IP packet, so don't assume that this bug only applies to small packets.
Quoted 10 lines · On Fri, 17 Nov 2023 13:11:50 +0100 Morten Brørup <[email protected]>…
Quoted 9 lines
rte_ipv4_udptcp_cksum_mbuf()andrte_ipv6_udptcp_cksum_mbuf()are inline
functions, unfortunately we can't version them.But those functions already gets IP header as parameter, can't we use IP
header to get the payload size? If so this can be fixed without updating
API.
Quoted 5 lines
If
rte_ipv4_udptcp_cksum_mbuf()- or any other function in the DPDK Network Headers library - includes Ethernet padding (which may be non-zero) when calculating the TCP/UDP checksum of an IPv4 packet, it is a bug, and must be fixed there.Our test cases should use random padding to catch bugs like this.
And I just realized that Ethernet padding may be added to any IP packet, so don't assume that this bug only applies to small packets.
Agree. And test code needs lots more header checks it is way too trusting that mbuf is valid.
Quoted 10 lines · On Fri, 17 Nov 2023 09:29:41 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 9 lines
Quoted 5 lines
I agree using '
l3_len' instead is correct fix.But this requires ABI/API change,
plus do we have any reason to keep the padding, discarding it as this patch does is also simpler alternative.Possibly an API version to change the args would work to fix.
Quoted 6 lines
rte_ipv4_udptcp_cksum_mbuf()andrte_ipv6_udptcp_cksum_mbuf()are inline functions, unfortunately we can't version them.But those functions already gets IP header as parameter, can't we use IP header to get the payload size? If so this can be fixed without updating API.
Inlines are easier. Just make a fixed new function and make sure the old one is not used. They shouldn't have been inline in the first place.
Quoted 16 lines · Stephen Hemminger
Quoted 13 lines · On Fri, 17 Nov 2023 09:29:41 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 9 lines
Quoted 5 lines
I agree using '
l3_len' instead is correct fix.But this requires ABI/API change,
plus do we have any reason to keep the padding, discarding it as this patch does is also simpler alternative.Possibly an API version to change the args would work to fix.
rte_ipv4_udptcp_cksum_mbuf()andrte_ipv6_udptcp_cksum_mbuf()are inline functions, unfortunately we can't version them.
Quoted 7 lines
Quoted 3 lines
But those functions already gets IP header as parameter, can't we use IP header to get the payload size? If so this can be fixed without updating API.
Inlines are easier. Just make a fixed new function and make sure the old one is not used. They shouldn't have been inline in the first place.
I guess inlines as because of performance concerns, since it is in datapath.
Quoted 48 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 17, 2023 8:50 AM
To: Stephen Hemminger <[email protected]>
Cc: Deng, KaiwenX <[email protected]>; [email protected]; [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 16 lines · Stephen Hemminger
Quoted 13 lines · On Thu, 2 Nov 2023 19:20:07 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines · Kaiwen Deng
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.
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Quoted 7 lines
Quoted 2 lines
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?The root cause is that
get_udptcp_cksum_mbufis usingm->pkt_lenwhich maybe larger than the actual data. The real issue is there and inrte_ip.hchecksum code. The correct fix would be to usel3_leninstead.I see, you are right.
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.I agree using '
l3_len' instead is correct fix.
Quoted 8 lines
But this requires ABI/API change,
plus do we have any reason to keep the padding, discarding it as this patch does is also simpler alternative.Other alternative can be to zero the padding bytes. I guess standard doesn't enforce them to be zero, but we can do this to remove its impact on checksum calculation.
I'm not sure if this is ok, it feels like it would reduce performance. I can try this alternative if needed.
Quoted 5 lines
@Kaiwen, did you able to test this with HW offload, what is the behavior of the HW, does is remove padding bytes?
I tested the HW offload case and the same tcp/udp checksum error occurs when padding is not 0, But if change pkt_len to the true length of the frame, the checksum is correct.
Quoted 6 lines
Quoted 5 lines
It also looks like test-pmd is not validating the IP header. Both
parse_ipv4()andparse_ipv6()should check if packet was truncated. Same for both UDP and TCP lengths.
Quoted 53 lines · KaiwenX
Quoted 53 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 17, 2023 8:50 AM
To: Stephen Hemminger <[email protected]>
Cc: Deng, KaiwenX <[email protected]>; [email protected]; [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 16 lines · Stephen Hemminger
Quoted 13 lines · On Thu, 2 Nov 2023 19:20:07 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines · Kaiwen Deng
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.
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Quoted 7 lines
Quoted 2 lines
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?The root cause is that
get_udptcp_cksum_mbufis usingm->pkt_lenwhich maybe larger than the actual data. The real issue is there and inrte_ip.hchecksum code. The correct fix would be to usel3_leninstead.I see, you are right.
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.I agree using '
l3_len' instead is correct fix.But this requires ABI/API change,
plus do we have any reason to keep the padding, discarding it as this patch does is also simpler alternative.
Quoted 6 lines
Quoted 3 lines
Other alternative can be to zero the padding bytes. I guess standard doesn't enforce them to be zero, but we can do this to remove its impact on checksum calculation.
I'm not sure if this is ok, it feels like it would reduce performance. I can try this alternative if needed.
Yes impacts performance, so not a good alternative, please scratch it.
As discussion with Stephen and Morten, consensus is to fix SW functions that calculates checksum.
'rte_ipv4_udptcp_cksum_mbuf()' & 'rte_ipv6_udptcp_cksum_mbuf()'.
Instead of using packet_len, those functions can use packet length, which will make the checksum correct.
Can you please send a patch to fix those functions? I think this can be done without changing function fingerprint, so without causing any ABI/API break.
Quoted 8 lines
Quoted 5 lines
@Kaiwen, did you able to test this with HW offload, what is the behavior of the HW, does is remove padding bytes?
I tested the HW offload case and the same tcp/udp checksum error occurs when padding is not 0, But if change
pkt_lento the true length of the frame, the checksum is correct.
I was expecting HW not impacted, since padding is part of the spec, my assumption would be HW only take the actual payload size into account, instead of buffer size.
Can you please double check? Which HW you are testing with, can you please add maintainer of that HW to this discussion?
If HW requires padding to be removed, we may go with your solution.
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
It also looks like test-pmd is not validating the IP header. Both
parse_ipv4()andparse_ipv6()should check if packet was truncated. Same for both UDP and TCP lengths.
Quoted 101 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Monday, November 20, 2023 6:46 PM
To: Deng, KaiwenX <[email protected]>; Stephen Hemminger <[email protected]>; Morten Brørup <[email protected]>
Cc: [email protected]; [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 39 lines · KaiwenX
Quoted 39 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 17, 2023 8:50 AM
To: Stephen Hemminger <[email protected]>
Cc: Deng, KaiwenX <[email protected]>; [email protected]; [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataQuoted 23 lines · Stephen Hemminger
Quoted 8 lines · On Thu, 2 Nov 2023 19:20:07 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 6 lines · Kaiwen Deng
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.
Quoted 7 lines
Hi Kaiwen,
I am trying to understand the problem, what is the testcase that has checksum error?
Are the received mbuf
data_len&pkt_lenwrong? Instead of trying to fix the mbuf during forwarding, can we fix where packet generated?The root cause is that
get_udptcp_cksum_mbufis usingm->pkt_lenwhich maybe larger than the actual data. The real issue is there and inrte_ip.hchecksum code. The correct fix would be to usel3_leninstead.Quoted 5 lines
Quoted 5 lines
I see, you are right.
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 wrongchecksum.
Quoted 9 lines
Quoted 9 lines
I agree using '
l3_len' instead is correct fix.But this requires ABI/API change,
plus do we have any reason to keep the padding, discarding it as this patch does is also simpler alternative.Quoted 6 lines
Quoted 3 lines
Other alternative can be to zero the padding bytes. I guess standard doesn't enforce them to be zero, but we can do this to remove its impact on checksum calculation.
I'm not sure if this is ok, it feels like it would reduce performance. I can try this alternative if needed.
Yes impacts performance, so not a good alternative, please scratch it.
As discussion with Stephen and Morten, consensus is to fix SW functions that calculates checksum.
'rte_ipv4_udptcp_cksum_mbuf()' & 'rte_ipv6_udptcp_cksum_mbuf()'.Instead of using
packet_len, those functions can use packet length, which will make the checksum correct.Can you please send a patch to fix those functions? I think this can be done without changing function fingerprint, so without causing any ABI/API break.
Quoted 7 lines
Quoted 5 lines
@Kaiwen, did you able to test this with HW offload, what is the behavior of the HW, does is remove padding bytes?
I tested the HW offload case and the same tcp/udp checksum error occurs when padding is not 0, But if change
pkt_lento the true length of theframe, the checksum is correct.
Quoted 1 line
Quoted 6 lines
I was expecting HW not impacted, since padding is part of the spec, my assumption would be HW only take the actual payload size into account, instead of buffer size.
Can you please double check? Which HW you are testing with, can you please add maintainer of that HW to this discussion?
I've tested hw offloads for udp and tcp with Intel E810. The hardware takes the size
of the buffer into account when calculating the udp/tcp checksum, not the size of the
actual payload.
Hi @Zhang, Qi Z,
Can you help confirm if this behavior is normal in hw?
Thanks!
Quoted 11 lines
If HW requires padding to be removed, we may go with your solution.
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
It also looks like test-pmd is not validating the IP header. Both
parse_ipv4()andparse_ipv6()should check if packet was truncated. Same for both UDP and TCP lengths.
Quoted 37 lines · Kaiwen Deng
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")Signed-off-by Kaiwen Deng <[email protected]>--- app/test-pmd/csumonly.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)app/test-pmd/csumonly.c +2
-0@@ -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 */
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs) · line 989
Quoted 8 lines
app/test-pmd/csumonly.c +4
-0@@ -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;
I don't know much about tunnel code but is above calculation correct for all tunnel protocols, like for the case inner packet over UDP, should outer l4_len also added etc...
Quoted 6 lines
app/test-pmd/csumonly.c +6
-0+ }else { + l3_off = info.l2_len; + } +switch (info.ethertype) { +case _htons (RTE_ETHER_TYPE_IPV4 ): + pad_len = rte_pktmbuf_data_len(m) -
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 10 lines
app/test-pmd/csumonly.c +9
-0+ (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));
As far as I remember ipv6 payload_len doesn't contain the header length, so pad_len calculation should be different than ipv4 one, like "l4_off + l3_hdr->payload_len", did you verify this code with ipv6?
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 10 lines
app/test-pmd/csumonly.c +9
-0+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);
Can't received mbuf be multi-segment mbuf, as far as I can see checksum calculation API takes this possibility into account. If so need to check that possibility here before updating 'pkt_len'
Quoted 57 lines
-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Friday, November 17, 2023 9:14 AM
To: Deng, KaiwenX <[email protected]>; [email protected]
Cc: [email protected]; Yang, Qiming <[email protected]>; Zhou, YidingX <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; Matz, Olivier <[email protected]>; De Lara Guarch, Pablo <[email protected]>
Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding dataapp/test-pmd/csumonly.c pkt_burst_checksum_forward(struct
Quoted 22 lines · Kaiwen Deng
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 checksumengine")
Cc: [email protected]Signed-off-by Kaiwen Deng <[email protected]>--- app/test-pmd/csumonly.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)app/test-pmd/csumonly.c index renamed from app/test-pmd/csumonly.c +0
-0
7af635e3f7..58b72b714a100644app/test-pmd/csumonly.c +0
-0@@ -853,12 +853,14 @@ pkt_burst_checksum_forward(struct
fwd_stream*fs)app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream
Quoted 15 lines
app/test-pmd/csumonly.c +2
-0uint16_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)
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream · line 982
Quoted 1 line
app/test-pmd/csumonly.c +0
-0l3_hdr = (char *)l3_hdr + info.outer_l3_len +info.l2_len;
Quoted 2 lines
app/test-pmd/csumonly.c +0
-0}
Quoted 9 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 5 lines
app/test-pmd/csumonly.c +4
-0+if (info.is_tunnel) { + l3_off = info.outer_l2_len + + info.outer_l3_len + + info.l2_len;I don't know much about tunnel code but is above calculation correct for all tunnel protocols, like for the case inner packet over UDP, should outer
l4_lenalso added etc...
According to the comments, these tunnel packets are supported.
* (1) Supported packets are:
* Ether / (vlan) / IP|IP6 / UDP|TCP|SCTP .
* Ether / (vlan) / outer IP|IP6 / outer UDP / VxLAN / Ether / IP|IP6 /
* UDP|TCP|SCTP
* Ether / (vlan) / outer IP|IP6 / outer UDP / VXLAN-GPE / Ether / IP|IP6 /
* UDP|TCP|SCTP
* Ether / (vlan) / outer IP|IP6 / outer UDP / VXLAN-GPE / IP|IP6 /
* UDP|TCP|SCTP
* Ether / (vlan) / outer IP / outer UDP / GTP / IP|IP6 / UDP|TCP|SCTP * Ether / (vlan) / outer IP|IP6 / GRE / Ether / IP|IP6 / UDP|TCP|SCTP * Ether / (vlan) / outer IP|IP6 / GRE / IP|IP6 / UDP|TCP|SCTP * Ether / (vlan) / outer IP|IP6 / IP|IP6 / UDP|TCP|SCTP
Quoted 15 lines
Quoted 15 lines
app/test-pmd/csumonly.c +12
-0+ }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) -
Quoted 9 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 5 lines
app/test-pmd/csumonly.c +3
-0+ (l3_off + +rte_be_to_cpu_16 ( + ((struct rte_ipv6_hdr *)l3_hdr)- payload_len));As far as I remember ipv6
payload_lendoesn't contain the header length, sopad_lencalculation should be different than ipv4 one, like "l4_off+ l3_hdr-Quoted 1 line
payload_len", did you verify this code with ipv6?
You're right, I didn't notice that and didn't test it adequately. I'll fix that.
Quoted 11 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs)
Quoted 10 lines
app/test-pmd/csumonly.c +8
-0+break ; +default : + pad_len =0 ; +break ; + } + +if (pad_len) { + rte_pktmbuf_data_len(m) =
rte_pktmbuf_data_len(m)-pad_len;
Quoted 6 lines
app/test-pmd/csumonly.c pkt_burst_checksum_forward(struct fwd_stream *fs) · line 1012
Quoted 2 lines
app/test-pmd/csumonly.c +1
-0+rte_pktmbuf_pkt_len (m) =rte_pktmbuf_data_len (m);Can't received mbuf be multi-segment mbuf, as far as I can see checksum calculation API takes this possibility into account. If so need to check that possibility here before updating '
pkt_len'
You are right.
Thanks
Quoted 1 line
PATCH v2 1/1 app/test-pmd: fix tcp/udp cksum with padding data
In reply to Kaiwen DengIEEE 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.
--- app/test-pmd/csumonly.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
app/test-pmd/csumonly.c +32 -0
@@ -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
Signature · 1 line
2.34.1
Re: [PATCH v2] app/test-pmd: fix tcp/udp cksum with padding data
Quoted 6 lines · Kaiwen Deng
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.
Quoted 8 lines
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")Signed-off-by Kaiwen Deng <[email protected]>
I think decision was to fix 'rte_ipv4_udptcp_cksum_mbuf()' & 'rte_ipv6_udptcp_cksum_mbuf()'.
PATCH v3 1/1 lib/net: fix tcp/udp cksum with padding data
In reply to Kaiwen DengIEEE 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.
--- lib/net/rte_ip.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
lib/net/rte_ip.h +7 -2
@@ -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 );
Signature · 1 line
2.34.1
RE: [PATCH v3] lib/net: fix tcp/udp cksum with padding data
Quoted 27 lines
From: Kaiwen Deng [mailto:[email protected]]
Sent: Tuesday, 12 December 2023 03.16IEEE 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")Signed-off-by Kaiwen Deng <[email protected]>--- lib/net/rte_ip.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)lib/net/rte_ip.h +0
-0
lib/net/rte_ip.h __rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf · line 425
Quoted 3 lines
lib/net/rte_ip.h +0
-0@@ -423,7 +423,10 @@ __rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, if (l4_off > m->pkt_len)return 0 ;
It's not directly related, but while you are at it, please also add unlikely to the above check:
- if (l4_off > m->pkt_len)
- return 0;
+ if (unlikely(l4_off > m->pkt_len))
+ return 0; /* invalid params, return a dummy value */
lib/net/rte_ip.h __rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, · line 429
Quoted 7 lines
lib/net/rte_ip.h +4
-1-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))
Please declare "uint16_t len;" with the other variables at the top of the function, and only set its value here. (It's allowed to declare here, but please follow this function's existing convention of where variables are declared.)
lib/net/rte_ip.h __rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf · line 671
Quoted 7 lines
lib/net/rte_ip.h +0
-0return 0 ;lib/net/rte_ip.h +0
-0cksum = 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 ;
Again not directly related, but please also add unlikely to this comparison:
- if (l4_off > m->pkt_len)
- return 0;
+ if (unlikely(l4_off > m->pkt_len))
+ return 0; /* invalid params, return a dummy value */
lib/net/rte_ip.h __rte_ipv6_udptcp_cksum_mbuf(const struct rte_mbuf *m, · line 674
Quoted 6 lines
lib/net/rte_ip.h +3
-1-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))
No need for "len" variable here, just use rte_be_to_cpu_16(ipv6_hdr->payload_len) directly:
- 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))
Quoted 5 lines
lib/net/rte_ip.h +0
-0return 0 ;cksum =
raw_cksum+rte_ipv6_phdr_cksum(ipv6_hdr, 0);
--
2.34.1
PATCH v4 1/1 lib/net: fix tcp/udp cksum with padding data
In reply to Kaiwen DengIEEE 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.
--- lib/net/rte_ip.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
lib/net/rte_ip.h +11 -6
@@ -419,11 +419,15 @@ __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 +667,11 @@ __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 );
Signature · 1 line
2.34.1
RE: [PATCH v4] lib/net: fix tcp/udp cksum with padding data
Quoted 11 lines
From: Kaiwen Deng [mailto:[email protected]]
Sent: Wednesday, 13 December 2023 05.38IEEE 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.
Quoted 7 lines
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")Signed-off-by Kaiwen Deng <[email protected]>
Please fix indentation, refer to the Coding Style:
https://doc.dpdk.org/guides/contributing/coding_style.html#c-indentation
Note that line length up to 100 characters is acceptable:
https://doc.dpdk.org/guides/contributing/coding_style.html#general-guidelines
To some degree, indentation is a matter of taste. Just stay within the boundaries of the Coding Style.
Quoted 12 lines
--- lib/net/rte_ip.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)lib/net/rte_ip.h +0
-0@@ -419,11 +419,15 @@ __rte_ipv4_udptcp_cksum_mbuf(const struct rte_mbuf *m, {uint16_t raw_cksum;
lib/net/rte_ip.h __rte_ipv4_udptcp_cksum_mbuf(const struct · line 429
Quoted 10 lines
lib/net/rte_ip.h +6
-2uint32_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);
Please fix indentation of this continuation line.
Quoted 11 lines
lib/net/rte_ip.h +1
-1-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 ;lib/net/rte_ip.h +0
-0cksum = raw_cksum +rte_ipv4_phdr_cksum (ipv4_hdr,0 );@@ -663,10 +667,11 @@ __rte_ipv6_udptcp_cksum_mbuf(const structrte_mbuf *m, uint16_t raw_cksum;uint32_t cksum;
lib/net/rte_ip.h __rte_ipv6_udptcp_cksum_mbuf(const struct · line 676
Quoted 10 lines
lib/net/rte_ip.h +4
-3-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))
Please fix indentation of this continuation line.
Quoted 5 lines
lib/net/rte_ip.h +0
-0return 0 ;cksum =
raw_cksum+rte_ipv6_phdr_cksum(ipv6_hdr, 0);
--
2.34.1
With indentation fixed,
PATCH v5 1/1 lib/net: fix tcp/udp cksum with padding data
In reply to Kaiwen DengIEEE 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.
--- lib/net/rte_ip.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
lib/net/rte_ip.h +9 -6
@@ -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 );
Signature · 1 line
2.34.1
RE: [PATCH v5] lib/net: fix tcp/udp cksum with padding data
Quoted 11 lines
From: Kaiwen Deng [mailto:[email protected]]
Sent: Thursday, 14 December 2023 10.23IEEE 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.
Quoted 8 lines
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")Signed-off-by Kaiwen Deng <[email protected]>---
Thomas Monjalon
AppliedRe: [PATCH v5] lib/net: fix tcp/udp cksum with padding data
14/12/2023 12:20, Morten Brørup:
Quoted 14 lines
Quoted 14 lines
From: Kaiwen Deng [mailto:[email protected]]
Sent: Thursday, 14 December 2023 10.23IEEE 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.
Quoted 6 lines
Quoted 4 lines
Fixes d178f693bbfe ("net: add UDP/TCP checksum in mbuf segments")Signed-off-by Kaiwen Deng <[email protected]>Reviewed-by Morten Brørup <[email protected]>
Applied, thanks.