RFC 9164

Concise Binary Object Representation (CBOR) Tags for IPv4 and IPv6 Addresses and Prefixes

πŸ“… published December 2021, from ietf

RFC 9164: CBOR Tags for IPv4 and IPv6 Addresses and Prefixes ✨

  • Title: Concise Binary Object Representation (CBOR) Tags for IPv4 and IPv6 Addresses and Prefixes πŸŽ€
  • Authors: M. Richardson (Sandelman Software Works) and C. Bormann (UniversitΓ€t Bremen TZI) πŸ’œ
  • Stream: IETF 🌸
  • Category: Standards Track πŸ‘‘
  • ISSN: 2070-1721
  • Date: December 2021 πŸ“…
  • Obsoletes / Updates: the title block doesn't list anything this one obsoletes or updates πŸ™ˆ

Abstract

okay so this spec defines two CBOR tags πŸ¦‹ for IPv6 and IPv4 addresses and prefixes. that's the whole pitch, bestie πŸ’–

Status of This Memo

this is an Internet Standards Track document ✨

it's a product of the Internet Engineering Task Force (IETF) 🌈. it represents the consensus of the IETF community, it got public review, and the Internet Engineering Steering Group (IESG) approved it for publication 🫢. if you want more on Internet Standards, check Section 2 of RFC 7841 πŸ’….

for the current status, any errata, and how to send feedback, head to https://www.rfc-editor.org/info/rfc9164 πŸ”₯.

Copyright (c) 2021 IETF Trust and the persons identified as the document authors. All rights reserved πŸ’œ.

this doc is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) as they stood on the publication date πŸ“œ. read them carefully, bestie, because they spell out your rights and restrictions for this document. any Code Components pulled out of this document must include Revised BSD License text, as described in Section 4.e of the Trust Legal Provisions, and they come without warranty, per the Revised BSD License 🌸.

Table of Contents

   1.  Introduction
   2.  Terminology
   3.  Protocol
     3.1.  Three Forms
       3.1.1.  Addresses
       3.1.2.  Prefixes
       3.1.3.  Interface Definition
     3.2.  IPv6
     3.3.  IPv4
   4.  Tag Validity
     4.1.  Deterministic Encoding
     4.2.  Encoder Considerations for Prefixes
     4.3.  Decoder Considerations for Prefixes
       4.3.1.  Example Implementation
   5.  CDDL
   6.  Security Considerations
   7.  IANA Considerations
     7.1.  Tag 54 - IPv6
     7.2.  Tag 52 - IPv4
     7.3.  Tags 260 and 261
   8.  References
     8.1.  Normative References
     8.2.  Informative References
   Acknowledgements
   Authors' Addresses

1. Introduction 🧚

okay so [RFC8949] already defines a bunch of CBOR tags for common stuff πŸ’…. tags 260 and 261 came later, in documents listed with IANA [IANA.cbor-tags] ✨. they were supposed to cover addresses (260) and prefixes (261).

here's the tea β˜•: tag 260 tells IPv6, IPv4, and MAC [RFC7042] addresses apart only by the length of the byte string πŸ™ˆ. so you literally can't drop trailing zeros when you encode an IP address, which is kinda a problem. tag 261 also never got documented well enough to actually use πŸ’€.

so this spec defines tags 54 and 52 πŸ¦‹, which explicitly say whether you've got IPv6 or IPv4 just from the tag number. these are the ones you should reach for instead of 260 and 261 πŸ’–. they give you formats for IPv6 and IPv4 addresses, prefixes, and addresses with prefixes, and they make it clear which family you're using πŸ‘‘. the prefix format omits trailing zeroes in the address part πŸ“. (the pure address format doesn't get that trailing-zero trick. testing it was complicated, so it was considered nonessential and this spec doesn't support it πŸ™ƒ.) and no, this spec doesn't cover MAC addresses (Section 2 of [RFC7042]) 🫢.

2. Terminology πŸ“–

so here's the key-word rule πŸ”₯. the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document get read as described in BCP 14 [RFC2119] [RFC8174], but only when they show up in all capitals, exactly like that πŸ’œ. lowercase versions are just regular words, bestie 🌈.

3. Protocol πŸŽ€

3.1. Three Forms ✨

3.1.1. Addresses πŸ¦‹

these tags can go on byte strings to represent a single address πŸ’–.

this form is called the "Address Format" πŸ“¦.

3.1.2. Prefixes 🌸

when the tags land on an array that starts with an unsigned integer, they represent a CIDR-style prefix of that length πŸ‘‘.

