RFC 1141

Incremental updating of the Internet checksum

πŸ“… published January 1990, from ietf

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