rbtdb.c revision d549c3734869b48e740c64e80890bcb6f3ce672c
/*
* Copyright (C) 1999, 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* Principal Author: Bob Halley
*/
#include <config.h>
#include <stddef.h>
#include <string.h>
#include <limits.h>
#include <isc/assertions.h>
#include <dns/fixedname.h>
#include <dns/dbiterator.h>
#include <dns/rdataslab.h>
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>
#include <dns/masterdump.h>
#ifdef DNS_RBTDB_VERSION64
#include "rbtdb64.h"
#else
#include "rbtdb.h"
#endif
#ifdef DNS_RBTDB_VERSION64
#else
#endif
#ifdef DNS_RBTDB_VERSION64
typedef isc_uint64_t rbtdb_serial_t;
#else
typedef isc_uint32_t rbtdb_serial_t;
#endif
typedef isc_uint32_t rbtdb_rdatatype_t;
#define RBTDB_RDATATYPE_VALUE(b, e) (((e) << 16) | (b))
#define RBTDB_RDATATYPE_SIGNXT \
#define RBTDB_RDATATYPE_SIGNS \
#define RBTDB_RDATATYPE_SIGCNAME \
#define RBTDB_RDATATYPE_NXDOMAIN \
typedef struct rdatasetheader {
/*
* Locked by the owning node's lock.
*/
/*
* We don't use the LIST macros, because the LIST structure has
* both head and tail pointers, and is doubly linked.
*/
struct rdatasetheader *next;
struct rdatasetheader *down;
#define RDATASET_ATTR_NONEXISTENT 0x01
#define RDATASET_ATTR_STALE 0x02
#define RDATASET_ATTR_IGNORE 0x04
#define NONEXISTENT(header) \
typedef struct {
unsigned int references;
typedef struct rbtdb_changed {
typedef struct rbtdb_version {
/* Not locked */
/* Locked by database lock. */
unsigned int references;
typedef struct {
/* Unlocked. */
unsigned int node_lock_count;
/* Locked by lock. */
unsigned int references;
unsigned int attributes;
/* Locked by tree_lock. */
} dns_rbtdb_t;
#define RBTDB_ATTR_LOADED 0x01
#define RBTDB_ATTR_LOADING 0x02
/*
* Search Context
*/
typedef struct {
dns_rbtdb_t * rbtdb;
unsigned int options;
/*
* Load Context
*/
typedef struct {
dns_rbtdb_t * rbtdb;
} rbtdb_load_t;
static dns_rdatasetmethods_t rdataset_methods = {
};
static dns_rdatasetitermethods_t rdatasetiter_methods = {
};
typedef struct rbtdb_rdatasetiter {
dns_name_t *name);
dns_name_t *name);
dns_name_t *name);
static dns_dbiteratormethods_t dbiterator_methods = {
};
typedef struct rbtdb_dbiterator {
/*
* Locking
*
* If a routine is going to lock more than one lock in this module, then
* the locking must be done in the following order:
*
* Tree Lock
*
* Node Lock (Only one from the set may be locked at one time by
* any caller)
*
* Database Lock
*
* Failure to follow this hierarchy can result in deadlock.
*/
/*
* Deleting Nodes
*
* Currently there is no deletion of nodes from the database, except when
* the database is being destroyed.
*
* If node deletion is added in the future, then for zone databases the node
* for the origin of the zone MUST NOT be deleted.
*/
/*
* DB Routines
*/
static void
rbtdb->references++;
}
static void
unsigned int i;
isc_region_t r;
sizeof (rbtdb_version_t));
for (i = 0; i < rbtdb->node_lock_count; i++)
}
static inline void
unsigned int i;
/* XXX check for open versions here */
/*
* Even though there are no external direct references, there still
* may be nodes in use.
*/
for (i = 0; i < rbtdb->node_lock_count; i++) {
if (set_exiting)
}
if (want_free)
}
static void
rbtdb->references--;
if (rbtdb->references == 0)
if (maybe_free)
}
static void
if (version->references == 0)
version->references++;
}
static inline rbtdb_version_t *
{
return (NULL);
return (version);
}
static isc_result_t
ISC_TRUE);
rbtdb->next_serial++;
}
return (DNS_R_NOMEMORY);
return (DNS_R_SUCCESS);
}
static void
{
rbtversion->references++;
*targetp = rbtversion;
}
static rbtdb_changed_t *
{
/*
* Caller must be holding the node lock.
*/
node->references++;
} else
return (changed);
}
static inline void
unsigned int size;
else
sizeof *rdataset);
}
static inline void
/*
* Caller must hold the node lock.
*/
/*
* We set the IGNORE attribute on rdatasets with serial number
* 'serial'. When the reference count goes to zero, these rdatasets
* will be cleaned up; until that time, they will be ignored.
*/
}
}
}
}
if (make_dirty)
}
static inline void
/*
* Caller must be holding the node lock.
*/
do {
}
/*
* If current is nonexistent or stale, we can clean it up.
*/
if ((current->attributes &
(RDATASET_ATTR_NONEXISTENT|RDATASET_ATTR_STALE)) != 0) {
else
} else
}
}
static inline void
{
/*
* Caller must be holding the node lock.
*/
REQUIRE(least_serial != 0);
/*
* Find the first rdataset less than the least serial, if
* any. On the way down, clean up any instances of multiple
* rdatasets with the same serial number, or that have the
* IGNORE attribute.
*/
break;
} else
}
/*
* If there is a such an rdataset, delete it and any older
* versions.
*/
do {
}
/*
* We've eliminated all IGNORE datasets with the possible
* exception of current, which we now check.
*/
else
/*
* current no longer exists, so we can
* just continue with the loop.
*/
continue;
} else {
/*
* Pull up current->down, making it the new
* current.
*/
else
}
}
/*
* Note. The serial number of 'current' might be less than
* least_serial too, but we cannot delete it because it is
* the most recent version, unless it is a NONEXISTENT
* rdataset or is IGNOREd.
*/
} else {
/*
* If this is a NONEXISTENT rdataset, we can delete it.
*/
!= 0) {
else
} else
}
}
if (!still_dirty)
}
static inline void
if (node->references == 0) {
}
node->references++;
}
static void
{
/*
* Caller must be holding the node lock.
*/
else {
if (least_serial == 0) {
/*
* Caller doesn't know the least serial.
* Get it.
*/
}
}
}
}
static inline void
{
/*
* Caller must be holding the database lock.
*/
}
static inline void
/*
* If the changed record is dirty, then
* an update created multiple versions of
* a given rdataset. We keep this list
* until we're the least open version, at
* which point it's safe to get rid of any
* older versions.
*
* If the changed record isn't dirty, then
* we don't need it anymore since we're
* committing and not rolling back.
*
* The caller must be holding the database lock.
*/
changed = next_changed) {
}
}
}
static void
version->references--;
if (version->references == 0) {
if (commit) {
/*
* We're going to become the least open
* version.
*/
&cleanup_list);
} else {
/*
* Some other open version is the
* least version. We can't cleanup
* records that were changed in this
* version because the older versions
* may still be in use by an open
* version.
*
* We can, however, discard the
* changed records for things that
* we've added that didn't exist in
* prior versions.
*/
&cleanup_list);
}
/*
* If the (soon to be former) current version
* isn't being used by anyone, we can clean
* it up.
*/
/*
* Become the current version.
*/
} else {
/*
* We're rolling back this transaction.
*/
}
} else {
/*
* There are no external or internal references
* to this version and it can be cleaned up.
*/
/*
* Find the version with the least serial
* number greater than ours.
*/
if (least_greater == NULL)
/*
* Is this the least open version?
*/
/*
* Yes. Install the new least open
* version.
*/
&cleanup_list);
} else {
/*
* Add any unexecuted cleanups to
* those of the least greater version.
*/
link);
}
}
}
}
if (cleanup_version != NULL)
sizeof *cleanup_version);
if (!EMPTY(cleanup_list)) {
changed = next_changed) {
rbtnode->references--;
if (rollback)
if (rbtnode->references == 0)
sizeof *changed);
}
}
}
static isc_result_t
{
unsigned int locknum;
if (result != DNS_R_SUCCESS) {
if (!create) {
if (result == DNS_R_PARTIALMATCH)
return (result);
}
/*
* It would be nice to try to upgrade the lock instead of
* unlocking then relocking.
*/
if (result == DNS_R_SUCCESS) {
} else if (result != DNS_R_EXISTS) {
return (result);
}
}
return (DNS_R_SUCCESS);
}
static isc_result_t
/*
* We only want to remember the topmost zone cut, since it's the one
* that counts, so we'll just continue if we've already found a
* zonecut.
*/
return (DNS_R_CONTINUE);
/*
* Look for an NS or DNAME rdataset active in our version.
*/
do {
/*
* Is this a "this rdataset doesn't
* exist" record?
*/
if ((header->attributes &
RDATASET_ATTR_NONEXISTENT) != 0)
break;
} else
/*
* We don't need to keep looking for
* NS records, because the DNAME has
* precedence.
*/
break;
/*
* We've found an NS rdataset that
* isn't at the origin node. We check
* that they're not at the origin node,
* because otherwise we'd erroneously
* treat the zone top as if it were
* a delegation.
*/
}
}
}
}
/*
* We increment the reference count on node to ensure that
* search->zonecut_rdataset will still be valid later.
*/
/*
* Since we've found a zonecut, anything beneath it is
* glue and is not subject to wildcard matching, so we
* may clear search->wild.
*/
/*
* Finding a DNAME stops all further searching.
*
* Note: We return DNS_R_PARTIALMATCH instead of
* DNS_R_DNAME here because that way zone_find()
* does fewer result code comparisions.
*/
/*
* If the caller does not want to find glue, then
* this is the best answer and the search should
* stop now.
*
* Note: We return DNS_R_PARTIALMATCH instead of
* DNS_R_DELEGATION here because that way zone_find()
* does fewer result code comparisions.
*/
} else {
/*
* The search will continue beneath the zone cut.
* This may or may not be the best match. In case it
* is, we need to remember the node name.
*/
NULL) ==
}
} else {
/*
* There is no zonecut at this node which is active in this
* version.
*
* If this is a "wild" node and the caller hasn't disabled
* wildcard matching, remember that we've seen a wild node
* in case we need to go searching for wildcard matches
* later on.
*/
}
return (result);
}
static inline void
{
unsigned char *raw;
unsigned int count;
/*
* Caller must be holding the node lock.
*/
return;
raw += 2;
if (count == 0) {
} else {
/*
* The private4 field is the number of rdata beyond
* the cursor position, so we decrement the total
* count by one before storing it.
*/
count--;
}
}
static inline isc_result_t
{
/*
* The caller MUST NOT be holding any node locks.
*/
/*
* If we have to set foundname, we do it before anything else.
* If we were to set foundname after we had set nodep or bound the
* rdataset, then we'd have to undo that work if dns_name_concatenate()
* failed. By setting foundname first, there's nothing to undo if
* we have trouble.
*/
if (result != DNS_R_SUCCESS)
return (result);
}
/*
* Note that we don't have to increment the node's reference
* count here because we're going to use the reference we
* already have in the search block.
*/
}
}
if (type == dns_rdatatype_dname)
return (DNS_R_DNAME);
return (DNS_R_DELEGATION);
}
static inline isc_boolean_t
{
unsigned char *raw;
/*
* No additional locking is required.
*/
/*
* Valid glue types are A, AAAA, A6. NS is also a valid glue type
* if it occurs at a zone cut, but is not valid below it.
*/
if (type == dns_rdatatype_ns) {
return (ISC_FALSE);
}
} else if (type != dns_rdatatype_a &&
type != dns_rdatatype_aaaa &&
type != dns_rdatatype_a6) {
return (ISC_FALSE);
}
raw += 2;
while (count > 0) {
count--;
raw += 2;
/*
* XXX Until we have rdata structures, we have no choice but
* to directly access the rdata format.
*/
break;
}
}
return (valid);
}
static inline isc_result_t
unsigned int i, j;
/*
* Caller must be holding the tree lock and MUST NOT be holding
* any node locks.
*/
/*
* Examine each ancestor level. If the level's wild bit
* is set, then construct the corresponding wildcard name and
* search for it. If the wildcard node exists, and is active in
* this version, we're done. If not, then we next check to see
* if the ancestor is active in this version. If so, then there
* can be no possible wildcard match and again we're done. If not,
* continue the search.
*/
do {
/*
* First we try to figure out if this node is active in
* the search's version. We do this now, even though we
* may not need the information, because it simplifies the
* locking and code flow.
*/
break;
}
else
else
if (wild) {
/*
* Construct the wildcard name for this level.
*/
j = i;
while (result == DNS_R_SUCCESS && j != 0) {
j--;
&name,
NULL);
}
if (result != DNS_R_SUCCESS)
break;
if (result == DNS_R_SUCCESS) {
/*
* We have found the wildcard node. If it
* is active in the search's version, we're
* done.
*/
break;
}
/*
* The wildcard node is active!
*
* Note: result is still DNS_R_SUCCESS
* so we don't have to set it.
*/
break;
}
} else if (result != DNS_R_NOTFOUND &&
result != DNS_R_PARTIALMATCH) {
/*
* An error has occurred. Bail out.
*/
break;
}
}
if (active) {
/*
* The level node is active. Any wildcarding
* present at higher levels has no
* effect and we're done.
*/
break;
}
if (i > 0) {
i--;
} else
} while (!done);
return (result);
}
static inline isc_result_t
{
do {
if (result != ISC_R_SUCCESS)
return (result);
header = header_next) {
/*
* Look for an active, extant NXT or SIG NXT.
*/
do {
/*
* Is this a "this rdataset doesn't
* exist" record?
*/
if ((header->attributes &
RDATASET_ATTR_NONEXISTENT) != 0)
break;
} else
/*
* We now know that there is at least one
* active rdataset at this node.
*/
break;
break;
}
}
}
if (!empty_node) {
/*
* We've found the right NXT record.
*
* XXXRTH Well, not necessarily. If
* someone adds an NS rdataset causing a
* tree to be obscured, we might be looking
* at a NXT record in the obscured part of
* the tree. To avoid this, we must either
* erase all the NXT records (causing lots
* of IXFR work), or we must somehow determine
* that we're looking at one. For now, we
* do nothing.
*/
if (result == ISC_R_SUCCESS) {
node);
}
rdataset);
}
} else {
/*
* We found an active node, but either the
* NXT or the SIG NXT is missing. This
* shouldn't happen.
*/
}
/*
* XXXRTH This is where we'll deal with obscured
* nodes. We have to do this whether we found
* a NXT or not, since we don't want to return
* DNS_R_BADDB for an obscured node that has no
* NXT (maybe the zone has been re-signed and the
* obscured NXTs eliminated). Here's what we'll
* do:
*
* Search the levels above us for a node
* with the find_callback bit set.
*
* See if there is an active DNAME or zonecut.
*
* If so, unbind any bindings we've made, and
* continue on. If we really feel ambitious,
* we can unwind the chain to the cut point,
* and continue searching from there. Probably
* not worth it for 9.0.0 since this will be a
* very uncommon case.
*
* Otherwise, the result we got (a NXT or
* DNS_R_BADDB) is the right result.
*/
} else {
/*
* This node isn't active. We've got to keep
* looking.
*/
NULL);
}
/*
* If the result is DNS_R_NOMORE, then we got to the beginning of
* the database and didn't find a NXT record. This shouldn't
* happen.
*/
if (result == DNS_R_NOMORE)
return (result);
}
static isc_result_t
{
/*
* We don't care about 'now'. We set it to zero so compilers won't
* complain about it being unused.
*/
now = 0;
/*
* If the caller didn't supply a version, attach to the current
* version.
*/
}
/*
* 'wild' will be true iff. we've matched a wildcard.
*/
/*
* Search down from the root of the tree. If, while going down, we
* encounter a callback node, zone_zonecut_callback() will search the
* rdatasets at the zone cut for active DNAME or NS rdatasets.
*/
if (result == DNS_R_PARTIALMATCH) {
rdataset);
goto tree_exit;
}
/*
* At least one of the levels in the search chain
* potentially has a wildcard. For each such level,
* we must see if there's a matching wildcard active
* in the current version.
*/
if (result == DNS_R_SUCCESS) {
if (result != DNS_R_SUCCESS)
goto tree_exit;
goto found;
}
else if (result != ISC_R_NOTFOUND)
goto tree_exit;
}
/*
* If we're here, then the name does not exist, is not
* beneath a zonecut, and there's no matching wildcard.
*/
if (result == ISC_R_SUCCESS)
} else
goto tree_exit;
} else if (result != DNS_R_SUCCESS)
goto tree_exit;
/*
* We have found a node whose name is the desired name, or we
* have matched a wildcard.
*/
/*
* If we're beneath a zone cut, we don't want to look for
* CNAMEs because they're not legitimate zone glue.
*/
} else {
/*
* The node may be a zone cut itself. If it might be one,
* make sure we check for it later.
*/
}
/*
* Certain DNSSEC types are not subject to CNAME matching
* (RFC 2535, section 2.3.5).
*
* We don't check for SIG, because we don't store SIG records
* directly.
*/
/*
* We now go looking for rdata...
*/
/*
* Look for an active, extant rdataset.
*/
do {
/*
* Is this a "this rdataset doesn't
* exist" record?
*/
if ((header->attributes &
RDATASET_ATTR_NONEXISTENT) != 0)
break;
} else
/*
* We now know that there is at least one active
* rdataset at this node.
*/
/*
* Do special zone cut handling, if requested.
*/
if (maybe_zonecut &&
/*
* We increment the reference count on node to
* ensure that search->zonecut_rdataset will
* still be valid later.
*/
&& type != dns_rdatatype_nxt
&& type != dns_rdatatype_key
&& type != dns_rdatatype_any) {
/*
* Glue is not OK, but any answer we
* could return would be glue. Return
* the delegation.
*/
break;
}
break;
}
/*
* If we found a type we were looking for,
* remember it.
*/
type == dns_rdatatype_any ||
cname_ok)) {
/*
* We've found the answer!
*/
cname_ok) {
/*
* We may be finding a CNAME instead
* of the desired type.
*
* If we've already got the CNAME SIG,
* use it, otherwise change sigtype
* so that we find it.
*/
else
sigtype =
}
/*
* If we've got all we need, end the search.
*/
break;
/*
* We've found the SIG rdataset for our
* target type. Remember it.
*/
/*
* If we've got all we need, end the search.
*/
break;
/*
* Remember a NXT rdataset even if we're
* not specifically looking for it, because
* we might need it later.
*/
/*
* If we need the NXT rdataset, we'll also
* need its signature.
*/
} else if (cname_ok &&
/*
* If we get a CNAME match, we'll also need
* its signature.
*/
}
}
}
if (empty_node) {
/*
* We have an exact match for the name, but there are no
* active rdatasets in the desired version. That means that
* this node doesn't exist in the desired version, and that
* we really have a partial match.
*
* If the node is the result of a wildcard match, then
* it must be active in the desired version, and hence
* empty_node should never be true. We INSIST upon it.
*/
goto partial_match;
}
/*
* If we didn't find what we were looking for...
*/
/*
* We were trying to find glue at a node beneath a
* zone cut, but didn't.
*
* Return the delegation.
*/
rdataset);
goto tree_exit;
} else {
/*
* The desired type doesn't exist.
*/
/*
* The zone is secure but there's no NXT,
* or the NXT has no signature!
*/
goto node_exit;
}
}
0, rdataset);
0, sigrdataset);
}
}
goto node_exit;
}
/*
* We found what we were looking for, or we found a CNAME.
*/
type != dns_rdatatype_any &&
/*
* We weren't doing an ANY query and we found a CNAME instead
* of the type we were looking for, so we need to indicate
* that result to the caller.
*/
/*
* If we're beneath a zone cut, we must indicate that the
* result is glue, unless we're actually at the zone cut
* and the type is NXT or KEY.
*/
if (type == dns_rdatatype_nxt ||
else if (type == dns_rdatatype_any)
else
result = DNS_R_GLUE;
} else
result = DNS_R_GLUE;
/*
* We might have found data that isn't glue, but was occluded
* by a dynamic update. If the caller cares about this, they
* will have told us to validate glue.
*
* XXX We should cache the glue validity state!
*/
if (result == DNS_R_GLUE &&
rdataset);
goto tree_exit;
}
} else {
/*
* An ordinary successful query!
*/
}
if (!at_zonecut)
else
}
if (type != dns_rdatatype_any) {
}
/*
* If we found a zonecut but aren't going to use it, we have to
* let go of it.
*/
if (search.need_cleanup) {
node->references--;
if (node->references == 0)
}
if (close_version)
return (result);
}
static isc_result_t
{
(void)db;
(void)name;
(void)options;
(void)now;
(void)nodep;
(void)foundname;
(void)rdataset;
(void)sigrdataset;
return (DNS_R_NOTIMPLEMENTED);
}
static isc_result_t
/* XXX comment */
/*
* Keep compiler silent.
*/
(void)name;
/*
* Look for a DNAME rdataset.
*/
header_prev = NULL;
/*
* This rdataset is stale. If no one else is
* using the node, we can clean it up right
* now, otherwise we mark it as stale, and
* the node as dirty, so it will get cleaned
* up later.
*/
if (node->references == 0) {
if (header_prev != NULL)
header_prev->next =
else
header);
} else {
header->attributes |=
}
0)
break;
else
}
/*
* We increment the reference count on node to ensure that
* search->zonecut_rdataset will still be valid later.
*/
} else
return (result);
}
static inline isc_result_t
{
unsigned int i;
/*
* Caller must be holding the tree lock.
*/
do {
/*
* Look for NS and SIG NS rdatasets.
*/
header_prev = NULL;
header = header_next) {
/*
* This rdataset is stale. If no one else is
* using the node, we can clean it up right
* now, otherwise we mark it as stale, and
* the node as dirty, so it will get cleaned
* up later.
*/
if (node->references == 0) {
if (header_prev != NULL)
header_prev->next =
else
header);
} else {
header->attributes |=
}
} else if ((header->attributes &
RDATASET_ATTR_NONEXISTENT) == 0) {
/*
* We've found an extant rdataset. See if
* we're interested in it.
*/
break;
break;
}
} else
}
/*
* If we have to set foundname, we do it before
* anything else. If we were to set foundname after
* we had set nodep or bound the rdataset, then we'd
* have to undo that work if dns_name_concatenate()
* failed. By setting foundname first, there's
* nothing to undo if we have trouble.
*/
while (result == DNS_R_SUCCESS && i > 0) {
i--;
&name);
result =
&name,
NULL);
}
if (result != DNS_R_SUCCESS) {
goto node_exit;
}
}
}
rdataset);
}
i--;
} else
} while (!done);
return (result);
}
static isc_result_t
{
if (now == 0)
/*
* Search down from the root of the tree. If, while going down, we
* encounter a callback node, cache_zonecut_callback() will search the
* rdatasets at the zone cut for a DNAME rdataset.
*/
if (result == DNS_R_PARTIALMATCH) {
rdataset);
goto tree_exit;
} else {
goto tree_exit;
}
} else if (result != DNS_R_SUCCESS)
goto tree_exit;
/*
* Certain DNSSEC types are not subject to CNAME matching
* (RFC 2535, section 2.3.5).
*
* We don't check for SIG, because we don't store SIG records
* directly.
*/
/*
* We now go looking for rdata...
*/
header_prev = NULL;
/*
* This rdataset is stale. If no one else is using the
* node, we can clean it up right now, otherwise we
* mark it as stale, and the node as dirty, so it will
* get cleaned up later.
*/
if (node->references == 0) {
if (header_prev != NULL)
else
header);
} else {
}
== 0) {
/*
* We now know that there is at least one active
* non-stale rdataset at this node.
*/
/*
* If we found a type we were looking for, remember
* it.
*/
(type == dns_rdatatype_any &&
/*
* We've found the answer.
*/
cname_ok &&
/*
* If we've already got the CNAME SIG,
* use it, otherwise change sigtype
* so that we find it.
*/
else
sigtype =
}
/*
* We've found the SIG rdataset for our
* target type. Remember it.
*/
/*
* We've found a negative cache entry.
*/
/*
* Remember a NS rdataset even if we're
* not specifically looking for it, because
* we might need it later.
*/
/*
* If we need the NS rdataset, we'll also
* need its signature.
*/
} else if (cname_ok &&
/*
* If we get a CNAME match, we'll also need
* its signature.
*/
}
} else
}
if (empty_node) {
/*
* We have an exact match for the name, but there are no
* extant rdatasets. That means that this node doesn't
* meaningfully exist, and that we really have a partial match.
*/
goto find_ns;
}
/*
* If we didn't find what we were looking for...
*/
((options & DNS_DBFIND_GLUEOK) == 0)) ||
((options & DNS_DBFIND_PENDINGOK) == 0))) {
/*
* If there is an NS rdataset at this node, then this is the
* deepest zone cut.
*/
}
rdataset);
goto node_exit;
}
/*
* Go find the deepest zone cut.
*/
goto find_ns;
}
/*
* We found what we were looking for, or we found a CNAME.
*/
}
/*
* We found a negative cache entry.
*/
else
type != dns_rdatatype_any &&
/*
* We weren't doing an ANY query and we found a CNAME instead
* of the type we were looking for, so we need to indicate
* that result to the caller.
*/
} else {
/*
* An ordinary successful query!
*/
}
rdataset);
}
return (result);
}
static isc_result_t
{
if (now == 0)
/*
* Search down from the root of the tree.
*/
if (result == DNS_R_PARTIALMATCH) {
goto tree_exit;
} else if (result != DNS_R_SUCCESS)
goto tree_exit;
/*
* We now go looking for an NS rdataset at the node.
*/
header_prev = NULL;
/*
* This rdataset is stale. If no one else is using the
* node, we can clean it up right now, otherwise we
* mark it as stale, and the node as dirty, so it will
* get cleaned up later.
*/
if (node->references == 0) {
if (header_prev != NULL)
else
header);
} else {
}
== 0) {
/*
* If we found a type we were looking for, remember
* it.
*/
/*
* Remember a NS rdataset even if we're
* not specifically looking for it, because
* we might need it later.
*/
/*
* If we need the NS rdataset, we'll also
* need its signature.
*/
}
} else
}
/*
* No NS records here.
*/
goto find_ns;
}
}
if (result == DNS_R_DELEGATION)
return (result);
}
static void
node->references++;
}
static void
node->references--;
if (node->references == 0) {
}
if (maybe_free)
}
static isc_result_t
if (now == 0)
/*
* We don't check if rbtnode->references == 0 and try
* to free like we do in cache_find(), because
* rbtnode->references must be non-zero. This is so
* because 'node' is an argument to the function.
*/
}
}
return (DNS_R_SUCCESS);
}
static void
do {
if (!first)
"\tserial = %lu, ttl = %u, "
"trust = %u, attributes = %u\n",
}
} else
}
static isc_result_t
{
return (DNS_R_NOMEMORY);
return (DNS_R_SUCCESS);
}
static isc_result_t
{
if (rbtversion == NULL) {
}
now = 0;
if (covers == 0)
else
sigmatchtype = 0;
do {
/*
* Is this a "this rdataset doesn't
* exist" record?
*/
if ((header->attributes &
RDATASET_ATTR_NONEXISTENT) != 0)
break;
} else
/*
* We have an active, extant rdataset. If it's a
* type we're looking for, remember it.
*/
break;
break;
}
}
}
}
if (close_version)
return (DNS_R_NOTFOUND);
return (DNS_R_SUCCESS);
}
static isc_result_t
{
if (now == 0)
if (covers == 0)
else
sigmatchtype = 0;
/*
* We don't check if rbtnode->references == 0 and try
* to free like we do in cache_find(), because
* rbtnode->references must be non-zero. This is so
* because 'node' is an argument to the function.
*/
0) {
}
}
}
return (DNS_R_NOTFOUND);
/*
* We found a negative cache entry.
*/
else
}
return (result);
}
static isc_result_t
{
return (DNS_R_NOMEMORY);
now = 0;
if (rbtversion == NULL)
else {
rbtversion->references++;
}
} else {
if (now == 0)
rbtversion = NULL;
}
rbtnode->references++;
return (DNS_R_SUCCESS);
}
static isc_result_t
{
unsigned char *merged;
/*
* Add an rdatasetheader_t to a node.
*/
/*
* Caller must be holding the node lock.
*/
if ((options & DNS_DBADD_MERGE) != 0)
else
if ((options & DNS_DBADD_FORCE) != 0)
else
/*
* We always add a changed record, even if no changes end up
* being made to this node, because it's harmless and
* simplifies the code.
*/
return (DNS_R_NOMEMORY);
}
}
nxtype = 0;
if (rdtype == 0) {
/*
* We're adding a negative cache entry.
*/
if (covers == dns_rdatatype_any) {
/*
* We're adding an NXDOMAIN negative cache
* entry.
*
* We make all other data stale so that the
* only rdataset that can be found at this
* node is the NXDOMAIN negative cache entry.
*/
topheader->attributes |=
}
goto find_header;
}
} else {
/*
* We're adding something that isn't a
* negative cache entry. Look for an extant
* non-stale NXDOMAIN negative cache entry.
*/
break;
}
/*
* Found one.
*/
/*
* The NXDOMAIN is more trusted.
*/
if (addedrdataset != NULL)
return (DNS_R_UNCHANGED);
}
/*
* The new rdataset is better. Expire the
* NXDOMAIN.
*/
goto find_header;
}
}
}
break;
}
/*
* If header isn't NULL, we've found the right type. There may be
* IGNORE rdatasets between the top of the chain and the first real
* data. We skip over them.
*/
/*
* Deleting an already non-existent rdataset has no effect.
*/
if (header_nx && newheader_nx) {
return (DNS_R_UNCHANGED);
}
/*
* Trying to add an rdataset with lower trust to a cache DB
* has no effect, provided that the cache data isn't stale.
*/
if (addedrdataset != NULL)
return (DNS_R_UNCHANGED);
}
/*
* Don't merge if a nonexistent rdataset is involved.
*/
/*
* XXXRTH We need to turn off merging for rdata types that
* cannot be merged, e.g. SOA, CNAME, WKS.
*/
/*
* If 'merge' is ISC_TRUE, we'll try to create a new rdataset
* that is the union of 'newheader' and 'header'.
*/
if (merge) {
(unsigned char *)header,
(unsigned char *)newheader,
(unsigned int)(sizeof *newheader),
&merged);
if (result == DNS_R_SUCCESS) {
/*
* If 'header' has the same serial number as
* we do, we could clean it up now if we knew
* that our caller had no references to it.
* We don't know this, however, so we leave it
* alone. It will get cleaned up when
* clean_zone_node() runs.
*/
} else {
return (result);
}
}
if (topheader_prev != NULL)
else
if (loading) {
/*
* There are no other references to 'header' when
* loading, so we MAY clean up 'header' now.
* Since we don't generate changed records when
* loading, we MUST clean up 'header' now.
*/
} else {
}
} else {
/*
* No non-IGNORED rdatasets of the given type exist at
* this node.
*/
/*
* If we're trying to delete the type, don't bother.
*/
if (newheader_nx) {
return (DNS_R_UNCHANGED);
}
/*
* We have an list of rdatasets of the given type,
* but they're all marked IGNORE. We simply insert
* the new rdataset at the head of the list.
*
* Ignored rdatasets cannot occur during loading, so
* we INSIST on it.
*/
if (topheader_prev != NULL)
else
} else {
/*
* No rdatasets of the given type exist at the node.
*/
}
}
if (addedrdataset != NULL)
return (DNS_R_SUCCESS);
}
static inline isc_boolean_t
{
if (type == dns_rdatatype_dname)
return (ISC_TRUE);
else
return (ISC_FALSE);
} else if (type == dns_rdatatype_dname ||
return (ISC_TRUE);
return (ISC_FALSE);
}
static isc_result_t
{
if (rbtversion == NULL) {
if (now == 0)
} else
now = 0;
®ion,
sizeof (rdatasetheader_t));
if (result != DNS_R_SUCCESS)
return (result);
newheader->attributes = 0;
if (rbtversion != NULL) {
now = 0;
} else {
}
/*
* If we're adding a delegation type (e.g. NS or DNAME for a zone,
* just DNAME for the cache), then we need to set the callback bit
* on the node, and to do that we must be holding an exclusive lock
* on the tree.
*/
} else
addedrdataset, now);
if (delegating)
return (result);
}
static isc_result_t
{
unsigned char *subresult;
®ion,
sizeof (rdatasetheader_t));
if (result != DNS_R_SUCCESS)
return (result);
newheader->attributes = 0;
return (DNS_R_NOMEMORY);
}
break;
}
/*
* If header isn't NULL, we've found the right type. There may be
* IGNORE rdatasets between the top of the chain and the first real
* data. We skip over them.
*/
(unsigned char *)header,
(unsigned char *)newheader,
(unsigned int)(sizeof *newheader),
&subresult);
if (result == DNS_R_SUCCESS) {
/*
* We have to set the serial since the rdataslab
* subtraction routine copies the reserved portion of
* header, not newheader.
*/
} else if (result == DNS_R_NXRDATASET) {
/*
* This subtraction would remove all of the rdata;
* add a nonexistent header instead.
*/
sizeof *newheader);
goto unlock;
}
} else {
goto unlock;
}
/*
* If we're here, we want to link newheader in front of
* topheader.
*/
if (topheader_prev != NULL)
else
} else {
/*
* The rdataset doesn't exist, so we don't need to do anything
* to satisfy the deletion request.
*/
}
return (result);
}
static isc_result_t
{
if (type == dns_rdatatype_any)
return (DNS_R_NOTIMPLEMENTED);
return (DNS_R_NOTIMPLEMENTED);
return (DNS_R_NOMEMORY);
if (rbtversion != NULL)
else
return (result);
}
static isc_result_t
unsigned int n;
/*
* This routine does no node locking. See comments in
* 'load' below for more information on loading and
* locking.
*/
if (dns_name_iswildcard(name)) {
/*
* In order for wildcard matching to work correctly in
* zone_find(), we must ensure that a node for the wildcarding
* level exists in the database, and has its 'find_callback'
* and 'wild' bits set.
*
* E.g. if the wildcard name is "*.sub.example." then we
* must ensure that "sub.example." exists and is marked as
* a wildcard level.
*/
n = dns_name_countlabels(name);
INSIST(n >= 2);
n--;
return (result);
}
return (result);
if (result != DNS_R_EXISTS) {
}
®ion,
sizeof (rdatasetheader_t));
if (result != DNS_R_SUCCESS)
return (result);
newheader->attributes = 0;
if (result == DNS_R_SUCCESS &&
else if (result == DNS_R_UNCHANGED)
return (result);
}
static isc_result_t
return (DNS_R_NOMEMORY);
else
== 0);
return (DNS_R_SUCCESS);
}
static isc_result_t
/*
* If there's a NXT rdataset at the zone origin, we consider
* the zone secure.
*/
{
break;
}
}
}
return (DNS_R_SUCCESS);
}
static isc_result_t
filename));
}
static void
}
}
static isc_boolean_t
return (secure);
}
static dns_dbmethods_t zone_methods = {
dump,
};
static dns_dbmethods_t cache_methods = {
dump,
};
#ifdef DNS_RBTDB_VERSION64
#else
#endif
{
int i;
/* Keep the compiler happy. */
(void)argc;
(void)argv;
return (DNS_R_NOMEMORY);
if (cache) {
} else
if (result != ISC_R_SUCCESS) {
"isc_mutex_init() failed: %s",
return (DNS_R_UNEXPECTED);
}
if (result != ISC_R_SUCCESS) {
"isc_rwlock_init() failed: %s",
return (DNS_R_UNEXPECTED);
}
if (rbtdb->node_lock_count == 0)
sizeof (rbtdb_nodelock_t));
for (i = 0; i < (int)(rbtdb->node_lock_count); i++) {
if (result != ISC_R_SUCCESS) {
i--;
while (i >= 0) {
i--;
}
sizeof (rbtdb_nodelock_t));
"isc_mutex_init() failed: %s",
return (DNS_R_UNEXPECTED);
}
}
/*
* Make a copy of the origin name.
*/
return (DNS_R_NOMEMORY);
}
/*
* Make the Red-Black Tree.
*/
if (result != DNS_R_SUCCESS) {
return (result);
}
/*
* In order to set the node callback bit correctly in zone databases,
* we need to know if the node has the origin name of the zone.
* In loading_addrdataset() we could simply compare the new name
* to the origin name, but this is expensive. Also, we don't know the
* node name in addrdataset(), so we need another way of knowing the
* zone's top.
*
* We now explicitly create a node for the zone's origin, and then
* we simply remember the node's address. This is safe, because
* the top-of-zone node can never be deleted, nor can its address
* change.
*/
&rbtdb->origin_node);
if (result != DNS_R_SUCCESS) {
return (result);
}
/*
* We need to give the origin node the right locknum.
*/
}
/*
* Misc. Initialization.
*/
rbtdb->attributes = 0;
/*
* Version Initialization.
*/
return (DNS_R_NOMEMORY);
}
return (DNS_R_SUCCESS);
}
/*
* Slabbed Rdataset Methods
*/
static void
}
static isc_result_t
unsigned int count;
if (count == 0) {
return (DNS_R_NOMORE);
}
raw += 2;
/*
* The private4 field is the number of rdata beyond the cursor
* position, so we decrement the total count by one before storing
* it.
*/
count--;
return (DNS_R_SUCCESS);
}
static isc_result_t
unsigned int count;
unsigned int length;
unsigned char *raw;
if (count == 0)
return (DNS_R_NOMORE);
count--;
return (DNS_R_SUCCESS);
}
static void
isc_region_t r;
raw += 2;
}
static void
/*
* Reset iterator state.
*/
}
static unsigned int
unsigned int count;
return (count);
}
/*
* Rdataset Iterator Methods
*/
static void
sizeof *rbtiterator);
}
static isc_result_t
now = 0;
} else {
serial = 1;
}
do {
/*
* Is this a "this rdataset doesn't
* exist" record?
*/
if ((header->attributes &
RDATASET_ATTR_NONEXISTENT) != 0 ||
break;
} else
break;
}
return (DNS_R_NOMORE);
return (DNS_R_SUCCESS);
}
static isc_result_t
return (DNS_R_NOMORE);
now = 0;
} else {
serial = 1;
}
do {
/*
* Is this a "this rdataset doesn't
* exist" record?
*/
if ((header->attributes &
RDATASET_ATTR_NONEXISTENT) != 0 ||
break;
} else
break;
}
}
return (DNS_R_NOMORE);
return (DNS_R_SUCCESS);
}
static void
rdataset);
}
/*
* Database Iterator Methods
*/
static inline void
node->references--;
if (node->references == 0)
}
}
static inline void
}
static void
if (rbtdbiter->tree_locked)
}
static isc_result_t
if (!rbtdbiter->tree_locked) {
}
origin);
if (result != DNS_R_NEWORIGIN) {
if (result == DNS_R_NOTFOUND) {
/*
* The tree is empty.
*/
}
} else {
if (result == DNS_R_SUCCESS)
else
}
return (result);
}
static isc_result_t
if (!rbtdbiter->tree_locked) {
}
origin);
if (result != DNS_R_NEWORIGIN) {
if (result == DNS_R_NOTFOUND) {
/*
* The tree is empty.
*/
}
} else {
if (result == DNS_R_SUCCESS)
else
}
return (result);
}
static isc_result_t
if (!rbtdbiter->tree_locked) {
}
if (result != DNS_R_SUCCESS) {
if (result == DNS_R_PARTIALMATCH)
} else {
if (result == DNS_R_SUCCESS)
else
}
return (result);
}
static isc_result_t
if (result == DNS_R_NEWORIGIN)
else
if (result != DNS_R_SUCCESS) {
}
} else
return (result);
}
static isc_result_t
if (result == DNS_R_NEWORIGIN)
else
if (result != DNS_R_SUCCESS) {
}
} else
return (result);
}
static inline isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
}
static isc_result_t
{
if (result != DNS_R_SUCCESS)
return (result);
} else
return (result);
}
static isc_result_t
}
return (DNS_R_SUCCESS);
}
static isc_result_t
}