RFC 1141
Incremental updating of the Internet checksum
Incremental Updating of the Internet Checksum π¦
okay bestie, title block tea β This is RFC 1141 π by Tracy Mallory and A. Kullberg of BBN Communications, dated January 1990 πΈ. It's an implementation technique, not a standard, so it's a really good trick and not a must-follow spec π . It obsoletes RFC 1071 and replaces the Incremental Update description in there β¨. No Updates field is listed.
Status of This Memo
Okay so the vibe is: this memo correctly describes the incremental update procedure for use with the standard Internet checksum π§. It's meant to replace the description of Incremental Update in RFC 1071. This is not a standard but rather an implementation technique π . Distribution of this memo is unlimited π.
Description
Okay so back in RFC 1071, on pages 4 and 5, there's a method to update the IP checksum in the IP header without fully recomputing it π. RFC 1071 recommends this equation for computing the updated checksum C' from the original checksum C, plus the old and new values of byte m:
C' = C + (-m) + m' = C + (m' - m)
Like, the equation is correct, but it's kinda not it for incremental updates π. It updates C itself, not the 1's complement of the checksum, ~C, which is the value actually stored in the checksum field. It also doesn't clearly say that ALL the arithmetic, including the unary negation, has to be 1's complement, so it's hard to turn into working code π. The useful calculation for 2's complement machines is:
~C' = ~(C + (-m) + m') = ~C + (m - m') = ~C + m + ~m'
The oft-mentioned case is updating the IP TTL field π. Subtracting one from the TTL means ADDING 1 or 256 as appropriate to the checksum field in the packet, using one's complement addition π₯. One big-endian, non-portable implementation in C looks like this:
unsigned long sum;
ipptr->ttl--; /* decrement ttl */
sum = ipptr->Checksum + 0x100; /* increment checksum high byte*/
ipptr->Checksum = (sum + (sum>>16)) /* add carry */
This special case can be optimized in many ways. For instance, you can bundle updating and checking the ttl. Compiler mileage may vary π. Here is a more general and possibly more helpful example, which updates the ttl by n seconds:
UpdateTTL(iph,n)
struct ip_hdr *ipptr;
unsigned char n;
{
unsigned long sum;
unsigned short old;
old = ntohs(*(unsigned short *)&ipptr->ttl);
ipptr->ttl -= n;
sum = old + (~ntohs(*(unsigned short *)&ipptr->ttl) & 0xffff);
sum += ntohs(ipptr->Checksum);
sum = (sum & 0xffff) + (sum>>16);
ipptr->Checksum = htons(sum + (sum>>16));
}
Security Considerations
Security issues are not addressed in this memo. π¨ Nothing about security is covered here, bestie, so don't assume it is π
Authors' Addresses
Tracy Mallory
BBN Communications Corporation
50 Moulton Street
Cambridge, MA 02238
Phone: (617) 873-3193
EMail: tmallory@CCV.BBN.COM
A. Kullberg
BBN Communications Corporation
50 Moulton Street
Cambridge, MA 02238
Phone: (617) 873-4000
EMail: akullberg@BBN.COM
π¦ where this page comes from
- ietf: rfc1141 1990-01
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms