db.c revision 3a34b87c878990c6303358efd22265c2c5980c65
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Copyright (C) 1999, 2000 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews/* $Id: db.c,v 1.55 2000/08/31 12:15:09 marka Exp $ */
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews/***
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews *** Imports
3761c433912beabe43abeed2c3513b6201c59f64Mark Andrews ***/
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <config.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <isc/buffer.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <isc/string.h>
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews#include <isc/util.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews#include <dns/callbacks.h>
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews#include <dns/log.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <dns/master.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <dns/rdata.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <dns/rdataset.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews/***
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews *** Private Types
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews ***/
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrewstypedef struct {
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews const char * name;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_result_t (*create)(isc_mem_t *mctx, dns_name_t *name,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_dbtype_t type,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_rdataclass_t rdclass,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int argc, char *argv[],
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_db_t **dbp);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews} impinfo_t;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews/***
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *** Supported DB Implementations Registry
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ***/
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews/*
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews * Supported database implementations must be registered here.
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * It might be nice to generate this automatically some day.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include "rbtdb.h"
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include "rbtdb64.h"
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include "sdb_p.h"
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrewsstatic impinfo_t implementations[] = {
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews { "rbt", dns_rbtdb_create },
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews { "rbt64", dns_rbtdb64_create },
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews { "simple", dns_sdb_create },
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews { NULL, NULL }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews};
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/***
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *** Basic DB Methods
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ***/
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsisc_result_t
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrewsdns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_dbtype_t type, dns_rdataclass_t rdclass,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews unsigned int argc, char *argv[], dns_db_t **dbp)
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews{
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews impinfo_t *impinfo;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrews /*
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrews * Create a new database using implementation 'db_type'.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrews REQUIRE(dbp != NULL && *dbp == NULL);
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrews REQUIRE(dns_name_isabsolute(origin));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews for (impinfo = implementations; impinfo->name != NULL; impinfo++)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (strcasecmp(db_type, impinfo->name) == 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return ((impinfo->create)(mctx, origin, type, rdclass,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews argc, argv, dbp));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews DNS_LOGMODULE_DB, ISC_LOG_ERROR,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "unsupported database type '%s'", db_type);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews return (ISC_R_NOTFOUND);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews}
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsvoid
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsdns_db_attach(dns_db_t *source, dns_db_t **targetp) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews /*
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Attach *targetp to source.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(DNS_DB_VALID(source));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(targetp != NULL && *targetp == NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews (source->methods->attach)(source, targetp);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ENSURE(*targetp == source);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrewsvoid
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrewsdns_db_detach(dns_db_t **dbp) {
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews /*
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Detach *dbp from its database.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(dbp != NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(DNS_DB_VALID(*dbp));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ((*dbp)->methods->detach)(dbp);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews ENSURE(*dbp == NULL);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews}
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsisc_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsdns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews{
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(DNS_DB_VALID(db));
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
return (isc_ondestroy_register(&db->ondest, task, eventp));
}
isc_boolean_t
dns_db_iscache(dns_db_t *db) {
/*
* Does 'db' have cache semantics?
*/
REQUIRE(DNS_DB_VALID(db));
if ((db->attributes & DNS_DBATTR_CACHE) != 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
isc_boolean_t
dns_db_iszone(dns_db_t *db) {
/*
* Does 'db' have zone semantics?
*/
REQUIRE(DNS_DB_VALID(db));
if ((db->attributes & (DNS_DBATTR_CACHE|DNS_DBATTR_STUB)) == 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
isc_boolean_t
dns_db_isstub(dns_db_t *db) {
/*
* Does 'db' have stub semantics?
*/
REQUIRE(DNS_DB_VALID(db));
if ((db->attributes & DNS_DBATTR_STUB) != 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
isc_boolean_t
dns_db_issecure(dns_db_t *db) {
/*
* Is 'db' secure?
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
return ((db->methods->issecure)(db));
}
isc_boolean_t
dns_db_ispersistent(dns_db_t *db) {
/*
* Is 'db' persistent?
*/
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->ispersistent)(db));
}
dns_name_t *
dns_db_origin(dns_db_t *db) {
/*
* The origin of the database.
*/
REQUIRE(DNS_DB_VALID(db));
return (&db->origin);
}
dns_rdataclass_t
dns_db_class(dns_db_t *db) {
/*
* The class of the database.
*/
REQUIRE(DNS_DB_VALID(db));
return (db->rdclass);
}
isc_result_t
dns_db_beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp,
dns_dbload_t **dbloadp) {
/*
* Begin loading 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(addp != NULL && *addp == NULL);
REQUIRE(dbloadp != NULL && *dbloadp == NULL);
return ((db->methods->beginload)(db, addp, dbloadp));
}
isc_result_t
dns_db_endload(dns_db_t *db, dns_dbload_t **dbloadp) {
/*
* Finish loading 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(dbloadp != NULL && *dbloadp != NULL);
return ((db->methods->endload)(db, dbloadp));
}
isc_result_t
dns_db_load(dns_db_t *db, const char *filename) {
isc_result_t result, eresult;
dns_rdatacallbacks_t callbacks;
isc_boolean_t age_ttl = ISC_FALSE;
/*
* Load master file 'filename' into 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
if ((db->attributes & DNS_DBATTR_CACHE) != 0)
age_ttl = ISC_TRUE;
dns_rdatacallbacks_init(&callbacks);
result = dns_db_beginload(db, &callbacks.add, &callbacks.add_private);
if (result != ISC_R_SUCCESS)
return (result);
result = dns_master_loadfile(filename, &db->origin, &db->origin,
db->rdclass, age_ttl,
&callbacks, db->mctx);
eresult = dns_db_endload(db, &callbacks.add_private);
/*
* We always call dns_db_endload(), but we only want to return its
* result if dns_master_loadfile() succeeded. If dns_master_loadfile()
* failed, we want to return the result code it gave us.
*/
if (result == ISC_R_SUCCESS)
result = eresult;
return (result);
}
isc_result_t
dns_db_dump(dns_db_t *db, dns_dbversion_t *version, const char *filename) {
/*
* Dump 'db' into master file 'filename'.
*/
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->dump)(db, version, filename));
}
/***
*** Version Methods
***/
void
dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
/*
* Open the current version for reading.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
REQUIRE(versionp != NULL && *versionp == NULL);
(db->methods->currentversion)(db, versionp);
}
isc_result_t
dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
/*
* Open a new version for reading and writing.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
REQUIRE(versionp != NULL && *versionp == NULL);
return ((db->methods->newversion)(db, versionp));
}
void
dns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
dns_dbversion_t **targetp)
{
/*
* Attach '*targetp' to 'source'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
REQUIRE(source != NULL);
REQUIRE(targetp != NULL && *targetp != NULL);
(db->methods->attachversion)(db, source, targetp);
ENSURE(*targetp != NULL);
}
void
dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
isc_boolean_t commit)
{
/*
* Close version '*versionp'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
REQUIRE(versionp != NULL && *versionp != NULL);
(db->methods->closeversion)(db, versionp, commit);
ENSURE(*versionp == NULL);
}
/***
*** Node Methods
***/
isc_result_t
dns_db_findnode(dns_db_t *db, dns_name_t *name,
isc_boolean_t create, dns_dbnode_t **nodep)
{
/*
* Find the node with name 'name'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(dns_name_issubdomain(name, &db->origin));
REQUIRE(nodep != NULL && *nodep == NULL);
return ((db->methods->findnode)(db, name, create, nodep));
}
isc_result_t
dns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
dns_dbnode_t **nodep, dns_name_t *foundname,
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
{
/*
* Find the best match for 'name' and 'type' in version 'version'
* of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(type != dns_rdatatype_sig);
REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
REQUIRE(dns_name_hasbuffer(foundname));
REQUIRE(rdataset == NULL ||
(DNS_RDATASET_VALID(rdataset) &&
! dns_rdataset_isassociated(rdataset)));
REQUIRE(sigrdataset == NULL ||
(DNS_RDATASET_VALID(sigrdataset) &&
! dns_rdataset_isassociated(sigrdataset)));
return ((db->methods->find)(db, name, version, type, options, now,
nodep, foundname, rdataset, sigrdataset));
}
isc_result_t
dns_db_findzonecut(dns_db_t *db, dns_name_t *name,
unsigned int options, isc_stdtime_t now,
dns_dbnode_t **nodep, dns_name_t *foundname,
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
{
/*
* Find the deepest known zonecut which encloses 'name' in 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
REQUIRE(dns_name_hasbuffer(foundname));
REQUIRE(sigrdataset == NULL ||
(DNS_RDATASET_VALID(sigrdataset) &&
! dns_rdataset_isassociated(sigrdataset)));
return ((db->methods->findzonecut)(db, name, options, now, nodep,
foundname, rdataset, sigrdataset));
}
void
dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
/*
* Attach *targetp to source.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(source != NULL);
REQUIRE(targetp != NULL && *targetp == NULL);
(db->methods->attachnode)(db, source, targetp);
}
void
dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep) {
/*
* Detach *nodep from its node.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(nodep != NULL && *nodep != NULL);
(db->methods->detachnode)(db, nodep);
ENSURE(*nodep == NULL);
}
isc_result_t
dns_db_expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) {
/*
* Mark as stale all records at 'node' which expire at or before 'now'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
REQUIRE(node != NULL);
return ((db->methods->expirenode)(db, node, now));
}
void
dns_db_printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) {
/*
* Print a textual representation of the contents of the node to
* 'out'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
(db->methods->printnode)(db, node, out);
}
/***
*** DB Iterator Creation
***/
isc_result_t
dns_db_createiterator(dns_db_t *db, isc_boolean_t relative_names,
dns_dbiterator_t **iteratorp)
{
/*
* Create an iterator for version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(iteratorp != NULL && *iteratorp == NULL);
return (db->methods->createiterator(db, relative_names, iteratorp));
}
/***
*** Rdataset Methods
***/
isc_result_t
dns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
dns_rdatatype_t type, dns_rdatatype_t covers,
isc_stdtime_t now, dns_rdataset_t *rdataset,
dns_rdataset_t *sigrdataset)
{
/*
* Search for an rdataset of type 'type' at 'node' that are in version
* 'version' of 'db'. If found, make 'rdataset' refer to it.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(! dns_rdataset_isassociated(rdataset));
REQUIRE(covers == 0 || type == dns_rdatatype_sig);
REQUIRE(type != dns_rdatatype_any);
REQUIRE(sigrdataset == NULL ||
(DNS_RDATASET_VALID(sigrdataset) &&
! dns_rdataset_isassociated(sigrdataset)));
return ((db->methods->findrdataset)(db, node, version, type, covers,
now, rdataset, sigrdataset));
}
isc_result_t
dns_db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
isc_stdtime_t now, dns_rdatasetiter_t **iteratorp)
{
/*
* Make '*iteratorp' an rdataset iteratator for all rdatasets at
* 'node' in version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(iteratorp != NULL && *iteratorp == NULL);
return ((db->methods->allrdatasets)(db, node, version, now,
iteratorp));
}
isc_result_t
dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
isc_stdtime_t now, dns_rdataset_t *rdataset,
unsigned int options, dns_rdataset_t *addedrdataset)
{
/*
* Add 'rdataset' to 'node' in version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL)||
((db->attributes & DNS_DBATTR_CACHE) != 0 &&
version == NULL && (options & DNS_DBADD_MERGE) == 0));
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(dns_rdataset_isassociated(rdataset));
REQUIRE(rdataset->rdclass == db->rdclass);
REQUIRE(addedrdataset == NULL ||
(DNS_RDATASET_VALID(addedrdataset) &&
! dns_rdataset_isassociated(addedrdataset)));
return ((db->methods->addrdataset)(db, node, version, now, rdataset,
options, addedrdataset));
}
isc_result_t
dns_db_subtractrdataset(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version, dns_rdataset_t *rdataset,
dns_rdataset_t *newrdataset)
{
/*
* Remove any rdata in 'rdataset' from 'node' in version 'version' of
* 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL);
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(dns_rdataset_isassociated(rdataset));
REQUIRE(rdataset->rdclass == db->rdclass);
REQUIRE(newrdataset == NULL ||
(DNS_RDATASET_VALID(newrdataset) &&
! dns_rdataset_isassociated(newrdataset)));
return ((db->methods->subtractrdataset)(db, node, version, rdataset,
newrdataset));
}
isc_result_t
dns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version, dns_rdatatype_t type,
dns_rdatatype_t covers)
{
/*
* Make it so that no rdataset of type 'type' exists at 'node' in
* version version 'version' of 'db'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL)||
((db->attributes & DNS_DBATTR_CACHE) != 0 && version == NULL));
return ((db->methods->deleterdataset)(db, node, version,
type, covers));
}
void
dns_db_overmem(dns_db_t *db, isc_boolean_t overmem) {
REQUIRE(DNS_DB_VALID(db));
(db->methods->overmem)(db, overmem);
}
isc_result_t
dns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, isc_uint32_t *serialp)
{
isc_result_t result;
dns_dbnode_t *node = NULL;
dns_rdataset_t rdataset;
dns_rdata_t rdata;
isc_buffer_t buffer;
REQUIRE(dns_db_iszone(db) || dns_db_isstub(db));
result = dns_db_findnode(db, dns_db_origin(db), ISC_FALSE, &node);
if (result != ISC_R_SUCCESS)
return (result);
dns_rdataset_init(&rdataset);
result = dns_db_findrdataset(db, node, ver, dns_rdatatype_soa, 0,
(isc_stdtime_t)0, &rdataset, NULL);
if (result != ISC_R_SUCCESS)
goto freenode;
result = dns_rdataset_first(&rdataset);
if (result != ISC_R_SUCCESS)
goto freerdataset;
dns_rdataset_current(&rdataset, &rdata);
INSIST(rdata.length > 20);
isc_buffer_init(&buffer, rdata.data, rdata.length);
isc_buffer_add(&buffer, rdata.length);
isc_buffer_forward(&buffer, rdata.length - 20);
*serialp = isc_buffer_getuint32(&buffer);
result = ISC_R_SUCCESS;
freerdataset:
dns_rdataset_disassociate(&rdataset);
freenode:
dns_db_detachnode(db, &node);
return (result);
}
unsigned int
dns_db_nodecount(dns_db_t *db) {
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->nodecount)(db));
}