2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

new: usr: Support for parsing the DSYNC record has been added

Closes #5440

Merge branch '5440-add-dsync-record' into 'main'

See merge request isc-projects/bind9!10776
This commit is contained in:
Mark Andrews
2025-08-05 18:11:41 +10:00
12 changed files with 568 additions and 1 deletions

View File

@@ -2548,6 +2548,7 @@ ds01.example. 3600 IN NS ns42.example.
ds01.example. 3600 IN DS 12892 5 2 26584835CA80C81C91999F31CFAF2A0E89D4FF1C8FAFD0DDB31A85C7 19277C13
ds02.example. 3600 IN NS ns43.example.
ds02.example. 3600 IN DS 12892 5 1 7AA4A3F416C2F2391FB7AB0D434F762CD62D1390
dsync01.example. 3600 IN DSYNC CDS NOTIFY 53 .
eid01.example. 3600 IN EID 1289AB
eui48.example. 3600 IN EUI48 01-23-45-67-89-ab
eui64.example. 3600 IN EUI64 01-23-45-67-89-ab-cd-ef

View File

@@ -2548,6 +2548,7 @@ ds01.example8. 3600 IN DS 12892 5 2 26584835CA80C81C91999F31CFAF2A0E89D4FF1C8FA
ds01.example8. 3600 IN NS ns42.example8.
ds02.example8. 3600 IN DS 12892 5 1 7AA4A3F416C2F2391FB7AB0D434F762CD62D1390
ds02.example8. 3600 IN NS ns43.example8.
dsync01.example8. 3600 IN DSYNC CDS NOTIFY 53 .
eid01.example8. 3600 IN EID 1289AB
eui48.example8. 3600 IN EUI48 01-23-45-67-89-ab
eui64.example8. 3600 IN EUI64 01-23-45-67-89-ab-cd-ef

View File

@@ -389,7 +389,10 @@ svcb1 SVCB 1 . port=60
https0 HTTPS 0 example.net.
https1 HTTPS 1 . port=60
; type 66 -- 98 (unassigned)
; type 66
dsync01 DSYNC CDS NOTIFY 53 .
; type 68 -- 98 (unassigned)
; type 99
spf01 SPF "v=spf1 -all"

View File

