Page MenuHomeFreeBSD

netinet: Deduplicate most in_cksum() implementations
ClosedPublic

Authored by markj on Nov 23 2021, 2:29 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 17 2024, 8:18 AM
Unknown Object (File)
Mar 17 2024, 8:18 AM
Unknown Object (File)
Mar 17 2024, 8:17 AM
Unknown Object (File)
Mar 14 2024, 3:45 PM
Unknown Object (File)
Mar 10 2024, 12:54 AM
Unknown Object (File)
Jan 19 2024, 3:26 AM
Unknown Object (File)
Jan 12 2024, 11:30 PM
Unknown Object (File)
Jan 5 2024, 11:46 AM

Details

Summary

in_cksum() and related routines are implemented separately for each
platform, but only i386 and arm have optimized versions. Other
platforms' copies of in_cksum.c are identical except for style
differences and support for big-endian CPUs.

Deduplicate the implementations for the rest of the platforms. This
will make it easier to implement in_cksum() for unmapped mbufs. On arm
and i386, define HAVE_MD_IN_CKSUM to mean that the MI implementation is
not to be compiled.

No functional change intended.

MFC after: 1 week
Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Nov 23 2021, 2:29 PM
This revision is now accepted and ready to land.Nov 23 2021, 4:34 PM

P.S., I spent some time trying to replace this implementation with an updated one from NetBSD. Theirs is easier to read and is licensed under BSD 2-clause. It got somewhat messy, though, and wasn't important to my immediate goal, so I dropped it. I think there's also some room for micro-optimizations here, for instance in_pseudo() and in_addword() should probably be inlines. in_pseudo() in particular is dead simple, it's just a ones complement sum:

static inline uint16_t
in_addword(uint16_t a, uint16_t b)
{
    uint32_t sum;

    sum = (uint32_t)a + b;
    return ((sum >> 16) + (sum & 0xffff));
}

in_pseudo() is similar. If anyone's interested in working further on this, I'm happy to help.