<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>
<!--
  Skeleton for an xml2rfc v3 Internet-Draft.
  Replace every TODO, rename docName to match the file name, and
  build with: make (see Makefile)
-->
<rfc xmlns:xi="http://www.w3.org/2001/XInclude"
     version="3"
     category="info"
     docName="draft-yourtchenko-intarea-internet-checksum-00"
     ipr="trust200902"
     submissionType="IETF"
     consensus="true"
     xml:lang="en"
     tocInclude="true"
     sortRefs="true"
     symRefs="true">

  <front>
    <title abbrev="Calculating Internet Checksum">On Calculating and Updating the Internet Checksum</title>
    <seriesInfo name="Internet-Draft" value="draft-yourtchenko-intarea-internet-checksum-00"/>

    <author fullname="Andrew Yourtchenko" initials="A." surname="Yourtchenko">
      <organization>Cisco</organization>
      <address>
        <postal>
          <street>De kleetlaan 6a</street>
          <city>Diegem</city>
          <region>BRABANT</region>
          <code>1831</code>
          <country>Belgium</country>
        </postal>
        <email>ayourtch@cisco.com</email>
      </address>
    </author>

    <date/>
    <area>Internet</area>
    <workgroup>Internet Area Working Group</workgroup>
    <keyword>internet checksum</keyword>

    <abstract>
      <t>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.
      </t>
    </abstract>
  </front>

  <middle>
    <section anchor="intro">
      <name>Introduction</name>
      <t>The Internet checksum computation was described in detail in <xref target="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. </t>
      <t>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, <xref target="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). <xref target="RFC1624"/> corrected this, but it was ambiguous in places.
This resulted in an erratum, which was itself incorrect and triggered additional errata. </t>
      <t>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 <xref target="RFC6935"/>, <xref target="RFC6936"/>. The rules in <xref target="RFC1624"/> do not take these special cases into account, thus resulting in subtle bugs even in recent code.</t>
      <t>Some protocols opted to either make their updates checksum-neutral (e.g. <xref target="RFC6296"/>, <xref target="RFC6052"/>), or allocate a "sacrificial field" whose sole purpose is to be updated when another part of the checksum-covered area changes (<xref target="RFC7820"/>, <xref target="RFC7821"/>, <xref target="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.</t>
      <t>This document does not redefine any of the existing protocols.</t>
    </section>

    <section anchor="conventions">
      <name>Conventions and Definitions</name>
      <t>The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
      "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>",
      "<bcp14>SHALL NOT</bcp14>", "<bcp14>SHOULD</bcp14>",
      "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>",
      "<bcp14>NOT RECOMMENDED</bcp14>", "<bcp14>MAY</bcp14>", and
      "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted as
      described in BCP&nbsp;14 <xref target="RFC2119"/> <xref target="RFC8174"/>
      when, and only when, they appear in all capitals, as shown here.</t>
    </section>
    <section anchor="proposedscope">
      <name>Proposed Scope and Contents</name>
      <t>Taking the above into account, and in stubborn defiance of the wisdom in <xref target="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:
        </t>
        <section>
            <name>A Recap of Internet Checksum Calculation</name>
            <t><xref target="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.</t>
        </section>
        <section>
            <name>A Survey Of Special-Use Values</name>
            <t>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.
            </t>
        </section>
        <section>
            <name>Incremental Update, Special Cases Included</name>
            <t>This section would refer to some of the available open source implementations as well as analyze the issues related to them.</t>
            <t>It would also demonstrate branch-free approaches to dealing with special-case values during the checksum calculation.</t>
        </section>
        <section>
            <name>Methods to Avoid the Need to Update the Checksum During Protocol Design</name>
            <t>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.</t>
        </section>
        <section>
            <name>Test Vectors and Example Code</name>
            <t>This section would include various examples and corner-case test vectors, intended to help verify the implementations.</t>
        </section>
    </section>

    <section anchor="security">
      <name>Security Considerations</name>
      <t>The document does not (yet) have any security considerations.</t>
    </section>

    <section anchor="iana">
      <name>IANA Considerations</name>
      <t>This document has no IANA actions.</t>
    </section>
  </middle>

  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
      </references>
      <references>
        <name>Informative References</name>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.1071.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.1141.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.1624.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.6052.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.6296.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.6935.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.6936.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.7820.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.7821.xml"/>
        <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.9197.xml"/>
	<reference anchor="XKCD927" target="https://xkcd.com/927/">
	  <front><title>Standards</title><author><organization>xkcd</organization></author><date/></front>
	</reference>
      </references>
    </references>

    <section anchor="acknowledgments" numbered="false">
      <name>Acknowledgments</name>
      <t>Thanks a lot to Martin Thomson for the inspiration to write this document and to Tim Chown for reviewing the pre-00 version.</t>
    </section>
  </back>
</rfc>
