<?xml version='1.0' encoding='utf-8'?>
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" version="3" category="std" consensus="true" docName="draft-ietf-cbor-network-addresses-13" indexInclude="true" ipr="trust200902" number="9164" prepTime="2021-12-13T15:02:50" scripts="Common,Latin" sortRefs="true" submissionType="IETF" symRefs="true" tocDepth="3" tocInclude="true" xml:lang="en">
  <link href="https://datatracker.ietf.org/doc/draft-ietf-cbor-network-addresses-13" rel="prev"/>
  <link href="https://dx.doi.org/10.17487/rfc9164" rel="alternate"/>
  <link href="urn:issn:2070-1721" rel="alternate"/>
  <front>
    <title abbrev="CBOR Tags for IP">Concise Binary Object Representation (CBOR) Tags for IPv4 and IPv6 Addresses and Prefixes</title>
    <seriesInfo name="RFC" value="9164" stream="IETF"/>
    <author initials="M." surname="Richardson" fullname="Michael Richardson">
      <organization showOnFrontPage="true">Sandelman Software Works</organization>
      <address>
        <email>mcr+ietf@sandelman.ca</email>
      </address>
    </author>
    <author initials="C." surname="Bormann" fullname="Carsten Bormann">
      <organization showOnFrontPage="true">Universität Bremen TZI</organization>
      <address>
        <postal>
          <country>Germany</country>
        </postal>
        <email>cabo@tzi.org</email>
      </address>
    </author>
    <date month="12" year="2021"/>
    <area>Internet</area>
    <workgroup>CBOR Working Group</workgroup>
    <keyword>binary format</keyword>
    <keyword>data interchange format</keyword>
    <keyword>interface address</keyword>
    <keyword>zone identifier</keyword>
    <abstract pn="section-abstract">
      <t indent="0" pn="section-abstract-1">This specification defines two Concise Binary Object Representation (CBOR) tags for use with IPv6 and IPv4 addresses and prefixes.</t>
    </abstract>
    <boilerplate>
      <section anchor="status-of-memo" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.1">
        <name slugifiedName="name-status-of-this-memo">Status of This Memo</name>
        <t indent="0" pn="section-boilerplate.1-1">
            This is an Internet Standards Track document.
        </t>
        <t indent="0" pn="section-boilerplate.1-2">
            This document is a product of the Internet Engineering Task Force
            (IETF).  It represents the consensus of the IETF community.  It has
            received public review and has been approved for publication by
            the Internet Engineering Steering Group (IESG).  Further
            information on Internet Standards is available in Section 2 of 
            RFC 7841.
        </t>
        <t indent="0" pn="section-boilerplate.1-3">
            Information about the current status of this document, any
            errata, and how to provide feedback on it may be obtained at
            <eref target="https://www.rfc-editor.org/info/rfc9164" brackets="none"/>.
        </t>
      </section>
      <section anchor="copyright" numbered="false" removeInRFC="false" toc="exclude" pn="section-boilerplate.2">
        <name slugifiedName="name-copyright-notice">Copyright Notice</name>
        <t indent="0" pn="section-boilerplate.2-1">
            Copyright (c) 2021 IETF Trust and the persons identified as the
            document authors. All rights reserved.
        </t>
        <t indent="0" pn="section-boilerplate.2-2">
            This document is subject to BCP 78 and the IETF Trust's Legal
            Provisions Relating to IETF Documents
            (<eref target="https://trustee.ietf.org/license-info" brackets="none"/>) in effect on the date of
            publication of this document. Please review these documents
            carefully, as they describe your rights and restrictions with
            respect to this document. Code Components extracted from this
            document must include Revised BSD License text as described in
            Section 4.e of the Trust Legal Provisions and are provided without
            warranty as described in the Revised BSD License.
        </t>
      </section>
    </boilerplate>
    <toc>
      <section anchor="toc" numbered="false" removeInRFC="false" toc="exclude" pn="section-toc.1">
        <name slugifiedName="name-table-of-contents">Table of Contents</name>
        <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1">
          <li pn="section-toc.1-1.1">
            <t indent="0" keepWithNext="true" pn="section-toc.1-1.1.1"><xref derivedContent="1" format="counter" sectionFormat="of" target="section-1"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-introduction">Introduction</xref></t>
          </li>
          <li pn="section-toc.1-1.2">
            <t indent="0" keepWithNext="true" pn="section-toc.1-1.2.1"><xref derivedContent="2" format="counter" sectionFormat="of" target="section-2"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-terminology">Terminology</xref></t>
          </li>
          <li pn="section-toc.1-1.3">
            <t indent="0" pn="section-toc.1-1.3.1"><xref derivedContent="3" format="counter" sectionFormat="of" target="section-3"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-protocol">Protocol</xref></t>
            <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.3.2">
              <li pn="section-toc.1-1.3.2.1">
                <t indent="0" pn="section-toc.1-1.3.2.1.1"><xref derivedContent="3.1" format="counter" sectionFormat="of" target="section-3.1"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-three-forms">Three Forms</xref></t>
                <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.3.2.1.2">
                  <li pn="section-toc.1-1.3.2.1.2.1">
                    <t indent="0" keepWithNext="true" pn="section-toc.1-1.3.2.1.2.1.1"><xref derivedContent="3.1.1" format="counter" sectionFormat="of" target="section-3.1.1"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-addresses">Addresses</xref></t>
                  </li>
                  <li pn="section-toc.1-1.3.2.1.2.2">
                    <t indent="0" pn="section-toc.1-1.3.2.1.2.2.1"><xref derivedContent="3.1.2" format="counter" sectionFormat="of" target="section-3.1.2"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-prefixes">Prefixes</xref></t>
                  </li>
                  <li pn="section-toc.1-1.3.2.1.2.3">
                    <t indent="0" pn="section-toc.1-1.3.2.1.2.3.1"><xref derivedContent="3.1.3" format="counter" sectionFormat="of" target="section-3.1.3"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-interface-definition">Interface Definition</xref></t>
                  </li>
                </ul>
              </li>
              <li pn="section-toc.1-1.3.2.2">
                <t indent="0" pn="section-toc.1-1.3.2.2.1"><xref derivedContent="3.2" format="counter" sectionFormat="of" target="section-3.2"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-ipv6">IPv6</xref></t>
              </li>
              <li pn="section-toc.1-1.3.2.3">
                <t indent="0" pn="section-toc.1-1.3.2.3.1"><xref derivedContent="3.3" format="counter" sectionFormat="of" target="section-3.3"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-ipv4">IPv4</xref></t>
              </li>
            </ul>
          </li>
          <li pn="section-toc.1-1.4">
            <t indent="0" pn="section-toc.1-1.4.1"><xref derivedContent="4" format="counter" sectionFormat="of" target="section-4"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-tag-validity">Tag Validity</xref></t>
            <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.4.2">
              <li pn="section-toc.1-1.4.2.1">
                <t indent="0" pn="section-toc.1-1.4.2.1.1"><xref derivedContent="4.1" format="counter" sectionFormat="of" target="section-4.1"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-deterministic-encoding">Deterministic Encoding</xref></t>
              </li>
              <li pn="section-toc.1-1.4.2.2">
                <t indent="0" pn="section-toc.1-1.4.2.2.1"><xref derivedContent="4.2" format="counter" sectionFormat="of" target="section-4.2"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-encoder-considerations-for-">Encoder Considerations for Prefixes</xref></t>
              </li>
              <li pn="section-toc.1-1.4.2.3">
                <t indent="0" pn="section-toc.1-1.4.2.3.1"><xref derivedContent="4.3" format="counter" sectionFormat="of" target="section-4.3"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-decoder-considerations-for-">Decoder Considerations for Prefixes</xref></t>
                <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.4.2.3.2">
                  <li pn="section-toc.1-1.4.2.3.2.1">
                    <t indent="0" pn="section-toc.1-1.4.2.3.2.1.1"><xref derivedContent="4.3.1" format="counter" sectionFormat="of" target="section-4.3.1"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-example-implementation">Example Implementation</xref></t>
                  </li>
                </ul>
              </li>
            </ul>
          </li>
          <li pn="section-toc.1-1.5">
            <t indent="0" pn="section-toc.1-1.5.1"><xref derivedContent="5" format="counter" sectionFormat="of" target="section-5"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-cddl">CDDL</xref></t>
          </li>
          <li pn="section-toc.1-1.6">
            <t indent="0" pn="section-toc.1-1.6.1"><xref derivedContent="6" format="counter" sectionFormat="of" target="section-6"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-security-considerations">Security Considerations</xref></t>
          </li>
          <li pn="section-toc.1-1.7">
            <t indent="0" pn="section-toc.1-1.7.1"><xref derivedContent="7" format="counter" sectionFormat="of" target="section-7"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-iana-considerations">IANA Considerations</xref></t>
            <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.7.2">
              <li pn="section-toc.1-1.7.2.1">
                <t indent="0" pn="section-toc.1-1.7.2.1.1"><xref derivedContent="7.1" format="counter" sectionFormat="of" target="section-7.1"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-tag-54-ipv6">Tag 54 - IPv6</xref></t>
              </li>
              <li pn="section-toc.1-1.7.2.2">
                <t indent="0" pn="section-toc.1-1.7.2.2.1"><xref derivedContent="7.2" format="counter" sectionFormat="of" target="section-7.2"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-tag-52-ipv4">Tag 52 - IPv4</xref></t>
              </li>
              <li pn="section-toc.1-1.7.2.3">
                <t indent="0" pn="section-toc.1-1.7.2.3.1"><xref derivedContent="7.3" format="counter" sectionFormat="of" target="section-7.3"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-tags-260-and-261">Tags 260 and 261</xref></t>
              </li>
            </ul>
          </li>
          <li pn="section-toc.1-1.8">
            <t indent="0" pn="section-toc.1-1.8.1"><xref derivedContent="8" format="counter" sectionFormat="of" target="section-8"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-references">References</xref></t>
            <ul bare="true" empty="true" indent="2" spacing="compact" pn="section-toc.1-1.8.2">
              <li pn="section-toc.1-1.8.2.1">
                <t indent="0" pn="section-toc.1-1.8.2.1.1"><xref derivedContent="8.1" format="counter" sectionFormat="of" target="section-8.1"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-normative-references">Normative References</xref></t>
              </li>
              <li pn="section-toc.1-1.8.2.2">
                <t indent="0" pn="section-toc.1-1.8.2.2.1"><xref derivedContent="8.2" format="counter" sectionFormat="of" target="section-8.2"/>.  <xref derivedContent="" format="title" sectionFormat="of" target="name-informative-references">Informative References</xref></t>
              </li>
            </ul>
          </li>
          <li pn="section-toc.1-1.9">
            <t indent="0" pn="section-toc.1-1.9.1"><xref derivedContent="" format="none" sectionFormat="of" target="section-appendix.a"/><xref derivedContent="" format="title" sectionFormat="of" target="name-acknowledgements">Acknowledgements</xref></t>
          </li>
          <li pn="section-toc.1-1.10">
            <t indent="0" pn="section-toc.1-1.10.1"><xref derivedContent="" format="none" sectionFormat="of" target="section-appendix.b"/><xref derivedContent="" format="title" sectionFormat="of" target="name-authors-addresses">Authors' Addresses</xref></t>
          </li>
        </ul>
      </section>
    </toc>
  </front>
  <middle>
    <section anchor="introduction" numbered="true" toc="include" removeInRFC="false" pn="section-1">
      <name slugifiedName="name-introduction">Introduction</name>
      <t indent="0" pn="section-1-1"><xref target="RFC8949" format="default" sectionFormat="of" derivedContent="RFC8949"/> defines a number of CBOR tags for common items.
