<?xml version="1.0" encoding="US-ASCII"?>
<!-- This template is for creating an Internet Draft using xml2rfc,
    which is available here: http://xml.resource.org. -->
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!-- One method to get references from the online citation libraries.
    There has to be one entity for each item to be referenced.
    An alternate method (rfc include) is described in the references. -->
<!ENTITY RFC768 SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.0768.xml">
<!ENTITY RFC793 SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.0793.xml">
<!ENTITY RFC1071 SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.1071.xml">
<!ENTITY RFC2119 SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY I-D.ietf-tsvwg-udp-options SYSTEM "https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.draft-ietf-tsvwg-udp-options-05.xml">
]>
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<!-- used by XSLT processors -->
<!-- For a complete list and description of processing instructions (PIs),
    please see http://xml.resource.org/authoring/README.html. -->
<!-- Below are generally applicable Processing Instructions (PIs) that most I-Ds might want to use.
    (Here they are set differently than their defaults in xml2rfc v1.32) -->
<?rfc strict="yes" ?>
<!-- give errors regarding ID-nits and DTD validation -->
<!-- control the table of contents (ToC) -->
<?rfc toc="yes"?>
<!-- generate a ToC -->
<?rfc tocdepth="4"?>
<!-- the number of levels of subsections in ToC. default: 3 -->
<!-- control references -->
<?rfc symrefs="yes"?>
<!-- use symbolic references tags, i.e, [RFC2119] instead of [1] -->
<?rfc sortrefs="yes" ?>
<!-- sort the reference entries alphabetically -->
<!-- control vertical white space
    (using these PIs as follows is recommended by the RFC Editor) -->
