IN_CKSUM(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… IN_CKSUM(9) β€” the Kernel Developer's Manual, but make it group-chat

okay so bestie, welcome to IN_CKSUM(9) from the Kernel Developer's Manual β€” this is the page about computing the Internet checksum, and honestly it's giving "low-level but iconic" energy. Let's go 🫢


✨ NAME ✨

in_cksum, in4_cksum, in6_cksum β€” compute Internet checksum. that's the whole vibe. three little functions, one big job 🌸


πŸŽ€ SYNOPSIS πŸŽ€

uint16_t
in_cksum(struct mbuf *m, int len);

uint16_t
in4_cksum(struct mbuf *m, uint8_t nxt, int off, int len);

uint16_t
in6_cksum(struct mbuf *m, uint8_t nxt, int off, int len);

literally just copy these exactly, your compiler will thank you πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

so these functions compute the ones-complement checksum that IP and IPv6 require. no cap, that's the whole point of them.

in4_cksum() is the one you call when you need the transport-layer checksum that tcp(4) and udp(4) want β€” it works over a range of bytes starting at off and continuing on for len bytes inside the mbuf m. 🧚

now, if the nxt parameter is non-zero, it's assumed to be an IP protocol number. it's also assumed that the data inside m starts with an IP header, and that the transport-layer header starts at off. a pseudo-header gets constructed as specified in RFC768 and RFC793, and that pseudo-header is prepended to the data covered by the checksum. slay, pseudo-header πŸ’…

in6_cksum() is the similar one β€” if nxt is non-zero, it's assumed that m starts with an IPv6 header, and that the transport-layer header starts after off bytes. same energy, IPv6 flavored 🌈

and in_cksum()? bestie, it's literally just equivalent to in4_cksum(m, 0, 0, len). that's it. that's the function. πŸ‘‘

⚠️ real talk: these functions are always performance critical and should be reimplemented in assembler or optimized C for each platform. when available, using repeated full-width add-with-carry followed by reduction of the sum to a 16 bit width usually leads to the best results. see RFC's 1071, 1141, 1624, and 1936 for more info about efficient computation of the internet checksum πŸ”₯

⭐ RETURN VALUES ⭐

all three functions return the computed checksum value. all three. every single one. consistent kings πŸ‘‘


πŸ“ SEE ALSO πŸ“

go read them, iykyk πŸ“š


πŸ’œ STANDARDS πŸ’œ

these functions implement the Internet transport-layer checksum as specified in RFC768, RFC793, and RFC2460. periodt. ✨


πŸ’€ BUGS πŸ’€

okay so this is the part where we hold hands 🫢: in6_cksum() currently requires special handling of link-local addresses in the pseudo-header due to the use of embedded scope-id's within link-local addresses. that's a thing. it's real. don't @ me, @ the scope-ids πŸ™ˆ


and that's the page!! brought to you by Debian, dated May 22, 2001, page IN_CKSUM(9) β€” yes she's been serving this same lewk since 2001 and she still ate πŸ’…πŸŽ€

πŸ“¦ where this page comes from