Tags 260 and 261 were later defined in documents listed with IANA <xref target="IANA.cbor-tags" format="default" sectionFormat="of" derivedContent="IANA.cbor-tags"/>.
These tags were intended to cover addresses (260) and prefixes (261).
Tag 260 distinguishes between IPv6, IPv4, and MAC <xref target="RFC7042" format="default" sectionFormat="of" derivedContent="RFC7042"/> addresses only through the length of the  byte string, making it impossible, for example, to drop trailing zeros in the encoding of IP addresses.  Tag 261 was not documented well enough for use.</t>
      <t indent="0" pn="section-1-2">This specification defines tags 54 and 52 to explicitly
indicate use of IPv6 or IPv4 by the tag number.
These new tags are intended to be used in preference to tags 260 and
261.
They provide formats for IPv6 and IPv4 addresses, prefixes,
and addresses with prefixes, while explicitly indicating use of IPv6 or IPv4.
The prefix format omits trailing zeroes in the address part.
(Due to the complexity of testing, the value of omitting trailing
zeros for the pure address format was considered nonessential, and
support for that is not provided in this specification.)
This specification does not deal with MAC addresses (<xref section="2" sectionFormat="of" target="RFC7042" format="default" derivedLink="https://rfc-editor.org/rfc/rfc7042#section-2" derivedContent="RFC7042"/>).</t>
    </section>
    <section anchor="terminology" numbered="true" toc="include" removeInRFC="false" pn="section-2">
      <name slugifiedName="name-terminology">Terminology</name>
      <t indent="0" pn="section-2-1">The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL</bcp14>
