2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 18:19:42 +00:00
bind/lib/dns/rdatalist.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

406 lines
8.7 KiB
C
Raw Normal View History

1999-01-15 08:05:14 +00:00
/*
2011-02-21 23:47:45 +00:00
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
1999-01-15 08:05:14 +00:00
*
* SPDX-License-Identifier: MPL-2.0
*
1999-01-15 08:05:14 +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/.
*
1999-01-15 08:05:14 +00:00
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
/*! \file */
2000-06-22 22:00:42 +00:00
1999-01-15 08:05:14 +00:00
#include <stddef.h>
#include <string.h>
1999-01-15 08:05:14 +00:00
2000-04-28 01:12:23 +00:00
#include <isc/util.h>
1999-01-15 08:05:14 +00:00
#include <dns/name.h>
#include <dns/nsec3.h>
1999-01-15 08:05:14 +00:00
#include <dns/rdata.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
static dns_rdatasetmethods_t methods = {
.disassociate = dns_rdatalist_disassociate,
.first = dns_rdatalist_first,
.next = dns_rdatalist_next,
.current = dns_rdatalist_current,
.clone = dns_rdatalist_clone,
.count = dns_rdatalist_count,
.addnoqname = dns_rdatalist_addnoqname,
.getnoqname = dns_rdatalist_getnoqname,
.addclosest = dns_rdatalist_addclosest,
.getclosest = dns_rdatalist_getclosest,
.setownercase = dns_rdatalist_setownercase,
.getownercase = dns_rdatalist_getownercase,
1999-01-15 08:05:14 +00:00
};
1999-10-27 00:43:43 +00:00
void
dns_rdatalist_init(dns_rdatalist_t *rdatalist) {
REQUIRE(rdatalist != NULL);
1999-10-27 00:43:43 +00:00
/*
* Initialize rdatalist.
*/
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
*rdatalist = (dns_rdatalist_t){
.rdata = ISC_LIST_INITIALIZER,
.link = ISC_LINK_INITIALIZER,
};
memset(rdatalist->upper, 0xeb, sizeof(rdatalist->upper));
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
/*
* Clear upper set bit.
*/
rdatalist->upper[0] &= ~0x01;
1999-10-27 00:43:43 +00:00
}
void
1999-01-15 08:05:14 +00:00
dns_rdatalist_tordataset(dns_rdatalist_t *rdatalist, dns_rdataset_t *rdataset) {
/*
* Make 'rdataset' refer to the rdata in 'rdatalist'.
*/
REQUIRE(rdatalist != NULL);
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(!dns_rdataset_isassociated(rdataset));
1999-01-15 08:05:14 +00:00
/* Check if dns_rdatalist_init has was called. */
REQUIRE(rdatalist->upper[0] == 0xea);
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
*rdataset = (dns_rdataset_t){
.methods = &methods,
.rdclass = rdatalist->rdclass,
.type = rdatalist->type,
.covers = rdatalist->covers,
.ttl = rdatalist->ttl,
.rdlist.list = rdatalist,
.link = rdataset->link,
.count = rdataset->count,
.attributes = rdataset->attributes,
.magic = rdataset->magic,
};
1999-01-15 08:05:14 +00:00
}
void
dns_rdatalist_fromrdataset(dns_rdataset_t *rdataset,
dns_rdatalist_t **rdatalist) {
REQUIRE(rdatalist != NULL && rdataset != NULL);
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
REQUIRE(rdataset->methods == &methods);
*rdatalist = rdataset->rdlist.list;
}
void
dns_rdatalist_disassociate(dns_rdataset_t *rdataset DNS__DB_FLARG) {
2000-05-11 22:47:00 +00:00
UNUSED(rdataset);
1999-01-15 08:05:14 +00:00
}
isc_result_t
dns_rdatalist_first(dns_rdataset_t *rdataset) {
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
dns_rdatalist_t *rdatalist = NULL;
1999-01-15 08:05:14 +00:00
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
rdatalist = rdataset->rdlist.list;
rdataset->rdlist.iter = ISC_LIST_HEAD(rdatalist->rdata);
1999-01-15 08:05:14 +00:00
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
if (rdataset->rdlist.iter == NULL) {
return ISC_R_NOMORE;
}
1999-01-15 08:05:14 +00:00
return ISC_R_SUCCESS;
1999-01-15 08:05:14 +00:00
}
isc_result_t
dns_rdatalist_next(dns_rdataset_t *rdataset) {
1999-01-15 08:05:14 +00:00
dns_rdata_t *rdata;
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
rdata = rdataset->rdlist.iter;
if (rdata == NULL) {
return ISC_R_NOMORE;
}
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
rdataset->rdlist.iter = ISC_LIST_NEXT(rdata, link);
1999-01-15 08:05:14 +00:00
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
if (rdataset->rdlist.iter == NULL) {
return ISC_R_NOMORE;
}
1999-01-15 08:05:14 +00:00
return ISC_R_SUCCESS;
1999-01-15 08:05:14 +00:00
}
void
dns_rdatalist_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) {
1999-01-15 08:05:14 +00:00
dns_rdata_t *list_rdata;
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
list_rdata = rdataset->rdlist.iter;
1999-01-15 08:05:14 +00:00
INSIST(list_rdata != NULL);
dns_rdata_clone(list_rdata, rdata);
1999-01-15 08:05:14 +00:00
}
1999-07-13 01:50:22 +00:00
void
dns_rdatalist_clone(dns_rdataset_t *source,
dns_rdataset_t *target DNS__DB_FLARG) {
REQUIRE(source != NULL);
REQUIRE(target != NULL);
1999-07-13 01:50:22 +00:00
*target = *source;
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
target->rdlist.iter = NULL;
1999-07-13 01:50:22 +00:00
}
1999-09-21 20:40:42 +00:00
unsigned int
dns_rdatalist_count(dns_rdataset_t *rdataset) {
dns_rdatalist_t *rdatalist = NULL;
1999-09-21 20:40:42 +00:00
unsigned int count;
REQUIRE(rdataset != NULL);
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
rdatalist = rdataset->rdlist.list;
1999-09-21 20:40:42 +00:00
count = 0;
ISC_LIST_FOREACH (rdatalist->rdata, rdata, link) {
1999-09-21 20:40:42 +00:00
count++;
}
1999-09-21 20:40:42 +00:00
return count;
}
isc_result_t
dns_rdatalist_addnoqname(dns_rdataset_t *rdataset, dns_name_t *name) {
dns_rdataset_t *neg = NULL;
dns_rdataset_t *negsig = NULL;
dns_ttl_t ttl;
REQUIRE(rdataset != NULL);
ISC_LIST_FOREACH (name->list, rdset, link) {
if (rdset->rdclass != rdataset->rdclass) {
continue;
}
if (dns_rdatatype_isnsec(rdset->type)) {
neg = rdset;
}
}
if (neg == NULL) {
return ISC_R_NOTFOUND;
}
ISC_LIST_FOREACH (name->list, rdset, link) {
if (rdset->type == dns_rdatatype_rrsig &&
2022-11-02 19:33:14 +01:00
rdset->covers == neg->type)
{
negsig = rdset;
}
}
if (negsig == NULL) {
return ISC_R_NOTFOUND;
}
/*
* Minimise ttl.
*/
ttl = rdataset->ttl;
if (neg->ttl < ttl) {
ttl = neg->ttl;
}
if (negsig->ttl < ttl) {
ttl = negsig->ttl;
}
rdataset->ttl = neg->ttl = negsig->ttl = ttl;
rdataset->attributes.noqname = true;
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
rdataset->rdlist.noqname = name;
return ISC_R_SUCCESS;
}
isc_result_t
dns_rdatalist_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name,
dns_rdataset_t *neg,
dns_rdataset_t *negsig DNS__DB_FLARG) {
dns_rdataclass_t rdclass;
dns_rdataset_t *tneg = NULL;
dns_rdataset_t *tnegsig = NULL;
dns_name_t *noqname = NULL;
REQUIRE(rdataset != NULL);
REQUIRE(rdataset->attributes.noqname);
rdclass = rdataset->rdclass;
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
noqname = rdataset->rdlist.noqname;
(void)dns_name_dynamic(noqname); /* Sanity Check. */
ISC_LIST_FOREACH (noqname->list, rdset, link) {
if (rdset->rdclass != rdclass) {
continue;
}
if (dns_rdatatype_isnsec(rdset->type)) {
tneg = rdset;
}
}
if (tneg == NULL) {
return ISC_R_NOTFOUND;
}
ISC_LIST_FOREACH (noqname->list, rdset, link) {
if (rdset->type == dns_rdatatype_rrsig &&
rdset->covers == tneg->type)
2022-11-02 19:33:14 +01:00
{
tnegsig = rdset;
}
}
if (tnegsig == NULL) {
return ISC_R_NOTFOUND;
}
dns_name_clone(noqname, name);
dns_rdataset_clone(tneg, neg);
dns_rdataset_clone(tnegsig, negsig);
return ISC_R_SUCCESS;
}
isc_result_t
dns_rdatalist_addclosest(dns_rdataset_t *rdataset, dns_name_t *name) {
dns_rdataset_t *neg = NULL;
dns_rdataset_t *negsig = NULL;
dns_ttl_t ttl;
REQUIRE(rdataset != NULL);
ISC_LIST_FOREACH (name->list, rdset, link) {
if (rdset->rdclass != rdataset->rdclass) {
continue;
}
if (dns_rdatatype_isnsec(rdset->type)) {
neg = rdset;
}
}
if (neg == NULL) {
return ISC_R_NOTFOUND;
}
ISC_LIST_FOREACH (name->list, rdset, link) {
if (rdset->type == dns_rdatatype_rrsig &&
2022-11-02 19:33:14 +01:00
rdset->covers == neg->type)
{
negsig = rdset;
}
}
if (negsig == NULL) {
return ISC_R_NOTFOUND;
}
/*
* Minimise ttl.
*/
ttl = rdataset->ttl;
if (neg->ttl < ttl) {
ttl = neg->ttl;
}
if (negsig->ttl < ttl) {
ttl = negsig->ttl;
}
rdataset->ttl = neg->ttl = negsig->ttl = ttl;
rdataset->attributes.closest = true;
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
rdataset->rdlist.closest = name;
return ISC_R_SUCCESS;
}
isc_result_t
dns_rdatalist_getclosest(dns_rdataset_t *rdataset, dns_name_t *name,
dns_rdataset_t *neg,
dns_rdataset_t *negsig DNS__DB_FLARG) {
dns_rdataclass_t rdclass;
dns_rdataset_t *tneg = NULL;
dns_rdataset_t *tnegsig = NULL;
dns_name_t *closest = NULL;
REQUIRE(rdataset != NULL);
REQUIRE(rdataset->attributes.closest);
rdclass = rdataset->rdclass;
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
closest = rdataset->rdlist.closest;
(void)dns_name_dynamic(closest); /* Sanity Check. */
ISC_LIST_FOREACH (closest->list, rdset, link) {
if (rdset->rdclass != rdclass) {
continue;
}
if (dns_rdatatype_isnsec(rdset->type)) {
tneg = rdset;
}
}
if (tneg == NULL) {
return ISC_R_NOTFOUND;
}
ISC_LIST_FOREACH (closest->list, rdset, link) {
if (rdset->type == dns_rdatatype_rrsig &&
rdset->covers == tneg->type)
2022-11-02 19:33:14 +01:00
{
tnegsig = rdset;
}
}
if (tnegsig == NULL) {
return ISC_R_NOTFOUND;
}
dns_name_clone(closest, name);
dns_rdataset_clone(tneg, neg);
dns_rdataset_clone(tnegsig, negsig);
return ISC_R_SUCCESS;
}
void
dns_rdatalist_setownercase(dns_rdataset_t *rdataset, const dns_name_t *name) {
dns_rdatalist_t *rdatalist;
unsigned int i;
2015-03-01 23:45:20 +00:00
/*
* We do not need to worry about label lengths as they are all
* less than or equal to 63.
*/
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
rdatalist = rdataset->rdlist.list;
memset(rdatalist->upper, 0, sizeof(rdatalist->upper));
for (i = 1; i < name->length; i++) {
if (name->ndata[i] >= 0x41 && name->ndata[i] <= 0x5a) {
rdatalist->upper[i / 8] |= 1 << (i % 8);
}
}
/*
* Record that upper has been set.
*/
rdatalist->upper[0] |= 0x01;
}
2015-03-01 23:45:20 +00:00
void
dns_rdatalist_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) {
dns_rdatalist_t *rdatalist;
unsigned int i;
2015-03-01 23:45:20 +00:00
Give the rdataset->privateN fields more helpful names BIND's rdataset structure is a view of some DNS records. It is polymorphic, so the details of how the records are stored can vary. For instance, the records can be held in an rdatalist, or in an rdataslab in the rbtdb. The dns_rdataset structure previously had a number of fields called `private1` up to `private7`, which were used by the various rdataset implementations. It was not at all clear what these fields were for, without reading the code and working it out from context. This change makes the rdataset inheritance hierarchy more clear. The polymorphic part of a `struct dns_rdataset` is now a union of structs, each of which is named for the class of implementation using it. The fields of these structs replace the old `privateN` fields. (Note: the term "inheritance hierarchy" refers to the fact that the builtin and SDLZ implementations are based on and inherit from the rdatalist implementation, which in turn inherits from the generic rdataset. Most of this change is mechanical, but there are a few extras. In keynode.c there were a number of REQUIRE()ments that were not necessary: they had already been checked by the rdataset method dispatch code. On the other hand, In ncache.c there was a public function which needed to REQUIRE() that an rdataset was valid. I have removed lots of "reset iterator state" comments, because it should now be clear from `target->iter = NULL` where before `target->private5 = NULL` could have been doing anything. Initialization is a bit neater in a few places, using C structure literals where appropriate. The pointer arithmetic for translating between an rdataslab header and its raw contents is now fractionally safer.
2023-04-28 01:12:39 +01:00
rdatalist = rdataset->rdlist.list;
if ((rdatalist->upper[0] & 0x01) == 0) {
return;
}
for (i = 0; i < name->length; i++) {
/*
* Set the case bit if it does not match the recorded bit.
*/
if (name->ndata[i] >= 0x61 && name->ndata[i] <= 0x7a &&
(rdatalist->upper[i / 8] & (1 << (i % 8))) != 0)
{
name->ndata[i] &= ~0x20; /* clear the lower case bit */
} else if (name->ndata[i] >= 0x41 && name->ndata[i] <= 0x5a &&
(rdatalist->upper[i / 8] & (1 << (i % 8))) == 0)
{
name->ndata[i] |= 0x20; /* set the lower case bit */
}
}
}