db.c revision 64e829fffb8d95e7507079767ef68327b4a7b4ca
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff/*
ca41b452ede6feaa9d8739ec3cae19389a7b0d03Bob Halley * Copyright (C) 1999 Internet Software Consortium.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff *
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * Permission to use, copy, modify, and distribute this software for any
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * purpose with or without fee is hereby granted, provided that the above
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * copyright notice and this permission notice appear in all copies.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff *
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * SOFTWARE.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff */
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff/***
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff *** Imports
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff ***/
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff#include <config.h>
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff#include <stddef.h>
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff#include <string.h>
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff#include <isc/assertions.h>
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff#include <dns/db.h>
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff#include <dns/master.h>
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff#include <dns/rdataset.h>
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff/***
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff *** Private Types
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff ***/
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Grafftypedef struct {
e45d323a2a0f4ca08d4b139546e60a5fa7bd3f0cMichael Graff char * name;
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson isc_result_t (*create)(isc_mem_t *mctx, dns_name_t *name,
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff isc_boolean_t cache,
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff dns_rdataclass_t rdclass,
41ac1e406f1be4ec2eba2d8bae673e762d54ea74Andreas Gustafsson unsigned int argc, char *argv[],
efa4ebbff3c9f6f38ab8b55540fb696243c1172cAndreas Gustafsson dns_db_t **dbp);
efa4ebbff3c9f6f38ab8b55540fb696243c1172cAndreas Gustafsson} impinfo_t;
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff/***
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff *** Supported DB Implementations Registry
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff ***/
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff/*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Supported database implementations must be registered here.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff *
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * It might be nice to generate this automatically some day.
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff */
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff#include "rbtdb.h"
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff#include "rbtdb64.h"
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffimpinfo_t implementations[] = {
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff { "rbt", dns_rbtdb_create },
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff { "rbt64", dns_rbtdb64_create },
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff { NULL, NULL }
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff};
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff/***
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff *** Basic DB Methods
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff ***/
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffisc_result_t
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graffdns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *origin,
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff isc_boolean_t cache, dns_rdataclass_t rdclass,
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff unsigned int argc, char *argv[], dns_db_t **dbp)
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff{
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff impinfo_t *impinfo;
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
fc4fe6e5e61dbc916707ab2e071ffd22aef9de7fMichael Graff /*
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff * Create a new database using implementation 'db_type'.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff */
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff REQUIRE(dbp != NULL && *dbp == NULL);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff REQUIRE(dns_name_isabsolute(origin));
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff for (impinfo = implementations; impinfo->name != NULL; impinfo++)
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff if (strcasecmp(db_type, impinfo->name) == 0)
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff return ((impinfo->create)(mctx, origin, cache, rdclass,
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff argc, argv, dbp));
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff return (DNS_R_NOTFOUND);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff}
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graffvoid
910df98b0efcbe8380b952887f4071051cc39a25Michael Graffdns_db_attach(dns_db_t *source, dns_db_t **targetp) {
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff /*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Attach *targetp to source.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff */
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff REQUIRE(DNS_DB_VALID(source));
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff REQUIRE(targetp != NULL);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff (source->methods->attach)(source, targetp);
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff ENSURE(*targetp == source);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff}
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffvoid
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffdns_db_detach(dns_db_t **dbp) {
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff /*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Detach *dbp from its database.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff */
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff REQUIRE(dbp != NULL);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff REQUIRE(DNS_DB_VALID(*dbp));
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff ((*dbp)->methods->detach)(dbp);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff ENSURE(*dbp == NULL);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff}
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffisc_boolean_t
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffdns_db_iscache(dns_db_t *db) {
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff /*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Does 'db' have cache semantics?
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff */
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff REQUIRE(DNS_DB_VALID(db));
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff if ((db->attributes & DNS_DBATTR_CACHE) != 0)
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff return (ISC_TRUE);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff return (ISC_FALSE);
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff}
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graffisc_boolean_t
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graffdns_db_iszone(dns_db_t *db) {
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff /*
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff * Does 'db' have zone semantics?
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff */
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff REQUIRE(DNS_DB_VALID(db));
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff if ((db->attributes & DNS_DBATTR_CACHE) == 0)
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff return (ISC_TRUE);
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff return (ISC_FALSE);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff}
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graffisc_boolean_t
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffdns_db_issecure(dns_db_t *db) {
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff /*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Is 'db' secure?
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff */
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff REQUIRE(DNS_DB_VALID(db));
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff return ((db->methods->issecure)(db));
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff}
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
3ac63b472022ff92691d1fe69ac715a729671965Michael Graffdns_name_t *
3ac63b472022ff92691d1fe69ac715a729671965Michael Graffdns_db_origin(dns_db_t *db) {
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff /*
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff * The origin of the database.
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff */
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff REQUIRE(DNS_DB_VALID(db));
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff return (&db->origin);
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff}
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffdns_rdataclass_t
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffdns_db_class(dns_db_t *db) {
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff /*
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff * The class of the database.
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff */
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff REQUIRE(DNS_DB_VALID(db));
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff return (db->rdclass);
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff}
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffisc_result_t
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffdns_db_beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp,
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff dns_dbload_t **dbloadp) {
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff /*
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff * Begin loading 'db'.
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff */
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson REQUIRE(DNS_DB_VALID(db));
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson REQUIRE(addp != NULL && *addp == NULL);
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson REQUIRE(dbloadp != NULL && *dbloadp == NULL);
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson return ((db->methods->beginload)(db, addp, dbloadp));
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson}
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffisc_result_t
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffdns_db_endload(dns_db_t *db, dns_dbload_t **dbloadp) {
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff /*
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff * Finish loading 'db'.
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff */
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff REQUIRE(DNS_DB_VALID(db));
5bd937c666375d03ee6a366a13d0bdb31aa3f07fBob Halley REQUIRE(dbloadp != NULL && *dbloadp != NULL);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff return ((db->methods->endload)(db, dbloadp));
efa4ebbff3c9f6f38ab8b55540fb696243c1172cAndreas Gustafsson}
e592dd7c344052ee51eb707cd744b48b34f4c74eBob Halley
efa4ebbff3c9f6f38ab8b55540fb696243c1172cAndreas Gustafssonisc_result_t
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffdns_db_load(dns_db_t *db, const char *filename) {
36ca83769dbba29a3d8670eef9acd95c7a71a7f6Michael Graff isc_result_t result, eresult;
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff int soacount, nscount;
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff dns_rdatacallbacks_t callbacks;
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff isc_boolean_t age_ttl = ISC_FALSE;
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff /*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Load master file 'filename' into 'db'.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff */
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff REQUIRE(DNS_DB_VALID(db));
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff if ((db->attributes & DNS_DBATTR_CACHE) != 0)
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff age_ttl = ISC_TRUE;
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff dns_rdatacallbacks_init(&callbacks);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff result = dns_db_beginload(db, &callbacks.add, &callbacks.add_private);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff if (result != DNS_R_SUCCESS)
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff return (result);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff result = dns_master_loadfile(filename, &db->origin, &db->origin,
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff db->rdclass, age_ttl, &soacount, &nscount,
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff &callbacks, db->mctx);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff eresult = dns_db_endload(db, &callbacks.add_private);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff /*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * We always call dns_db_endload(), but we only want to return its
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * result if dns_master_loadfile() succeeded. If dns_master_loadfile()
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * failed, we want to return the result code it gave us.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff */
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff if (result == ISC_R_SUCCESS)
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff result = eresult;
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff return (result);
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff}
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graffisc_result_t
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graffdns_db_dump(dns_db_t *db, dns_dbversion_t *version, const char *filename) {
897c9ddb4d745b2bfecf98b17e5487bb6656299aMichael Graff /*
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff * Dump 'db' into master file 'filename'.
6a68df334f6dd02429d3e7a8866e552e9e9d84ecBob Halley */
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff REQUIRE(DNS_DB_VALID(db));
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff return ((db->methods->dump)(db, version, filename));
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff}
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff/***
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff *** Version Methods
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff ***/
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffvoid
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffdns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff /*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Open the current version for reading.
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff */
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
da547174e2b7beb6d6119d58197ad0bc85b91179Michael Graff REQUIRE(DNS_DB_VALID(db));
da547174e2b7beb6d6119d58197ad0bc85b91179Michael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
da547174e2b7beb6d6119d58197ad0bc85b91179Michael Graff REQUIRE(versionp != NULL && *versionp == NULL);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff (db->methods->currentversion)(db, versionp);
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff}
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
58aaab3687aac838542ee4ef65a9c094a5d34ab0Michael Graffisc_result_t
f00d96a15cdd11e764437f9359e67328631caaeaMichael Graffdns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff /*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Open a new version for reading and writing.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff */
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff REQUIRE(DNS_DB_VALID(db));
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff REQUIRE(versionp != NULL && *versionp == NULL);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff return ((db->methods->newversion)(db, versionp));
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff}
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffvoid
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffdns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff dns_dbversion_t **targetp)
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff{
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff /*
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff * Attach '*targetp' to 'source'.
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff */
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff REQUIRE(DNS_DB_VALID(db));
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff REQUIRE(source != NULL);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff REQUIRE(targetp != NULL && *targetp != NULL);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff (db->methods->attachversion)(db, source, targetp);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff ENSURE(*targetp != NULL);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff}
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graffvoid
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graffdns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff isc_boolean_t commit)
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff{
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff /*
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff * Close version '*versionp'.
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff */
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff REQUIRE(DNS_DB_VALID(db));
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff REQUIRE(versionp != NULL && *versionp != NULL);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff (db->methods->closeversion)(db, versionp, commit);
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff ENSURE(*versionp == NULL);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff}
738b9aa3ded1ef724922d6695cb04ec2e721bdd1Bob Halley
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff/***
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff *** Node Methods
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff ***/
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graffisc_result_t
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffdns_db_findnode(dns_db_t *db, dns_name_t *name,
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graff isc_boolean_t create, dns_dbnode_t **nodep)
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff{
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graff /*
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Find the node with name 'name'.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff */
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graff
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff REQUIRE(DNS_DB_VALID(db));
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff REQUIRE(dns_name_issubdomain(name, &db->origin));
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff REQUIRE(nodep != NULL && *nodep == NULL);
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff return ((db->methods->findnode)(db, name, create, nodep));
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff}
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graffisc_result_t
528829aa8ad69238e674cd81078bc14d4199691bMichael Graffdns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff dns_dbnode_t **nodep, dns_name_t *foundname,
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff{
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff /*
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff * Find the best match for 'name' and 'type' in version 'version'
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff * of 'db'.
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff */
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graff
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff REQUIRE(DNS_DB_VALID(db));
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff REQUIRE(type != dns_rdatatype_sig);
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff REQUIRE(dns_name_hasbuffer(foundname));
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff REQUIRE(rdataset == NULL ||
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff (DNS_RDATASET_VALID(rdataset) && rdataset->methods == NULL));
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff REQUIRE(sigrdataset == NULL ||
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff (DNS_RDATASET_VALID(sigrdataset) &&
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff sigrdataset->methods == NULL));
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff return ((db->methods->find)(db, name, version, type, options, now,
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff nodep, foundname, rdataset, sigrdataset));
78854e02c127f31ab90f56da0531542004b45377Michael Graff}
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graffisc_result_t
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graffdns_db_findzonecut(dns_db_t *db, dns_name_t *name,
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graff unsigned int options, isc_stdtime_t now,
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff dns_dbnode_t **nodep, dns_name_t *foundname,
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff{
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff /*
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff * Find the deepest known zonecut which encloses 'name' in 'db'.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff */
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff REQUIRE(DNS_DB_VALID(db));
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
d4d2a13916a114879763562db6a19b70b1444ec1Michael Graff REQUIRE(dns_name_hasbuffer(foundname));
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff REQUIRE(sigrdataset == NULL ||
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff (DNS_RDATASET_VALID(sigrdataset) &&
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff sigrdataset->methods == NULL));
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff
a9ece9973c35d4d780338e89e288fb6a59575324Michael Graff return ((db->methods->findzonecut)(db, name, options, now, nodep,
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff foundname, rdataset, sigrdataset));
3ac63b472022ff92691d1fe69ac715a729671965Michael Graff}
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffvoid
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffdns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff /*
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * Attach *targetp to source.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff */
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff REQUIRE(DNS_DB_VALID(db));
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff REQUIRE(source != NULL);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff 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(rdataset->methods == NULL);
REQUIRE(covers == 0 || type == dns_rdatatype_sig);
REQUIRE(type != dns_rdatatype_any);
REQUIRE(sigrdataset == NULL ||
(DNS_RDATASET_VALID(sigrdataset) &&
sigrdataset->methods == NULL));
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(rdataset->methods != NULL);
REQUIRE(rdataset->rdclass == db->rdclass);
REQUIRE(addedrdataset == NULL ||
(DNS_RDATASET_VALID(addedrdataset) &&
addedrdataset->methods == NULL));
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(rdataset->methods != NULL);
REQUIRE(rdataset->rdclass == db->rdclass);
REQUIRE(newrdataset == NULL ||
(DNS_RDATASET_VALID(newrdataset) &&
newrdataset->methods == NULL));
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)
{
/*
* 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));
}