NOT", "<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 14 <xref target="RFC2119" format="default" sectionFormat="of" derivedContent="RFC2119"/> <xref target="RFC8174" format="default" sectionFormat="of" derivedContent="RFC8174"/> when, and only when, they
appear in all capitals, as shown here.</t>
    </section>
    <section anchor="protocol" numbered="true" toc="include" removeInRFC="false" pn="section-3">
      <name slugifiedName="name-protocol">Protocol</name>
      <section anchor="three-forms" numbered="true" toc="include" removeInRFC="false" pn="section-3.1">
        <name slugifiedName="name-three-forms">Three Forms</name>
        <section anchor="addresses" numbered="true" toc="include" removeInRFC="false" pn="section-3.1.1">
          <name slugifiedName="name-addresses">Addresses</name>
          <t indent="0" pn="section-3.1.1-1">These tags can be applied to byte strings to represent a single address.</t>
          <t indent="0" pn="section-3.1.1-2">This form is called the "Address Format".</t>
        </section>
        <section anchor="prefixes" numbered="true" toc="include" removeInRFC="false" pn="section-3.1.2">
          <name slugifiedName="name-prefixes">Prefixes</name>
          <t indent="0" pn="section-3.1.2-1">When applied to an array that starts with an unsigned integer, the tags represent a
CIDR-style prefix of that length.</t>
          <t indent="0" pn="section-3.1.2-2">When the Address Format (i.e., without prefix) appears in a context where a prefix is expected, then it is to be assumed that all bits are relevant.
That is, for IPv4, a /32 is implied, and for IPv6, a /128 is implied.</t>
          <t indent="0" pn="section-3.1.2-3">This form is called the "Prefix Format".</t>
        </section>
        <section anchor="interface-definition" numbered="true" toc="include" removeInRFC="false" pn="section-3.1.3">
          <name slugifiedName="name-interface-definition">Interface Definition</name>
          <t indent="0" pn="section-3.1.3-1">When applied to an array that starts with a byte string, which stands
for an IP address, followed by an unsigned integer giving the bit
length of a prefix built out of the first <tt>length</tt> bits of the
address, the tags represent information that is commonly used to specify
both the network prefix and the IP address of an interface.</t>
          <t indent="0" pn="section-3.1.3-2">The length of the byte string is always 16 bytes (for IPv6) and 4 bytes (for IPv4).</t>
          <t indent="0" pn="section-3.1.3-3">This form is called the "Interface Format".</t>
          <t indent="0" pn="section-3.1.3-4">Interface Format definitions support an optional third element to the array, which is to be used as the IPv6 link-local zone identifier from <xref section="6" sectionFormat="of" target="RFC4007" format="default" derivedLink="https://rfc-editor.org/rfc/rfc4007#section-6" derivedContent="RFC4007"/>;
for symmetry, this is also provided for IPv4 as in <xref target="RFC4001" format="default" sectionFormat="of" derivedContent="RFC4001"/> and <xref target="RFC6991" format="default" sectionFormat="of" derivedContent="RFC6991"/>.
The zone identifier may be an integer, in which case it is to be interpreted as the interface index.
It may be a text string, in which case it is to be interpreted as an interface name.</t>
          <t indent="0" pn="section-3.1.3-5">As explained in <xref target="RFC4007" format="default" sectionFormat="of" derivedContent="RFC4007"/>, the zone identifiers are strictly local to the node.
They are useful for communications within a node about connected addresses (for instance, where a link-local peer is discovered by one daemon and another daemon needs to be informed).
They may also have utility in some management protocols.</t>
          <t indent="0" pn="section-3.1.3-6">In the cases where the Interface Format is being used to represent