@@ -49,6 +49,7 @@ pytestmark = pytest.mark.extra_artifacts(
"DNSKEY",
"DOA",
"DS",
"DSYNC",
"EID",
"EUI48",
"EUI64",

View File

@@ -49,6 +49,7 @@ ds01.example. 3600 IN DS 12892 5 2 26584835CA80C81C91999F31CFAF2A0E89D4FF1C8FAF
ds01.example. 3600 IN NS ns42.example.
ds02.example. 3600 IN DS 12892 5 1 7AA4A3F416C2F2391FB7AB0D434F762CD62D1390
ds02.example. 3600 IN NS ns43.example.
dsync01.example. 3600 IN DSYNC CDS NOTIFY 53 .
eid01.example. 3600 IN EID 1289AB
eui48.example. 3600 IN EUI48 01-23-45-67-89-ab
eui64.example. 3600 IN EUI64 01-23-45-67-89-ab-cd-ef

View File

@@ -49,6 +49,7 @@ ds01.example. 3600 IN NS ns42.example.
ds01.example. 3600 IN DS 12892 5 2 26584835CA80C81C91999F31CFAF2A0E89D4FF1C8FAFD0DDB31A85C7 19277C13
ds02.example. 3600 IN NS ns43.example.
ds02.example. 3600 IN DS 12892 5 1 7AA4A3F416C2F2391FB7AB0D434F762CD62D1390
dsync01.example. 3600 IN DSYNC CDS NOTIFY 53 .
eid01.example. 3600 IN EID 1289AB
eui48.example. 3600 IN EUI48 01-23-45-67-89-ab
eui64.example. 3600 IN EUI64 01-23-45-67-89-ab-cd-ef

View File

@@ -0,0 +1,27 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#pragma once
#define DNS_DSYNCSCHEME_NOTIFY (1)
#define DNS_DSYNCSCHEMEFORMAT_SIZE (7)
isc_result_t
dns_dsyncscheme_fromtext(dns_dsyncscheme_t *schemep, isc_textregion_t *source);
isc_result_t
dns_dsyncscheme_totext(dns_dsyncscheme_t scheme, isc_buffer_t *target);
void
dns_dsyncscheme_format(dns_dsyncscheme_t scheme, char *cp, unsigned int size);

View File

@@ -81,6 +81,7 @@ typedef ISC_LIST(dns_dns64_t) dns_dns64list_t;
typedef struct dns_dnsseckey dns_dnsseckey_t;
typedef ISC_LIST(dns_dnsseckey_t) dns_dnsseckeylist_t;
typedef uint8_t dns_dsdigest_t;
typedef uint8_t dns_dsyncscheme_t;
typedef struct dns_dtdata dns_dtdata_t;
typedef struct dns_dtenv dns_dtenv_t;
typedef struct dns_dtmsg dns_dtmsg_t;

View File

@@ -29,6 +29,7 @@
#include <dns/cert.h>
#include <dns/ds.h>
#include <dns/dsdigest.h>
#include <dns/dsync.h>
#include <dns/keyflags.h>
#include <dns/keyvalues.h>
#include <dns/rcode.h>
@@ -166,6 +167,8 @@
{ DNS_DSDIGEST_GOST2012, "GOST2012", 0 }, \
DSDIGESTPRIVATENAMES SENTINEL
#define DSYNCSCHEMES { DNS_DSYNCSCHEME_NOTIFY, "NOTIFY", 0 }, SENTINEL
struct tbl {
unsigned int value;
const char *name;
@@ -179,6 +182,7 @@ static struct tbl secalgs[] = { SECALGNAMES };
static struct tbl secprotos[] = { SECPROTONAMES };
static struct tbl hashalgs[] = { HASHALGNAMES };
static struct tbl dsdigests[] = { DSDIGESTNAMES };
static struct tbl dsyncschemes[] = { DSYNCSCHEMES };
static struct tbl privatednss[] = { PRIVATEDNSS SENTINEL };
static struct tbl privateoids[] = { PRIVATEOIDS SENTINEL };
static struct tbl dstalgorithms[] = { PRIVATEDNSS PRIVATEOIDS SECALGNAMES };
@@ -547,6 +551,41 @@ dns_dsdigest_format(dns_dsdigest_t typ, char *cp, unsigned int size) {
}
}
/*
* DSYNC Scheme
*/
isc_result_t
dns_dsyncscheme_fromtext(dns_dsyncscheme_t *schemep, isc_textregion_t *source) {
unsigned int value;
REQUIRE(schemep != NULL);
RETERR(dns_mnemonic_fromtext(&value, source, dsyncschemes, 0xff));
*schemep = value;
return ISC_R_SUCCESS;
}
isc_result_t
dns_dsyncscheme_totext(dns_dsyncscheme_t scheme, isc_buffer_t *target) {
return dns_mnemonic_totext(scheme, target, dsyncschemes);
}
void
dns_dsyncscheme_format(dns_dsyncscheme_t scheme, char *cp, unsigned int size) {
isc_buffer_t b;
isc_region_t r;
isc_result_t result;
REQUIRE(cp != NULL && size > 0);
isc_buffer_init(&b, cp, size - 1);
result = dns_dsyncscheme_totext(scheme, &b);
isc_buffer_usedregion(&b, &r);
r.base[r.length] = 0;
if (result != ISC_R_SUCCESS) {
r.base[0] = 0;
}
}
/*
* This uses lots of hard coded values, but how often do we actually
* add classes?

View File

@@ -0,0 +1,361 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#ifndef RDATA_GENERIC_DSYNC_66_C
#define RDATA_GENERIC_DSYNC_66_C
#include <string.h>
#include <isc/net.h>
#include <dns/dsync.h>
#include <dns/fixedname.h>
#define RRTYPE_DSYNC_ATTRIBUTES (0)
static isc_result_t
fromtext_dsync(ARGS_FROMTEXT) {
isc_token_t token;
isc_result_t result;
dns_fixedname_t fn;
dns_name_t *name = dns_fixedname_initname(&fn);
isc_buffer_t buffer;
dns_rdatatype_t rrtype;
dns_dsyncscheme_t scheme;
bool ok = true;
REQUIRE(type == dns_rdatatype_dsync);
UNUSED(type);
UNUSED(rdclass);
UNUSED(callbacks);
/*
* RRtype
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
false));
result = dns_rdatatype_fromtext(&rrtype, &token.value.as_textregion);
if (result != ISC_R_SUCCESS && result != ISC_R_NOTIMPLEMENTED) {
char *e = NULL;
long i = strtol(DNS_AS_STR(token), &e, 10);
if (i < 0 || i > 65535) {
RETTOK(ISC_R_RANGE);
}
if (*e != 0) {
RETTOK(result);
}
rrtype = (dns_rdatatype_t)i;
}
RETERR(uint16_tobuffer(rrtype, target));
/*
* Scheme
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
false));
RETERR(dns_dsyncscheme_fromtext(&scheme, &token.value.as_textregion));
RETERR(uint8_tobuffer(scheme, target));
/*
* Port
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
false));
if (token.value.as_ulong > 0xffffU) {
RETTOK(ISC_R_RANGE);
}
RETERR(uint16_tobuffer(token.value.as_ulong, target));
/*
* Target
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
false));
buffer_fromregion(&buffer, &token.value.as_region);
if (origin == NULL) {
origin = dns_rootname;
}
RETTOK(dns_name_fromtext(name, &buffer, origin, options));
RETTOK(dns_name_towire(name, NULL, target));
if ((options & DNS_RDATA_CHECKNAMES) != 0) {
ok = dns_name_ishostname(name, false);
}
if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) {
RETTOK(DNS_R_BADNAME);
}
if (!ok && callbacks != NULL) {
warn_badname(name, lexer, callbacks);
}
return ISC_R_SUCCESS;
}
static isc_result_t
totext_dsync(ARGS_TOTEXT) {
isc_region_t region;
dns_name_t name;
dns_name_t prefix;
unsigned int opts;
char buf[sizeof("TYPE64000")];
unsigned short num;
dns_rdatatype_t type;
dns_dsyncscheme_t scheme;
REQUIRE(rdata->type == dns_rdatatype_dsync);
REQUIRE(rdata->length != 0);
dns_name_init(&name);
dns_name_init(&prefix);
dns_rdata_toregion(rdata, &region);
/*
* Type.
*/
type = uint16_fromregion(&region);
isc_region_consume(&region, 2);
/*
* XXXAG We should have something like dns_rdatatype_isknown()
* that does the right thing with type 0.
*/
if (dns_rdatatype_isknown(type) && type != 0) {
RETERR(dns_rdatatype_totext(type, target));
} else {
snprintf(buf, sizeof(buf), "TYPE%u", type);
RETERR(str_totext(buf, target));
}
RETERR(str_totext(" ", target));
/*
* Scheme.
*/
scheme = uint8_fromregion(&region);
isc_region_consume(&region, 1);
RETERR(dns_dsyncscheme_totext(scheme, target));
RETERR(str_totext(" ", target));
/*
* Port
*/
num = uint16_fromregion(&region);
isc_region_consume(&region, 2);
snprintf(buf, sizeof(buf), "%u", num);
RETERR(str_totext(buf, target));
RETERR(str_totext(" ", target));
/*
* Target
*/
dns_name_fromregion(&name, &region);
opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT
: 0;
return dns_name_totext(&prefix, opts, target);
}
static isc_result_t
fromwire_dsync(ARGS_FROMWIRE) {
dns_name_t name;
isc_region_t sregion;
REQUIRE(type == dns_rdatatype_dsync);
UNUSED(type);
UNUSED(rdclass);
dctx = dns_decompress_setpermitted(dctx, false);
dns_name_init(&name);
isc_buffer_activeregion(source, &sregion);
if (sregion.length < 5) {
return ISC_R_UNEXPECTEDEND;
}
RETERR(mem_tobuffer(target, sregion.base, 5));
isc_buffer_forward(source, 5);
return dns_name_fromwire(&name, source, dctx, target);
}
static isc_result_t
towire_dsync(ARGS_TOWIRE) {
dns_name_t name;
isc_region_t region;
REQUIRE(rdata->type == dns_rdatatype_dsync);
REQUIRE(rdata->length != 0);
dns_compress_setpermitted(cctx, false);
dns_rdata_toregion(rdata, &region);
RETERR(mem_tobuffer(target, region.base, 5));
isc_region_consume(&region, 5);
dns_name_init(&name);
dns_name_fromregion(&name, &region);
return dns_name_towire(&name, cctx, target);
}
static int
compare_dsync(ARGS_COMPARE) {
isc_region_t region1;
isc_region_t region2;
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->rdclass == rdata2->rdclass);
REQUIRE(rdata1->type == dns_rdatatype_dsync);
REQUIRE(rdata1->length != 0);
REQUIRE(rdata2->length != 0);
dns_rdata_toregion(rdata1, &region1);
dns_rdata_toregion(rdata2, &region2);
return isc_region_compare(&region1, &region2);
}
static isc_result_t
fromstruct_dsync(ARGS_FROMSTRUCT) {
dns_rdata_dsync_t *dsync = source;
isc_region_t region;
REQUIRE(type == dns_rdatatype_dsync);
REQUIRE(dsync != NULL);
REQUIRE(dsync->common.rdtype == type);
REQUIRE(dsync->common.rdclass == rdclass);
UNUSED(type);
UNUSED(rdclass);
RETERR(uint16_tobuffer(dsync->type, target));
RETERR(uint16_tobuffer(dsync->scheme, target));
RETERR(uint16_tobuffer(dsync->port, target));
dns_name_toregion(&dsync->target, &region);
return isc_buffer_copyregion(target, &region);
}
static isc_result_t
tostruct_dsync(ARGS_TOSTRUCT) {
isc_region_t region;
dns_rdata_dsync_t *dsync = target;
dns_name_t name;
REQUIRE(rdata->type == dns_rdatatype_dsync);
REQUIRE(dsync != NULL);
REQUIRE(rdata->length != 0);
dsync->common.rdclass = rdata->rdclass;
dsync->common.rdtype = rdata->type;
dns_name_init(&name);
dns_rdata_toregion(rdata, &region);
dsync->type = uint16_fromregion(&region);
isc_region_consume(&region, 2);
dsync->scheme = uint8_fromregion(&region);
isc_region_consume(&region, 1);
dsync->port = uint16_fromregion(&region);
isc_region_consume(&region, 2);
dns_name_fromregion(&name, &region);
dns_name_init(&dsync->target);
name_duporclone(&name, mctx, &dsync->target);
dsync->mctx = mctx;
return ISC_R_SUCCESS;
}
static void
freestruct_dsync(ARGS_FREESTRUCT) {
dns_rdata_dsync_t *dsync = source;
REQUIRE(dsync != NULL);
REQUIRE(dsync->common.rdtype == dns_rdatatype_dsync);
if (dsync->mctx == NULL) {
return;
}
dns_name_free(&dsync->target, dsync->mctx);
dsync->mctx = NULL;
}
static isc_result_t
additionaldata_dsync(ARGS_ADDLDATA) {
dns_name_t name;
isc_region_t region;
REQUIRE(rdata->type == dns_rdatatype_dsync);
UNUSED(owner);
dns_name_init(&name);
dns_rdata_toregion(rdata, &region);
isc_region_consume(&region, 5);
dns_name_fromregion(&name, &region);
if (dns_name_equal(&name, dns_rootname)) {
return ISC_R_SUCCESS;
}
return (add)(arg, &name, dns_rdatatype_a, NULL DNS__DB_FILELINE);
}
static isc_result_t
digest_dsync(ARGS_DIGEST) {
isc_region_t r1;
REQUIRE(rdata->type == dns_rdatatype_dsync);
dns_rdata_toregion(rdata, &r1);
return (digest)(arg, &r1);
}
static bool
checkowner_dsync(ARGS_CHECKOWNER) {
REQUIRE(type == dns_rdatatype_dsync);
UNUSED(name);
UNUSED(rdclass);
UNUSED(type);
UNUSED(wildcard);
return true;
}
static bool
checknames_dsync(ARGS_CHECKNAMES) {
isc_region_t region;
dns_name_t name;
REQUIRE(rdata->type == dns_rdatatype_dsync);
REQUIRE(rdata->length > 5);
UNUSED(owner);
dns_rdata_toregion(rdata, &region);
isc_region_consume(&region, 5);
dns_name_init(&name);
dns_name_fromregion(&name, &region);
if (!dns_name_ishostname(&name, false)) {
if (bad != NULL) {
dns_name_clone(&name, bad);
}
return false;
}
return true;
}
static int
casecompare_dsync(ARGS_COMPARE) {
return compare_dsync(rdata1, rdata2);
}
#endif /* RDATA_GENERIC_DSYNC_66_C */

