2003-09-30 06:00:40 +00:00
|
|
|
/*
|
2011-01-13 04:59:26 +00:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2003-09-30 06:00:40 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
*
|
2003-09-30 06:00:40 +00:00
|
|
|
* 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/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
2003-09-30 06:00:40 +00:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
|
|
|
*/
|
|
|
|
|
2008-07-15 05:45:34 +00:00
|
|
|
/* RFC 3845 */
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
#ifndef RDATA_GENERIC_NSEC_47_C
|
|
|
|
#define RDATA_GENERIC_NSEC_47_C
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The attributes do not include DNS_RDATATYPEATTR_SINGLETON
|
|
|
|
* because we must be able to handle a parent/child NSEC pair.
|
|
|
|
*/
|
2018-11-26 10:57:02 +11:00
|
|
|
#define RRTYPE_NSEC_ATTRIBUTES \
|
|
|
|
(DNS_RDATATYPEATTR_DNSSEC | DNS_RDATATYPEATTR_ZONECUTAUTH | \
|
|
|
|
DNS_RDATATYPEATTR_ATCNAME)
|
2020-02-12 13:59:18 +01:00
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2003-09-30 06:00:40 +00:00
|
|
|
fromtext_nsec(ARGS_FROMTEXT) {
|
|
|
|
isc_token_t token;
|
|
|
|
isc_buffer_t buffer;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(type == dns_rdatatype_nsec);
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
UNUSED(callbacks);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Next domain.
|
|
|
|
*/
|
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
|
2018-04-17 08:29:14 -07:00
|
|
|
false));
|
2003-09-30 06:00:40 +00:00
|
|
|
buffer_fromregion(&buffer, &token.value.as_region);
|
2015-09-18 07:43:43 +10:00
|
|
|
if (origin == NULL) {
|
|
|
|
origin = dns_rootname;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2025-02-22 00:11:38 -08:00
|
|
|
RETTOK(dns_name_wirefromtext(&buffer, origin, options, target));
|
2003-09-30 06:00:40 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return typemap_fromtext(lexer, target, false);
|
2003-09-30 06:00:40 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2003-09-30 06:00:40 +00:00
|
|
|
totext_nsec(ARGS_TOTEXT) {
|
|
|
|
isc_region_t sr;
|
|
|
|
dns_name_t name;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_nsec);
|
2003-09-30 06:00:40 +00:00
|
|
|
REQUIRE(rdata->length != 0);
|
|
|
|
|
2011-01-13 00:55:49 +00:00
|
|
|
UNUSED(tctx);
|
|
|
|
|
2025-02-21 12:09:39 +01:00
|
|
|
dns_name_init(&name);
|
2003-09-30 06:00:40 +00:00
|
|
|
dns_rdata_toregion(rdata, &sr);
|
|
|
|
dns_name_fromregion(&name, &sr);
|
|
|
|
isc_region_consume(&sr, name_length(&name));
|
2023-08-15 18:52:17 -07:00
|
|
|
RETERR(dns_name_totext(&name, 0, target));
|
2018-05-23 18:40:48 +05:30
|
|
|
/*
|
|
|
|
* Don't leave a trailing space when there's no typemap present.
|
|
|
|
*/
|
|
|
|
if (sr.length > 0) {
|
|
|
|
RETERR(str_totext(" ", target));
|
|
|
|
}
|
2015-09-18 23:45:12 +10:00
|
|
|
return typemap_totext(&sr, NULL, target);
|
2003-09-30 06:00:40 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2003-12-13 04:20:44 +00:00
|
|
|
fromwire_nsec(ARGS_FROMWIRE) {
|
2003-09-30 06:00:40 +00:00
|
|
|
isc_region_t sr;
|
|
|
|
dns_name_t name;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(type == dns_rdatatype_nsec);
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
|
2022-05-05 16:36:52 +01:00
|
|
|
dctx = dns_decompress_setpermitted(dctx, false);
|
2003-09-30 06:00:40 +00:00
|
|
|
|
2025-02-21 12:09:39 +01:00
|
|
|
dns_name_init(&name);
|
2022-11-09 17:10:59 +00:00
|
|
|
RETERR(dns_name_fromwire(&name, source, dctx, target));
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
isc_buffer_activeregion(source, &sr);
|
2018-04-17 08:29:14 -07:00
|
|
|
RETERR(typemap_test(&sr, false));
|
2003-09-30 06:00:40 +00:00
|
|
|
RETERR(mem_tobuffer(target, sr.base, sr.length));
|
|
|
|
isc_buffer_forward(source, sr.length);
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2003-09-30 06:00:40 +00:00
|
|
|
towire_nsec(ARGS_TOWIRE) {
|
|
|
|
isc_region_t sr;
|
|
|
|
dns_name_t name;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_nsec);
|
2003-09-30 06:00:40 +00:00
|
|
|
REQUIRE(rdata->length != 0);
|
|
|
|
|
2022-05-05 14:52:44 +01:00
|
|
|
dns_compress_setpermitted(cctx, false);
|
2025-02-21 12:09:39 +01:00
|
|
|
dns_name_init(&name);
|
2003-09-30 06:00:40 +00:00
|
|
|
dns_rdata_toregion(rdata, &sr);
|
|
|
|
dns_name_fromregion(&name, &sr);
|
|
|
|
isc_region_consume(&sr, name_length(&name));
|
2025-02-21 18:14:55 -08:00
|
|
|
RETERR(dns_name_towire(&name, cctx, target));
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
return mem_tobuffer(target, sr.base, sr.length);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static int
|
2003-09-30 06:00:40 +00:00
|
|
|
compare_nsec(ARGS_COMPARE) {
|
|
|
|
isc_region_t r1;
|
|
|
|
isc_region_t r2;
|
|
|
|
|
|
|
|
REQUIRE(rdata1->type == rdata2->type);
|
|
|
|
REQUIRE(rdata1->rdclass == rdata2->rdclass);
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata1->type == dns_rdatatype_nsec);
|
2003-09-30 06:00:40 +00:00
|
|
|
REQUIRE(rdata1->length != 0);
|
|
|
|
REQUIRE(rdata2->length != 0);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata1, &r1);
|
|
|
|
dns_rdata_toregion(rdata2, &r2);
|
|
|
|
return isc_region_compare(&r1, &r2);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2003-09-30 06:00:40 +00:00
|
|
|
fromstruct_nsec(ARGS_FROMSTRUCT) {
|
|
|
|
dns_rdata_nsec_t *nsec = source;
|
|
|
|
isc_region_t region;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(type == dns_rdatatype_nsec);
|
2019-09-27 10:40:51 +02:00
|
|
|
REQUIRE(nsec != NULL);
|
2003-09-30 06:00:40 +00:00
|
|
|
REQUIRE(nsec->common.rdtype == type);
|
|
|
|
REQUIRE(nsec->common.rdclass == rdclass);
|
|
|
|
REQUIRE(nsec->typebits != NULL || nsec->len == 0);
|
|
|
|
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
|
|
|
|
dns_name_toregion(&nsec->next, ®ion);
|
|
|
|
RETERR(isc_buffer_copyregion(target, ®ion));
|
2015-09-18 23:45:12 +10:00
|
|
|
|
|
|
|
region.base = nsec->typebits;
|
|
|
|
region.length = nsec->len;
|
2018-04-17 08:29:14 -07:00
|
|
|
RETERR(typemap_test(®ion, false));
|
2003-09-30 06:00:40 +00:00
|
|
|
return mem_tobuffer(target, nsec->typebits, nsec->len);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2003-09-30 06:00:40 +00:00
|
|
|
tostruct_nsec(ARGS_TOSTRUCT) {
|
|
|
|
isc_region_t region;
|
|
|
|
dns_rdata_nsec_t *nsec = target;
|
|
|
|
dns_name_t name;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_nsec);
|
2019-09-27 10:40:51 +02:00
|
|
|
REQUIRE(nsec != NULL);
|
2003-09-30 06:00:40 +00:00
|
|
|
REQUIRE(rdata->length != 0);
|
|
|
|
|
|
|
|
nsec->common.rdclass = rdata->rdclass;
|
|
|
|
nsec->common.rdtype = rdata->type;
|
|
|
|
ISC_LINK_INIT(&nsec->common, link);
|
|
|
|
|
2025-02-21 12:09:39 +01:00
|
|
|
dns_name_init(&name);
|
2003-09-30 06:00:40 +00:00
|
|
|
dns_rdata_toregion(rdata, ®ion);
|
|
|
|
dns_name_fromregion(&name, ®ion);
|
|
|
|
isc_region_consume(®ion, name_length(&name));
|
2025-02-21 12:09:39 +01:00
|
|
|
dns_name_init(&nsec->next);
|
2021-10-06 12:57:24 +02:00
|
|
|
name_duporclone(&name, mctx, &nsec->next);
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
nsec->len = region.length;
|
|
|
|
nsec->typebits = mem_maybedup(mctx, region.base, region.length);
|
|
|
|
nsec->mctx = mctx;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static void
|
2003-09-30 06:00:40 +00:00
|
|
|
freestruct_nsec(ARGS_FREESTRUCT) {
|
|
|
|
dns_rdata_nsec_t *nsec = source;
|
|
|
|
|
2019-09-27 10:40:51 +02:00
|
|
|
REQUIRE(nsec != NULL);
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(nsec->common.rdtype == dns_rdatatype_nsec);
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
if (nsec->mctx == NULL) {
|
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
dns_name_free(&nsec->next, nsec->mctx);
|
|
|
|
if (nsec->typebits != NULL) {
|
|
|
|
isc_mem_free(nsec->mctx, nsec->typebits);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-09-30 06:00:40 +00:00
|
|
|
nsec->mctx = NULL;
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2003-09-30 06:00:40 +00:00
|
|
|
additionaldata_nsec(ARGS_ADDLDATA) {
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_nsec);
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
UNUSED(rdata);
|
2019-07-05 16:20:20 +10:00
|
|
|
UNUSED(owner);
|
2003-09-30 06:00:40 +00:00
|
|
|
UNUSED(add);
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static isc_result_t
|
2003-09-30 06:00:40 +00:00
|
|
|
digest_nsec(ARGS_DIGEST) {
|
|
|
|
isc_region_t r;
|
|
|
|
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_nsec);
|
2003-09-30 06:00:40 +00:00
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, &r);
|
|
|
|
return (digest)(arg, &r);
|
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static bool
|
2004-02-27 20:41:51 +00:00
|
|
|
checkowner_nsec(ARGS_CHECKOWNER) {
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(type == dns_rdatatype_nsec);
|
2004-02-27 20:41:51 +00:00
|
|
|
|
|
|
|
UNUSED(name);
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
UNUSED(wildcard);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return true;
|
2004-02-27 20:41:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static bool
|
2004-02-27 20:41:51 +00:00
|
|
|
checknames_nsec(ARGS_CHECKNAMES) {
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata->type == dns_rdatatype_nsec);
|
2004-02-27 20:41:51 +00:00
|
|
|
|
|
|
|
UNUSED(rdata);
|
|
|
|
UNUSED(owner);
|
|
|
|
UNUSED(bad);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return true;
|
2004-02-27 20:41:51 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 13:43:12 +02:00
|
|
|
static int
|
2009-12-04 21:09:34 +00:00
|
|
|
casecompare_nsec(ARGS_COMPARE) {
|
2009-12-04 22:06:37 +00:00
|
|
|
isc_region_t region1;
|
|
|
|
isc_region_t region2;
|
|
|
|
dns_name_t name1;
|
|
|
|
dns_name_t name2;
|
|
|
|
int order;
|
2009-12-04 21:09:34 +00:00
|
|
|
|
2009-12-04 22:06:37 +00:00
|
|
|
REQUIRE(rdata1->type == rdata2->type);
|
|
|
|
REQUIRE(rdata1->rdclass == rdata2->rdclass);
|
2015-08-17 12:23:35 +05:30
|
|
|
REQUIRE(rdata1->type == dns_rdatatype_nsec);
|
2009-12-04 22:06:37 +00:00
|
|
|
REQUIRE(rdata1->length != 0);
|
|
|
|
REQUIRE(rdata2->length != 0);
|
2009-12-04 21:09:34 +00:00
|
|
|
|
2025-02-21 12:09:39 +01:00
|
|
|
dns_name_init(&name1);
|
|
|
|
dns_name_init(&name2);
|
2009-12-04 21:09:34 +00:00
|
|
|
|
2009-12-04 22:06:37 +00:00
|
|
|
dns_rdata_toregion(rdata1, ®ion1);
|
|
|
|
dns_rdata_toregion(rdata2, ®ion2);
|
2009-12-04 21:09:34 +00:00
|
|
|
|
2009-12-04 22:06:37 +00:00
|
|
|
dns_name_fromregion(&name1, ®ion1);
|
|
|
|
dns_name_fromregion(&name2, ®ion2);
|
2009-12-04 21:09:34 +00:00
|
|
|
|
2009-12-04 22:06:37 +00:00
|
|
|
order = dns_name_rdatacompare(&name1, &name2);
|
|
|
|
if (order != 0) {
|
|
|
|
return order;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-12-04 21:09:34 +00:00
|
|
|
|
2009-12-04 22:06:37 +00:00
|
|
|
isc_region_consume(®ion1, name_length(&name1));
|
|
|
|
isc_region_consume(®ion2, name_length(&name2));
|
2009-12-04 21:09:34 +00:00
|
|
|
|
|
|
|
return isc_region_compare(®ion1, ®ion2);
|
|
|
|
}
|
2003-09-30 06:00:40 +00:00
|
|
|
#endif /* RDATA_GENERIC_NSEC_47_C */
|