only an address with a zone identifier and no interface prefix information, the prefix length may be replaced with the CBOR "null" (0xF6).</t>
        </section>
      </section>
      <section anchor="ipv6" numbered="true" toc="include" removeInRFC="false" pn="section-3.2">
        <name slugifiedName="name-ipv6">IPv6</name>
        <t indent="0" pn="section-3.2-1">IANA has allocated tag 54 for IPv6 uses.
(This is the ASCII code for '6'.)</t>
        <t indent="0" pn="section-3.2-2">An IPv6 address is to be encoded as a sixteen-byte byte string
(<xref section="3.1" sectionFormat="of" target="RFC8949" format="default" derivedLink="https://rfc-editor.org/rfc/rfc8949#section-3.1" derivedContent="RFC8949"/>, major type 2), enclosed in tag number 54.</t>
        <t indent="0" pn="section-3.2-3">For example:</t>
        <artwork name="" type="" align="left" alt="" pn="section-3.2-4">
54(h'20010db81234deedbeefcafefacefeed')
</artwork>
        <t indent="0" pn="section-3.2-5">An IPv6 prefix, such as 2001:db8:1234::/48, is to be encoded as a two-element array, with the length of the prefix first.
See <xref target="validity" format="default" sectionFormat="of" derivedContent="Section 4"/> for the detailed construction of the second element.</t>
        <t indent="0" pn="section-3.2-6">For example:</t>
        <artwork name="" type="" align="left" alt="" pn="section-3.2-7">
54([48, h'20010db81234'])
</artwork>
        <t indent="0" pn="section-3.2-8">An IPv6 address combined with a prefix length, such as one used for
configuring an interface, is to be encoded as a two-element array,
with the (full-length) IPv6 address first and the length of the
associated network the prefix next; a third element can be added for
the zone identifier.</t>
        <t indent="0" pn="section-3.2-9">For example:</t>
        <artwork name="" type="" align="left" alt="" pn="section-3.2-10">
54([h'20010db81234deedbeefcafefacefeed', 56])
</artwork>
        <t indent="0" pn="section-3.2-11">The address-with-prefix form can be reliably distinguished
from the prefix form only in the sequence of the array elements.</t>
        <t indent="0" pn="section-3.2-12">An example of a link-local IPv6 address with a 64-bit prefix:</t>
        <artwork name="" type="" align="left" alt="" pn="section-3.2-13">
54([h'fe8000000000020202fffffffe030303', 64, 'eth0'])
</artwork>
        <t indent="0" pn="section-3.2-14">with a numeric zone identifier:</t>
        <artwork name="" type="" align="left" alt="" pn="section-3.2-15">
54([h'fe8000000000020202fffffffe030303', 64, 42])
</artwork>
        <t indent="0" pn="section-3.2-16">An IPv6 link-local address without a prefix length:</t>
        <artwork name="" type="" align="left" alt="" pn="section-3.2-17">
54([h'fe8000000000020202fffffffe030303', null, 42])
</artwork>
        <t indent="0" pn="section-3.2-18">Zone identifiers may be used with any kind of IP address, not just link-local addresses.
In particular, they are valid for multicast addresses, and there may still be some significance
for Globally Unique Addresses (GUAs).</t>
      </section>
      <section anchor="ipv4" numbered="true" toc="include" removeInRFC="false" pn="section-3.3">
        <name slugifiedName="name-ipv4">IPv4</name>
        <t indent="0" pn="section-3.3-1">IANA has allocated tag 52 for IPv4 uses.
(This is the ASCII code for '4'.)</t>
        <t indent="0" pn="section-3.3-2">An IPv4 address is to be encoded as a four-byte byte string
(<xref section="3.1" sectionFormat="of" target="RFC8949" format="default" derivedLink="https://rfc-editor.org/rfc/rfc8949#section-3.1" derivedContent="RFC8949"/>, major type 2), enclosed in tag number 52.</t>
        <t indent="0" pn="section-3.3-3">For example:</t>
        <artwork name="" type="" align="left" alt="" pn="section-3.3-4">
52(h'c0000201')
</artwork>
        <t indent="0" pn="section-3.3-5">An IPv4 prefix, such as 192.0.2.0/24, is to be encoded as a two-element array, with the length of the prefix first.
See <xref target="validity" format="default" sectionFormat="of" derivedContent="Section 4"/> for the detailed construction of the second element.</t>
        <t indent="0" pn="section-3.3-6">For example:</t>
        <artwork name="" type="" align="left" alt="" pn="section-3.3-7">
52([24, h'c00002'])
</artwork>
        <t indent="0" pn="section-3.3-8">An IPv4 address combined with a prefix length, such as being used for
configuring an interface, is to be encoded as a two-element array,
with the (full-length) IPv4 address first and the length of the
associated network the prefix next; a third element can be added for
the zone identifier.</t>
        <t indent="0" pn="section-3.3-9">For example, 192.0.2.1/24 is to be encoded as a two-element array,
with the length of the prefix (implied 192.0.2.0/24) last.</t>
        <artwork name="" type="" align="left" alt="" pn="section-3.3-10">
52([h'c0000201', 24])
</artwork>
        <t indent="0" pn="section-3.3-11">The address-with-prefix form can be reliably distinguished
from the prefix form only in the sequence of the array elements.</t>
      </section>
    </section>
    <section anchor="validity" numbered="true" toc="include" removeInRFC="false" pn="section-4">
      <name slugifiedName="name-tag-validity">Tag Validity</name>
      <t indent="0" pn="section-4-1">This section discusses when tag 54 or tag 52 is valid (<xref section="5.3.2" sectionFormat="of" target="RFC8949" format="default" derivedLink="https://rfc-editor.org/rfc/rfc8949#section-5.3.2" derivedContent="RFC8949"/>).
