db.c revision 7a00d69909ace5dc11bcff9c1e07c311f92a7f8e
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff/*
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2004, 2005, 2007-2009, 2011-2013, 2015 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2001, 2003 Internet Software Consortium.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff *
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Permission to use, copy, modify, and/or distribute this software for any
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * purpose with or without fee is hereby granted, provided that the above
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
e61793f0865117ad87a19d6e245bea8f3b712d1bDanny Mayer/*! \file */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff/***
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff *** Imports
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff ***/
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff#include <config.h>
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
90c845947a6987a95d4facaed61406362fbb58dfBrian Wellington#include <isc/buffer.h>
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff#include <isc/mem.h>
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff#include <isc/once.h>
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff#include <isc/rwlock.h>
3c0a81897768d0378813865278a49d285c95b8b8Brian Wellington#include <isc/string.h>
363cb30a83e8e57bc8874e621910f0e23dd84909Mark Andrews#include <isc/util.h>
363cb30a83e8e57bc8874e621910f0e23dd84909Mark Andrews
363cb30a83e8e57bc8874e621910f0e23dd84909Mark Andrews#include <dns/callbacks.h>
363cb30a83e8e57bc8874e621910f0e23dd84909Mark Andrews#include <dns/clientinfo.h>
363cb30a83e8e57bc8874e621910f0e23dd84909Mark Andrews#include <dns/db.h>
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff#include <dns/dbiterator.h>
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff#include <dns/log.h>
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff#include <dns/master.h>
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff#include <dns/rdata.h>
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence#include <dns/rdataset.h>
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence#include <dns/rdatasetiter.h>
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence#include <dns/result.h>
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence/***
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence *** Private Types
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence ***/
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrencestruct dns_dbimplementation {
71811653336a000f6c61d26d4b2a0c0d2cec9c25Danny Mayer const char * name;
001d1ceec69e181f62367f4d344fb386135d91b1Andreas Gustafsson dns_dbcreatefunc_t create;
71811653336a000f6c61d26d4b2a0c0d2cec9c25Danny Mayer isc_mem_t * mctx;
71811653336a000f6c61d26d4b2a0c0d2cec9c25Danny Mayer void * driverarg;
001d1ceec69e181f62367f4d344fb386135d91b1Andreas Gustafsson ISC_LINK(dns_dbimplementation_t) link;
001d1ceec69e181f62367f4d344fb386135d91b1Andreas Gustafsson};
001d1ceec69e181f62367f4d344fb386135d91b1Andreas Gustafsson
001d1ceec69e181f62367f4d344fb386135d91b1Andreas Gustafsson/***
3489d64bde03af5c7950661b083b530bd285ec27Mark Andrews *** Supported DB Implementations Registry
001d1ceec69e181f62367f4d344fb386135d91b1Andreas Gustafsson ***/
001d1ceec69e181f62367f4d344fb386135d91b1Andreas Gustafsson
71811653336a000f6c61d26d4b2a0c0d2cec9c25Danny Mayer/*
71811653336a000f6c61d26d4b2a0c0d2cec9c25Danny Mayer * Built in database implementations are registered here.
71811653336a000f6c61d26d4b2a0c0d2cec9c25Danny Mayer */
e61793f0865117ad87a19d6e245bea8f3b712d1bDanny Mayer
e61793f0865117ad87a19d6e245bea8f3b712d1bDanny Mayer#include "rbtdb.h"
412e5c62115e881cce79921e2467c6c0990a0a8aBrian Wellington#include "rbtdb64.h"
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrencestatic ISC_LIST(dns_dbimplementation_t) implementations;
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrencestatic isc_rwlock_t implock;
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrencestatic isc_once_t once = ISC_ONCE_INIT;
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrencestatic dns_dbimplementation_t rbtimp;
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrencestatic dns_dbimplementation_t rbt64imp;
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffstatic void
01933e930208da3291de3722cb0d0787636b1e4fMichael Graffinitialize(void) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RUNTIME_CHECK(isc_rwlock_init(&implock, 0, 0) == ISC_R_SUCCESS);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff rbtimp.name = "rbt";
efe2f579ba6fbec4229129015780f2d925085b04Michael Graff rbtimp.create = dns_rbtdb_create;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff rbtimp.mctx = NULL;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff rbtimp.driverarg = NULL;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ISC_LINK_INIT(&rbtimp, link);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington rbt64imp.name = "rbt64";
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff rbt64imp.create = dns_rbtdb64_create;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff rbt64imp.mctx = NULL;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff rbt64imp.driverarg = NULL;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ISC_LINK_INIT(&rbt64imp, link);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ISC_LIST_INIT(implementations);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ISC_LIST_APPEND(implementations, &rbtimp, link);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ISC_LIST_APPEND(implementations, &rbt64imp, link);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff}
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffstatic inline dns_dbimplementation_t *
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffimpfind(const char *name) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff dns_dbimplementation_t *imp;
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff for (imp = ISC_LIST_HEAD(implementations);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff imp != NULL;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff imp = ISC_LIST_NEXT(imp, link))
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff if (strcasecmp(name, imp->name) == 0)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (imp);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (NULL);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff}
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff/***
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff *** Basic DB Methods
1d1d2fa57a954333c32ca3104b812b4e2389196fBrian Wellington ***/
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graffisc_result_t
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graffdns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin,
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff dns_dbtype_t type, dns_rdataclass_t rdclass,
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff unsigned int argc, char *argv[], dns_db_t **dbp)
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff{
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff dns_dbimplementation_t *impinfo;
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Create a new database using implementation 'db_type'.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff REQUIRE(dbp != NULL && *dbp == NULL);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff REQUIRE(dns_name_isabsolute(origin));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RWLOCK(&implock, isc_rwlocktype_read);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff impinfo = impfind(db_type);
c1cfd8ef05f47f2ccb5db80639e9501c9f16864cMichael Graff if (impinfo != NULL) {
c1cfd8ef05f47f2ccb5db80639e9501c9f16864cMichael Graff isc_result_t result;
c1cfd8ef05f47f2ccb5db80639e9501c9f16864cMichael Graff result = ((impinfo->create)(mctx, origin, type,
c1cfd8ef05f47f2ccb5db80639e9501c9f16864cMichael Graff rdclass, argc, argv,
c1cfd8ef05f47f2ccb5db80639e9501c9f16864cMichael Graff impinfo->driverarg, dbp));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RWUNLOCK(&implock, isc_rwlocktype_read);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (result);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff }
7a166c5c61a5aaa6eeb929bed152dc0a6b128e3dMichael Graff
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence RWUNLOCK(&implock, isc_rwlocktype_read);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff DNS_LOGMODULE_DB, ISC_LOG_ERROR,
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff "unsupported database type '%s'", db_type);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff return (ISC_R_NOTFOUND);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence}
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffvoid
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffdns_db_attach(dns_db_t *source, dns_db_t **targetp) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff /*
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Attach *targetp to source.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff REQUIRE(DNS_DB_VALID(source));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff REQUIRE(targetp != NULL && *targetp == NULL);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff (source->methods->attach)(source, targetp);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ENSURE(*targetp == source);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence}
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffvoid
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffdns_db_detach(dns_db_t **dbp) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff /*
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Detach *dbp from its database.
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence */
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff REQUIRE(dbp != NULL);
68aa880dd538ab5643abdb07a800d0443e630d2eBrian Wellington REQUIRE(DNS_DB_VALID(*dbp));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ((*dbp)->methods->detach)(dbp);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ENSURE(*dbp == NULL);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff}
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffisc_result_t
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffdns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff{
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff REQUIRE(DNS_DB_VALID(db));
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence return (isc_ondestroy_register(&db->ondest, task, eventp));
68aa880dd538ab5643abdb07a800d0443e630d2eBrian Wellington}
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffisc_boolean_t
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffdns_db_iscache(dns_db_t *db) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
01933e930208da3291de3722cb0d0787636b1e4fMichael Graff /*
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Does 'db' have cache semantics?
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff */
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington REQUIRE(DNS_DB_VALID(db));
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington if ((db->attributes & DNS_DBATTR_CACHE) != 0)
3c0a81897768d0378813865278a49d285c95b8b8Brian Wellington return (ISC_TRUE);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington return (ISC_FALSE);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington}
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtonisc_boolean_t
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtondns_db_iszone(dns_db_t *db) {
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson /*
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson * Does 'db' have zone semantics?
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson */
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson REQUIRE(DNS_DB_VALID(db));
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson if ((db->attributes & (DNS_DBATTR_CACHE|DNS_DBATTR_STUB)) == 0)
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson return (ISC_TRUE);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff return (ISC_FALSE);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington}
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtonisc_boolean_t
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtondns_db_isstub(dns_db_t *db) {
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington /*
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * Does 'db' have stub semantics?
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington */
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington REQUIRE(DNS_DB_VALID(db));
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington if ((db->attributes & DNS_DBATTR_STUB) != 0)
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington return (ISC_TRUE);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington return (ISC_FALSE);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington}
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtonisc_boolean_t
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffdns_db_isdnssec(dns_db_t *db) {
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff /*
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff * Is 'db' secure or partially secure?
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff */
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff REQUIRE(DNS_DB_VALID(db));
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff if (db->methods->isdnssec != NULL)
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff return ((db->methods->isdnssec)(db));
001d1ceec69e181f62367f4d344fb386135d91b1Andreas Gustafsson return ((db->methods->issecure)(db));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson}
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssonisc_boolean_t
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffdns_db_issecure(dns_db_t *db) {
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff /*
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Is 'db' secure?
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff */
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE(DNS_DB_VALID(db));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson return ((db->methods->issecure)(db));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson}
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssonisc_boolean_t
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssondns_db_ispersistent(dns_db_t *db) {
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington /*
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * Is 'db' persistent?
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington */
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington REQUIRE(DNS_DB_VALID(db));
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington return ((db->methods->ispersistent)(db));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson}
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssondns_name_t *
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssondns_db_origin(dns_db_t *db) {
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson /*
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson * The origin of the database.
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson */
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE(DNS_DB_VALID(db));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson return (&db->origin);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson}
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssondns_rdataclass_t
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssondns_db_class(dns_db_t *db) {
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson /*
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * The class of the database.
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington */
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE(DNS_DB_VALID(db));
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington return (db->rdclass);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington}
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtonisc_result_t
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtondns_db_beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington /*
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * Begin loading 'db'.
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson */
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE(DNS_DB_VALID(db));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE(DNS_CALLBACK_VALID(callbacks));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson return ((db->methods->beginload)(db, callbacks));
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington}
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssonisc_result_t
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssondns_db_endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson dns_dbonupdatelistener_t *listener;
5733d25b06b46067b3751d10436d82aef09cd705Brian Wellington
5733d25b06b46067b3751d10436d82aef09cd705Brian Wellington /*
5733d25b06b46067b3751d10436d82aef09cd705Brian Wellington * Finish loading 'db'.
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson */
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE(DNS_DB_VALID(db));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE(DNS_CALLBACK_VALID(callbacks));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE(callbacks->add_private != NULL);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington for (listener = ISC_LIST_HEAD(db->update_listeners);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington listener != NULL;
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington listener = ISC_LIST_NEXT(listener, link))
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington listener->onupdate(db, listener->onupdate_arg);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington return ((db->methods->endload)(db, callbacks));
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington}
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtonisc_result_t
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtondns_db_load(dns_db_t *db, const char *filename) {
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington return (dns_db_load3(db, filename, dns_masterformat_text, 0));
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington}
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssonisc_result_t
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssondns_db_load2(dns_db_t *db, const char *filename, dns_masterformat_t format) {
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson return (dns_db_load3(db, filename, format, 0));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson}
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssonisc_result_t
01933e930208da3291de3722cb0d0787636b1e4fMichael Graffdns_db_load3(dns_db_t *db, const char *filename, dns_masterformat_t format,
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff unsigned int options)
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff{
1a70537f01305cb84d402c84b1ba7cc89b97a5dcMichael Graff isc_result_t result, eresult;
1a70537f01305cb84d402c84b1ba7cc89b97a5dcMichael Graff dns_rdatacallbacks_t callbacks;
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson /*
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff * Load master file 'filename' into 'db'.
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff */
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff REQUIRE(DNS_DB_VALID(db));
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence if ((db->attributes & DNS_DBATTR_CACHE) != 0)
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence options |= DNS_MASTER_AGETTL;
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence dns_rdatacallbacks_init(&callbacks);
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence result = dns_db_beginload(db, &callbacks);
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence if (result != ISC_R_SUCCESS)
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence return (result);
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence result = dns_master_loadfile2(filename, &db->origin, &db->origin,
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff db->rdclass, options,
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff &callbacks, db->mctx, format);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson eresult = dns_db_endload(db, &callbacks);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson /*
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson * We always call dns_db_endload(), but we only want to return its
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff * result if dns_master_loadfile() succeeded. If dns_master_loadfile()
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff * failed, we want to return the result code it gave us.
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff */
d257033612f3052265085e0d7fdc116c871a28c0Michael Graff if (eresult != ISC_R_SUCCESS &&
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE))
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff result = eresult;
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff return (result);
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff}
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graffisc_result_t
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graffdns_db_serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file) {
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff REQUIRE(DNS_DB_VALID(db));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson if (db->methods->serialize == NULL)
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson return (ISC_R_NOTIMPLEMENTED);
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff return ((db->methods->serialize)(db, version, file));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson}
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graffisc_result_t
dns_db_dump(dns_db_t *db, dns_dbversion_t *version, const char *filename) {
return ((db->methods->dump)(db, version, filename,
dns_masterformat_text));
}
isc_result_t
dns_db_dump2(dns_db_t *db, dns_dbversion_t *version, const char *filename,
dns_masterformat_t masterformat) {
/*
* Dump 'db' into master file 'filename' in the 'masterformat' format.
* XXXJT: is it okay to modify the interface to the existing "dump"
* method?
*/
REQUIRE(DNS_DB_VALID(db));
return ((db->methods->dump)(db, version, filename, masterformat));
}
/***
*** 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)
{
dns_dbonupdatelistener_t *listener;
/*
* 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);
if (commit == ISC_TRUE) {
for (listener = ISC_LIST_HEAD(db->update_listeners);
listener != NULL;
listener = ISC_LIST_NEXT(listener, link))
listener->onupdate(db, listener->onupdate_arg);
}
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(nodep != NULL && *nodep == NULL);
if (db->methods->findnode != NULL)
return ((db->methods->findnode)(db, name, create, nodep));
else
return ((db->methods->findnodeext)(db, name, create,
NULL, NULL, nodep));
}
isc_result_t
dns_db_findnodeext(dns_db_t *db, dns_name_t *name,
isc_boolean_t create, dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo, dns_dbnode_t **nodep)
{
/*
* Find the node with name 'name', passing 'arg' to the database
* implementation.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(nodep != NULL && *nodep == NULL);
if (db->methods->findnodeext != NULL)
return ((db->methods->findnodeext)(db, name, create,
methods, clientinfo, nodep));
else
return ((db->methods->findnode)(db, name, create, nodep));
}
isc_result_t
dns_db_findnsec3node(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(nodep != NULL && *nodep == NULL);
return ((db->methods->findnsec3node)(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_rrsig);
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)));
if (db->methods->find != NULL)
return ((db->methods->find)(db, name, version, type,
options, now, nodep, foundname,
rdataset, sigrdataset));
else
return ((db->methods->findext)(db, name, version, type,
options, now, nodep, foundname,
NULL, NULL,
rdataset, sigrdataset));
}
isc_result_t
dns_db_findext(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_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo,
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
{
/*
* Find the best match for 'name' and 'type' in version 'version'
* of 'db', passing in 'arg'.
*/
REQUIRE(DNS_DB_VALID(db));
REQUIRE(type != dns_rdatatype_rrsig);
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)));
if (db->methods->findext != NULL)
return ((db->methods->findext)(db, name, version, type,
options, now, nodep, foundname,
methods, clientinfo,
rdataset, sigrdataset));
else
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);
}
void
dns_db_transfernode(dns_db_t *db, dns_dbnode_t **sourcep,
dns_dbnode_t **targetp)
{
REQUIRE(DNS_DB_VALID(db));
REQUIRE(targetp != NULL && *targetp == NULL);
/*
* This doesn't check the implementation magic. If we find that
* we need such checks in future then this will be done in the
* method.
*/
REQUIRE(sourcep != NULL && *sourcep != NULL);
UNUSED(db);
if (db->methods->transfernode == NULL) {
*targetp = *sourcep;
*sourcep = NULL;
} else
(db->methods->transfernode)(db, sourcep, targetp);
ENSURE(*sourcep == 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, unsigned int flags,
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, flags, 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)
{
REQUIRE(DNS_DB_VALID(db));
REQUIRE(node != NULL);
REQUIRE(DNS_RDATASET_VALID(rdataset));
REQUIRE(! dns_rdataset_isassociated(rdataset));
REQUIRE(covers == 0 || type == dns_rdatatype_rrsig);
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((options & DNS_DBADD_EXACT) == 0 ||
(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,
unsigned int options, 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,
options, 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 = DNS_RDATA_INIT;
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);
result = dns_rdataset_next(&rdataset);
INSIST(result == ISC_R_NOMORE);
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));
}
size_t
dns_db_hashsize(dns_db_t *db) {
REQUIRE(DNS_DB_VALID(db));
if (db->methods->hashsize == NULL)
return (0);
return ((db->methods->hashsize)(db));
}
void
dns_db_settask(dns_db_t *db, isc_task_t *task) {
REQUIRE(DNS_DB_VALID(db));
(db->methods->settask)(db, task);
}
isc_result_t
dns_db_register(const char *name, dns_dbcreatefunc_t create, void *driverarg,
isc_mem_t *mctx, dns_dbimplementation_t **dbimp)
{
dns_dbimplementation_t *imp;
REQUIRE(name != NULL);
REQUIRE(dbimp != NULL && *dbimp == NULL);
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
RWLOCK(&implock, isc_rwlocktype_write);
imp = impfind(name);
if (imp != NULL) {
RWUNLOCK(&implock, isc_rwlocktype_write);
return (ISC_R_EXISTS);
}
imp = isc_mem_get(mctx, sizeof(dns_dbimplementation_t));
if (imp == NULL) {
RWUNLOCK(&implock, isc_rwlocktype_write);
return (ISC_R_NOMEMORY);
}
imp->name = name;
imp->create = create;
imp->mctx = NULL;
imp->driverarg = driverarg;
isc_mem_attach(mctx, &imp->mctx);
ISC_LINK_INIT(imp, link);
ISC_LIST_APPEND(implementations, imp, link);
RWUNLOCK(&implock, isc_rwlocktype_write);
*dbimp = imp;
return (ISC_R_SUCCESS);
}
void
dns_db_unregister(dns_dbimplementation_t **dbimp) {
dns_dbimplementation_t *imp;
isc_mem_t *mctx;
REQUIRE(dbimp != NULL && *dbimp != NULL);
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
imp = *dbimp;
*dbimp = NULL;
RWLOCK(&implock, isc_rwlocktype_write);
ISC_LIST_UNLINK(implementations, imp, link);
mctx = imp->mctx;
isc_mem_put(mctx, imp, sizeof(dns_dbimplementation_t));
isc_mem_detach(&mctx);
RWUNLOCK(&implock, isc_rwlocktype_write);
ENSURE(*dbimp == NULL);
}
isc_result_t
dns_db_getoriginnode(dns_db_t *db, dns_dbnode_t **nodep) {
REQUIRE(DNS_DB_VALID(db));
REQUIRE(dns_db_iszone(db) == ISC_TRUE);
REQUIRE(nodep != NULL && *nodep == NULL);
if (db->methods->getoriginnode != NULL)
return ((db->methods->getoriginnode)(db, nodep));
return (ISC_R_NOTFOUND);
}
dns_stats_t *
dns_db_getrrsetstats(dns_db_t *db) {
REQUIRE(DNS_DB_VALID(db));
if (db->methods->getrrsetstats != NULL)
return ((db->methods->getrrsetstats)(db));
return (NULL);
}
isc_result_t
dns_db_setcachestats(dns_db_t *db, isc_stats_t *stats) {
REQUIRE(DNS_DB_VALID(db));
if (db->methods->setcachestats != NULL)
return ((db->methods->setcachestats)(db, stats));
return (ISC_R_NOTIMPLEMENTED);
}
isc_result_t
dns_db_getnsec3parameters(dns_db_t *db, dns_dbversion_t *version,
dns_hash_t *hash, isc_uint8_t *flags,
isc_uint16_t *iterations,
unsigned char *salt, size_t *salt_length)
{
REQUIRE(DNS_DB_VALID(db));
REQUIRE(dns_db_iszone(db) == ISC_TRUE);
if (db->methods->getnsec3parameters != NULL)
return ((db->methods->getnsec3parameters)(db, version, hash,
flags, iterations,
salt, salt_length));
return (ISC_R_NOTFOUND);
}
isc_result_t
dns_db_setsigningtime(dns_db_t *db, dns_rdataset_t *rdataset,
isc_stdtime_t resign)
{
if (db->methods->setsigningtime != NULL)
return ((db->methods->setsigningtime)(db, rdataset, resign));
return (ISC_R_NOTIMPLEMENTED);
}
isc_result_t
dns_db_getsigningtime(dns_db_t *db, dns_rdataset_t *rdataset, dns_name_t *name)
{
if (db->methods->getsigningtime != NULL)
return ((db->methods->getsigningtime)(db, rdataset, name));
return (ISC_R_NOTFOUND);
}
void
dns_db_resigned(dns_db_t *db, dns_rdataset_t *rdataset,
dns_dbversion_t *version)
{
if (db->methods->resigned != NULL)
(db->methods->resigned)(db, rdataset, version);
}
/*
* Attach a database to policy zone databases.
* This should only happen when the caller has already ensured that
* it is dealing with a database that understands response policy zones.
*/
void
dns_db_rpz_attach(dns_db_t *db, dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num) {
REQUIRE(db->methods->rpz_attach != NULL);
(db->methods->rpz_attach)(db, rpzs, rpz_num);
}
/*
* Finish loading a response policy zone.
*/
isc_result_t
dns_db_rpz_ready(dns_db_t *db) {
if (db->methods->rpz_ready == NULL)
return (ISC_R_SUCCESS);
return ((db->methods->rpz_ready)(db));
}
/**
* Attach a notify-on-update function the database
*/
isc_result_t
dns_db_updatenotify_register(dns_db_t *db,
dns_dbupdate_callback_t fn,
void *fn_arg)
{
dns_dbonupdatelistener_t *listener;
REQUIRE(db != NULL);
REQUIRE(fn != NULL);
listener = isc_mem_get(db->mctx, sizeof(dns_dbonupdatelistener_t));
if (listener == NULL)
return (ISC_R_NOMEMORY);
listener->onupdate = fn;
listener->onupdate_arg = fn_arg;
ISC_LINK_INIT(listener, link);
ISC_LIST_APPEND(db->update_listeners, listener, link);
return (ISC_R_SUCCESS);
}
isc_result_t
dns_db_updatenotify_unregister(dns_db_t *db,
dns_dbupdate_callback_t fn,
void *fn_arg)
{
dns_dbonupdatelistener_t *listener;
REQUIRE(db != NULL);
for (listener = ISC_LIST_HEAD(db->update_listeners);
listener != NULL;
listener = ISC_LIST_NEXT(listener, link))
{
if ((listener->onupdate == fn) &&
(listener->onupdate_arg == fn_arg))
{
ISC_LIST_UNLINK(db->update_listeners, listener, link);
isc_mem_put(db->mctx, listener,
sizeof(dns_dbonupdatelistener_t));
return (ISC_R_SUCCESS);
}
}
return (ISC_R_NOTFOUND);
}