Skip to content

Commit

Permalink
Additional rr types (#246)
Browse files Browse the repository at this point in the history
  * DSYNC RR type
  * Support for the EID and NIMLOC RR types
  * Support for SINK, TALINK and DOA RR types
  * CDS and CDNSKEY DNSSEC Delete Algorithm
    Which allows '0' to indicate no keying material.
    Also, empty DOA-DATA can be specified with a '-', but '0' is also accepted for backwards compatibility.
  * ATMA RR type
  * AMTRELAY RR type
  * IPN RR type
  • Loading branch information
wtoorop authored Jan 23, 2025
1 parent 3becf25 commit 80f5f44
Show file tree
Hide file tree
Showing 16 changed files with 1,093 additions and 98 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support for EID, NIMLOC, SINK, TALINK, DSYNC, DOA, AMTRELAY and IPN RR types.

### Fixed

- Empty base16 and base64 in CDS and CDNSKEY can be represented with a '0'.
As specified in Section 4 of RFC 8078.

## [0.2.1] - 2025-01-17

Expand Down
18 changes: 18 additions & 0 deletions include/zone.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ extern "C" {
#define ZONE_TYPE_LOC (29u)
/** Next domain @rfc{3755} @rfc{2535} @obsolete */
#define ZONE_TYPE_NXT (30u)
/** Endpoint Identifier */
#define ZONE_TYPE_EID (31u)
/** Nimrod Locator */
#define ZONE_TYPE_NIMLOC (32u)
/** Server Selection @rfc{2782} */
#define ZONE_TYPE_SRV (33u)
/** ATM Address */
#define ZONE_TYPE_ATMA (34u)
/** Naming Authority Pointer @rfc{2915} @rfc{2168} @rfc{3403} */
#define ZONE_TYPE_NAPTR (35u)
/** Key Exchanger @rfc{2230} */
Expand All @@ -131,6 +137,8 @@ extern "C" {
#define ZONE_TYPE_A6 (38u)
/** DNAME @rfc{6672} */
#define ZONE_TYPE_DNAME (39u)
/** SINK @draft{eastlake, kitchen-sink} */
#define ZONE_TYPE_SINK (40u)
/** Address Prefix List @rfc{3123} */
#define ZONE_TYPE_APL (42u)
/** Delegation Signer @rfc{4034} @rfc{3658} */
Expand Down Expand Up @@ -161,6 +169,8 @@ extern "C" {
#define ZONE_TYPE_NINFO (56u)
/** RKEY */
#define ZONE_TYPE_RKEY (57u)
/** Trust Anchor LINK @draft{ietf, dnsop-dnssec-trust-history} */
#define ZONE_TYPE_TALINK (58u)
/** Child DS @rfc{7344} */
#define ZONE_TYPE_CDS (59u)
/** DNSKEY(s) the Child wants reflected in DS @rfc{7344} */
Expand All @@ -176,6 +186,8 @@ extern "C" {
/** Service binding @rfc{9460} */
#define ZONE_TYPE_HTTPS (65u)
/** Sender Policy Framework @rfc{7208} */
#define ZONE_TYPE_DSYNC (66u)
/** Endpoint discovery for delegation synchronization @draft{ietf, dnsop-generalized-notify} */
#define ZONE_TYPE_SPF (99u)
/** Node Identifier @rfc{6742} */
#define ZONE_TYPE_NID (104u)
Expand All @@ -195,12 +207,18 @@ extern "C" {
#define ZONE_TYPE_CAA (257u)
/** DNS Authoritative Source (DNS-AS) */
#define ZONE_TYPE_AVC (258u)
/** Digital Object Architecture @draft{durand, doa-over-dns} */
#define ZONE_TYPE_DOA (259u)
/** Automatic Multicast Tunneling Relay @rfc{8777} */
#define ZONE_TYPE_AMTRELAY (260u)
/** Resolver Information as Key/Value Pairs @rfc{9606} */
#define ZONE_TYPE_RESINFO (261u)
/** Public wallet address */
#define ZONE_TYPE_WALLET (262u)
/** BP Convergence Layer Adapter */
#define ZONE_TYPE_CLA (263u)
/** BP Node Number */
#define ZONE_TYPE_IPN (264u)
/** DNSSEC Trust Authorities */
#define ZONE_TYPE_TA (32768u)
/** DNSSEC Lookaside Validation @rfc{4431} @obsolete */
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-RR-types.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ RECORDS=`xmlstarlet select --template --match "/_:registry/_:registry[@id='dns-p
rm ${TEMPFILE}
for RECORD in ${RECORDS}
do
TYPE=`echo ${RECORD} | awk -F# '{ print $1 }'`
TYPE=`echo ${RECORD} | awk -F# '{ print $1 }'|sed 's/-/_/g'`
VALUE=`echo ${RECORD} | awk -F# '{ print $2 }'`
RECORD_TYPE=`echo ${RECORD} | awk -F# '{ print $3 }'`
RECORD_REF=`echo ${RECORD} | awk -F# '{ print $4 }'`
Expand Down
13 changes: 11 additions & 2 deletions scripts/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ static const tuple_t types_and_classes[] = {
{ "AAAA", 28, true },
{ "LOC", 29, true },
{ "NXT", 30, true },
{ "EID", 31, true },
{ "NIMLOC", 32, true },
{ "SRV", 33, true },
{ "ATMA", 34, true },
{ "NAPTR", 35, true },
{ "KX", 36, true },
{ "CERT", 37, true },
{ "A6", 38, true },
{ "DNAME", 39, true },
{ "SINK", 40, true },
{ "APL", 42, true },
{ "DS", 43, true },
{ "SSHFP", 44, true },
Expand All @@ -76,13 +80,15 @@ static const tuple_t types_and_classes[] = {
{ "HIP", 55, true },
{ "NINFO", 56, true },
{ "RKEY", 57, true },
{ "TALINK", 58, true },
{ "CDS", 59, true },
{ "CDNSKEY", 60, true },
{ "OPENPGPKEY", 61, true },
{ "CSYNC", 62, true },
{ "ZONEMD", 63, true },
{ "SVCB", 64, true },
{ "HTTPS", 65, true },
{ "DSYNC", 66, true },
{ "SPF", 99, true },
{ "NID", 104, true },
{ "L32", 105, true },
Expand All @@ -93,9 +99,12 @@ static const tuple_t types_and_classes[] = {
{ "URI", 256, true },
{ "CAA", 257, true },
{ "AVC", 258, true },
{ "DOA", 259, true },
{ "AMTRELAY", 260, true },
{ "RESINFO", 261, true },
{ "WALLET", 262, true },
{ "CLA", 263, true },
{ "IPN", 264, true },
{ "TA", 32768, true },
{ "DLV", 32769, true }
};
Expand Down Expand Up @@ -127,9 +136,9 @@ static void print_table(uint64_t magic)
for (size_t j=i+8; i < j; i++) {
uint16_t code;
switch(keys[i].code) {
case 32768: code = 265; // index of TA in types array in generic/types.h
case 32768: code = 270; // index of TA in types array in generic/types.h
break;
case 32769: code = 266; // index of DLV in types array in generic/types.h
case 32769: code = 271; // index of DLV in types array in generic/types.h
break;
default : code = keys[i].code;
break;
Expand Down
1 change: 1 addition & 0 deletions src/fallback/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "generic/apl.h"
#include "generic/svcb.h"
#include "generic/cert.h"
#include "generic/atma.h"
#include "generic/algorithm.h"
#include "generic/types.h"
#include "generic/type.h"
Expand Down
215 changes: 215 additions & 0 deletions src/generic/atma.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
* atma.h -- ATMA parser (see: https://web.archive.org/web/20190112072924/http://www.broadband-forum.org/ftp/pub/approved-specs/af-dans-0152.000.pdf )
*
* Copyright (c) 2025, NLnet Labs. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#ifndef ATMA_H
#define ATMA_H

static const uint8_t bad_atma_chars[256] = {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x00 - 0x07
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x08 - 0x0f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x10 - 0x17
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x18 - 0x1f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x20 - 0x27
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01, // 0x28 - 0x2f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x30 - 0x37
0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x38 - 0x3f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x40 - 0x47
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x48 - 0x4f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x50 - 0x57
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x58 - 0x5f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x60 - 0x67
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x68 - 0x6f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x70 - 0x77
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x78 - 0x7f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x80 - 0x87
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x88 - 0x8f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x90 - 0x97
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x98 - 0x9f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xa0 - 0xa7
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xa8 - 0xaf
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xb0 - 0xb7
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xb8 - 0xbf
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xc0 - 0xc7
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xc8 - 0xcf
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xd0 - 0xd7
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xd8 - 0xdf
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xe0 - 0xe7
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xe0 - 0xe7
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xf8 - 0xff
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0xf8 - 0xff
};

static const uint8_t atma_increment[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x01 - 0x07
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x08 - 0x0f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x10 - 0x17
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x18 - 0x1f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x20 - 0x27
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x28 - 0x2f
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, // 0x30 - 0x37
0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x38 - 0x3f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x40 - 0x47
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x48 - 0x4f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x50 - 0x57
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x58 - 0x5f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x60 - 0x67
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x68 - 0x6f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x70 - 0x77
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x78 - 0x7f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x80 - 0x87
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x88 - 0x8f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x90 - 0x97
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x98 - 0x9f
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xa0 - 0xa7
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xa8 - 0xaf
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xb0 - 0xb7
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xb8 - 0xbf
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xc0 - 0xc7
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xc8 - 0xcf
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xd0 - 0xd7
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xd8 - 0xdf
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xe0 - 0xe7
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xe0 - 0xe7
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xf8 - 0x00
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0xf8 - 0x00
};


nonnull_all
static really_inline int32_t parse_atma_e164(
parser_t *parser,
const type_info_t *type,
const rdata_info_t *field,
rdata_t *rdata,
const token_t *token)
{
uint32_t bad_chars = 0;
for (size_t count=1; count < token->length; count++) {
const uint8_t octet = (uint8_t)token->data[count];
*rdata->octets = octet;
rdata->octets += atma_increment[octet];
bad_chars |= bad_atma_chars[octet];
}
if (bad_chars)
SEMANTIC_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));

return 0;
}

nonnull((1,2,4,5))
static really_inline int atma_stream_decode(
struct base16_state *state,
const char *src,
size_t srclen,
uint8_t *out,
size_t *outlen)
{
int ret = 0;
const uint8_t *s = (const uint8_t *) src;
uint8_t *o = (uint8_t *) out;
uint32_t q;

// Use local temporaries to avoid cache thrashing:
size_t olen = 0;
size_t slen = srclen;
struct base16_state st;
st.eof = state->eof;
st.bytes = state->bytes;
st.carry = state->carry;

if (st.eof) {
*outlen = 0;
return ret;
}

// Duff's device again:
switch (st.bytes)
{
#if defined(__SUNPRO_C)
#pragma error_messages(off, E_STATEMENT_NOT_REACHED)
#endif
for (;;)
#if defined(__SUNPRO_C)
#pragma error_messages(default, E_STATEMENT_NOT_REACHED)
#endif
{
case 0:
base16_dec_loop_generic_32(&s, &slen, &o, &olen);
if (slen-- == 0) {
ret = 1;
break;
}
if ((q = base16_table_dec_32bit_d0[*s++]) == 256) {
st.eof = BASE16_EOF;
break;
} else if (q == 257) {
continue;
}
st.carry = (uint8_t)q;
st.bytes = 1;

// fallthrough

case 1:
if (slen-- == 0) {
ret = 1;
break;
}
if ((q = base16_table_dec_32bit_d1[*s++]) == 256) {
st.eof = BASE16_EOF;
break;
} else if (q == 257) {
continue;
}
*o++ = st.carry | (uint8_t)q;
st.carry = 0;
st.bytes = 0;
olen++;
}
}

state->eof = st.eof;
state->bytes = st.bytes;
state->carry = st.carry;
*outlen = olen;
return ret;
}

nonnull((1,3,4))
static really_inline int atma_decode(
const char *src, size_t srclen, uint8_t *out, size_t *outlen)
{
struct base16_state state = { .eof = 0, .bytes = 0, .carry = 0 };
return atma_stream_decode(&state, src, srclen, out, outlen) & !state.bytes;
}

nonnull_all
static really_inline int32_t parse_atma(
parser_t *parser,
const type_info_t *type,
const rdata_info_t *field,
rdata_t *rdata,
const token_t *token)
{
if (token->length && (char)*token->data == '+') {
*rdata->octets++ = 1;
if ((uintptr_t)rdata->limit - (uintptr_t)rdata->octets < token->length)
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
return parse_atma_e164(parser, type, field, rdata, token);
}
size_t length = token->length / 2;
if ((uintptr_t)rdata->limit - (uintptr_t)rdata->octets < length)
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
*rdata->octets++ = 0;
if (!atma_decode(token->data, token->length, rdata->octets, &length))
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(field), NAME(type));
rdata->octets += length;
return 0;
}

#endif // ATMA_H
4 changes: 2 additions & 2 deletions src/generic/base16.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static const uint32_t base16_table_dec_32bit_d0[256] = {
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 257, 256,
0, 16, 32, 48, 64, 80, 96, 112, 128, 144, 256, 256,
256, 256, 256, 256, 256, 160, 176, 192, 208, 224, 240, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
Expand All @@ -52,7 +52,7 @@ static const uint32_t base16_table_dec_32bit_d1[256] = {
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 257, 256,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 256, 256,
256, 256, 256, 256, 256, 10, 11, 12, 13, 14, 15, 256,
256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256,
Expand Down
Loading

0 comments on commit 80f5f44

Please sign in to comment.