View File

@@ -0,0 +1,24 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/* */
#pragma once
typedef struct dns_rdata_dsync {
dns_rdatacommon_t common;
isc_mem_t *mctx;
uint16_t type;
uint8_t scheme;
uint16_t port;
dns_name_t target;
} dns_rdata_dsync_t;

View File

@@ -1712,6 +1712,113 @@ ISC_RUN_TEST_IMPL(ds) {
dns_rdatatype_ds, sizeof(dns_rdata_ds_t));
}
/*
* DSYNC tests.
*
* draft-ietf-dnsop-generalized-notify-09
*
* 2.1. Wire Format
*
* The DSYNC RDATA wire format is encoded as follows:
*
* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | RRtype | Scheme | Port
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Target ... /
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-/
*
* RRtype The type of generalized NOTIFY that this DSYNC RR defines the
* desired target address for (see "Resource Record (RR) TYPEs" IANA
* registry). For now, only CDS and CSYNC are supported values, with
* the former indicating an updated CDS or CDNSKEY record set.
*
* Scheme The mode used for contacting the desired notification
* address. This is an 8-bit unsigned integer. Records with value 0
* (null scheme) are ignored by consumers. Value 1 is described in
* this document, and values 128-255 are reserved for private use.
* All other values are currently unassigned.
*
* Port The port on the target host of the notification service. This
* is a 16-bit unsigned integer in network byte order. Records with
* value 0 are ignored by consumers.
*
* Target The fully-qualified, uncompressed domain name of the target
* host providing the service of listening for generalized
* notifications of the specified type. This name MUST resolve to
* one or more address records.
*
* 2.2. Presentation Format
*
* The presentation format of the RDATA portion is as follows:
*
* * The RRtype field is represented as a mnemonic from the "Resource
* Record (RR) TYPEs" registry.
*
* * The Scheme field is represented by its mnemonic if assigned (see
* Section 6.2), otherwise as an unsigned decimal integer.
*
* * The Port field is represented as an unsigned decimal integer.
*
* * The Target field is represented as a <domain-name> ([RFC1035],
* Section 5.1).
*/
ISC_RUN_TEST_IMPL(dsync) {
text_ok_t text_ok[] = {
/*
* Invalid, empty record.
*/
TEXT_INVALID(""),
/*
* Known type and known scheme.
*/
TEXT_VALID("CDS NOTIFY 0 example.com"),
/*
* Known type and unknown scheme.
*/
TEXT_VALID("CDS 3 0 example.com"),
/*
* Unknown type and known scheme.
*/
TEXT_VALID("TYPE1000 NOTIFY 0 example.com"),
/*
* Unknown type and unknown scheme.
*/
TEXT_VALID("TYPE1000 3 0 example.com"),
/*
* Unknown type and unknown scheme, max port.
*/
TEXT_VALID("TYPE1000 3 65535 example.com"),
/*
* Unknown type and max scheme, max port.
*/
TEXT_VALID("TYPE64000 255 65535 example.com"),
/*
* Invalid type and max scheme, max port.
*/
TEXT_INVALID("INVALID 255 65536 example.com"),
/*
* Unknown type and too big scheme, max port.
*/
TEXT_INVALID("TYPE1000 256 65536 example.com"),
/*
* Unknown type and unknown scheme, port too big.
*/
TEXT_INVALID("TYPE1000 3 65536 example.com"),
/*
* Unknown type and bad scheme, max port.
*/
TEXT_INVALID("TYPE1000 UNKNOWN 65535 example.com"),
/*
* Sentinel.
*/
TEXT_SENTINEL()
};
check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in,
dns_rdatatype_dsync, sizeof(dns_rdata_dsync_t));
}
/*
* EDNS Client Subnet tests.
*