Page MenuHomeFreeBSD

netinet: Deduplicate most in_cksum() implementations

Authored by markj on Tue, Nov 23, 2:29 PM.



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

R10 FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

markj requested review of this revision.Tue, Nov 23, 2:29 PM
This revision is now accepted and ready to land.Tue, Nov 23, 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.