IN_CKSUM(9)
π 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's1071,1141,1624, and1936for 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
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2001 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms