> -----Original Message-----
> From: Ferruh Yigit <ferruh.yi...@amd.com>
> Sent: Friday, November 17, 2023 9:14 AM
> To: Deng, KaiwenX <kaiwenx.d...@intel.com>; dev@dpdk.org
> Cc: sta...@dpdk.org; Yang, Qiming <qiming.y...@intel.com>; Zhou, YidingX
> <yidingx.z...@intel.com>; Singh, Aman Deep <aman.deep.si...@intel.com>;
> Zhang, Yuying <yuying.zh...@intel.com>; Matz, Olivier
> <olivier.m...@6wind.com>; De Lara Guarch, Pablo
> <pablo.de.lara.gua...@intel.com>
> Subject: Re: [PATCH] app/test-pmd: fix L4 checksum with padding data
> 
> On 8/4/2023 9:28 AM, Kaiwen Deng wrote:
> > 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: sta...@dpdk.org
> >
> > Signed-off-by: Kaiwen Deng <kaiwenx.d...@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;
> >
> 
> 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...
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
> 
> 
> > +           } 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));
> >
> 
> 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?
You're right, I didn't notice that and didn't test it adequately. I'll fix that.
> 
> 
> > +                   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'
You are right.

Thanks
> 

Reply via email to