<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="4"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<rfc category="std" docName="draft-boucadair-tcpm-rst-diagnostic-payload-05"
     ipr="trust200902">
  <front>
    <title abbrev="RST Diagnostic Payload">TCP RST Diagnostic Payload</title>

    <author fullname="Mohamed Boucadair" initials="M." surname="Boucadair">
      <organization>Orange</organization>

      <address>
        <postal>
          <street></street>

          <city>Rennes</city>

          <region></region>

          <code>35000</code>

          <country>France</country>
        </postal>

        <email>mohamed.boucadair@orange.com</email>
      </address>
    </author>

    <author fullname="Tirumaleswar Reddy" initials="T." surname="Reddy">
      <organization>Nokia</organization>

      <address>
        <postal>
          <street></street>

          <city></city>

          <region></region>

          <code></code>

          <country>India</country>
        </postal>

        <email>kondtir@gmail.com</email>
      </address>
    </author>

    <date />

    <workgroup>tcpm</workgroup>

    <abstract>
      <t>This document specifies a diagnostic payload format to be returned in
      TCP RST segments. Such payloads are used to share with the endpoints the
      reasons for which a TCP connection has been reset. This is meant to ease
      diagnostic and troubleshooting.</t>
    </abstract>
  </front>

  <middle>
    <section anchor="introduction" title="Introduction">
      <t>A TCP connection <xref target="RFC9293"></xref> can be reset by a
      peer for various reasons, e.g., received data does not correspond to an
      active connection. Also, a TCP connection can be reset by an on-path
      service function (e.g., CGN <xref target="RFC6888"></xref>, NAT64 <xref
      target="RFC6146"></xref>, or firewall) for several reasons. Typically, a
      Network Address Translator (NAT) function can generate an RST segment to
      notify the endpoints upon the expiry of the lifetime of the
      corresponding mapping entry or because an RST segment was received from
      a peer (Section 2.2 of <xref target="RFC7857"></xref>). A TCP connection
      can also be closed by a user or an application at any time. However, the
      peer that receives an RST segment does not have any hint about the
      reason that led to terminating the connection. Likewise, the application
      that relies upon such a TCP connection may not easily identify the
      reason for the connection closure. Troubleshooting such events at the
      remote side of the connection that receives the RST segment may not be
      trivial.</t>

      <t>This document fills this void by specifying a format of the
      diagnostic payload that is returned in an RST segment. Returning such
      data is consistent with the provision in Section 3.5.3 of <xref
      target="RFC9293"></xref> for RST segments, especially: <list
          style="empty">
          <t>"TCP implementations SHOULD allow a received RST segment to
          include data (SHLD-2)."</t>
        </list></t>

      <t>This document does not change the conditions under which an RST
      segment is generated (Section 3.5.2 of <xref
      target="RFC9293"></xref>).</t>

      <t>The generic procedure for processing an RST segment is specified in
      Section 3.5.3 of <xref target="RFC9293"></xref>. Only the deviations
      from that procedure to insert and validate an enclosed diagnostic
      payload is provided in <xref target="new"></xref>. <xref
      target="examples"></xref> provides a set of examples to illustrate the
      use of TCP RST diagnostic payloads.</t>

      <t>This document specifies the format and the overall approach to ease
      maintaining the list of codes while allowing for adding new codes as
      needed in the future and accommodating any existing vendor-specific
      codes. An initial version of error codes is available in <xref
      target="initial"></xref>. However, the authoritative source to retrieve
      the full list of error codes is the IANA-maintained registry <xref
      target="reg"></xref>.</t>

      <t>Preliminary investigation based on some major CGN vendors revealed
      that RSTs with data are not discarded and are translated according to
      any matching mapping entry. </t>
    </section>

    <section anchor="notation" title="Terminology">
      <t>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
      <xref target="RFC2119"></xref> <xref target="RFC8174"></xref> when, and
      only when, they appear in all capitals, as shown here.</t>

      <t>This document makes use of the terms defined in Section 4 of <xref
      target="RFC9293"></xref>.</t>
    </section>

    <section anchor="new" title="RST Diagnostic Payload">
      <t>The RST diagnostic payload MUST be encoded using Concise Binary
      Object Representation (CBOR) Sequence <xref target="RFC8742"></xref>.
      The Concise Data Definition Language (CDDL) <xref
      target="RFC8610"></xref> for the diagnostic payload is as
      follows:<figure anchor="sddl"
          title="Structure of the RST Diagnostic Payload">
          <artwork><![CDATA[   ; This defines an array, the elements of which are to be used
   ; in a CBOR Sequence. There is exactly one occurrence. 
   diagnostic-payload = [magic-cookie, reason]
   ; Magic cookie to identify a payload that follows this specification
   magic-cookie = 12345
   ; Reset reason details:
   reason= {
     ? reason-code: uint,
     ? pen:uint, 
     ? reason-description: tstr,
   }
]]></artwork>
        </figure></t>

      <t>The RST diagnostic payload comprises a magic cookie that is used to
      unambiguously identify an RST payload that follows this specification.
      It MUST be set to the RFC number to be assigned to this document. <list
          style="empty">
          <t>Note to the RFC Editor: Please replace "12345" with the RFC
          number assigned to this document.</t>
        </list></t>

      <t>All parameters in the reason component of an RST diagnostic payload
      are mapped to their CBOR key values as specified in <xref
      target="map"></xref>. The description of these parameters is as follows:
      <list style="hanging">
          <t hangText="reason-code:">This parameter takes a value from an
          available registry such as the "TCP Failure Causes" registry (<xref
          target="reg"></xref>).</t>

          <t hangText="pen:">Includes a Private Enterprise Number <xref
          target="Private-Enterprise-Numbers"></xref>. This parameter MAY be
          included when the reason code is not taken from the IANA-maintained
          registry (<xref target="reg"></xref>), but from a vendor-specific
          registry.</t>

          <t hangText="reason-description:">Includes a brief description of
          the reset reason encoded as UTF-8 <xref target="RFC3629"></xref>.
          This parameter SHOULD NOT be included if a reason code is supplied.
          This parameter is useful only for reset reasons that are not yet
          registered or for application-specific reset reasons.</t>
        </list></t>

      <t>At least one of "reason-code" and "reason-description" parameters
      MUST be included in an RST diagnostic payload. The "pen" parameter MUST
      be omitted if a reason code from the IANA-maintained registry (<xref
      target="reg"></xref>) fits the reset case.</t>

      <t>Malformed RST diagnostic payload messages that include the magic
      cookie MUST be silently ignored by the receiver.</t>

      <t>A peer that receives a valid diagnostic payload may pass the reset
      reason information to the local application in addition to the
      information (MUST-12) described in Section 3.6 of <xref
      target="RFC9293"></xref>. That information may also be logged locally,
      unless a local policy specifies otherwise. How the information is passed
      to an application and how it is stored locally is implementation
      specific.</t>

      <t>As per Section 3.6 of <xref target="RFC9293"></xref>, one or more RST
      segments can be sent to reset a connection. Whether a TCP endpoint
      elects to send more than one RST with only a subset of them that include
      the diagnostic payload is implementation specific. </t>
    </section>

    <section anchor="examples" title="Some Examples">
      <t>To ease readability, the CBOR diagnostic notation (Section 8 of <xref
      target="RFC8949"></xref>) with the parameter names rather than their
      CBOR key values in <xref target="map"></xref> is used in Figures <xref
      format="counter" target="ex1"></xref>, <xref format="counter"
      target="ex2"></xref>, <xref format="counter" target="ex3"></xref>, and
      <xref format="counter" target="ex4"></xref>.</t>

      <t><xref target="ex1a"></xref> depicts an example of the RST diagnostic
      payload that is generated to inform the peer that the TCP connection is
      reset because an ACK was received from that peer while the connection is
      still in the LISTEN state (Section 3.10.7.2 of <xref
      target="RFC9293"></xref>).</t>

      <t><figure anchor="ex1a"
          title="Example of an RST Diagnostic Payload with Reason Code (CBOR Encoding)">
          <artwork><![CDATA[19 3039 # unsigned(12345)
A1    # map(1)
   01 # unsigned(1)
   02 # unsigned(2)
]]></artwork>
        </figure></t>

      <t><xref target="ex1"></xref> depicts the same RST diagnostic payload as
      the one shown in <xref target="ex1a"></xref> but following the CBOR
      diagnostic notation.</t>

      <t><figure anchor="ex1"
          title="Example of an RST Diagnostic Payload with Reason Code (Diagnostic Notation)">
          <artwork><![CDATA[[
  12345,
  {
    "reason-code": 2
  }
]
]]></artwork>
        </figure></t>

      <t><xref target="ex2"></xref> shows an example of an RST diagnostic
      payload that includes a free description to report a case that is not
      covered by an appropriate code from the IANA-maintained registry (<xref
      target="reg"></xref>).</t>

      <t><figure anchor="ex2"
          title="Example of an RST Diagnostic Payload with Reason Description (Diagnostic Notation)">
          <artwork><![CDATA[[
  12345,
  {
    "reason-description": "brief human-readable description"
  }
]
]]></artwork>
        </figure></t>

      <t>An RST diagnostic payload may also be sent by an on-path service
      function. For example, the following diagnostic payload is returned by a
      NAT upon expiry of the mapping entry to which the TCP connection is
      bound (<xref target="ex3"></xref>).</t>

      <t><figure anchor="ex3"
          title="Example of an RST Diagnostic Payload to Report Connection Timeout (Diagnostic Notation)">
          <artwork><![CDATA[[
  12345,
  {
    "reason-code": 8
  }
]
]]></artwork>
        </figure></t>

      <t><xref target="ex4"></xref> illustrates the RST diagnostic payload
      that is returned by a peer that resets a TCP connection for a reason
      code 1234 defined by a vendor with the private enterprise number
      32473.</t>

      <t><figure anchor="ex4"
          title="Example of an RST Diagnostic Payload to Report Vendor-Specific Reason Code (Diagnostic Notation)">
          <artwork><![CDATA[[
  12345,
  {
    "reason-code": 1234,
    "pen": 32473
  }
]
]]></artwork>
        </figure></t>

      <t><xref target="ex4"></xref> uses the Enterprise Number 32473 defined
      for documentation use <xref target="RFC5612"></xref>.</t>
    </section>

    <section anchor="IANA" title="IANA Considerations">
      <t></t>

      <section anchor="map" title="RST Diagnostic Payload CBOR Key Values">
        <t>IANA is requested to create a new subregistry titled "RST
        Diagnostic Payload CBOR Key Values" under the "Transmission Control
        Protocol (TCP) Parameters" registry <xref
        target="IANA-TCP"></xref>.</t>

        <t>The key value MUST be an integer in the 1-255 range.</t>

        <t>The assignment policy for this registry is "IETF Review" (Section
        4.8 of <xref target="RFC8126"></xref>).</t>

        <t>The structure of this subregistry and the initial values are
        provided below:</t>

        <t><figure align="center">
            <artwork align="center"><![CDATA[+--------------------+------+---------------+--------------+
| Parameter Name     | CBOR | CBOR Major    | Reference    |
|                    | Key  |    Type &     |              |
|                    |      | Information   |              |
+====================+======+===============+==============+
| reason-code        |   1  | 0 unsigned    |[ThisDocument]|
| pen                |   2  | 0 unsigned    |[ThisDocument]|
| reason-description |   3  | 3 text string |[ThisDocument]|
+====================+======+===============+==============+
]]></artwork>
          </figure></t>
      </section>

      <section anchor="reg" title="New Registry for TCP Failure Causes">
        <t>This document requests IANA to create a new subregistry entitled
        "TCP Failure Causes" under the "Transmission Control Protocol (TCP)
        Parameters" registry <xref target="IANA-TCP"></xref>.</t>

        <t>Values are taken from the 1-65535 range.</t>

        <t>The assignment policy for this registry is "Expert Review" (Section
        4.5 of <xref target="RFC8126"></xref>).</t>

        <t>The designated experts may approve registration once they checked
        that the new requested code is not covered by an existing code and if
        the provided reasoning to register the new code is acceptable. A
        registration request may supply a pointer to a specification where
        that code is defined. However, a registration may be accepted even if
        no permanent and readily available public specification is
        available.</t>

        <t>The registry is initially populated with the following values:</t>

        <texttable anchor="initial" title="Initial TCP Failure Causes">
          <ttcol>Value</ttcol>

          <ttcol>Description</ttcol>

          <ttcol>Specification (if available)</ttcol>

          <c>1</c>

          <c>New data is received after CLOSE is called</c>

          <c>Sections 3.6.1 and 3.10.7.1 of <xref target="RFC9293"></xref></c>

          <c>2</c>

          <c>Received ACK while the connection is still in the LISTEN
          state</c>

          <c>Section 3.10.7.2 of <xref target="RFC9293"></xref></c>

          <c>3</c>

          <c>Illegal Option</c>

          <c>Section 3.1 of <xref target="RFC9293"></xref></c>

          <c>4</c>

          <c>Malformed Message</c>

          <c>[ThisDocument]</c>

          <c>5</c>

          <c>Not Authorized</c>

          <c>[ThisDocument]</c>

          <c>6</c>

          <c>Resource Exceeded</c>

          <c>[ThisDocument]</c>

          <c>7</c>

          <c>Network Failure</c>

          <c>[ThisDocument]</c>

          <c>8</c>

          <c>Reset received from the peer</c>

          <c>[ThisDocument]</c>

          <c>9</c>

          <c>Destination Unreachable</c>

          <c>[ThisDocument]</c>

          <c>10</c>

          <c>Connection Timeout.</c>

          <c>[ThisDocument]</c>

          <c>11</c>

          <c>Too much outstanding data</c>

          <c>Section 3.6 of <xref target="RFC8684"></xref></c>

          <c>12</c>

          <c>Unacceptable performance</c>

          <c>Section 3.6 of <xref target="RFC8684"></xref></c>

          <c>12</c>

          <c>Middlebox interference</c>

          <c>Section 3.6 of <xref target="RFC8684"></xref></c>
        </texttable>

        <t>Note that codes in the 6-10 range can be used by service functions
        such as translators.</t>
      </section>
    </section>

    <section anchor="security" title="Security Considerations">
      <t><xref target="RFC9293"></xref> discusses TCP-related security
      considerations. In particular, RST-specific attacks and their
      mitigations are discussed in Section 3.10.7.3 of <xref
      target="RFC9293"></xref>.</t>

      <t>In addition to these considerations, it is RECOMMENDED to control the
      size of acceptable diagnostic payload and keep it as brief as possible.
      The RECOMMENDED acceptable maximum size of the RST diagnostic payload is
      255 octets.</t>

      <t>Also, it is RECOMMENDED to avoid leaking privacy-related information
      as part of the diagnostic payload (e.g., including a description such as
      "user X resets explicitly the connection" is not recommended). The
      "reason-description" string, when present, should not include any
      private information that an observer would not otherwise have access
      to.</t>

      <t>The presence of vendor-specific reason codes (<xref
      target="new"></xref>) may be used to fingerprint hosts. Such a concern
      does not apply if the reason codes are taken from the IANA-maintained
      registry. Implementers are, thus, encouraged to register new codes
      within IANA instead of maintaining specific registries.</t>

      <t>The reason description, when present, is not intended to be displayed
      to end users, but to be consumed by applications. Such a description may
      carry a malicious message to mislead the end-user.</t>
    </section>

    <section anchor="ack" title="Acknowledgements">
      <t>The "diagnostic payload" name is inspired by Section 5.5.2 of <xref
      target="RFC7252"></xref> that was cited by Carsten Bormann in the tcpm
      mailing list.</t>

      <t>Thanks to Jon Shallow for the comments.</t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <?rfc include='reference.RFC.2119'?>

      <?rfc include='reference.RFC.8174'?>

      <?rfc include='reference.RFC.8126'?>

      <?rfc include='reference.RFC.8949'?>

      <?rfc include='reference.RFC.8610'?>

      <?rfc include='reference.RFC.8742'?>

      <?rfc include='reference.RFC.3629'?>

      <?rfc include='reference.RFC.9293'?>

      <?rfc include='reference.RFC.8684'?>

      <reference anchor="Private-Enterprise-Numbers"
                 target="https://www.iana.org/assignments/enterprise-numbers">
        <front>
          <title>Private Enterprise Numbers</title>

          <author>
            <organization></organization>
          </author>

          <date day="04" month="May" year="2020" />
        </front>
      </reference>
    </references>

    <references title="Informative References">
      <?rfc include='reference.RFC.6888'?>

      <?rfc include='reference.RFC.7857'?>

      <?rfc include='reference.RFC.6146'?>

      <?rfc include='reference.RFC.5612'?>

      <?rfc include='reference.RFC.7252'?>

      <reference anchor="IANA-TCP"
                 target="https://www.iana.org/assignments/tcp-parameters/tcp- parameters.xhtml">
        <front>
          <title>Transmission Control Protocol (TCP) Parameters</title>

          <author>
            <organization>IANA YANG</organization>
          </author>

          <date day="" month="" year="" />
        </front>
      </reference>
    </references>
  </back>
</rfc>