As with all CBOR tags, validity checking can be handled in a generic
CBOR library or in the application.
A generic CBOR library needs to document whether and how it handles
validity checking.</t>
      <t indent="0" pn="section-4-2">The rule <tt>ip-address-or-prefix</tt> in <xref target="cddl-types" format="default" sectionFormat="of" derivedContent="Figure 1"/> shows how to check the
overall structure of these tags and their content, the ranges of
integer values, and the lengths of byte strings.
An instance of tag 52 or 54 is valid if it matches that rule and, for
ipv6-prefix and ipv4-prefix, the considerations of Sections
<xref format="counter" target="valid-encoder" sectionFormat="of" derivedContent="4.2"/> and <xref format="counter" target="valid-decoder" sectionFormat="of" derivedContent="4.3"/>.</t>
      <section anchor="deterministic-encoding" numbered="true" toc="include" removeInRFC="false" pn="section-4.1">
        <name slugifiedName="name-deterministic-encoding">Deterministic Encoding</name>
        <t indent="0" pn="section-4.1-1">The tag validity rules, combined with the rules in <xref section="4.2.1" sectionFormat="of" target="RFC8949" format="default" derivedLink="https://rfc-editor.org/rfc/rfc8949#section-4.2.1" derivedContent="RFC8949"/>, lead to deterministic encoding for tags 54 and 52 and require
no further additional deterministic encoding considerations as per
<xref section="4.2.2" sectionFormat="of" target="RFC8949" format="default" derivedLink="https://rfc-editor.org/rfc/rfc8949#section-4.2.2" derivedContent="RFC8949"/>.</t>
      </section>
      <section anchor="valid-encoder" numbered="true" toc="include" removeInRFC="false" pn="section-4.2">
        <name slugifiedName="name-encoder-considerations-for-">Encoder Considerations for Prefixes</name>
        <t indent="0" pn="section-4.2-1">For the byte strings used as the second element in the array
representing a prefix:</t>
        <t indent="0" pn="section-4.2-2">(1) An encoder <bcp14>MUST</bcp14> set any unused bytes and any unused bits in the
	final byte, if any, to zero.
Unused bytes (or bits) are bytes (or bits) that are not covered by the prefix length given.
So, for example, <tt>2001:db8:1230::/44</tt> <bcp14>MUST</bcp14> be encoded as:</t>
        <artwork name="" type="" align="left" alt="" pn="section-4.2-3">
54([44, h'20010db81230'])
</artwork>
        <t indent="0" pn="section-4.2-4">even though variations like:</t>
        <artwork name="" type="" align="left" alt="" pn="section-4.2-5">
54([44, h'20010db81233'])
54([44, h'20010db8123f'])
54([44, h'20010db8123012'])
</artwork>
        <t indent="0" pn="section-4.2-6">start with the same 44 bits but are not valid.</t>
        <t indent="0" pn="section-4.2-7">(Analogous examples can be constructed for IPv4 prefixes.)</t>
        <t indent="0" pn="section-4.2-8">(2) An encoder <bcp14>MUST</bcp14> then omit any right-aligned (trailing) sequence of
bytes in which the bytes are all zeros.</t>
        <t indent="0" pn="section-4.2-9">There is no relationship between the number of bytes omitted and the prefix length.
For instance, the prefix 2001:db8::/64 is encoded as:</t>
        <artwork name="" type="" align="left" alt="" pn="section-4.2-10">
54([64, h'20010db8'])
</artwork>
      </section>
      <section anchor="valid-decoder" numbered="true" toc="include" removeInRFC="false" pn="section-4.3">
        <name slugifiedName="name-decoder-considerations-for-">Decoder Considerations for Prefixes</name>
        <t indent="0" pn="section-4.3-1">A decoder <bcp14>MUST</bcp14> check that all unused bits encoded in the byte string
ipv6-prefix-bytes/ipv4-prefix-bytes, i.e., the bits to the right of
the prefix length, are zero.</t>
        <t indent="0" pn="section-4.3-2">A decoder <bcp14>MUST</bcp14> also check that the byte string does not end in a zero
byte.</t>
        <t indent="0" pn="section-4.3-3">Since encoders are required to remove zero-valued trailing bytes, a
decoder <bcp14>MUST</bcp14> handle cases where a prefix length specifies that more
bits are relevant than are actually present in the byte string.</t>
        <t indent="0" pn="section-4.3-4">As an example, ::/128 is encoded as</t>
        <artwork name="" type="" align="left" alt="" pn="section-4.3-5">
54([128, h''])
</artwork>
        <section anchor="example-implementation" numbered="true" toc="include" removeInRFC="false" pn="section-4.3.1">
          <name slugifiedName="name-example-implementation">Example Implementation</name>
          <t indent="0" pn="section-4.3.1-1">A recommendation for prefix decoder implementations is to first create
	  an array of 16 (or 4) zero bytes.</t>
          <t indent="0" pn="section-4.3.1-2">Then, taking whichever is smaller between (a) the length of the
included byte string and (b) the number of bytes covered by the
prefix length rounded up to the next multiple of 8, fail if that
number is greater than 16 (or 4) and then copy that many bytes from
the byte string into the byte array.</t>
          <t indent="0" pn="section-4.3.1-3">Finally, when looking at the number of unused bits in the last byte (if
any) of the range covered by the prefix length, check that any unused
bits in the byte string are zero:</t>
          <sourcecode type="c" markers="false" pn="section-4.3.1-4">
