Page MenuHomeFreeBSD

netinet: Deduplicate most in_cksum() implementations
ClosedPublic

Authored by markj on Nov 23 2021, 2:29 PM.
Tags
None
Referenced Files
F102214209: D33095.diff
Sat, Nov 9, 1:34 AM
Unknown Object (File)
Thu, Nov 7, 4:20 PM
Unknown Object (File)
Tue, Oct 29, 10:24 AM
Unknown Object (File)
Sun, Oct 27, 9:51 PM
Unknown Object (File)
Sun, Oct 27, 9:30 PM
Unknown Object (File)
Sep 29 2024, 8:41 PM
Unknown Object (File)
Sep 28 2024, 10:29 AM
Unknown Object (File)
Sep 28 2024, 1:10 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.