patches for DPDK stable branches
 help / color / mirror / Atom feed
* Re: [dpdk-stable] [dpdk-dev] [PATCH] lib/librte_net: fix bug for ipv4 checksumcalculating
       [not found] ` <98CBD80474FA8B44BF855DF32C47DC35C60FC4@smartserver.smartshare.dk>
@ 2020-05-14 14:19   ` Olivier Matz
  0 siblings, 0 replies; only message in thread
From: Olivier Matz @ 2020-05-14 14:19 UTC (permalink / raw)
  To: Morten Brørup
  Cc: guohongzhi, dev, konstantin.ananyev, jiayu.hu, ferruh.yigit,
	nicolas.chautru, cristian.dumitrescu, zhoujingbin, chenchanghu,
	jerry.lilijun, haifeng.lin, stable

Hi,

On Thu, May 14, 2020 at 02:56:41PM +0200, Morten Brørup wrote:
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of guohongzhi
> > Sent: Thursday, May 14, 2020 3:27 AM
> > 
> > The function of rte_ipv4_cksum for calculating the
> > checksum of IPv4 header is incorrect.
> > This function will return checksum value like 0xffff.
> > This value, however, is considered an illegal checksum on some
> > switches(like Trident3).
> > 
> > RFC 1624 specifies the IPv4 checksum as follows:
> > https://tools.ietf.org/rfc/rfc1624
> > Since there is guaranteed to be at least one
> >    non-zero field in the IP header, and the checksum field in the
> >    protocol header is the complement of the sum, the checksum field can
> >    never contain ~(+0), which is -0 (0xFFFF).  It can, however, contain
> >    ~(-0), which is +0 (0x0000).
> > 
> > ---
> >  lib/librte_net/rte_ip.h | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/lib/librte_net/rte_ip.h b/lib/librte_net/rte_ip.h
> > index 1ceb7b7..ece2e43 100644
> > --- a/lib/librte_net/rte_ip.h
> > +++ b/lib/librte_net/rte_ip.h
> > @@ -267,7 +267,7 @@ rte_ipv4_cksum(const struct rte_ipv4_hdr *ipv4_hdr)
> >  {
> >  	uint16_t cksum;
> >  	cksum = rte_raw_cksum(ipv4_hdr, sizeof(struct rte_ipv4_hdr));
> > -	return (cksum == 0xffff) ? cksum : (uint16_t)~cksum;
> > +	return (uint16_t)~cksum;
> >  }
> > 
> >  /**
> > --
> > 2.21.0.windows.1
> > 
> > 
> 
> Well spotted!

Indeed.

> Reviewed-By: Morten Brørup <mb@smartsharesystems.com>

Fixes: 6006818cfb26 ("net: new checksum functions")
Cc: stable@dpdk.org

Acked-by: Olivier Matz <olivier.matz@6wind.com>

> Would you consider writing another patch splitting
> rte_ipv4_udptcp_cksum() up into rte_ipv4_udp_cksum() and
> rte_ipv4_tcp_cksum(), so the TCP checksum will be calculated
> correctly?
> 
> RFC 768 for UDP specifies:
> 
> If the computed checksum is zero, it is transmitted as all ones (the
> equivalent in one's complement arithmetic).  An all zero transmitted
> checksum value means that the transmitter generated no checksum (for
> debugging or for higher level protocols that don't care).
>
> RFC 793 for TCP has no such special treatment for the checksum of
> zero, but rte_ipv4_udptcp_cksum() implements the UDP special treatment
> anyway.

I agree the following test is useless in case of TCPv4 and TCPv6:

	if (cksum == 0)
                cksum =	0xffff;

For UDPv4, it is needed because 0 means "no checksum".
For UDPv6, it is needed because 0 is forbidden.

So yes, I think we could have specific csum functions for tcp and udp
checksum as Morten suggests (as soon as we keep the backward compat).

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-05-14 14:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200514012729.23920-1-guohongzhi1@huawei.com>
     [not found] ` <98CBD80474FA8B44BF855DF32C47DC35C60FC4@smartserver.smartshare.dk>
2020-05-14 14:19   ` [dpdk-stable] [dpdk-dev] [PATCH] lib/librte_net: fix bug for ipv4 checksumcalculating Olivier Matz

patches for DPDK stable branches

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/stable/0 stable/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 stable stable/ https://inbox.dpdk.org/stable \
		stable@dpdk.org
	public-inbox-index stable

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.stable


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git