unused_bits = (8 - (prefix_length_in_bits % 8)) % 8;
if (length_in_bytes &gt; 0 &amp;&amp;
    (address_bytes[length_in_bytes - 1] &amp; ~(0xFF &lt;&lt; unused_bits))
       != 0)
  fail();
</sourcecode>
        </section>
      </section>
    </section>
    <section anchor="cddl" numbered="true" toc="include" removeInRFC="false" pn="section-5">
      <name slugifiedName="name-cddl">CDDL</name>
      <t indent="0" pn="section-5-1">For use with Concise Data Definition Language (CDDL) <xref target="RFC8610" format="default" sectionFormat="of" derivedContent="RFC8610"/>, the type names defined in <xref target="cddl-types" format="default" sectionFormat="of" derivedContent="Figure 1"/>
are recommended:</t>
      <figure anchor="cddl-types" align="left" suppress-title="false" pn="figure-1">
        <name slugifiedName="name-cddl-types-for-tags-54-and-">CDDL Types for Tags 54 and 52</name>
        <sourcecode type="cddl" markers="false" pn="section-5-2.1">
ip-address-or-prefix = ipv6-address-or-prefix /
                       ipv4-address-or-prefix

ipv6-address-or-prefix = #6.54(ipv6-address /
                               ipv6-address-with-prefix /
                               ipv6-prefix)
ipv4-address-or-prefix = #6.52(ipv4-address /
                               ipv4-address-with-prefix /
                               ipv4-prefix)

ipv6-address = bytes .size 16
ipv4-address = bytes .size 4

ipv6-address-with-prefix = [ipv6-address,
                            ipv6-prefix-length / null,
                            ?ip-zone-identifier]
ipv4-address-with-prefix = [ipv4-address,
                            ipv4-prefix-length / null,
                            ?ip-zone-identifier]

ipv6-prefix-length = 0..128
ipv4-prefix-length = 0..32

ipv6-prefix = [ipv6-prefix-length, ipv6-prefix-bytes]
ipv4-prefix = [ipv4-prefix-length, ipv4-prefix-bytes]

ipv6-prefix-bytes = bytes .size (uint .le 16)
ipv4-prefix-bytes = bytes .size (uint .le 4)

ip-zone-identifier = uint / text

</sourcecode>
      </figure>
    </section>
    <section anchor="security-considerations" numbered="true" toc="include" removeInRFC="false" pn="section-6">
      <name slugifiedName="name-security-considerations">Security Considerations</name>
      <t indent="0" pn="section-6-1">This document provides a CBOR encoding for IPv4 and IPv6 address information.
Any applications using these encodings will need to consider the security
implications of this data in their specific context.  For example, identifying
which byte sequences in a protocol are addresses may allow an attacker or
eavesdropper to better understand what parts of a packet to attack.</t>
      <t indent="0" pn="section-6-2">Applications need to check the validity (<xref target="validity" format="default" sectionFormat="of" derivedContent="Section 4"/>) of a tag before
acting on any of its contents.
If the validity checking is not done in the generic CBOR decoder, it
needs to be done in the application; in any case, it needs to be done
before the tag is transformed into a platform-specific representation
that could conceal validity errors.</t>
      <t indent="0" pn="section-6-3">The right-hand bits of the prefix, after the prefix length, are set to
zero by this protocol.
(Otherwise, a malicious party could use them to transmit covert data
in a way that would not affect the primary use of this encoding.
Such abuse is detected by tag validity checking and can also be
detected by examination of the raw protocol bytes.)</t>
    </section>
    <section anchor="iana-considerations" numbered="true" toc="include" removeInRFC="false" pn="section-7">
      <name slugifiedName="name-iana-considerations">IANA Considerations</name>
      <t indent="0" pn="section-7-1">IANA has allocated two tags from the Specification Required <xref target="RFC8126" format="default" sectionFormat="of" derivedContent="RFC8126"/> area of
