From 309f2878e4a8ca5316526a72f714f1e937a54a16 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Sat, 21 Sep 2024 12:06:05 +0200 Subject: [PATCH] Add RFC1035-like name compression --- draft-lenders-dns-cbor.md | 54 ++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/draft-lenders-dns-cbor.md b/draft-lenders-dns-cbor.md index bf6b200..f59e6de 100644 --- a/draft-lenders-dns-cbor.md +++ b/draft-lenders-dns-cbor.md @@ -147,11 +147,50 @@ or resource record. {:cddl: sourcecode-name="dns-cbor.cddl"} ~~~ cddl -domain-name = (+ label) +domain-name = ( + + label, + ? #6.TBDt(uint), +) label = tstr ~~~ {:cddl #fig:domain-name title="Domain Name Definition"} +### Name Compression {#sec:name-compression} + +For name compression, a tag TBDt encapsulating an unsigned integer _i_ can be appended to the sequence of text strings. +To extend the name, the unsigned integer _i_ points to the _i_-th text string (counted depth first) in the overall DNS message. +That string and all strings or another tag TBDt following the _i_-th string are appended to the domain. +If another tag TBDt is encountered it is resolved in the same way. +Strings following a tag TBDt MUST NOT be appended to the domain name. +To prevent circular references, the DNS name suffix extension algorithm should error whenever a string is +encountered more than once during the extension of a name. +Decompression stops when any other type than a text string or any other tag than tag TBDt are +encountered. +The pseudo-code for this DNS name suffix extension algorithm can be seen in {{fig:decode-name}}. + +~~~ +function decode_name(cbor_pointer: cbor_major_type) -> array +{ + name: array = [] + visited: set = [] + while (typeof(cbor_pointer) in [tstr, tag]): + if typeof(cbor_pointer) == tag: + if tag_number(cbor_pointer) != TBDt: + break + i: uint = tag_value(cbor_pointer) + cbor_pointer = go to i-th string (depth first) in CBOR object + if cbor_pointer in visited: + return ERROR("Circular reference") + # cbor_pointer should be of type tstr at this point + name.append(cbor_pointer) + visited.add(cbor_pointer) + return name +} +~~~ +{: #fig:decode-name title="Name Suffix Extension Algorithm"} + +The tag TBDt is included in the definition in {{fig:domain-name}}. + ## DNS Resource Records {#sec:rr} This document specifies the representation of both standard DNS resource records (RRs, see {{-dns}}) @@ -501,10 +540,12 @@ dns-response = [ ~~~ {:cddl #fig:dns-response title="DNS Response Definition"} -# Name and Address Compression with CBOR-packed +# Further Compression with CBOR-packed -If both DNS server and client support CBOR-packed {{-cbor-packed}}, it MAY be used for name and -address compression in DNS responses. +If both DNS server and client support CBOR-packed {{-cbor-packed}}, it MAY be used for further +compression in DNS responses. +Especially IPv6 addresses in, e.g., AAAA resource records can benefit from straight referencing to +compress common address prefixes. ## Media Type Negotiation @@ -723,8 +764,9 @@ Reference: \[TBD-this-spec\] In the registry "{{cbor-tags (CBOR Tags)