when the Address Format (so, without a prefix) shows up somewhere a prefix is expected, you assume all the bits are relevant πŸ”₯. for IPv4 that means a /32 is implied, and for IPv6 it means a /128 πŸ™Œ.

this form is called the "Prefix Format" πŸ’….

3.1.3. Interface Definition πŸ§šβ€β™€οΈ

when the tags go on an array that starts with a byte string (an IP address), followed by an unsigned integer giving the bit length of a prefix built from the first length bits of the address, they carry the info people usually use to specify both the network prefix and the IP address of an interface πŸ’œ.

the byte string is always 16 bytes long for IPv6 and 4 bytes long for IPv4 🌈.

this form is called the "Interface Format" ✨.

Interface Format definitions can take an optional third element in the array πŸŽ€. it's the IPv6 link-local zone identifier from Section 6 of [RFC4007]. for symmetry, IPv4 gets it too, as in [RFC4001] and [RFC6991] πŸ¦‹. the zone identifier can be an integer, in which case it gets interpreted as the interface index. it can also be a text string, in which case it gets interpreted as an interface name πŸ“.

as [RFC4007] explains, zone identifiers are strictly local to the node 🏠. they're useful for talking within a node about connected addresses (like when one daemon finds a link-local peer and another daemon needs to hear about it) 🫢. they might also come in handy in some management protocols ✨.

when the Interface Format is only representing an address with a zone identifier and no interface prefix info, the prefix length may get swapped out for the CBOR "null" (0xF6) πŸ’€.

3.2. IPv6 πŸ’–