the "Concise Binary Object Representation (CBOR) Tags" registry <xref target="IANA.cbor-tags" format="default" sectionFormat="of" derivedContent="IANA.cbor-tags"/>:</t>
      <section anchor="tag-54-ipv6" numbered="true" toc="include" removeInRFC="false" pn="section-7.1">
        <name slugifiedName="name-tag-54-ipv6">Tag 54 - IPv6</name>
        <dl spacing="compact" indent="3" newline="false" pn="section-7.1-1">
          <dt pn="section-7.1-1.1">Data Item:</dt>
          <dd pn="section-7.1-1.2"> byte string or array</dd>
          <dt pn="section-7.1-1.3">Semantics:</dt>
          <dd pn="section-7.1-1.4"> IPv6, [prefixlen,IPv6], [IPv6,prefixpart]</dd>
        </dl>
      </section>
      <section anchor="tag-52-ipv4" numbered="true" toc="include" removeInRFC="false" pn="section-7.2">
        <name slugifiedName="name-tag-52-ipv4">Tag 52 - IPv4</name>
        <dl spacing="compact" indent="3" newline="false" pn="section-7.2-1">
          <dt pn="section-7.2-1.1">Data Item:</dt>
          <dd pn="section-7.2-1.2"> byte string or array</dd>
          <dt pn="section-7.2-1.3">Semantics:</dt>
          <dd pn="section-7.2-1.4"> IPv4, [prefixlen,IPv4], [IPv4,prefixpart]</dd>
        </dl>
      </section>
      <section anchor="tags-260-and-261" numbered="true" toc="include" removeInRFC="false" pn="section-7.3">
        <name slugifiedName="name-tags-260-and-261">Tags 260 and 261</name>
        <t indent="0" pn="section-7.3-1">IANA has added the note "DEPRECATED in favor of 52 and 54 for IP addresses" to registrations 260 and 261.</t>
      </section>
    </section>
  </middle>
  <back>
    <references pn="section-8">
      <name slugifiedName="name-references">References</name>
      <references pn="section-8.1">
        <name slugifiedName="name-normative-references">Normative References</name>
        <reference anchor="RFC2119" target="https://www.rfc-editor.org/info/rfc2119" quoteTitle="true" derivedAnchor="RFC2119">
          <front>
            <title>Key words for use in RFCs to Indicate Requirement Levels</title>
            <author initials="S." surname="Bradner" fullname="S. Bradner">
              <organization showOnFrontPage="true"/>
            </author>
            <date year="1997" month="March"/>
            <abstract>
              <t indent="0">In many standards track documents several words are used to signify the requirements in the specification.  These words are often capitalized. This document defines these words as they should be interpreted in IETF documents.  This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t>
            </abstract>
          </front>
          <seriesInfo name="BCP" value="14"/>
          <seriesInfo name="RFC" value="2119"/>
          <seriesInfo name="DOI" value="10.17487/RFC2119"/>
        </reference>
        <reference anchor="RFC8126" target="https://www.rfc-editor.org/info/rfc8126" quoteTitle="true" derivedAnchor="RFC8126">
          <front>
            <title>Guidelines for Writing an IANA Considerations Section in RFCs</title>
            <author initials="M." surname="Cotton" fullname="M. Cotton">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="B." surname="Leiba" fullname="B. Leiba">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="T." surname="Narten" fullname="T. Narten">
              <organization showOnFrontPage="true"/>
            </author>
            <date year="2017" month="June"/>
            <abstract>
              <t indent="0">Many protocols make use of points of extensibility that use constants to identify various protocol parameters.  To ensure that the values in these fields do not have conflicting uses and to promote interoperability, their allocations are often coordinated by a central record keeper.  For IETF protocols, that role is filled by the Internet Assigned Numbers Authority (IANA).</t>
              <t indent="0">To make assignments in a given registry prudently, guidance describing the conditions under which new values should be assigned, as well as when and how modifications to existing values can be made, is needed.  This document defines a framework for the documentation of these guidelines by specification authors, in order to assure that the provided guidance for the IANA Considerations is clear and addresses the various issues that are likely in the operation of a registry.</t>
              <t indent="0">This is the third edition of this document; it obsoletes RFC 5226.</t>
            </abstract>
          </front>
          <seriesInfo name="BCP" value="26"/>
          <seriesInfo name="RFC" value="8126"/>
          <seriesInfo name="DOI" value="10.17487/RFC8126"/>
        </reference>
        <reference anchor="RFC8174" target="https://www.rfc-editor.org/info/rfc8174" quoteTitle="true" derivedAnchor="RFC8174">
          <front>
            <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
            <author initials="B." surname="Leiba" fullname="B. Leiba">
              <organization showOnFrontPage="true"/>
            </author>
            <date year="2017" month="May"/>
            <abstract>
              <t indent="0">RFC 2119 specifies common key words that may be used in protocol  specifications.  This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the  defined special meanings.</t>
            </abstract>
          </front>
          <seriesInfo name="BCP" value="14"/>
          <seriesInfo name="RFC" value="8174"/>
          <seriesInfo name="DOI" value="10.17487/RFC8174"/>
        </reference>
        <reference anchor="RFC8610" target="https://www.rfc-editor.org/info/rfc8610" quoteTitle="true" derivedAnchor="RFC8610">
          <front>
            <title>Concise Data Definition Language (CDDL): A Notational Convention to Express Concise Binary Object Representation (CBOR) and JSON Data Structures</title>
            <author initials="H." surname="Birkholz" fullname="H. Birkholz">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="C." surname="Vigano" fullname="C. Vigano">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="C." surname="Bormann" fullname="C. Bormann">
              <organization showOnFrontPage="true"/>
            </author>
            <date year="2019" month="June"/>
            <abstract>
              <t indent="0">This document proposes a notational convention to express Concise Binary Object Representation (CBOR) data structures (RFC 7049).  Its main goal is to provide an easy and unambiguous way to express structures for protocol messages and data formats that use CBOR or JSON.</t>
            </abstract>
          </front>
          <seriesInfo name="RFC" value="8610"/>
          <seriesInfo name="DOI" value="10.17487/RFC8610"/>
        </reference>
        <reference anchor="RFC8949" target="https://www.rfc-editor.org/info/rfc8949" quoteTitle="true" derivedAnchor="RFC8949">
          <front>
            <title>Concise Binary Object Representation (CBOR)</title>
            <author initials="C." surname="Bormann" fullname="C. Bormann">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="P." surname="Hoffman" fullname="P. Hoffman">
              <organization showOnFrontPage="true"/>
            </author>
            <date year="2020" month="December"/>
            <abstract>
              <t indent="0">The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely small code size, fairly small message size, and extensibility without the need for version negotiation. These design goals make it different from earlier binary serializations such as ASN.1 and MessagePack.</t>
              <t indent="0">This document obsoletes RFC 7049, providing editorial improvements, new details, and errata fixes while keeping full compatibility with the interchange format of RFC 7049.  It does not create a new version of the format.</t>
            </abstract>
          </front>
          <seriesInfo name="STD" value="94"/>
          <seriesInfo name="RFC" value="8949"/>
          <seriesInfo name="DOI" value="10.17487/RFC8949"/>
        </reference>
      </references>
      <references pn="section-8.2">
        <name slugifiedName="name-informative-references">Informative References</name>
        <reference anchor="IANA.cbor-tags" target="https://www.iana.org/assignments/cbor-tags" quoteTitle="true" derivedAnchor="IANA.cbor-tags">
          <front>
            <title>Concise Binary Object Representation (CBOR) Tags</title>
            <author>
              <organization showOnFrontPage="true">IANA</organization>
            </author>
            <date/>
          </front>
        </reference>
        <reference anchor="RFC4001" target="https://www.rfc-editor.org/info/rfc4001" quoteTitle="true" derivedAnchor="RFC4001">
          <front>
            <title>Textual Conventions for Internet Network Addresses</title>
            <author initials="M." surname="Daniele" fullname="M. Daniele">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="B." surname="Haberman" fullname="B. Haberman">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="S." surname="Routhier" fullname="S. Routhier">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="J." surname="Schoenwaelder" fullname="J. Schoenwaelder">
              <organization showOnFrontPage="true"/>
            </author>
            <date year="2005" month="February"/>
            <abstract>
              <t indent="0">This MIB module defines textual conventions to represent commonly used Internet network layer addressing information.  The intent is that these textual conventions will be imported and used in MIB modules that would otherwise define their own representations.  [STANDARDS-TRACK]</t>
            </abstract>
          </front>
          <seriesInfo name="RFC" value="4001"/>
          <seriesInfo name="DOI" value="10.17487/RFC4001"/>
        </reference>
        <reference anchor="RFC4007" target="https://www.rfc-editor.org/info/rfc4007" quoteTitle="true" derivedAnchor="RFC4007">
          <front>
            <title>IPv6 Scoped Address Architecture</title>
            <author initials="S." surname="Deering" fullname="S. Deering">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="B." surname="Haberman" fullname="B. Haberman">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="T." surname="Jinmei" fullname="T. Jinmei">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="E." surname="Nordmark" fullname="E. Nordmark">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="B." surname="Zill" fullname="B. Zill">
              <organization showOnFrontPage="true"/>
            </author>
            <date year="2005" month="March"/>
            <abstract>
              <t indent="0">This document specifies the architectural characteristics, expected behavior, textual representation, and usage of IPv6 addresses of different scopes.  According to a decision in the IPv6 working group, this document intentionally avoids the syntax and usage of unicast site-local addresses.  [STANDARDS-TRACK]</t>
            </abstract>
          </front>
          <seriesInfo name="RFC" value="4007"/>
          <seriesInfo name="DOI" value="10.17487/RFC4007"/>
        </reference>
        <reference anchor="RFC6991" target="https://www.rfc-editor.org/info/rfc6991" quoteTitle="true" derivedAnchor="RFC6991">
          <front>
            <title>Common YANG Data Types</title>
            <author initials="J." surname="Schoenwaelder" fullname="J. Schoenwaelder" role="editor">
              <organization showOnFrontPage="true"/>
            </author>
            <date year="2013" month="July"/>
            <abstract>
              <t indent="0">This document introduces a collection of common data types to be used with the YANG data modeling language.  This document obsoletes RFC 6021.</t>
            </abstract>
          </front>
          <seriesInfo name="RFC" value="6991"/>
          <seriesInfo name="DOI" value="10.17487/RFC6991"/>
        </reference>
        <reference anchor="RFC7042" target="https://www.rfc-editor.org/info/rfc7042" quoteTitle="true" derivedAnchor="RFC7042">
          <front>
            <title>IANA Considerations and IETF Protocol and Documentation Usage for IEEE 802 Parameters</title>
            <author initials="D." surname="Eastlake 3rd" fullname="D. Eastlake 3rd">
              <organization showOnFrontPage="true"/>
            </author>
            <author initials="J." surname="Abley" fullname="J. Abley">
              <organization showOnFrontPage="true"/>
            </author>
            <date year="2013" month="October"/>
            <abstract>
              <t indent="0">Some IETF protocols make use of Ethernet frame formats and IEEE 802 parameters.  This document discusses several uses of such parameters in IETF protocols, specifies IANA considerations for assignment of points under the IANA OUI (Organizationally Unique Identifier), and provides some values for use in documentation. This document obsoletes RFC 5342.</t>
            </abstract>
          </front>
          <seriesInfo name="BCP" value="141"/>
          <seriesInfo name="RFC" value="7042"/>
          <seriesInfo name="DOI" value="10.17487/RFC7042"/>
        </reference>
      </references>
    </references>
    <section numbered="false" anchor="acknowledgements" toc="include" removeInRFC="false" pn="section-appendix.a">
      <name slugifiedName="name-acknowledgements">Acknowledgements</name>
      <t indent="0" pn="section-appendix.a-1"><contact fullname="Roman Danyliw"/>, <contact fullname="Donald Eastlake"/>, <contact fullname="Ben Kaduk"/>, <contact fullname="Barry Leiba"/>, and <contact fullname="Éric Vyncke"/> reviewed the document and provided suggested text.
<contact fullname="Jürgen Schönwälder"/> helped find the history of IPv4 zone identifiers.</t>
    </section>
    <section anchor="authors-addresses" numbered="false" removeInRFC="false" toc="include" pn="section-appendix.b">
      <name slugifiedName="name-authors-addresses">Authors' Addresses</name>
      <author initials="M." surname="Richardson" fullname="Michael Richardson">
        <organization showOnFrontPage="true">Sandelman Software Works</organization>
        <address>
          <email>mcr+ietf@sandelman.ca</email>
        </address>
      </author>
      <author initials="C." surname="Bormann" fullname="Carsten Bormann">
        <organization showOnFrontPage="true">Universität Bremen TZI</organization>
        <address>
          <postal>
            <country>Germany</country>
          </postal>
          <email>cabo@tzi.org</email>
        </address>
      </author>
    </section>
  </back>
</rfc>
