Internet-Draft Calculating Internet Checksum October 2026
Yourtchenko Expires 29 April 2027 [Page]
Workgroup:
Internet Area Working Group
Internet-Draft:
draft-yourtchenko-intarea-internet-checksum-00
Published:
Intended Status:
Informational
Expires:
Author:
A. Yourtchenko
Cisco

On Calculating and Updating the Internet Checksum

Abstract

Over the past four decades, the Internet checksum has been used by many protocols: IPv4, TCP, UDP, and others. The practical details related to calculation and updates are scattered across different RFCs. Several protocols introduce special-case handling for +0 and -0, thus making the term "Internet checksum" ambiguous. This affects any protocol implementation which modifies the data covered by any variant of the Internet checksum. This document provides the problem statement and outlines the scope for potential future work to build a consolidated source for the Internet checksum. If there is interest in such work, this document may be converted into that consolidated specification.

Status of This Memo

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

This Internet-Draft will expire on 29 April 2027.

▲

Table of Contents

1. Introduction

The Internet checksum computation was described in detail in [RFC1071] 38 years ago as a 1's complement of the 16-bit 1's complement sum of all 16-bit words over the range the checksum covers, with the checksum field itself set to all-zero. The same document also defined the process of checksum verification being 1's complement sum across the area, the checksum field included. If the result is 0xffff (-0 in 1's complement arithmetic), the check is successful.

Intermediate nodes, like routers, often need to update the fields covered by the checksum, and recomputing it from scratch every time is inefficient. Thus, the original document also describes the incremental checksum update mechanism. The initial formulation did not lend itself to efficient implementation. To address that, [RFC1141] described a streamlined incremental checksum update process. However, the process described there can yield an updated header checksum of -0 (0xffff) when it should be +0 (0x0000). [RFC1624] corrected this, but it was ambiguous in places. This resulted in an erratum, which was itself incorrect and triggered additional errata.

1's complement arithmetic has two representations of zero, +0 (0x0000) and -0 (0xffff), and this redundancy resulted in some protocols treating these values differently. For example, a correct IPv4 sender never computes a header checksum of -0 (0xffff) by construction, whereas UDP uses 0x0000 as a signal "checksum not computed", and requires the computed checksum of zero to be transmitted as 0xffff. Additionally, the rules for when the checksum computation can be skipped are different between UDP-over-IPv4 and UDP-over-IPv6: the latter allows it only for the outer UDP header of the tunneled traffic [RFC6935], [RFC6936]. The rules in [RFC1624] do not take these special cases into account, thus resulting in subtle bugs even in recent code.

Some protocols opted to either make their updates checksum-neutral (e.g. [RFC6296], [RFC6052]), or allocate a "sacrificial field" whose sole purpose is to be updated when another part of the checksum-covered area changes ([RFC7820], [RFC7821], [RFC9197]). This is a useful design technique if the header layout is still open. It may also improve performance: the "sacrificial" checksum correction field can be placed next to the fields which have to be modified, and thus end up already in the processor cache. Also, some protocols opted to use entirely different checksum mechanisms.

This document does not redefine any of the existing protocols.

2. Conventions and Definitions

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.

3. Proposed Scope and Contents

Taking the above into account, and in stubborn defiance of the wisdom in [XKCD927], this document proposes to be a single reference for all matters related to the Internet checksum, collecting the various aspects of it into the following sections:

3.1. A Recap of Internet Checksum Calculation

[RFC1071] covers this at length, but a shorter version, focusing on incremental update and the +0/-0 properties, would be useful. This section would discuss how to verify the checksum, and why recalculating the checksum and comparing it with the received one can result in occasional spurious packet drops.

3.2. A Survey Of Special-Use Values

A correct IPv4 sender never transmits 0xffff as its header checksum; UDP never transmits 0x0000 unless the checksum is disabled; UDP over IPv6 permits a zero checksum only when it is the outer protocol for tunneled traffic. Handling these special cases is a frequent source of bugs. This section would contrast how different protocols use the Internet checksum.

