From ce6078d2b9d65bc9727ff0799117d34bdf0ca56c Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Sat, 26 Jul 2025 06:17:20 +0200 Subject: [PATCH] Add support for parsing DSYNC scheme mnemonics Adds dns_dsyncscheme_fromtext, dns_dsyncscheme_totext and dns_dsyncscheme_format. Adds type dns_dsyncscheme_t. (cherry picked from commit 6e1311c624d15e6c4d0184deea3bb670e8a5785d) --- lib/dns/Makefile.am | 3 ++- lib/dns/include/dns/dsync.h | 27 +++++++++++++++++++++++ lib/dns/include/dns/types.h | 1 + lib/dns/rcode.c | 43 +++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 lib/dns/include/dns/dsync.h diff --git a/lib/dns/Makefile.am b/lib/dns/Makefile.am index 3428131fcc..49553d0332 100644 --- a/lib/dns/Makefile.am +++ b/lib/dns/Makefile.am @@ -67,9 +67,10 @@ libdns_la_HEADERS = \ include/dns/dns64.h \ include/dns/dnsrps.h \ include/dns/dnssec.h \ + include/dns/dnstap.h \ include/dns/ds.h \ include/dns/dsdigest.h \ - include/dns/dnstap.h \ + include/dns/dsync.h \ include/dns/dyndb.h \ include/dns/ecs.h \ include/dns/ede.h \ diff --git a/lib/dns/include/dns/dsync.h b/lib/dns/include/dns/dsync.h new file mode 100644 index 0000000000..9533d4c2e5 --- /dev/null +++ b/lib/dns/include/dns/dsync.h @@ -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); diff --git a/lib/dns/include/dns/types.h b/lib/dns/include/dns/types.h index 6b124bf734..6cd5085478 100644 --- a/lib/dns/include/dns/types.h +++ b/lib/dns/include/dns/types.h @@ -80,6 +80,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; diff --git a/lib/dns/rcode.c b/lib/dns/rcode.c index 6c957e870c..e2a7309664 100644 --- a/lib/dns/rcode.c +++ b/lib/dns/rcode.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,10 @@ #define TOTEXTONLY 0x01 +/* clang-format off */ +#define SENTINEL { 0, NULL, 0 } +/* clang-format on */ + #define RCODENAMES \ /* standard rcodes */ \ { dns_rcode_noerror, "NOERROR", 0 }, \ @@ -130,6 +135,8 @@ { DNS_DSDIGEST_SHA384, "SHA-384", 0 }, \ { DNS_DSDIGEST_SHA384, "SHA384", 0 }, { 0, NULL, 0 } +#define DSYNCSCHEMES { DNS_DSYNCSCHEME_NOTIFY, "NOTIFY", 0 }, SENTINEL + struct tbl { unsigned int value; const char *name; @@ -143,6 +150,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 keyflag { const char *name; @@ -450,6 +458,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?