<?rfc compact="yes" ?>
<!-- do not start each main section on a new page -->
<?rfc subcompact="no" ?>
<!-- keep one blank line between list items -->
<!-- end of list of popular I-D processing instructions -->
<rfc category="std"
     docName="draft-fairhurst-udp-options-cco-00.txt"
     ipr="trust200902">
  <!-- category values: std, bcp, info, exp, and historic
     ipr values: trust200902, noModificationTrust200902, noDerivativesTrust200902,
                 or pre5378Trust200902
    you can add the attributes updates="NNNN" and obsoletes="NNNN"
    they will automatically be output with "(if approved)" -->

  <!-- ***** FRONT MATTER ***** -->

  <front>
    <!-- The abbreviated title is used in the page header - it is only necessary if the
     full title is longer than 39 characters -->

    <title abbrev="UDPO CCO">Checksum Compensation Options for UDP Options</title>

    <!-- add 'role="editor"' below for the editors if appropriate -->

    <!-- Another author who claims to be an editor -->

    <author fullname="Godred Fairhurst" initials="G" surname="Fairhurst">
      <organization>University of Aberdeen</organization>

      <address>
        <postal>
          <street>School of Engineering</street>

          <street>Fraser Noble Building</street>

          <city>Aberdeen</city>

          <region></region>

          <code>AB24 3UE</code>

          <country>UK</country>
        </postal>

        <email>gorry@erg.abdn.ac.uk</email>
      </address>
    </author>

    <author fullname="Tom Jones" initials="T" surname="Jones">
      <organization>University of Aberdeen</organization>

      <address>
        <postal>
          <street>School of Engineering</street>

          <street>Fraser Noble Building</street>

          <city>Aberdeen</city>

          <region></region>

          <code>AB24 3UE</code>

          <country>UK</country>
        </postal>

        <email>tom@erg.abdn.ac.uk</email>
      </address>
    </author>

    <author fullname="Raffaele Zullo" initials="R" surname="Zullo">
      <organization>University of Aberdeen</organization>

      <address>
        <postal>
          <street>School of Engineering</street>

          <street>Fraser Noble Building</street>

          <city>Aberdeen</city>

          <region></region>

          <code>AB24 3UE</code>

          <country>UK</country>
        </postal>

        <email>raffaele@erg.abdn.ac.uk </email>
      </address>
    </author>

    <date day="19" month="October" year="2018" />

    <!-- Meta-data Declarations -->

    <area>Transport</area>

    <workgroup>Internet Engineering Task Force</workgroup>

    <!-- WG name at the upperleft corner of the doc,
     IETF is fine for individual submissions. If this element is not
     present, the default is "Network Working Group", which is used by the
     RFC Editor as a nod to the history of the IETF. -->

    <keyword>UDP UDP-Options</keyword>

    <!-- Keywords will be incorporated into HTML output
     files in a meta tag but they have no effect on text or nroff output. If
     you submit your draft to the RFC Editor, the keywords will be used for
     the search engine. -->

    <abstract>
      <t>This document describes a robust method for calculating checksums for
      use with UDP Options.  The new method proposes an alternative checksum
      calculation for coverage of the option space. This is based on the IP
      checksum calculation, but uses an updated pseudoheader. The new method
      only checks the option portion of a UDP packet, but creates a checksum
      that compensates for the range of IP and UDP chekcsum validation
      methods that have been deployed, in this way the new method enhances the
      proability of NAPT traversal for packets that carry UDP-Options.  </t>
    </abstract>
  </front>

  <middle>
    <section title="Introduction">
      <t>UDP Options <xref target="I-D.ietf-tsvwg-udp-options"></xref> adds
      support for transport options in UDP <xref target="RFC0768"></xref>. When
      UDP is carried in IP two length fields describe the UDP datagram, the IP
      transport carries a payload length and the UDP header carries the length
      of the UDP datagram. In most datagrams currently forwarded by network
      devices the IP payload length is equal to the UDP length, UDP Options
      <xref target="I-D.ietf-tsvwg-udp-options"></xref> creates a surplus area
      by increasing the IP payload length while not varying the UDP length.
      Transport Options are then added in this surplus area in the form of a
      TLV encoded list.</t>

      <t> The current specification for UDP permits sending datagrams with
      surplus data, but are not commonly observed, and many network devices
      assume that IP payload length is equal to UDP length and have used this
      value when calculating UDP checksums. This leads to the case where some
      middlebox devices (e.g. Firewalls, NAPT) and some endpoint
      implementations check or modify the UDP checksum in a way that leads
      to discard of UDP datagrams that carry UDP options.</t>

      <t>This document describes common pathologies of network devices that 
      incorrectly calculate the UDP checksum and proposes a new UDP Option to
      compensate for incorrect UDP checksum calculation.
      </t>
    </section>

    <section title="Terminology">
      <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
      "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
      document are to be interpreted as described in <xref
      target="RFC2119"></xref>.</t>
    </section>

    <section anchor="middlebox-pathologies" title="Middlebox Pathologies">
	<t> Middleboxes and network interfaces can compute the UDP Checksum
	incorrectly in the presence of UDP Options based on the assumption that
	IP Payload Length and UDP Length coincide (an assumption that was
	equivalent before UDP Options). </t>

	<t> These middleboxes use the IP Payload Length (obtained as IP Total
	Length -  IP Header Length) to fill UDP pseudo-header Length field and
	also compute the checksum over the all IP Payload bytes.  </t>

	<t> This can lead to UDP Options packets that carry a correctly
	calculated checksum to be discarded by end-hosts or by middleboxes
	along the path.  </t>

	<t><xref target="fig-udpsumcalc"></xref> shows UDP Checksum computation
	based on UDP Length and based on IP Payload Length and the fields that
	are different for the two calculation methods.  </t>

        <t><figure anchor="fig-udpsumcalc" title="Checksum calculations">
            <artwork align="center"><![CDATA[

Sum based on UDP Len   Sum basd on IP len       Delta between two

+--------+--------+    +--------+--------+    +--------+--------+
|     Source      |    |     Source      |    |                 |
|     Address     |    |     Address     |    |                 |
+--------+--------+    +--------+--------+    +--------+--------+
|   Destination   |    |   Destination   |    |                 |
|     Address     |    |     Address     |    |                 |
+--------+--------+    +--------+--------+    +--------+--------+
|  zero  |  PTCL  |    |  zero  |  PTCL  |    |        |        |
+--------+--------+    +--------+--------+    +--------+--------+
|   UDP Length    |    |IP Payload Length|    | Options Length  |
+--------+--------+    +--------+--------+    +--------+--------+
                                              
+--------+--------+    +--------+--------+    +--------+--------+
|   Source Port   |    |   Source Port   |    |                 |
+--------+--------+    +--------+--------+    +--------+--------+
|    Dest Port    |    |    Dest Port    |    |                 |
+--------+--------+    +--------+--------+    +--------+--------+
|  UDP  Checksum  |    |  UDP  Checksum  |    |                 |
+--------+--------+    +--------+--------+    +--------+--------+
|   UDP Length    |    |   UDP Length    |    |                 |
+--------+--------+    +--------+--------+    +--------+--------+
                                              
+--------+--------+    +--------+--------+    +--------+--------+
|                 |    |                 |    |                 |
|                 |    |                 |    |                 |
|   UDP Payload   |    |   UDP Payload   |    |                 |
|                 |    |                 |    |                 |
|                 |    |                 |    |                 |
+--------+--------+    +--------+--------+    +--------+--------+
                                              
                       +--------+--------+    +--------+--------+
                       |                 |    |                 |
                       |   UDP Options   |    |   UDP Options   |
                       |                 |    |                 |
                       +--------+--------+    +--------+--------+
            ]]></artwork>
	</figure></t>
    </section>

    <section anchor="UDPOPT-CCO" title="Checksum Compensation Option">

	<t>This section introduces the Checksum Compensation Option (CCO),
	which suggests a new way to calculate the checksum for the option
	field.</t>

	<t> The design of the CCO seeks to increase UDP Options compatibility
	with middleboxes and other existing network equipment, while at the
	same time providing error detection on UDP Options area in the same way
	that the UDP Checksum provides an integrity check for the UDP Header
	and UDP Payload.  </t>

	<t>CCO provides a checksum for UDP Option packets that is compatible
	with both variants of the checksum computation making the final value
	of the UDP Checksum computed on the whole IP Payload coincide with the
	the value that would be correctly computed soley on the UDP Length.
	</t>

	<t> The Checksum Compensation Option (CCO) is the 2 byte one's
	complement sum of the one's complement sum of all 2 byte words in the
	UDP Options. <xref target="fig-ccoopt"></xref> describes the format of
	the CCO.   The UDP Options area is divided into 2 byte words based on
	their alignment with the first byte of UDP packet (and not the first
	byte of UDP Options). This means that the first and the last byte of
	UDP Options can not preceded or be followed by another byte: in these
	cases the unpaired byte must padded respectively on the left and on the
	right with zero to form a 2 byte word.</t>

        <figure anchor="fig-ccoopt" title="UDP CCO Option Format">
                <artwork align="center"><![CDATA[
        +---------+--------+------------+
        | Kind=xx | Len=4  |  Checksum  |
        +---------+--------+------------+
          1 byte    1 byte    2 bytes       
                ]]></artwork>
        </figure>

	<t><xref target="RFC0793"></xref> specifies:
	   "The checksum field is the 16 bit one's complement of the one's
	    complement sum of all 16 bit words in the header and text.  If a
	    segment contains an odd number of header and text octets to be
	    checksummed, the last octet is padded on the right with zeros to
	    form a 16 bit word for checksum purposes.  The pad is not
	    transmitted as part of the segment.  While computing the checksum,
	    the checksum field itself is replaced with zeros."
	This method is equivalent to that specified for UDP <xref
	target="RFC0768"></xref>.</t>

	<t> The checksum also covers a 2 byte pseudo header conceptually
	prefixed to the UDP Options area.  This pseudo header contains the
	length of UDP Options area. (The length also forms a part of the TCP
	and UDP pseudo field <xref target="RFC0793"></xref>).</t>

	<t><xref target="fig-ccobytes"></xref> shows the bytes on which CCO is
	computed and how, when present, the unpaired byte at the start and/or at
	end of Options area are included in the sum.</t>

        <t><figure anchor="fig-ccobytes" title="UDP ECHORES Option Format">
                <artwork align="center"><![CDATA[
       +--------+--------+
       | Options  Length |
       +--------+--------+
       +--------+--------+
       |                 |
       |                 |
       |   UDP Options   |
       |                 | 
       |                 |
       +--------+--------+

       +--------+--------+
       | Options  Length | 
       +--------+--------+
       +--------+--------+ 
       |  0x00  |        |
       +--------+ - - - -| 
       |                 |
       |   UDP Options   |
       |                 |
       |- - - - +--------+
       |        |  0x00  |
       +--------+--------+
        ]]></artwork>
        </figure></t>

	<t>When this CCO checksum and the UDP Options field are covered by the
	UDP checksum calculation <xref target="RFC0768"></xref>, the resulting
	UDP checksum value is numerically the same as when the UDP checksum
	calculation is calculated over only the UDP Payload. That is, the
	result retuned by both checksum computations <xref
	target="fig-udpsumcalc"></xref> coincide.</t>

    	<section title="Calculating the CCO">
		<t> The CCO can be present at any position within the Options
		space, the checksum field of the CCO MUST be aligned on a 2
		byte boundary. This condition can be achieved by placing a NOP
		Option before the CCO in the case the number of bytes preceding
		the CCO (UDP Payload + UDP Options placed before CCO) is odd
		(see <xref target="fig-optlayout"></xref>).
		</t>

        <t><figure anchor="fig-optlayout" title="Option Space layout">
                <artwork align="center"><![CDATA[
+--------+--------+
|    UDP Header   |
|       ...       |
+--------+--------+
|   UDP Payload   |
|    and other    |
|   UDP Options   |
|       ...       |
|        +--------+
|        |  NOP   |
+--------+--------+
|  CCO   | CCOLen |
+--------+--------+
|    CCO  value   |
+--------+--------+
|Other UDP Options|
|       ...       |
+--------+--------+
                ]]></artwork>
        </figure></t>

		<t>When calculated in this way, the CCO value is initialized to
		zero and the checksum is calculated over the UDP Options and
		the pseudo-header: the one's complement of the result is then
		stored in the CCO field.  </t>

		<t> An alternative implementation could be to initialise the
		CCO field with the size of the UDP Options area (instead of
		initialising the CCO value to zero and combining with a pseudo
		header). This produces the same result, but allows the checksum
		to be performed using solely the UDP Options area.</t>
	</section>

    	<section title="Validating CCO">
	    <t>When a UDP packet containing CCO is received the Internet
	    Checksum should be computed on the UDP Options area (2 byte aligned
	    as described in <xref target="cco-examples"></xref>) and the
	    pseudo-header (the length of the received UDP Options), and the
	    Options is valid if the one's complement of the result is zero.</t>
  
	    <t>If the option checksum fails, all options MUST be ignored and
	    any trailing surplus data (and Lite data, if used) silently
	    discarded.  UDP data that is validated by a correct UDP checksum
	    MUST be delivered to the application layer, even if the UDP option
	    checksum fails.</t>
	</section>

	<section anchor="cco-examples" title="CCO Calculation Examples">
		<t> This section provides examples of calculating the Checksum
		Compensation Option, similar to those presented in <xref
		target="RFC1071"></xref>.  </t>

		<t>XXX IANA NOTE: The type of the CCO option has yet too be
		assigned, and may change. XXX</t>

		<t>These examples use 204 (0xCC) as the type for the CCO
		option</t>

		<t> In the first example the UDP Payload length is even and a
		MSS Option has been  already placed in UDP Options area. CCO
		value is initialized with UDP Options Length (0x0008).</t>

        <t><figure anchor="fig-ccoaligned" title="Checksum calculations">
            <artwork align="center"><![CDATA[
UDP Length:               Even 
Preceding UDP Options:    MSS (kind 5, len 4, val 0x5c0) 
Following UDP Options:    None

NOP Padding before CCO:   No 
Total UDP Options Length: 8    

UDP Options bytes 0/1:    0504 
UDP Options bytes 2/3:    05c0 
UDP Options bytes 4/5:    cc04 
UDP Options bytes 6/7:    0008 
                          ---- 
Sum:                      d6d0

CCO:                      292f
                ]]></artwork>
        </figure></t>

		<t>In the second example the UDP Payload length is odd and a
		MSS Option has been already placed in UDP Options area.  The
		available space for CCO starts at an odd byte (NOP padding
		before CCO) and also UDP options space starts at odd byte (left
		zero padding of first byte).  CCO value is initialized with UDP
		Options Length (0x0009).</t>

        <t><figure anchor="fig-ccounalgined" title="Checksum calculations">
            <artwork align="center"><![CDATA[
UDP Length:               Odd 
Preceding UDP Options:    MSS (kind 5, len 4, val 0x5c0) 
Following UDP Options:    None

NOP Padding before CCO:   Yes 
Total UDP Options Length: 9

UDP Options bytes   0:    0005 
UDP Options bytes 1/2:    0405 
UDP Options bytes 3/4:    c001 
UDP Options bytes 5/6:    cc04 
UDP Options bytes 7/8:    0009 
                          ----
Sum:                      9019

CCO:                      6fe6
                ]]></artwork>
        </figure></t>

	</section>

    	<section title="Interaction with other UDP Options">
	<t>Interaction with other UDP Options <list style="hanging">

	    <t hangText="AE:"> Similarly to what happens with OCS, AE can be
	    computed as if the AE hash and CCO value are zero. CCO value can be
	    computed as if the CCO value is zero and after the AE hash has been
	    computed.  </t>

	    <t hangText="ACS:"> The CCO has no interference with ACS since an ACS
	    is computed only on UDP Payload bytes (no Header, no Options). The
	    CCO value must be computed after the ACS has already been computed.
	    </t>

	    <t hangText="LITE:"> The CCO covers the entire UDP Option area,
	    including any LITE option as formatted after swapping (or
	    relocation) for transmission (or, equivalently, before the
	    swap/relocation after reception). The CCO is computed after LITE
	    swapping/relocation to guarantee the checksum compensation
	    of the packet actually sent.</t>
	</list></t>
	</section>
    </section>

    <section anchor="Acknowledgements" title="Acknowledgements">
	<t>This work is partially supported by the European Commission under
	Horizon 2020 grant agreement no. 688421 Measurement and Architecture
	for a Middleboxed Internet (MAMI).</t>
    </section>

    <section anchor="IANA" title="IANA Considerations">
        <t> This memo includes no requests to IANA
        </t>
    </section>

    <section anchor="Security" title="Security Considerations">
      <t> The security considerations for are described in <xref
      target="I-D.ietf-tsvwg-udp-options"></xref>.  The proposed new method
      does not change the integrity protection offered by the UDP options
      method.
      </t>
    </section>
  </middle>

  <back>
    <!-- References split into informative and normative -->

    <references title="Normative References">
      <!--?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml"?-->

      &RFC768;

      &RFC793;

      &RFC1071;

      &RFC2119;

      &I-D.ietf-tsvwg-udp-options;

    </references>
<!--
    <references title="Informative References">

    </references>
-->
    <section title="Revision Notes">
      <t>Note to RFC-Editor: please remove this entire section prior to
      publication.</t>

      <t>Individual draft -00: <list style="symbols">
          <t hangText="Individual draft -00">Comments and corrections are
          welcome directly to the authors or via the IETF TSVWG working group
          mailing list.</t>

          <t hangText="Individual draft -00">This update is proposed for WG
          comments.</t>
        </list></t>
    </section>
  </back>
</rfc>
