1999-01-27 08:44:10 +00:00
|
|
|
/*
|
2013-12-05 15:04:53 +11:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
1999-01-27 08:44:10 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
2021-06-03 08:37:05 +02:00
|
|
|
*
|
1999-01-27 08:44:10 +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
|
|
|
*
|
1999-01-27 08:44:10 +00:00
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
2006-03-03 00:43:35 +00:00
|
|
|
* information regarding copyright ownership.
|
1999-01-27 08:44:10 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
1999-01-27 08:44:10 +00:00
|
|
|
|
2023-05-09 23:07:50 -07:00
|
|
|
#include <ctype.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2000-09-01 01:35:21 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-05-09 23:07:50 -07:00
|
|
|
#include <isc/ascii.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/mem.h>
|
1999-01-27 08:44:10 +00:00
|
|
|
#include <isc/region.h>
|
2021-10-04 17:14:53 +02:00
|
|
|
#include <isc/result.h>
|
2022-04-11 15:53:34 +01:00
|
|
|
#include <isc/string.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-01-27 08:44:10 +00:00
|
|
|
|
2023-05-09 23:07:50 -07:00
|
|
|
#include <dns/db.h>
|
1999-01-27 08:44:10 +00:00
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataset.h>
|
|
|
|
#include <dns/rdataslab.h>
|
2023-05-09 23:07:50 -07:00
|
|
|
#include <dns/stats.h>
|
|
|
|
|
|
|
|
#define CASESET(header) \
|
|
|
|
((atomic_load_acquire(&(header)->attributes) & \
|
|
|
|
DNS_SLABHEADERATTR_CASESET) != 0)
|
|
|
|
#define CASEFULLYLOWER(header) \
|
|
|
|
((atomic_load_acquire(&(header)->attributes) & \
|
|
|
|
DNS_SLABHEADERATTR_CASEFULLYLOWER) != 0)
|
|
|
|
#define NONEXISTENT(header) \
|
|
|
|
((atomic_load_acquire(&(header)->attributes) & \
|
|
|
|
DNS_SLABHEADERATTR_NONEXISTENT) != 0)
|
2025-01-31 15:47:33 +01:00
|
|
|
#define NEGATIVE(header) \
|
|
|
|
((atomic_load_acquire(&(header)->attributes) & \
|
|
|
|
DNS_SLABHEADERATTR_NEGATIVE) != 0)
|
1999-01-27 08:44:10 +00:00
|
|
|
|
2006-03-03 00:43:35 +00:00
|
|
|
/*
|
|
|
|
* The rdataslab structure allows iteration to occur in both load order
|
|
|
|
* and DNSSEC order. The structure is as follows:
|
|
|
|
*
|
2025-02-07 20:07:53 -08:00
|
|
|
* header (dns_slabheader_t)
|
2006-03-03 00:43:35 +00:00
|
|
|
* record count (2 bytes)
|
|
|
|
* offset table (4 x record count bytes in load order)
|
|
|
|
* data records
|
|
|
|
* data length (2 bytes)
|
|
|
|
* order (2 bytes)
|
2008-04-01 01:37:25 +00:00
|
|
|
* meta data (1 byte for RRSIG's)
|
2006-03-03 00:43:35 +00:00
|
|
|
* data (data length bytes)
|
|
|
|
*
|
2025-02-07 20:07:53 -08:00
|
|
|
* A "raw" rdataslab is the same but without the header.
|
|
|
|
*
|
2006-03-03 00:43:35 +00:00
|
|
|
* DNSSEC order traversal is performed by walking the data records.
|
|
|
|
*
|
2009-01-17 14:59:03 +00:00
|
|
|
* The order is stored with record to allow for efficient reconstruction
|
2006-03-03 00:43:35 +00:00
|
|
|
* of the offset table following a merge or subtraction.
|
|
|
|
*
|
|
|
|
* The iterator methods in rbtdb support both load order and DNSSEC order
|
|
|
|
* iteration.
|
|
|
|
*
|
|
|
|
* WARNING:
|
|
|
|
* rbtdb.c directly interacts with the slab's raw structures. If the
|
|
|
|
* structure changes then rbtdb.c also needs to be updated to reflect
|
|
|
|
* the changes. See the areas tagged with "RDATASLAB".
|
|
|
|
*/
|
|
|
|
|
2024-08-15 09:36:53 +02:00
|
|
|
#define peek_uint16(buffer) ({ ((uint16_t)*(buffer) << 8) | *((buffer) + 1); })
|
2024-02-29 22:26:29 +01:00
|
|
|
#define get_uint16(buffer) \
|
|
|
|
({ \
|
|
|
|
uint16_t __ret = peek_uint16(buffer); \
|
|
|
|
buffer += sizeof(uint16_t); \
|
|
|
|
__ret; \
|
|
|
|
})
|
2025-02-07 14:31:33 -08:00
|
|
|
#define put_uint16(buffer, val) \
|
|
|
|
({ \
|
|
|
|
*buffer++ = (val & 0xff00) >> 8; \
|
|
|
|
*buffer++ = (val & 0x00ff); \
|
|
|
|
})
|
2024-02-29 22:26:29 +01:00
|
|
|
|
2023-05-09 23:07:50 -07:00
|
|
|
static void
|
|
|
|
rdataset_disassociate(dns_rdataset_t *rdataset DNS__DB_FLARG);
|
|
|
|
static isc_result_t
|
|
|
|
rdataset_first(dns_rdataset_t *rdataset);
|
|
|
|
static isc_result_t
|
|
|
|
rdataset_next(dns_rdataset_t *rdataset);
|
|
|
|
static void
|
|
|
|
rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata);
|
|
|
|
static void
|
|
|
|
rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target DNS__DB_FLARG);
|
|
|
|
static unsigned int
|
|
|
|
rdataset_count(dns_rdataset_t *rdataset);
|
|
|
|
static isc_result_t
|
|
|
|
rdataset_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name,
|
|
|
|
dns_rdataset_t *neg, dns_rdataset_t *negsig DNS__DB_FLARG);
|
|
|
|
static isc_result_t
|
|
|
|
rdataset_getclosest(dns_rdataset_t *rdataset, dns_name_t *name,
|
|
|
|
dns_rdataset_t *neg, dns_rdataset_t *negsig DNS__DB_FLARG);
|
|
|
|
static void
|
|
|
|
rdataset_settrust(dns_rdataset_t *rdataset, dns_trust_t trust);
|
|
|
|
static void
|
|
|
|
rdataset_expire(dns_rdataset_t *rdataset DNS__DB_FLARG);
|
|
|
|
static void
|
|
|
|
rdataset_clearprefetch(dns_rdataset_t *rdataset);
|
|
|
|
static void
|
|
|
|
rdataset_setownercase(dns_rdataset_t *rdataset, const dns_name_t *name);
|
|
|
|
static void
|
|
|
|
rdataset_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name);
|
2025-02-08 15:41:31 -08:00
|
|
|
static dns_slabheader_t *
|
|
|
|
rdataset_getheader(const dns_rdataset_t *rdataset);
|
2023-05-09 23:07:50 -07:00
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*% Note: the "const void *" are just to make qsort happy. */
|
2000-09-01 01:35:21 +00:00
|
|
|
static int
|
|
|
|
compare_rdata(const void *p1, const void *p2) {
|
2024-12-06 14:13:56 +01:00
|
|
|
return dns_rdata_compare(p1, p2);
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
|
|
|
|
2025-02-07 20:07:53 -08:00
|
|
|
static isc_result_t
|
|
|
|
makeslab(dns_rdataset_t *rdataset, isc_mem_t *mctx, isc_region_t *region,
|
|
|
|
uint32_t maxrrperset, bool raw) {
|
2012-06-01 23:33:16 +10:00
|
|
|
/*
|
|
|
|
* Use &removed as a sentinel pointer for duplicate
|
|
|
|
* rdata as rdata.data == NULL is valid.
|
|
|
|
*/
|
|
|
|
static unsigned char removed;
|
2024-12-06 14:13:56 +01:00
|
|
|
dns_rdata_t *rdata = NULL;
|
2023-05-11 09:38:26 -07:00
|
|
|
unsigned char *rawbuf = NULL;
|
2025-02-07 20:07:53 -08:00
|
|
|
unsigned int headerlen = raw ? 0 : sizeof(dns_slabheader_t);
|
1999-01-27 08:44:10 +00:00
|
|
|
unsigned int buflen;
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t result;
|
1999-01-27 08:44:10 +00:00
|
|
|
unsigned int nitems;
|
2000-09-01 01:35:21 +00:00
|
|
|
unsigned int nalloc;
|
2022-04-11 12:34:47 +01:00
|
|
|
unsigned int length;
|
2000-09-01 01:35:21 +00:00
|
|
|
unsigned int i;
|
1999-01-27 08:44:10 +00:00
|
|
|
|
2025-02-07 20:07:53 -08:00
|
|
|
buflen = headerlen + 2;
|
2000-09-01 01:35:21 +00:00
|
|
|
|
2014-05-20 11:36:03 +10:00
|
|
|
nitems = dns_rdataset_count(rdataset);
|
2000-09-01 01:35:21 +00:00
|
|
|
|
2014-05-20 11:36:03 +10:00
|
|
|
/*
|
|
|
|
* If there are no rdata then we can just need to allocate a header
|
|
|
|
* with zero a record count.
|
|
|
|
*/
|
|
|
|
if (nitems == 0) {
|
|
|
|
if (rdataset->type != 0) {
|
|
|
|
return ISC_R_FAILURE;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-05-20 11:36:03 +10:00
|
|
|
rawbuf = isc_mem_get(mctx, buflen);
|
|
|
|
region->base = rawbuf;
|
|
|
|
region->length = buflen;
|
2025-02-07 20:07:53 -08:00
|
|
|
rawbuf += headerlen;
|
2014-05-20 11:36:03 +10:00
|
|
|
*rawbuf++ = 0;
|
|
|
|
*rawbuf = 0;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
2006-03-03 00:43:35 +00:00
|
|
|
|
2024-03-01 08:26:07 +01:00
|
|
|
if (maxrrperset > 0 && nitems > maxrrperset) {
|
|
|
|
return DNS_R_TOOMANYRECORDS;
|
|
|
|
}
|
|
|
|
|
2014-05-20 11:36:03 +10:00
|
|
|
if (nitems > 0xffff) {
|
|
|
|
return ISC_R_NOSPACE;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-02-03 12:18:12 +00:00
|
|
|
|
2014-05-20 11:36:03 +10:00
|
|
|
/*
|
|
|
|
* Remember the original number of items.
|
|
|
|
*/
|
|
|
|
nalloc = nitems;
|
2024-12-06 14:13:56 +01:00
|
|
|
rdata = isc_mem_cget(mctx, nalloc, sizeof(rdata[0]));
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Save all of the rdata members into an array.
|
|
|
|
*/
|
2000-09-01 16:37:30 +00:00
|
|
|
result = dns_rdataset_first(rdataset);
|
2011-02-03 07:35:56 +00:00
|
|
|
if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) {
|
2000-11-22 00:18:34 +00:00
|
|
|
goto free_rdatas;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-11-22 00:18:34 +00:00
|
|
|
for (i = 0; i < nalloc && result == ISC_R_SUCCESS; i++) {
|
2000-09-01 01:35:21 +00:00
|
|
|
INSIST(result == ISC_R_SUCCESS);
|
2024-12-06 14:13:56 +01:00
|
|
|
dns_rdata_init(&rdata[i]);
|
|
|
|
dns_rdataset_current(rdataset, &rdata[i]);
|
|
|
|
INSIST(rdata[i].data != &removed);
|
2000-09-01 01:35:21 +00:00
|
|
|
result = dns_rdataset_next(rdataset);
|
|
|
|
}
|
2014-05-20 11:36:03 +10:00
|
|
|
if (i != nalloc || result != ISC_R_NOMORE) {
|
2000-11-22 00:18:34 +00:00
|
|
|
/*
|
|
|
|
* Somehow we iterated over fewer rdatas than
|
2014-05-20 11:36:03 +10:00
|
|
|
* dns_rdataset_count() said there were or there
|
|
|
|
* were more items than dns_rdataset_count said
|
|
|
|
* there were.
|
2000-11-22 00:18:34 +00:00
|
|
|
*/
|
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
goto free_rdatas;
|
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
|
2006-03-03 00:43:35 +00:00
|
|
|
/*
|
|
|
|
* Put into DNSSEC order.
|
|
|
|
*/
|
2014-05-20 11:36:03 +10:00
|
|
|
if (nalloc > 1U) {
|
2024-12-06 14:13:56 +01:00
|
|
|
qsort(rdata, nalloc, sizeof(rdata[0]), compare_rdata);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
/*
|
2000-11-22 00:18:34 +00:00
|
|
|
* Remove duplicates and compute the total storage required.
|
|
|
|
*
|
|
|
|
* If an rdata is not a duplicate, accumulate the storage size
|
|
|
|
* required for the rdata. We do not store the class, type, etc,
|
|
|
|
* just the rdata, so our overhead is 2 bytes for the number of
|
2006-03-03 00:43:35 +00:00
|
|
|
* records, and 8 for each rdata, (length(2), offset(4) and order(2))
|
|
|
|
* and then the rdata itself.
|
2000-09-01 01:35:21 +00:00
|
|
|
*/
|
|
|
|
for (i = 1; i < nalloc; i++) {
|
2024-12-06 14:13:56 +01:00
|
|
|
if (compare_rdata(&rdata[i - 1], &rdata[i]) == 0) {
|
|
|
|
rdata[i - 1].data = &removed;
|
2000-09-01 01:35:21 +00:00
|
|
|
nitems--;
|
2008-04-01 01:37:25 +00:00
|
|
|
} else {
|
2024-12-06 14:13:56 +01:00
|
|
|
buflen += (2 + rdata[i - 1].length);
|
2008-04-01 01:37:25 +00:00
|
|
|
/*
|
|
|
|
* Provide space to store the per RR meta data.
|
|
|
|
*/
|
|
|
|
if (rdataset->type == dns_rdatatype_rrsig) {
|
|
|
|
buflen++;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-04-01 01:37:25 +00:00
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
2014-05-20 11:36:03 +10:00
|
|
|
|
1999-01-27 08:44:10 +00:00
|
|
|
/*
|
2000-11-22 00:18:34 +00:00
|
|
|
* Don't forget the last item!
|
1999-01-27 08:44:10 +00:00
|
|
|
*/
|
2024-12-06 14:13:56 +01:00
|
|
|
buflen += (2 + rdata[i - 1].length);
|
2025-02-07 20:07:53 -08:00
|
|
|
|
2008-04-01 01:37:25 +00:00
|
|
|
/*
|
|
|
|
* Provide space to store the per RR meta data.
|
|
|
|
*/
|
|
|
|
if (rdataset->type == dns_rdatatype_rrsig) {
|
|
|
|
buflen++;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-01-27 08:44:10 +00:00
|
|
|
|
2000-11-22 00:18:34 +00:00
|
|
|
/*
|
2000-11-22 01:55:38 +00:00
|
|
|
* Ensure that singleton types are actually singletons.
|
2000-11-22 00:18:34 +00:00
|
|
|
*/
|
|
|
|
if (nitems > 1 && dns_rdatatype_issingleton(rdataset->type)) {
|
|
|
|
/*
|
|
|
|
* We have a singleton type, but there's more than one
|
|
|
|
* RR in the rdataset.
|
|
|
|
*/
|
|
|
|
result = DNS_R_SINGLETON;
|
|
|
|
goto free_rdatas;
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
1999-01-27 08:44:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate the memory, set up a buffer, start copying in
|
|
|
|
* data.
|
|
|
|
*/
|
2023-08-23 11:05:14 +02:00
|
|
|
rawbuf = isc_mem_cget(mctx, 1, buflen);
|
2008-04-01 23:47:10 +00:00
|
|
|
|
1999-01-27 08:44:10 +00:00
|
|
|
region->base = rawbuf;
|
|
|
|
region->length = buflen;
|
|
|
|
|
2025-02-07 20:07:53 -08:00
|
|
|
rawbuf += headerlen;
|
2018-01-13 00:31:30 +05:30
|
|
|
|
2025-02-07 14:31:33 -08:00
|
|
|
put_uint16(rawbuf, nitems);
|
2006-03-03 00:43:35 +00:00
|
|
|
|
2000-09-01 01:35:21 +00:00
|
|
|
for (i = 0; i < nalloc; i++) {
|
2024-12-06 14:13:56 +01:00
|
|
|
if (rdata[i].data == &removed) {
|
2000-09-01 01:35:21 +00:00
|
|
|
continue;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2024-12-06 14:13:56 +01:00
|
|
|
length = rdata[i].length;
|
2008-04-01 01:37:25 +00:00
|
|
|
if (rdataset->type == dns_rdatatype_rrsig) {
|
|
|
|
length++;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-08-16 09:42:14 +10:00
|
|
|
INSIST(length <= 0xffff);
|
2025-02-07 20:07:53 -08:00
|
|
|
|
2025-02-07 14:31:33 -08:00
|
|
|
put_uint16(rawbuf, length);
|
|
|
|
|
2008-04-01 01:37:25 +00:00
|
|
|
/*
|
|
|
|
* Store the per RR meta data.
|
|
|
|
*/
|
|
|
|
if (rdataset->type == dns_rdatatype_rrsig) {
|
2024-12-06 14:13:56 +01:00
|
|
|
*rawbuf++ = (rdata[i].flags & DNS_RDATA_OFFLINE)
|
2008-04-01 01:37:25 +00:00
|
|
|
? DNS_RDATASLAB_OFFLINE
|
|
|
|
: 0;
|
|
|
|
}
|
2024-12-06 14:13:56 +01:00
|
|
|
if (rdata[i].length != 0) {
|
|
|
|
memmove(rawbuf, rdata[i].data, rdata[i].length);
|
2024-03-13 10:15:03 +11:00
|
|
|
}
|
2024-12-06 14:13:56 +01:00
|
|
|
rawbuf += rdata[i].length;
|
1999-01-27 08:44:10 +00:00
|
|
|
}
|
2008-04-01 23:47:10 +00:00
|
|
|
|
2000-09-01 19:59:35 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
1999-01-27 08:44:10 +00:00
|
|
|
|
2000-09-01 19:59:35 +00:00
|
|
|
free_rdatas:
|
2024-12-06 14:13:56 +01:00
|
|
|
isc_mem_cput(mctx, rdata, nalloc, sizeof(rdata[0]));
|
2000-09-01 19:59:35 +00:00
|
|
|
return result;
|
1999-01-27 08:44:10 +00:00
|
|
|
}
|
|
|
|
|
2025-02-07 20:07:53 -08:00
|
|
|
isc_result_t
|
|
|
|
dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
|
|
|
|
isc_region_t *region, uint32_t maxrrperset) {
|
2025-02-07 21:06:34 -08:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = makeslab(rdataset, mctx, region, maxrrperset, false);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
dns_slabheader_t *new = (dns_slabheader_t *)region->base;
|
|
|
|
|
|
|
|
*new = (dns_slabheader_t){
|
|
|
|
.type = DNS_TYPEPAIR_VALUE(rdataset->type,
|
|
|
|
rdataset->covers),
|
|
|
|
.trust = rdataset->trust,
|
|
|
|
.ttl = rdataset->ttl,
|
|
|
|
.link = ISC_LINK_INITIALIZER,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2025-02-07 20:07:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_rdataslab_raw_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
|
|
|
|
isc_region_t *region, uint32_t maxrrperset) {
|
|
|
|
return makeslab(rdataset, mctx, region, maxrrperset, true);
|
|
|
|
}
|
|
|
|
|
1999-02-06 00:07:09 +00:00
|
|
|
unsigned int
|
2025-02-07 21:21:52 -08:00
|
|
|
dns_rdataslab_sizeraw(unsigned char *slab) {
|
1999-02-06 00:07:09 +00:00
|
|
|
REQUIRE(slab != NULL);
|
|
|
|
|
2025-02-07 21:21:52 -08:00
|
|
|
unsigned char *current = slab;
|
2024-02-29 22:26:29 +01:00
|
|
|
uint16_t count = get_uint16(current);
|
|
|
|
|
|
|
|
while (count-- > 0) {
|
|
|
|
uint16_t length = get_uint16(current);
|
2007-03-14 05:57:10 +00:00
|
|
|
current += length;
|
1999-02-06 00:07:09 +00:00
|
|
|
}
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-02-06 00:07:09 +00:00
|
|
|
return (unsigned int)(current - slab);
|
1999-01-27 08:44:10 +00:00
|
|
|
}
|
1999-04-01 04:00:39 +00:00
|
|
|
|
2020-02-22 00:37:05 -08:00
|
|
|
unsigned int
|
2025-02-07 21:21:52 -08:00
|
|
|
dns_rdataslab_size(dns_slabheader_t *header) {
|
|
|
|
REQUIRE(header != NULL);
|
2020-02-22 00:37:05 -08:00
|
|
|
|
2025-02-07 21:21:52 -08:00
|
|
|
unsigned char *s = (unsigned char *)header + sizeof(dns_slabheader_t);
|
|
|
|
return dns_rdataslab_sizeraw(s) + sizeof(dns_slabheader_t);
|
2020-02-22 00:37:05 -08:00
|
|
|
}
|
|
|
|
|
2016-11-02 17:31:27 +11:00
|
|
|
unsigned int
|
2025-02-07 21:21:52 -08:00
|
|
|
dns_rdataslab_count(dns_slabheader_t *header) {
|
|
|
|
REQUIRE(header != NULL);
|
2016-11-02 17:31:27 +11:00
|
|
|
|
2025-02-07 21:21:52 -08:00
|
|
|
unsigned char *current = (unsigned char *)header + sizeof(*header);
|
2024-02-29 22:26:29 +01:00
|
|
|
uint16_t count = get_uint16(current);
|
|
|
|
|
2016-11-02 17:31:27 +11:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2000-09-01 19:59:35 +00:00
|
|
|
/*
|
|
|
|
* Make the dns_rdata_t 'rdata' refer to the slab item
|
|
|
|
* beginning at '*current', which is part of a slab of type
|
|
|
|
* 'type' and class 'rdclass', and advance '*current' to
|
|
|
|
* point to the next item in the slab.
|
|
|
|
*/
|
2021-10-11 13:43:12 +02:00
|
|
|
static void
|
2025-02-07 14:31:33 -08:00
|
|
|
rdata_from_slabitem(unsigned char **current, dns_rdataclass_t rdclass,
|
|
|
|
dns_rdatatype_t type, dns_rdata_t *rdata) {
|
2000-09-01 19:59:35 +00:00
|
|
|
unsigned char *tcurrent = *current;
|
|
|
|
isc_region_t region;
|
2018-04-17 08:29:14 -07:00
|
|
|
bool offline = false;
|
2024-02-29 22:26:29 +01:00
|
|
|
uint16_t length = get_uint16(tcurrent);
|
2008-04-01 01:37:25 +00:00
|
|
|
|
|
|
|
if (type == dns_rdatatype_rrsig) {
|
|
|
|
if ((*tcurrent & DNS_RDATASLAB_OFFLINE) != 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
offline = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-04-01 01:37:25 +00:00
|
|
|
length--;
|
|
|
|
tcurrent++;
|
|
|
|
}
|
|
|
|
region.length = length;
|
2000-09-01 19:59:35 +00:00
|
|
|
region.base = tcurrent;
|
|
|
|
tcurrent += region.length;
|
|
|
|
dns_rdata_fromregion(rdata, rdclass, type, ®ion);
|
2008-04-02 02:37:42 +00:00
|
|
|
if (offline) {
|
2008-04-01 01:37:25 +00:00
|
|
|
rdata->flags |= DNS_RDATA_OFFLINE;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-09-01 19:59:35 +00:00
|
|
|
*current = tcurrent;
|
|
|
|
}
|
|
|
|
|
2025-02-07 14:31:33 -08:00
|
|
|
static void
|
|
|
|
rdata_to_slabitem(unsigned char **current, dns_rdatatype_t type,
|
|
|
|
dns_rdata_t *rdata) {
|
|
|
|
unsigned int length = rdata->length;
|
|
|
|
unsigned char *data = rdata->data;
|
|
|
|
unsigned char *p = *current;
|
|
|
|
|
|
|
|
if (type == dns_rdatatype_rrsig) {
|
|
|
|
length++;
|
|
|
|
data--;
|
|
|
|
}
|
|
|
|
|
|
|
|
put_uint16(p, length);
|
|
|
|
memmove(p, data, length);
|
|
|
|
p += length;
|
|
|
|
|
|
|
|
*current = p;
|
|
|
|
}
|
|
|
|
|
2025-02-09 20:03:01 -08:00
|
|
|
typedef struct slabinfo {
|
|
|
|
unsigned char *pos;
|
|
|
|
dns_rdata_t rdata;
|
|
|
|
bool dup;
|
|
|
|
} slabinfo_t;
|
2000-09-01 01:35:21 +00:00
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2025-02-07 21:21:52 -08:00
|
|
|
dns_rdataslab_merge(dns_slabheader_t *oheader, dns_slabheader_t *nheader,
|
|
|
|
isc_mem_t *mctx, dns_rdataclass_t rdclass,
|
|
|
|
dns_rdatatype_t type, unsigned int flags,
|
|
|
|
uint32_t maxrrperset, dns_slabheader_t **theaderp) {
|
2025-02-09 20:03:01 -08:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
unsigned char *ocurrent = NULL, *ncurrent = NULL, *tcurrent = NULL;
|
|
|
|
unsigned int ocount, ncount, tlength, tcount = 0;
|
|
|
|
slabinfo_t *oinfo = NULL, *ninfo = NULL;
|
|
|
|
size_t o = 0, n = 0;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2025-02-07 21:21:52 -08:00
|
|
|
REQUIRE(theaderp != NULL && *theaderp == NULL);
|
2025-02-07 14:31:33 -08:00
|
|
|
REQUIRE(oheader != NULL && nheader != NULL);
|
1999-04-01 04:00:39 +00:00
|
|
|
|
2025-02-07 14:31:33 -08:00
|
|
|
ocurrent = (unsigned char *)oheader + sizeof(dns_slabheader_t);
|
2024-02-29 22:26:29 +01:00
|
|
|
ocount = get_uint16(ocurrent);
|
2025-02-07 14:31:33 -08:00
|
|
|
|
|
|
|
ncurrent = (unsigned char *)nheader + sizeof(dns_slabheader_t);
|
2024-02-29 22:26:29 +01:00
|
|
|
ncount = get_uint16(ncurrent);
|
2025-02-07 14:31:33 -08:00
|
|
|
|
1999-04-01 04:00:39 +00:00
|
|
|
INSIST(ocount > 0 && ncount > 0);
|
|
|
|
|
2024-03-01 08:26:07 +01:00
|
|
|
if (maxrrperset > 0 && ocount + ncount > maxrrperset) {
|
|
|
|
return DNS_R_TOOMANYRECORDS;
|
|
|
|
}
|
|
|
|
|
1999-04-01 04:00:39 +00:00
|
|
|
/*
|
2025-02-09 20:03:01 -08:00
|
|
|
* Figure out the target length. Start with the header,
|
|
|
|
* plus 2 octets for the count.
|
1999-04-01 04:00:39 +00:00
|
|
|
*/
|
2025-02-07 14:31:33 -08:00
|
|
|
tlength = sizeof(dns_slabheader_t) + 2;
|
1999-04-01 04:00:39 +00:00
|
|
|
|
|
|
|
/*
|
2025-02-09 20:03:01 -08:00
|
|
|
* Gather the rdatas in the old slab and add their lengths to
|
|
|
|
* the larget length.
|
1999-04-01 04:00:39 +00:00
|
|
|
*/
|
2025-02-09 20:03:01 -08:00
|
|
|
oinfo = isc_mem_cget(mctx, ocount, sizeof(struct slabinfo));
|
2025-02-07 14:31:33 -08:00
|
|
|
for (size_t i = 0; i < ocount; i++) {
|
2025-02-09 20:03:01 -08:00
|
|
|
oinfo[i].pos = ocurrent;
|
|
|
|
dns_rdata_init(&oinfo[i].rdata);
|
|
|
|
rdata_from_slabitem(&ocurrent, rdclass, type, &oinfo[i].rdata);
|
|
|
|
tlength += ocurrent - oinfo[i].pos;
|
2025-02-07 14:31:33 -08:00
|
|
|
}
|
1999-04-01 04:00:39 +00:00
|
|
|
|
|
|
|
/*
|
2025-02-09 20:03:01 -08:00
|
|
|
* Then add the length of rdatas in the new slab that aren't
|
|
|
|
* duplicated in the old slab.
|
1999-04-01 04:00:39 +00:00
|
|
|
*/
|
2025-02-09 20:03:01 -08:00
|
|
|
ninfo = isc_mem_cget(mctx, ncount, sizeof(struct slabinfo));
|
2025-02-07 14:31:33 -08:00
|
|
|
for (size_t i = 0; i < ncount; i++) {
|
2025-02-09 20:03:01 -08:00
|
|
|
ninfo[i].pos = ncurrent;
|
|
|
|
dns_rdata_init(&ninfo[i].rdata);
|
|
|
|
rdata_from_slabitem(&ncurrent, rdclass, type, &ninfo[i].rdata);
|
|
|
|
|
|
|
|
for (size_t j = 0; j < ocount; j++) {
|
|
|
|
if (oinfo[j].dup) {
|
|
|
|
/*
|
|
|
|
* This was already found to be
|
|
|
|
* duplicated; no need to compare
|
|
|
|
* it again.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dns_rdata_compare(&oinfo[j].rdata,
|
|
|
|
&ninfo[i].rdata) == 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Found a dup. Mark the old copy as a
|
|
|
|
* duplicate so we don't check it again;
|
|
|
|
* mark the new copy as a duplicate so we
|
|
|
|
* don't copy it to the target.
|
|
|
|
*/
|
|
|
|
oinfo[j].dup = ninfo[i].dup = true;
|
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-04-01 04:00:39 +00:00
|
|
|
}
|
2025-02-09 20:03:01 -08:00
|
|
|
|
|
|
|
if (ninfo[i].dup) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We will be copying this item to the target, so
|
|
|
|
* add its length to tlength and increment tcount.
|
|
|
|
*/
|
|
|
|
tlength += ncurrent - ninfo[i].pos;
|
|
|
|
tcount++;
|
2025-02-07 14:31:33 -08:00
|
|
|
}
|
1999-04-01 04:00:39 +00:00
|
|
|
|
2025-02-07 14:31:33 -08:00
|
|
|
/*
|
|
|
|
* If the EXACT flag is set, there can't be any rdata in
|
2025-02-09 20:03:01 -08:00
|
|
|
* the new slab that was also in the old. If tcount is less
|
|
|
|
* than ncount, then we found such a duplicate.
|
2025-02-07 14:31:33 -08:00
|
|
|
*/
|
|
|
|
if (((flags & DNS_RDATASLAB_EXACT) != 0) && (tcount < ncount)) {
|
2025-02-09 20:03:01 -08:00
|
|
|
result = DNS_R_NOTEXACT;
|
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-11-30 23:59:08 +00:00
|
|
|
|
2025-02-07 14:31:33 -08:00
|
|
|
/*
|
2025-02-09 20:03:01 -08:00
|
|
|
* If nothing's being copied in from the new slab, and the
|
|
|
|
* FORCE flag isn't set, we're done.
|
2025-02-07 14:31:33 -08:00
|
|
|
*/
|
2025-02-09 20:03:01 -08:00
|
|
|
if (tcount == 0 && (flags & DNS_RDATASLAB_FORCE) == 0) {
|
|
|
|
result = DNS_R_UNCHANGED;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add to tcount the total number of items from the old slab. */
|
2025-02-07 14:31:33 -08:00
|
|
|
tcount += ocount;
|
|
|
|
|
2025-02-09 20:03:01 -08:00
|
|
|
/* Resposition ncurrent at the first item. */
|
|
|
|
ncurrent = (unsigned char *)nheader + sizeof(dns_slabheader_t) + 2;
|
1999-06-16 21:03:07 +00:00
|
|
|
|
2025-02-09 20:03:01 -08:00
|
|
|
/* Single types can't have more than one RR. */
|
2000-11-22 01:55:38 +00:00
|
|
|
if (tcount > 1 && dns_rdatatype_issingleton(type)) {
|
2025-02-09 20:03:01 -08:00
|
|
|
result = DNS_R_SINGLETON;
|
|
|
|
goto cleanup;
|
2000-11-22 01:55:38 +00:00
|
|
|
}
|
|
|
|
|
2006-03-03 00:43:35 +00:00
|
|
|
if (tcount > 0xffff) {
|
2025-02-09 20:03:01 -08:00
|
|
|
result = ISC_R_NOSPACE;
|
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-03-03 00:43:35 +00:00
|
|
|
|
2025-02-09 20:03:01 -08:00
|
|
|
/* Allocate the target buffer and copy the new slab's header */
|
|
|
|
unsigned char *tstart = isc_mem_get(mctx, tlength);
|
|
|
|
|
2025-02-07 14:31:33 -08:00
|
|
|
memmove(tstart, nheader, sizeof(dns_slabheader_t));
|
2025-02-07 21:21:52 -08:00
|
|
|
tcurrent = tstart + sizeof(dns_slabheader_t);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2025-02-09 20:03:01 -08:00
|
|
|
/* Write the new count, then start merging the slabs. */
|
2025-02-07 14:31:33 -08:00
|
|
|
put_uint16(tcurrent, tcount);
|
1999-04-01 04:00:39 +00:00
|
|
|
|
|
|
|
/*
|
2025-02-09 20:03:01 -08:00
|
|
|
* Now walk the sets together, adding each item in DNSSEC order,
|
|
|
|
* and skipping over any more dups in the new slab.
|
1999-04-01 04:00:39 +00:00
|
|
|
*/
|
2025-02-09 20:03:01 -08:00
|
|
|
while (o < ocount || n < ncount) {
|
2018-04-17 08:29:14 -07:00
|
|
|
bool fromold;
|
2025-02-07 14:31:33 -08:00
|
|
|
|
2025-02-09 20:03:01 -08:00
|
|
|
/* Skip to the next non-duplicate in the new slab. */
|
|
|
|
for (; n < ncount && ninfo[n].dup; n++)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (o == ocount) {
|
2018-04-17 08:29:14 -07:00
|
|
|
fromold = false;
|
2025-02-09 20:03:01 -08:00
|
|
|
} else if (n == ncount) {
|
2018-04-17 08:29:14 -07:00
|
|
|
fromold = true;
|
2000-09-01 01:35:21 +00:00
|
|
|
} else {
|
2025-02-09 20:03:01 -08:00
|
|
|
fromold = dns_rdata_compare(&oinfo[o].rdata,
|
|
|
|
&ninfo[n].rdata) < 0;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2025-02-07 14:31:33 -08:00
|
|
|
|
2000-09-01 01:35:21 +00:00
|
|
|
if (fromold) {
|
2025-02-09 20:03:01 -08:00
|
|
|
rdata_to_slabitem(&tcurrent, type, &oinfo[o].rdata);
|
|
|
|
if (++o < ocount) {
|
2025-02-07 14:31:33 -08:00
|
|
|
/* Skip to the next rdata in the old slab */
|
2025-02-09 20:03:01 -08:00
|
|
|
continue;
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
2025-02-09 20:03:01 -08:00
|
|
|
rdata_to_slabitem(&tcurrent, type, &ninfo[n++].rdata);
|
1999-04-01 04:00:39 +00:00
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
1999-04-01 04:00:39 +00:00
|
|
|
|
2000-09-01 19:59:35 +00:00
|
|
|
INSIST(tcurrent == tstart + tlength);
|
|
|
|
|
2025-02-07 21:21:52 -08:00
|
|
|
*theaderp = (dns_slabheader_t *)tstart;
|
1999-04-01 04:00:39 +00:00
|
|
|
|
2025-02-09 20:03:01 -08:00
|
|
|
cleanup:
|
|
|
|
isc_mem_cput(mctx, oinfo, ocount, sizeof(struct slabinfo));
|
|
|
|
isc_mem_cput(mctx, ninfo, ncount, sizeof(struct slabinfo));
|
|
|
|
|
|
|
|
return result;
|
1999-04-01 04:00:39 +00:00
|
|
|
}
|
1999-06-16 21:03:07 +00:00
|
|
|
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t
|
2025-02-09 20:43:39 -08:00
|
|
|
dns_rdataslab_subtract(dns_slabheader_t *oheader, dns_slabheader_t *sheader,
|
2025-02-07 21:21:52 -08:00
|
|
|
isc_mem_t *mctx, dns_rdataclass_t rdclass,
|
|
|
|
dns_rdatatype_t type, unsigned int flags,
|
|
|
|
dns_slabheader_t **theaderp) {
|
2025-02-09 20:43:39 -08:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
unsigned char *ocurrent = NULL, *scurrent = NULL;
|
2023-05-11 09:38:26 -07:00
|
|
|
unsigned char *tstart = NULL, *tcurrent = NULL;
|
2025-02-09 20:43:39 -08:00
|
|
|
unsigned int ocount, scount, tlength;
|
2025-02-07 14:31:33 -08:00
|
|
|
unsigned int tcount = 0, rcount = 0;
|
2025-02-09 20:43:39 -08:00
|
|
|
slabinfo_t *oinfo = NULL, *sinfo = NULL;
|
1999-06-16 21:03:07 +00:00
|
|
|
|
2025-02-07 21:21:52 -08:00
|
|
|
REQUIRE(theaderp != NULL && *theaderp == NULL);
|
2025-02-09 20:43:39 -08:00
|
|
|
REQUIRE(oheader != NULL && sheader != NULL);
|
1999-06-16 21:03:07 +00:00
|
|
|
|
2025-02-09 20:43:39 -08:00
|
|
|
ocurrent = (unsigned char *)oheader + sizeof(dns_slabheader_t);
|
|
|
|
ocount = get_uint16(ocurrent);
|
2025-02-07 14:31:33 -08:00
|
|
|
|
|
|
|
scurrent = (unsigned char *)sheader + sizeof(dns_slabheader_t);
|
2024-02-29 22:26:29 +01:00
|
|
|
scount = get_uint16(scurrent);
|
2025-02-07 14:31:33 -08:00
|
|
|
|
2025-02-09 20:43:39 -08:00
|
|
|
INSIST(ocount > 0 && scount > 0);
|
1999-06-16 21:03:07 +00:00
|
|
|
|
2025-02-09 20:43:39 -08:00
|
|
|
/* Get info about the rdatas being subtracted */
|
|
|
|
sinfo = isc_mem_cget(mctx, scount, sizeof(struct slabinfo));
|
|
|
|
for (size_t i = 0; i < scount; i++) {
|
|
|
|
sinfo[i].pos = scurrent;
|
|
|
|
dns_rdata_init(&sinfo[i].rdata);
|
|
|
|
rdata_from_slabitem(&scurrent, rdclass, type, &sinfo[i].rdata);
|
|
|
|
}
|
1999-06-16 21:03:07 +00:00
|
|
|
|
|
|
|
/*
|
2025-02-09 20:43:39 -08:00
|
|
|
* Figure out the target length. Start with the header,
|
|
|
|
* plus 2 octets for the count.
|
1999-06-16 21:03:07 +00:00
|
|
|
*/
|
2025-02-07 21:21:52 -08:00
|
|
|
tlength = sizeof(dns_slabheader_t) + 2;
|
2006-03-03 00:43:35 +00:00
|
|
|
|
1999-06-16 21:03:07 +00:00
|
|
|
/*
|
2025-02-09 20:43:39 -08:00
|
|
|
* Add the length of the rdatas in the old slab that
|
|
|
|
* aren't being subtracted.
|
1999-06-16 21:03:07 +00:00
|
|
|
*/
|
2025-02-09 20:43:39 -08:00
|
|
|
oinfo = isc_mem_cget(mctx, ocount, sizeof(struct slabinfo));
|
|
|
|
for (size_t i = 0; i < ocount; i++) {
|
|
|
|
bool matched = false;
|
|
|
|
|
|
|
|
oinfo[i].pos = ocurrent;
|
|
|
|
dns_rdata_init(&oinfo[i].rdata);
|
|
|
|
rdata_from_slabitem(&ocurrent, rdclass, type, &oinfo[i].rdata);
|
|
|
|
|
|
|
|
for (size_t j = 0; j < scount; j++) {
|
|
|
|
if (sinfo[j].dup) {
|
|
|
|
continue;
|
|
|
|
} else if (dns_rdata_compare(&oinfo[i].rdata,
|
|
|
|
&sinfo[j].rdata) == 0)
|
|
|
|
{
|
|
|
|
matched = true;
|
|
|
|
oinfo[i].dup = sinfo[j].dup = true;
|
1999-06-16 21:03:07 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-06-16 21:03:07 +00:00
|
|
|
}
|
2025-02-09 20:43:39 -08:00
|
|
|
|
|
|
|
if (matched) {
|
|
|
|
/* This item will be subtracted. */
|
|
|
|
rcount++;
|
|
|
|
} else {
|
1999-06-16 21:03:07 +00:00
|
|
|
/*
|
2025-02-09 20:43:39 -08:00
|
|
|
* This rdata wasn't in the slab to be subtracted,
|
|
|
|
* so copy it to the target. Add its length to
|
|
|
|
* tlength and increment tcount.
|
1999-06-16 21:03:07 +00:00
|
|
|
*/
|
2025-02-09 20:43:39 -08:00
|
|
|
tlength += ocurrent - oinfo[i].pos;
|
1999-06-16 21:03:07 +00:00
|
|
|
tcount++;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-03-03 00:43:35 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 23:53:31 +00:00
|
|
|
/*
|
2025-02-09 20:43:39 -08:00
|
|
|
* If the EXACT flag wasn't set, check that all the records that
|
|
|
|
* were to be subtracted actually did exist in the original slab.
|
|
|
|
* (The numeric check works here because rdataslabs do not contain
|
|
|
|
* duplicates.)
|
2000-10-18 23:53:31 +00:00
|
|
|
*/
|
2025-02-09 20:43:39 -08:00
|
|
|
if ((flags & DNS_RDATASLAB_EXACT) != 0 && rcount != scount) {
|
|
|
|
result = DNS_R_NOTEXACT;
|
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-10-18 23:53:31 +00:00
|
|
|
|
1999-06-16 21:03:07 +00:00
|
|
|
/*
|
2025-02-09 20:43:39 -08:00
|
|
|
* If the resulting rdataslab would be empty, don't bother to
|
|
|
|
* create a new buffer, just return.
|
1999-06-16 21:03:07 +00:00
|
|
|
*/
|
|
|
|
if (tcount == 0) {
|
2025-02-09 20:43:39 -08:00
|
|
|
result = DNS_R_NXRRSET;
|
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-06-16 21:03:07 +00:00
|
|
|
|
1999-06-17 00:31:32 +00:00
|
|
|
/*
|
2025-02-09 20:43:39 -08:00
|
|
|
* If nothing is going to change, stop.
|
1999-06-17 00:31:32 +00:00
|
|
|
*/
|
2000-10-18 23:53:31 +00:00
|
|
|
if (rcount == 0) {
|
2025-02-09 20:43:39 -08:00
|
|
|
result = DNS_R_UNCHANGED;
|
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-06-17 00:31:32 +00:00
|
|
|
|
1999-06-16 21:03:07 +00:00
|
|
|
/*
|
2025-02-09 20:43:39 -08:00
|
|
|
* Allocate the target buffer and copy the old slab's header.
|
1999-06-16 21:03:07 +00:00
|
|
|
*/
|
|
|
|
tstart = isc_mem_get(mctx, tlength);
|
2025-02-09 20:43:39 -08:00
|
|
|
memmove(tstart, oheader, sizeof(dns_slabheader_t));
|
2025-02-07 21:21:52 -08:00
|
|
|
tcurrent = tstart + sizeof(dns_slabheader_t);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-06-16 21:03:07 +00:00
|
|
|
/*
|
|
|
|
* Write the new count.
|
|
|
|
*/
|
2025-02-07 14:31:33 -08:00
|
|
|
put_uint16(tcurrent, tcount);
|
1999-06-16 21:03:07 +00:00
|
|
|
|
|
|
|
/*
|
2025-02-09 20:43:39 -08:00
|
|
|
* Copy the parts of the old slab that didn't have duplicates.
|
1999-06-16 21:03:07 +00:00
|
|
|
*/
|
2025-02-09 20:43:39 -08:00
|
|
|
for (size_t i = 0; i < ocount; i++) {
|
|
|
|
if (!oinfo[i].dup) {
|
|
|
|
rdata_to_slabitem(&tcurrent, type, &oinfo[i].rdata);
|
1999-06-16 21:03:07 +00:00
|
|
|
}
|
2006-03-03 00:43:35 +00:00
|
|
|
}
|
|
|
|
|
2000-09-01 19:59:35 +00:00
|
|
|
INSIST(tcurrent == tstart + tlength);
|
|
|
|
|
2025-02-07 21:21:52 -08:00
|
|
|
*theaderp = (dns_slabheader_t *)tstart;
|
1999-06-16 21:03:07 +00:00
|
|
|
|
2025-02-09 20:43:39 -08:00
|
|
|
cleanup:
|
|
|
|
isc_mem_cput(mctx, oinfo, ocount, sizeof(struct slabinfo));
|
|
|
|
isc_mem_cput(mctx, sinfo, scount, sizeof(struct slabinfo));
|
|
|
|
|
|
|
|
return result;
|
1999-06-16 21:03:07 +00:00
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
2025-02-06 15:50:52 -08:00
|
|
|
dns_rdataslab_equal(dns_slabheader_t *slab1, dns_slabheader_t *slab2) {
|
2023-05-09 23:07:50 -07:00
|
|
|
unsigned char *current1 = NULL, *current2 = NULL;
|
2000-09-01 01:35:21 +00:00
|
|
|
unsigned int count1, count2;
|
|
|
|
|
2025-02-06 15:50:52 -08:00
|
|
|
current1 = (unsigned char *)slab1 + sizeof(dns_slabheader_t);
|
2024-02-29 22:26:29 +01:00
|
|
|
count1 = get_uint16(current1);
|
2000-09-01 01:35:21 +00:00
|
|
|
|
2025-02-06 15:50:52 -08:00
|
|
|
current2 = (unsigned char *)slab2 + sizeof(dns_slabheader_t);
|
2024-02-29 22:26:29 +01:00
|
|
|
count2 = get_uint16(current2);
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
if (count1 != count2) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return false;
|
2025-02-06 15:50:52 -08:00
|
|
|
} else if (count1 == 0) {
|
|
|
|
return true;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
|
2024-02-29 22:26:29 +01:00
|
|
|
while (count1-- > 0) {
|
2025-02-07 21:21:52 -08:00
|
|
|
unsigned int length1 = get_uint16(current1);
|
|
|
|
unsigned int length2 = get_uint16(current2);
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
if (length1 != length2 ||
|
2022-11-02 19:33:14 +01:00
|
|
|
memcmp(current1, current2, length1) != 0)
|
|
|
|
{
|
2018-04-17 08:29:14 -07:00
|
|
|
return false;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-09-01 01:35:21 +00:00
|
|
|
|
|
|
|
current1 += length1;
|
|
|
|
current2 += length1;
|
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
return true;
|
2000-09-01 01:35:21 +00:00
|
|
|
}
|
2002-11-12 23:24:45 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
2025-02-06 15:50:52 -08:00
|
|
|
dns_rdataslab_equalx(dns_slabheader_t *slab1, dns_slabheader_t *slab2,
|
|
|
|
dns_rdataclass_t rdclass, dns_rdatatype_t type) {
|
2023-05-09 23:07:50 -07:00
|
|
|
unsigned char *current1 = NULL, *current2 = NULL;
|
2002-11-12 23:24:45 +00:00
|
|
|
unsigned int count1, count2;
|
|
|
|
|
2025-02-06 15:50:52 -08:00
|
|
|
current1 = (unsigned char *)slab1 + sizeof(dns_slabheader_t);
|
2024-02-29 22:26:29 +01:00
|
|
|
count1 = get_uint16(current1);
|
2002-11-12 23:24:45 +00:00
|
|
|
|
2025-02-06 15:50:52 -08:00
|
|
|
current2 = (unsigned char *)slab2 + sizeof(dns_slabheader_t);
|
2024-02-29 22:26:29 +01:00
|
|
|
count2 = get_uint16(current2);
|
2002-11-12 23:24:45 +00:00
|
|
|
|
|
|
|
if (count1 != count2) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return false;
|
2025-02-06 15:50:52 -08:00
|
|
|
} else if (count1 == 0) {
|
|
|
|
return true;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2002-11-12 23:24:45 +00:00
|
|
|
|
|
|
|
while (count1-- > 0) {
|
2025-02-07 21:21:52 -08:00
|
|
|
dns_rdata_t rdata1 = DNS_RDATA_INIT;
|
|
|
|
dns_rdata_t rdata2 = DNS_RDATA_INIT;
|
|
|
|
|
2025-02-07 14:31:33 -08:00
|
|
|
rdata_from_slabitem(¤t1, rdclass, type, &rdata1);
|
|
|
|
rdata_from_slabitem(¤t2, rdclass, type, &rdata2);
|
2002-11-12 23:24:45 +00:00
|
|
|
if (dns_rdata_compare(&rdata1, &rdata2) != 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return false;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2002-11-12 23:24:45 +00:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
return true;
|
2002-11-12 23:24:45 +00:00
|
|
|
}
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
void *
|
|
|
|
dns_slabheader_raw(dns_slabheader_t *header) {
|
|
|
|
return header + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_slabheader_setownercase(dns_slabheader_t *header, const dns_name_t *name) {
|
|
|
|
unsigned int i;
|
|
|
|
bool fully_lower;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not need to worry about label lengths as they are all
|
|
|
|
* less than or equal to 63.
|
|
|
|
*/
|
|
|
|
memset(header->upper, 0, sizeof(header->upper));
|
|
|
|
fully_lower = true;
|
|
|
|
for (i = 0; i < name->length; i++) {
|
|
|
|
if (isupper(name->ndata[i])) {
|
|
|
|
header->upper[i / 8] |= 1 << (i % 8);
|
|
|
|
fully_lower = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DNS_SLABHEADER_SETATTR(header, DNS_SLABHEADERATTR_CASESET);
|
|
|
|
if (fully_lower) {
|
|
|
|
DNS_SLABHEADER_SETATTR(header,
|
|
|
|
DNS_SLABHEADERATTR_CASEFULLYLOWER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_slabheader_copycase(dns_slabheader_t *dest, dns_slabheader_t *src) {
|
|
|
|
if (CASESET(src)) {
|
|
|
|
uint_least16_t attr = DNS_SLABHEADER_GETATTR(
|
|
|
|
src, (DNS_SLABHEADERATTR_CASESET |
|
|
|
|
DNS_SLABHEADERATTR_CASEFULLYLOWER));
|
|
|
|
DNS_SLABHEADER_SETATTR(dest, attr);
|
|
|
|
memmove(dest->upper, src->upper, sizeof(src->upper));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_slabheader_reset(dns_slabheader_t *h, dns_db_t *db, dns_dbnode_t *node) {
|
|
|
|
ISC_LINK_INIT(h, link);
|
|
|
|
h->heap_index = 0;
|
|
|
|
h->heap = NULL;
|
|
|
|
h->db = db;
|
|
|
|
h->node = node;
|
|
|
|
|
|
|
|
atomic_init(&h->attributes, 0);
|
|
|
|
atomic_init(&h->last_refresh_fail_ts, 0);
|
|
|
|
|
|
|
|
STATIC_ASSERT((sizeof(h->attributes) == 2),
|
|
|
|
"The .attributes field of dns_slabheader_t needs to be "
|
|
|
|
"16-bit int type exactly.");
|
|
|
|
}
|
|
|
|
|
|
|
|
dns_slabheader_t *
|
|
|
|
dns_slabheader_new(dns_db_t *db, dns_dbnode_t *node) {
|
|
|
|
dns_slabheader_t *h = NULL;
|
|
|
|
|
|
|
|
h = isc_mem_get(db->mctx, sizeof(*h));
|
|
|
|
*h = (dns_slabheader_t){
|
|
|
|
.link = ISC_LINK_INITIALIZER,
|
|
|
|
};
|
|
|
|
dns_slabheader_reset(h, db, node);
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dns_slabheader_destroy(dns_slabheader_t **headerp) {
|
|
|
|
unsigned int size;
|
|
|
|
dns_slabheader_t *header = *headerp;
|
|
|
|
|
|
|
|
*headerp = NULL;
|
|
|
|
|
|
|
|
isc_mem_t *mctx = header->db->mctx;
|
|
|
|
|
|
|
|
dns_db_deletedata(header->db, header->node, header);
|
|
|
|
|
|
|
|
if (NONEXISTENT(header)) {
|
|
|
|
size = sizeof(*header);
|
|
|
|
} else {
|
2025-02-07 21:21:52 -08:00
|
|
|
size = dns_rdataslab_size(header);
|
2023-05-09 23:07:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_mem_put(mctx, header, size);
|
|
|
|
}
|
|
|
|
|
2023-10-01 01:06:49 -07:00
|
|
|
void
|
|
|
|
dns_slabheader_freeproof(isc_mem_t *mctx, dns_slabheader_proof_t **proof) {
|
|
|
|
if (dns_name_dynamic(&(*proof)->name)) {
|
|
|
|
dns_name_free(&(*proof)->name, mctx);
|
|
|
|
}
|
|
|
|
if ((*proof)->neg != NULL) {
|
|
|
|
isc_mem_put(mctx, (*proof)->neg,
|
2025-02-07 21:21:52 -08:00
|
|
|
dns_rdataslab_sizeraw((*proof)->neg));
|
2023-10-01 01:06:49 -07:00
|
|
|
}
|
|
|
|
if ((*proof)->negsig != NULL) {
|
|
|
|
isc_mem_put(mctx, (*proof)->negsig,
|
2025-02-07 21:21:52 -08:00
|
|
|
dns_rdataslab_sizeraw((*proof)->negsig));
|
2023-10-01 01:06:49 -07:00
|
|
|
}
|
|
|
|
isc_mem_put(mctx, *proof, sizeof(**proof));
|
|
|
|
*proof = NULL;
|
|
|
|
}
|
|
|
|
|
2025-02-08 15:41:31 -08:00
|
|
|
dns_slabheader_t *
|
|
|
|
dns_slabheader_top(dns_slabheader_t *header) {
|
|
|
|
dns_typepair_t type, negtype;
|
|
|
|
dns_rdatatype_t rdtype, covers;
|
|
|
|
|
|
|
|
type = header->type;
|
|
|
|
rdtype = DNS_TYPEPAIR_TYPE(header->type);
|
|
|
|
if (NEGATIVE(header)) {
|
|
|
|
covers = DNS_TYPEPAIR_COVERS(header->type);
|
|
|
|
negtype = DNS_TYPEPAIR_VALUE(covers, 0);
|
|
|
|
} else {
|
|
|
|
negtype = DNS_TYPEPAIR_VALUE(0, rdtype);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the start of the header chain for the next type
|
|
|
|
* by walking back up the list.
|
|
|
|
*/
|
|
|
|
while (header->up != NULL &&
|
|
|
|
(header->up->type == type || header->up->type == negtype))
|
|
|
|
{
|
|
|
|
header = header->up;
|
|
|
|
}
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2023-05-09 23:07:50 -07:00
|
|
|
dns_rdatasetmethods_t dns_rdataslab_rdatasetmethods = {
|
|
|
|
.disassociate = rdataset_disassociate,
|
|
|
|
.first = rdataset_first,
|
|
|
|
.next = rdataset_next,
|
|
|
|
.current = rdataset_current,
|
|
|
|
.clone = rdataset_clone,
|
|
|
|
.count = rdataset_count,
|
|
|
|
.getnoqname = rdataset_getnoqname,
|
|
|
|
.getclosest = rdataset_getclosest,
|
|
|
|
.settrust = rdataset_settrust,
|
|
|
|
.expire = rdataset_expire,
|
|
|
|
.clearprefetch = rdataset_clearprefetch,
|
|
|
|
.setownercase = rdataset_setownercase,
|
|
|
|
.getownercase = rdataset_getownercase,
|
2025-02-08 15:41:31 -08:00
|
|
|
.getheader = rdataset_getheader,
|
2023-05-09 23:07:50 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Fixed RRSet helper macros */
|
|
|
|
|
|
|
|
#define DNS_RDATASET_LENGTH 2;
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdataset_disassociate(dns_rdataset_t *rdataset DNS__DB_FLARG) {
|
|
|
|
dns_db_t *db = rdataset->slab.db;
|
|
|
|
dns_dbnode_t *node = rdataset->slab.node;
|
|
|
|
|
|
|
|
dns__db_detachnode(db, &node DNS__DB_FLARG_PASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
rdataset_first(dns_rdataset_t *rdataset) {
|
2024-02-29 22:26:29 +01:00
|
|
|
unsigned char *raw = rdataset->slab.raw;
|
|
|
|
uint16_t count = peek_uint16(raw);
|
2023-05-09 23:07:50 -07:00
|
|
|
if (count == 0) {
|
|
|
|
rdataset->slab.iter_pos = NULL;
|
|
|
|
rdataset->slab.iter_count = 0;
|
|
|
|
return ISC_R_NOMORE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* iter_count is the number of rdata beyond the cursor
|
|
|
|
* position, so we decrement the total count by one before
|
|
|
|
* storing it.
|
|
|
|
*
|
2024-12-06 14:13:56 +01:00
|
|
|
* 'raw' points to the first record.
|
2023-05-09 23:07:50 -07:00
|
|
|
*/
|
|
|
|
rdataset->slab.iter_pos = raw + DNS_RDATASET_LENGTH;
|
|
|
|
rdataset->slab.iter_count = count - 1;
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
rdataset_next(dns_rdataset_t *rdataset) {
|
2024-02-29 22:26:29 +01:00
|
|
|
uint16_t count = rdataset->slab.iter_count;
|
2023-05-09 23:07:50 -07:00
|
|
|
if (count == 0) {
|
|
|
|
rdataset->slab.iter_pos = NULL;
|
|
|
|
return ISC_R_NOMORE;
|
|
|
|
}
|
|
|
|
rdataset->slab.iter_count = count - 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip forward one record (length + 4) or one offset (4).
|
|
|
|
*/
|
2024-02-29 22:26:29 +01:00
|
|
|
unsigned char *raw = rdataset->slab.iter_pos;
|
2024-12-06 14:13:56 +01:00
|
|
|
uint16_t length = peek_uint16(raw);
|
|
|
|
raw += length;
|
|
|
|
rdataset->slab.iter_pos = raw + DNS_RDATASET_LENGTH;
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
|
|
|
|
unsigned char *raw = NULL;
|
|
|
|
unsigned int length;
|
|
|
|
isc_region_t r;
|
|
|
|
unsigned int flags = 0;
|
|
|
|
|
|
|
|
raw = rdataset->slab.iter_pos;
|
|
|
|
REQUIRE(raw != NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the start of the record if not already in iter_pos
|
|
|
|
* then skip the length and order fields.
|
|
|
|
*/
|
2024-02-29 22:26:29 +01:00
|
|
|
length = peek_uint16(raw);
|
2023-05-09 23:07:50 -07:00
|
|
|
|
2024-12-06 14:13:56 +01:00
|
|
|
raw += DNS_RDATASET_LENGTH;
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
if (rdataset->type == dns_rdatatype_rrsig) {
|
|
|
|
if (*raw & DNS_RDATASLAB_OFFLINE) {
|
|
|
|
flags |= DNS_RDATA_OFFLINE;
|
|
|
|
}
|
|
|
|
length--;
|
|
|
|
raw++;
|
|
|
|
}
|
|
|
|
r.length = length;
|
|
|
|
r.base = raw;
|
|
|
|
dns_rdata_fromregion(rdata, rdataset->rdclass, rdataset->type, &r);
|
|
|
|
rdata->flags |= flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdataset_clone(dns_rdataset_t *source, dns_rdataset_t *target DNS__DB_FLARG) {
|
|
|
|
dns_db_t *db = source->slab.db;
|
|
|
|
dns_dbnode_t *node = source->slab.node;
|
|
|
|
dns_dbnode_t *cloned_node = NULL;
|
|
|
|
|
|
|
|
dns__db_attachnode(db, node, &cloned_node DNS__DB_FLARG_PASS);
|
|
|
|
INSIST(!ISC_LINK_LINKED(target, link));
|
|
|
|
*target = *source;
|
|
|
|
ISC_LINK_INIT(target, link);
|
|
|
|
|
|
|
|
target->slab.iter_pos = NULL;
|
|
|
|
target->slab.iter_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
rdataset_count(dns_rdataset_t *rdataset) {
|
|
|
|
unsigned char *raw = NULL;
|
|
|
|
unsigned int count;
|
|
|
|
|
|
|
|
raw = rdataset->slab.raw;
|
2024-02-29 22:26:29 +01:00
|
|
|
count = get_uint16(raw);
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
rdataset_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name,
|
|
|
|
dns_rdataset_t *nsec,
|
|
|
|
dns_rdataset_t *nsecsig DNS__DB_FLARG) {
|
|
|
|
dns_db_t *db = rdataset->slab.db;
|
|
|
|
dns_dbnode_t *node = rdataset->slab.node;
|
2023-10-01 01:06:49 -07:00
|
|
|
const dns_slabheader_proof_t *noqname = rdataset->slab.noqname;
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Usually, rdataset->slab.raw refers the data following a
|
|
|
|
* dns_slabheader, but in this case it points to a bare
|
|
|
|
* rdataslab belonging to the dns_slabheader's `noqname` field.
|
2025-02-08 15:41:31 -08:00
|
|
|
* The DNS_RDATASETATTR_NOHEADER attribute is set so that
|
|
|
|
* dns_rdataset_getheader() will return NULL, and the _KEEPCASE
|
|
|
|
* attribute is set to prevent setownercase and getownercase
|
|
|
|
* methods from affecting the case of NSEC/NSEC3 owner names.
|
2023-05-09 23:07:50 -07:00
|
|
|
*/
|
|
|
|
dns__db_attachnode(db, node,
|
|
|
|
&(dns_dbnode_t *){ NULL } DNS__DB_FLARG_PASS);
|
|
|
|
*nsec = (dns_rdataset_t){
|
|
|
|
.methods = &dns_rdataslab_rdatasetmethods,
|
|
|
|
.rdclass = db->rdclass,
|
|
|
|
.type = noqname->type,
|
|
|
|
.ttl = rdataset->ttl,
|
|
|
|
.trust = rdataset->trust,
|
|
|
|
.slab.db = db,
|
|
|
|
.slab.node = node,
|
|
|
|
.slab.raw = noqname->neg,
|
|
|
|
.link = nsec->link,
|
|
|
|
.count = nsec->count,
|
2025-02-08 15:41:31 -08:00
|
|
|
.attributes = nsec->attributes | DNS_RDATASETATTR_KEEPCASE |
|
|
|
|
DNS_RDATASETATTR_NOHEADER,
|
2023-05-09 23:07:50 -07:00
|
|
|
.magic = nsec->magic,
|
|
|
|
};
|
|
|
|
|
|
|
|
dns__db_attachnode(db, node,
|
|
|
|
&(dns_dbnode_t *){ NULL } DNS__DB_FLARG_PASS);
|
|
|
|
*nsecsig = (dns_rdataset_t){
|
|
|
|
.methods = &dns_rdataslab_rdatasetmethods,
|
|
|
|
.rdclass = db->rdclass,
|
|
|
|
.type = dns_rdatatype_rrsig,
|
|
|
|
.covers = noqname->type,
|
|
|
|
.ttl = rdataset->ttl,
|
|
|
|
.trust = rdataset->trust,
|
|
|
|
.slab.db = db,
|
|
|
|
.slab.node = node,
|
|
|
|
.slab.raw = noqname->negsig,
|
|
|
|
.link = nsecsig->link,
|
|
|
|
.count = nsecsig->count,
|
2025-02-08 15:41:31 -08:00
|
|
|
.attributes = nsecsig->attributes | DNS_RDATASETATTR_KEEPCASE |
|
|
|
|
DNS_RDATASETATTR_NOHEADER,
|
2023-05-09 23:07:50 -07:00
|
|
|
.magic = nsecsig->magic,
|
|
|
|
};
|
|
|
|
|
|
|
|
dns_name_clone(&noqname->name, name);
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
rdataset_getclosest(dns_rdataset_t *rdataset, dns_name_t *name,
|
|
|
|
dns_rdataset_t *nsec,
|
|
|
|
dns_rdataset_t *nsecsig DNS__DB_FLARG) {
|
|
|
|
dns_db_t *db = rdataset->slab.db;
|
|
|
|
dns_dbnode_t *node = rdataset->slab.node;
|
2023-10-01 01:06:49 -07:00
|
|
|
const dns_slabheader_proof_t *closest = rdataset->slab.closest;
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* As mentioned above, rdataset->slab.raw usually refers the data
|
|
|
|
* following an dns_slabheader, but in this case it points to a bare
|
|
|
|
* rdataslab belonging to the dns_slabheader's `closest` field.
|
|
|
|
*/
|
|
|
|
dns__db_attachnode(db, node,
|
|
|
|
&(dns_dbnode_t *){ NULL } DNS__DB_FLARG_PASS);
|
|
|
|
*nsec = (dns_rdataset_t){
|
|
|
|
.methods = &dns_rdataslab_rdatasetmethods,
|
|
|
|
.rdclass = db->rdclass,
|
|
|
|
.type = closest->type,
|
|
|
|
.ttl = rdataset->ttl,
|
|
|
|
.trust = rdataset->trust,
|
|
|
|
.slab.db = db,
|
|
|
|
.slab.node = node,
|
|
|
|
.slab.raw = closest->neg,
|
|
|
|
.link = nsec->link,
|
|
|
|
.count = nsec->count,
|
2025-02-08 15:41:31 -08:00
|
|
|
.attributes = nsec->attributes | DNS_RDATASETATTR_KEEPCASE |
|
|
|
|
DNS_RDATASETATTR_NOHEADER,
|
2023-05-09 23:07:50 -07:00
|
|
|
.magic = nsec->magic,
|
|
|
|
};
|
|
|
|
|
|
|
|
dns__db_attachnode(db, node,
|
|
|
|
&(dns_dbnode_t *){ NULL } DNS__DB_FLARG_PASS);
|
|
|
|
*nsecsig = (dns_rdataset_t){
|
|
|
|
.methods = &dns_rdataslab_rdatasetmethods,
|
|
|
|
.rdclass = db->rdclass,
|
|
|
|
.type = dns_rdatatype_rrsig,
|
|
|
|
.covers = closest->type,
|
|
|
|
.ttl = rdataset->ttl,
|
|
|
|
.trust = rdataset->trust,
|
|
|
|
.slab.db = db,
|
|
|
|
.slab.node = node,
|
|
|
|
.slab.raw = closest->negsig,
|
|
|
|
.link = nsecsig->link,
|
|
|
|
.count = nsecsig->count,
|
2025-02-08 15:41:31 -08:00
|
|
|
.attributes = nsecsig->attributes | DNS_RDATASETATTR_KEEPCASE |
|
|
|
|
DNS_RDATASETATTR_NOHEADER,
|
2023-05-09 23:07:50 -07:00
|
|
|
.magic = nsecsig->magic,
|
|
|
|
};
|
|
|
|
|
|
|
|
dns_name_clone(&closest->name, name);
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdataset_settrust(dns_rdataset_t *rdataset, dns_trust_t trust) {
|
2025-02-08 15:41:31 -08:00
|
|
|
dns_slabheader_t *header = dns_rdataset_getheader(rdataset);
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
dns_db_locknode(header->db, header->node, isc_rwlocktype_write);
|
|
|
|
header->trust = rdataset->trust = trust;
|
|
|
|
dns_db_unlocknode(header->db, header->node, isc_rwlocktype_write);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdataset_expire(dns_rdataset_t *rdataset DNS__DB_FLARG) {
|
2025-02-08 15:41:31 -08:00
|
|
|
dns_slabheader_t *header = dns_rdataset_getheader(rdataset);
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
dns_db_expiredata(header->db, header->node, header);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdataset_clearprefetch(dns_rdataset_t *rdataset) {
|
2025-02-08 15:41:31 -08:00
|
|
|
dns_slabheader_t *header = dns_rdataset_getheader(rdataset);
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
dns_db_locknode(header->db, header->node, isc_rwlocktype_write);
|
|
|
|
DNS_SLABHEADER_CLRATTR(header, DNS_SLABHEADERATTR_PREFETCH);
|
|
|
|
dns_db_unlocknode(header->db, header->node, isc_rwlocktype_write);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdataset_setownercase(dns_rdataset_t *rdataset, const dns_name_t *name) {
|
2025-02-08 15:41:31 -08:00
|
|
|
dns_slabheader_t *header = dns_rdataset_getheader(rdataset);
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
dns_db_locknode(header->db, header->node, isc_rwlocktype_write);
|
|
|
|
dns_slabheader_setownercase(header, name);
|
|
|
|
dns_db_unlocknode(header->db, header->node, isc_rwlocktype_write);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rdataset_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) {
|
2025-02-08 15:41:31 -08:00
|
|
|
dns_slabheader_t *header = dns_rdataset_getheader(rdataset);
|
2023-05-09 23:07:50 -07:00
|
|
|
uint8_t mask = (1 << 7);
|
|
|
|
uint8_t bits = 0;
|
|
|
|
|
2023-08-03 12:51:41 -07:00
|
|
|
dns_db_locknode(header->db, header->node, isc_rwlocktype_read);
|
2023-05-09 23:07:50 -07:00
|
|
|
|
|
|
|
if (!CASESET(header)) {
|
|
|
|
goto unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CASEFULLYLOWER(header)) {
|
|
|
|
isc_ascii_lowercopy(name->ndata, name->ndata, name->length);
|
|
|
|
} else {
|
|
|
|
uint8_t *nd = name->ndata;
|
|
|
|
for (size_t i = 0; i < name->length; i++) {
|
|
|
|
if (mask == (1 << 7)) {
|
|
|
|
bits = header->upper[i / 8];
|
|
|
|
mask = 1;
|
|
|
|
} else {
|
|
|
|
mask <<= 1;
|
|
|
|
}
|
|
|
|
nd[i] = (bits & mask) ? isc_ascii_toupper(nd[i])
|
|
|
|
: isc_ascii_tolower(nd[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unlock:
|
2023-08-03 12:51:41 -07:00
|
|
|
dns_db_unlocknode(header->db, header->node, isc_rwlocktype_read);
|
2023-05-09 23:07:50 -07:00
|
|
|
}
|
2025-01-31 15:47:33 +01:00
|
|
|
|
2025-02-08 15:41:31 -08:00
|
|
|
static dns_slabheader_t *
|
|
|
|
rdataset_getheader(const dns_rdataset_t *rdataset) {
|
|
|
|
dns_slabheader_t *header = (dns_slabheader_t *)rdataset->slab.raw;
|
|
|
|
return header - 1;
|
2025-01-31 15:47:33 +01:00
|
|
|
}
|