3.3. Incremental Update, Special Cases Included

This section would refer to some of the available open source implementations as well as analyze the issues related to them.

It would also demonstrate branch-free approaches to dealing with special-case values during the checksum calculation.

3.4. Methods to Avoid the Need to Update the Checksum During Protocol Design

During protocol design, it might make sense to make any updates unnecessary by making the transformation checksum-neutral. This section would survey the existing protocols that make use of two techniques for this: defining the transform to be checksum-neutral, or allocating a special field so that a variable transform stays checksum-neutral.

3.5. Test Vectors and Example Code

This section would include various examples and corner-case test vectors, intended to help verify the implementations.

4. Security Considerations

The document does not (yet) have any security considerations.

5. IANA Considerations

This document has no IANA actions.

6. References

6.1. Normative References

[RFC2119]
Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, , <https://www.rfc-editor.org/info/rfc2119>.
[RFC8174]
Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, , <https://www.rfc-editor.org/info/rfc8174>.

6.2. Informative References

[RFC1071]
Braden, R., Borman, D., and C. Partridge, "Computing the Internet checksum", RFC 1071, DOI 10.17487/RFC1071, , <https://www.rfc-editor.org/info/rfc1071>.
[RFC1141]
Mallory, T. and A. Kullberg, "Incremental updating of the Internet checksum", RFC 1141, DOI 10.17487/RFC1141, , <https://www.rfc-editor.org/info/rfc1141>.
[RFC1624]
Rijsinghani, A., Ed., "Computation of the Internet Checksum via Incremental Update", RFC 1624, DOI 10.17487/RFC1624, , <https://www.rfc-editor.org/info/rfc1624>.
[RFC6052]
Bao, C., Huitema, C., Bagnulo, M., Boucadair, M., and X. Li, "IPv6 Addressing of IPv4/IPv6 Translators", RFC 6052, DOI 10.17487/RFC6052, , <https://www.rfc-editor.org/info/rfc6052>.
[RFC6296]
Wasserman, M. and F. Baker, "IPv6-to-IPv6 Network Prefix Translation", RFC 6296, DOI 10.17487/RFC6296, , <https://www.rfc-editor.org/info/rfc6296>.
[RFC6935]
Eubanks, M., Chimento, P., and M. Westerlund, "IPv6 and UDP Checksums for Tunneled Packets", RFC 6935, DOI 10.17487/RFC6935, , <https://www.rfc-editor.org/info/rfc6935>.
[RFC6936]
Fairhurst, G. and M. Westerlund, "Applicability Statement for the Use of IPv6 UDP Datagrams with Zero Checksums", RFC 6936, DOI 10.17487/RFC6936, , <https://www.rfc-editor.org/info/rfc6936>.
[RFC7820]
Mizrahi, T., "UDP Checksum Complement in the One-Way Active Measurement Protocol (OWAMP) and Two-Way Active Measurement Protocol (TWAMP)", RFC 7820, DOI 10.17487/RFC7820, , <https://www.rfc-editor.org/info/rfc7820>.
[RFC7821]
Mizrahi, T., "UDP Checksum Complement in the Network Time Protocol (NTP)", RFC 7821, DOI 10.17487/RFC7821, , <https://www.rfc-editor.org/info/rfc7821>.
[RFC9197]
Brockners, F., Ed., Bhandari, S., Ed., and T. Mizrahi, Ed., "Data Fields for In Situ Operations, Administration, and Maintenance (IOAM)", RFC 9197, DOI 10.17487/RFC9197, , <https://www.rfc-editor.org/info/rfc9197>.
[XKCD927]
xkcd, "Standards", <https://xkcd.com/927/>.

Acknowledgments

Thanks a lot to Martin Thomson for the inspiration to write this document and to Tim Chown for reviewing the pre-00 version.

Author's Address

Andrew Yourtchenko
Cisco
De kleetlaan 6a
1831 Diegem
Belgium