[PATCH 5/6] net: add smaller IPv4 cksum function for simple cases
Bruce Richardson
bruce.richardson at intel.com
Thu Oct 17 21:03:13 CEST 2024
On Thu, Oct 17, 2024 at 07:15:10PM +0200, Morten Brørup wrote:
> > +/**
> > + * Process the IPv4 checksum of an IPv4 header without any extensions.
> > + *
> > + * The checksum field does NOT have to be set by the caller, the field
> > + * is skipped by the calculation.
> > + *
> > + * @param ipv4_hdr
> > + * The pointer to the contiguous IPv4 header.
> > + * @return
> > + * The complemented checksum to set in the IP packet.
> > + */
> > +__rte_experimental
> > +static inline uint16_t
> > +rte_ipv4_cksum_simple(const struct rte_ipv4_hdr *ipv4_hdr)
> > +{
> > + const uint16_t *v16_h;
> > + uint32_t ip_cksum;
> > +
> > + /*
> > + * Compute the sum of successive 16-bit words of the IPv4 header,
> > + * skipping the checksum field of the header.
> > + */
> > + v16_h = (const unaligned_uint16_t *)&ipv4_hdr->version_ihl;
> > + ip_cksum = v16_h[0] + v16_h[1] + v16_h[2] + v16_h[3] +
> > + v16_h[4] + v16_h[6] + v16_h[7] + v16_h[8] + v16_h[9];
> > +
> > + /* reduce 32 bit checksum to 16 bits and complement it */
> > + ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
> > + ip_cksum = (ip_cksum & 0xffff) + (ip_cksum >> 16);
> > + ip_cksum = (~ip_cksum) & 0x0000FFFF;
> > + return (ip_cksum == 0) ? 0xFFFF : (uint16_t) ip_cksum;
>
> The zero exception does not apply to the checksum stored in the IP header, only to the checksum in the UDP header.
>
I was wondering about that, because I didn't see it mentioned anywhere in
the RFCs I consulted, but on the other hand all the implementations in the
code seemed to have the check for zero.
> > +}
>
> Besides that, for the series,
So, just to confirm, the zero check at the end of the new ip_cksum_simple
function should be removed and we always return the computed value
directly?
> Acked-by: Morten Brørup <mb at smartsharesystems.com>
>
More information about the dev
mailing list