IANA gave tag 54 to IPv6 uses πŸ‘‘. (fun fact: that's the ASCII code for '6' πŸ™ˆ.)

an IPv6 address gets encoded as a sixteen-byte byte string (Section 3.1 of [RFC8949], major type 2), wrapped in tag number 54 πŸ¦‹.

for example:

54(h'20010db81234deedbeefcafefacefeed')

an IPv6 prefix, like 2001:db8:1234::/48, gets encoded as a two-element array, with the prefix length first 🌸. see Section 4 for how to build the second element in detail πŸ“–.

for example:

54([48, h'20010db81234'])

an IPv6 address combined with a prefix length (the kind you'd use to configure an interface) gets encoded as a two-element array 🧚. the full-length IPv6 address goes first, and the length of the associated network prefix comes next. you can add a third element for the zone identifier πŸŽ€.

for example:

54([h'20010db81234deedbeefcafefacefeed', 56])

the address-with-prefix form and the prefix form can only be told apart by the order of the array elements πŸ’….

here's a link-local IPv6 address with a 64-bit prefix ✨:

54([h'fe8000000000020202fffffffe030303', 64, 'eth0'])

and with a numeric zone identifier 🌈:

54([h'fe8000000000020202fffffffe030303', 64, 42])

here's an IPv6 link-local address without a prefix length 🫢:

54([h'fe8000000000020202fffffffe030303', null, 42])

zone identifiers can go with any kind of IP address, not just link-local ones πŸ’œ. in particular they're valid for multicast addresses, and they may still matter for Globally Unique Addresses (GUAs) πŸ‘‘.

3.3. IPv4 🌸

IANA gave tag 52 to IPv4 uses πŸ¦‹. (that's the ASCII code for '4' πŸ’–.)

an IPv4 address gets encoded as a four-byte byte string (Section 3.1 of [RFC8949], major type 2), wrapped in tag number 52 ✨.

for example:

52(h'c0000201')

an IPv4 prefix, like 192.0.2.0/24, gets encoded as a two-element array, with the prefix length first πŸŽ€. see Section 4 for how to build the second element πŸ“–.

for example:

52([24, h'c00002'])

an IPv4 address combined with a prefix length (like the ones used to configure an interface) gets encoded as a two-element array 🧚. the full-length IPv4 address goes first, and the length of the associated network prefix comes next. a third element can be added for the zone identifier 🌈.

for example, 192.0.2.1/24 gets encoded as a two-element array, with the prefix length (implied 192.0.2.0/24) last πŸ“.

52([h'c0000201', 24])

again, the address-with-prefix form and the prefix form can only be told apart by the order of the array elements πŸ’….

4. Tag Validity πŸ”

this section covers when tag 54 or tag 52 is valid (Section 5.3.2 of [RFC8949]) πŸ’œ. like with all CBOR tags, validity checking can happen in a generic CBOR library or in the application 🫢. a generic CBOR library needs to document whether and how it does validity checking πŸ“œ.

the ip-address-or-prefix rule in 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 in Sections 4.2 and 4.3 are also met πŸ¦‹.

4.1. Deterministic Encoding 🧚

the tag validity rules, together with the rules in Section 4.2.1 of [RFC8949], lead to deterministic encoding for tags 54 and 52. they don't need any extra deterministic encoding considerations, per Section 4.2.2 of [RFC8949] πŸ’–.

4.2. Encoder Considerations for Prefixes πŸŽ€

for the byte strings used as the second element in the array that represents a prefix πŸ“:

(1) An encoder MUST set any unused bytes and any unused bits in the final byte, if any, to zero. unused bytes (or bits) are the ones not covered by the given prefix length πŸ™ˆ. so, for example, 2001:db8:1230::/44 MUST be encoded as:

54([44, h'20010db81230'])

even though variations like these ✨:

54([44, h'20010db81233'])
54([44, h'20010db8123f'])
54([44, h'20010db8123012'])

start with the same 44 bits, they are not valid πŸ’€.

(Analogous examples can be built for IPv4 prefixes 🌸.)

(2) An encoder MUST then omit any right-aligned (trailing) sequence of bytes where all the bytes are zeros 🫢.

there's no relationship between the number of bytes omitted and the prefix length πŸ™ƒ. for instance, the prefix 2001:db8::/64 gets encoded as:

54([64, h'20010db8'])

4.3. Decoder Considerations for Prefixes πŸ”₯

A decoder MUST 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 πŸ’….

A decoder MUST also check that the byte string does not end in a zero byte 🌈.

encoders are required to remove zero-valued trailing bytes, so a decoder MUST handle cases where a prefix length says more bits are relevant than are actually present in the byte string 🧚. that's the trade-off, bestie πŸ’œ.

as an example, ::/128 gets encoded as:

54([128, h''])

✨ to be continued in part 2 ✨

4.3.1. Example Implementation

okay bestie, here's the suggested move for prefix decoders 🧸✨. Start by making an array of 16 (or 4) zero bytes.

Next, look at two numbers and grab whichever one is smaller: (a) the length of the included byte string, or (b) the number of bytes covered by the prefix length, rounded up to the next multiple of 8. If that number is greater than 16 (or 4), fail πŸ™…β€β™€οΈ. Otherwise, copy that many bytes from the byte string into the byte array.

Last step, the bit-check glow-up πŸ’…. Look at the unused bits in the last byte (if there are any) of the range covered by the prefix length, and make sure any unused bits in the byte string are zero:

unused_bits = (8 - (prefix_length_in_bits % 8)) % 8;
if (length_in_bytes > 0 &&
    (address_bytes[length_in_bytes - 1] & ~(0xFF << unused_bits))
       != 0)
  fail();

5. CDDL πŸŽ€

For use with Concise Data Definition Language (CDDL) [RFC8610], the type names defined in Figure 1 are recommended πŸ“:

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

               Figure 1: CDDL Types for Tags 54 and 52

6. Security Considerations 🚨

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 πŸ‘€.

Applications need to check the validity (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 πŸ™ˆ.

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 πŸ’€.

7. IANA Considerations 🌸

IANA has allocated two tags from the Specification Required [RFC8126] area of the "Concise Binary Object Representation (CBOR) Tags" registry [IANA.cbor-tags]:

7.1. Tag 54 - IPv6

Data Item:  byte string or array
Semantics:  IPv6, [prefixlen,IPv6], [IPv6,prefixpart]

7.2. Tag 52 - IPv4

Data Item:  byte string or array
Semantics:  IPv4, [prefixlen,IPv4], [IPv4,prefixpart]

7.3. Tags 260 and 261

IANA has added the note "DEPRECATED in favor of 52 and 54 for IP addresses" to registrations 260 and 261. Those older tags are officially retired in favor of the new ones πŸ¦‹.


8. References πŸ“š

8.1. Normative References

8.2. Informative References


Acknowledgements πŸ’œ

Roman Danyliw, Donald Eastlake, Ben Kaduk, Barry Leiba, and Γ‰ric Vyncke reviewed the document and provided suggested text. JΓΌrgen SchΓΆnwΓ€lder helped find the history of IPv4 zone identifiers. Huge thanks to everyone, you're all iconic 🫢✨.

Authors' Addresses 🧚

Michael Richardson Sandelman Software Works

Email: mcr+ietf@sandelman.ca

Carsten Bormann UniversitΓ€t Bremen TZI Germany

Email: cabo@tzi.org

πŸ“¦ where this page comes from