1ccbfca64ae86ace521053773001cb995352f96fBob Halley/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999-2001, 2003-2005, 2007-2009, 2011-2013, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley/***
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley *** Imports
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ***/
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley#include <config.h>
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff#include <isc/buffer.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <isc/mem.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <isc/once.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <isc/rwlock.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/string.h>
364a82f7c25b62967678027043425201a5e5171aBob Halley#include <isc/util.h>
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <dns/callbacks.h>
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt#include <dns/clientinfo.h>
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington#include <dns/db.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <dns/dbiterator.h>
c03ce72a3b1bd639d5bc430ed37f791051125c56Andreas Gustafsson#include <dns/log.h>
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley#include <dns/master.h>
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff#include <dns/rdata.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley#include <dns/rdataset.h>
cfb1587eb9a6dc6d1d36ea0344e1b20068b81e88Evan Hunt#include <dns/rdatasetiter.h>
b20ee662a7c847c9ef7b96ab9e5e34543efe5c0dMark Andrews#include <dns/result.h>
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley/***
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley *** Private Types
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ***/
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstruct dns_dbimplementation {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington const char * name;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_dbcreatefunc_t create;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_t * mctx;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington void * driverarg;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LINK(dns_dbimplementation_t) link;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington};
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley/***
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley *** Supported DB Implementations Registry
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ***/
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley/*
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Built in database implementations are registered here.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley#include "rbtdb.h"
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley#include "rbtdb64.h"
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic ISC_LIST(dns_dbimplementation_t) implementations;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic isc_rwlock_t implock;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic isc_once_t once = ISC_ONCE_INIT;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic dns_dbimplementation_t rbtimp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic dns_dbimplementation_t rbt64imp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic void
b61c97cebd9c23e7bbfbdc9508cf022c68461d46Danny Mayerinitialize(void) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RUNTIME_CHECK(isc_rwlock_init(&implock, 0, 0) == ISC_R_SUCCESS);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rbtimp.name = "rbt";
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rbtimp.create = dns_rbtdb_create;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rbtimp.mctx = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rbtimp.driverarg = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LINK_INIT(&rbtimp, link);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rbt64imp.name = "rbt64";
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rbt64imp.create = dns_rbtdb64_create;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rbt64imp.mctx = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rbt64imp.driverarg = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LINK_INIT(&rbt64imp, link);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LIST_INIT(implementations);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LIST_APPEND(implementations, &rbtimp, link);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LIST_APPEND(implementations, &rbt64imp, link);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonstatic inline dns_dbimplementation_t *
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonimpfind(const char *name) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_dbimplementation_t *imp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater for (imp = ISC_LIST_HEAD(implementations);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp != NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp = ISC_LIST_NEXT(imp, link))
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (strcasecmp(name, imp->name) == 0)
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (imp);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley/***
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley *** Basic DB Methods
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ***/
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin,
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews dns_dbtype_t type, dns_rdataclass_t rdclass,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int argc, char *argv[], dns_db_t **dbp)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley{
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_dbimplementation_t *impinfo;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Create a new database using implementation 'db_type'.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(dbp != NULL && *dbp == NULL);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(dns_name_isabsolute(origin));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RWLOCK(&implock, isc_rwlocktype_read);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington impinfo = impfind(db_type);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (impinfo != NULL) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_result_t result;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington result = ((impinfo->create)(mctx, origin, type,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington rdclass, argc, argv,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington impinfo->driverarg, dbp));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RWUNLOCK(&implock, isc_rwlocktype_read);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (result);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RWUNLOCK(&implock, isc_rwlocktype_read);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
c03ce72a3b1bd639d5bc430ed37f791051125c56Andreas Gustafsson isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
c03ce72a3b1bd639d5bc430ed37f791051125c56Andreas Gustafsson DNS_LOGMODULE_DB, ISC_LOG_ERROR,
c03ce72a3b1bd639d5bc430ed37f791051125c56Andreas Gustafsson "unsupported database type '%s'", db_type);
c03ce72a3b1bd639d5bc430ed37f791051125c56Andreas Gustafsson
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOTFOUND);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyvoid
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_attach(dns_db_t *source, dns_db_t **targetp) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Attach *targetp to source.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(source));
2d63e8f8d2a8ef70e404182caf5b0d95dbcf2027Andreas Gustafsson REQUIRE(targetp != NULL && *targetp == NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley (source->methods->attach)(source, targetp);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ENSURE(*targetp == source);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyvoid
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_detach(dns_db_t **dbp) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Detach *dbp from its database.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley */
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(dbp != NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(*dbp));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley ((*dbp)->methods->detach)(dbp);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ENSURE(*dbp == NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
d549c3734869b48e740c64e80890bcb6f3ce672cJames Bristerisc_result_t
d549c3734869b48e740c64e80890bcb6f3ce672cJames Bristerdns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp)
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister{
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister REQUIRE(DNS_DB_VALID(db));
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister return (isc_ondestroy_register(&db->ondest, task, eventp));
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister}
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister
d549c3734869b48e740c64e80890bcb6f3ce672cJames Brister
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyisc_boolean_t
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_iscache(dns_db_t *db) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Does 'db' have cache semantics?
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley if ((db->attributes & DNS_DBATTR_CACHE) != 0)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (ISC_TRUE);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (ISC_FALSE);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyisc_boolean_t
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_iszone(dns_db_t *db) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Does 'db' have zone semantics?
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews if ((db->attributes & (DNS_DBATTR_CACHE|DNS_DBATTR_STUB)) == 0)
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews return (ISC_TRUE);
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews return (ISC_FALSE);
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews}
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrewsisc_boolean_t
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrewsdns_db_isstub(dns_db_t *db) {
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews /*
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews * Does 'db' have stub semantics?
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews REQUIRE(DNS_DB_VALID(db));
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews if ((db->attributes & DNS_DBATTR_STUB) != 0)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (ISC_TRUE);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (ISC_FALSE);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrewsisc_boolean_t
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrewsdns_db_isdnssec(dns_db_t *db) {
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews /*
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * Is 'db' secure or partially secure?
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews */
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews REQUIRE(DNS_DB_VALID(db));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if (db->methods->isdnssec != NULL)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews return ((db->methods->isdnssec)(db));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews return ((db->methods->issecure)(db));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews}
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halleyisc_boolean_t
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halleydns_db_issecure(dns_db_t *db) {
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley /*
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley * Is 'db' secure?
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley REQUIRE(DNS_DB_VALID(db));
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley return ((db->methods->issecure)(db));
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley}
b3e2e7c4d6b5c5ee90ba5bb775d635834dccec81Bob Halley
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellingtonisc_boolean_t
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellingtondns_db_ispersistent(dns_db_t *db) {
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington /*
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington * Is 'db' persistent?
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington */
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington REQUIRE(DNS_DB_VALID(db));
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington return ((db->methods->ispersistent)(db));
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington}
fe12eb4fc27f49c6b3e42b1d7a6b40310e41e6dfBrian Wellington
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halleydns_name_t *
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halleydns_db_origin(dns_db_t *db) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * The origin of the database.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley REQUIRE(DNS_DB_VALID(db));
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (&db->origin);
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley}
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley
48481c9b6e19501457bcbc2995555412f352b99fBob Halleydns_rdataclass_t
48481c9b6e19501457bcbc2995555412f352b99fBob Halleydns_db_class(dns_db_t *db) {
48481c9b6e19501457bcbc2995555412f352b99fBob Halley /*
48481c9b6e19501457bcbc2995555412f352b99fBob Halley * The class of the database.
48481c9b6e19501457bcbc2995555412f352b99fBob Halley */
48481c9b6e19501457bcbc2995555412f352b99fBob Halley
48481c9b6e19501457bcbc2995555412f352b99fBob Halley REQUIRE(DNS_DB_VALID(db));
48481c9b6e19501457bcbc2995555412f352b99fBob Halley
48481c9b6e19501457bcbc2995555412f352b99fBob Halley return (db->rdclass);
48481c9b6e19501457bcbc2995555412f352b99fBob Halley}
48481c9b6e19501457bcbc2995555412f352b99fBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
7829fad4093f2c1985b1efb7cea00287ff015d2bckbdns_db_beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley /*
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley * Begin loading 'db'.
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley */
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley REQUIRE(DNS_DB_VALID(db));
7829fad4093f2c1985b1efb7cea00287ff015d2bckb REQUIRE(DNS_CALLBACK_VALID(callbacks));
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7829fad4093f2c1985b1efb7cea00287ff015d2bckb return ((db->methods->beginload)(db, callbacks));
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley}
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
7829fad4093f2c1985b1efb7cea00287ff015d2bckbdns_db_endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki dns_dbonupdatelistener_t *listener;
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley /*
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley * Finish loading 'db'.
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley */
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley REQUIRE(DNS_DB_VALID(db));
7829fad4093f2c1985b1efb7cea00287ff015d2bckb REQUIRE(DNS_CALLBACK_VALID(callbacks));
7829fad4093f2c1985b1efb7cea00287ff015d2bckb REQUIRE(callbacks->add_private != NULL);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki for (listener = ISC_LIST_HEAD(db->update_listeners);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener != NULL;
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener = ISC_LIST_NEXT(listener, link))
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener->onupdate(db, listener->onupdate_arg);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7829fad4093f2c1985b1efb7cea00287ff015d2bckb return ((db->methods->endload)(db, callbacks));
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley}
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
bad8294771671374e811afac79a20cc6927e3e2fBob Halleydns_db_load(dns_db_t *db, const char *filename) {
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt return (dns_db_load3(db, filename, dns_masterformat_text, 0));
e174044290953a2499f574e35cc9c22ba126a303Mark Andrews}
e174044290953a2499f574e35cc9c22ba126a303Mark Andrews
e174044290953a2499f574e35cc9c22ba126a303Mark Andrewsisc_result_t
e174044290953a2499f574e35cc9c22ba126a303Mark Andrewsdns_db_load2(dns_db_t *db, const char *filename, dns_masterformat_t format) {
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt return (dns_db_load3(db, filename, format, 0));
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt}
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Hunt
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntisc_result_t
553ead32ff5b00284e574dcabc39115d4d74ec66Evan Huntdns_db_load3(dns_db_t *db, const char *filename, dns_masterformat_t format,
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki unsigned int options)
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki{
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result, eresult;
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley dns_rdatacallbacks_t callbacks;
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Load master file 'filename' into 'db'.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley REQUIRE(DNS_DB_VALID(db));
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley if ((db->attributes & DNS_DBATTR_CACHE) != 0)
0deebcd15ad440c7ecaaa77f8e06232b331aae79Mark Andrews options |= DNS_MASTER_AGETTL;
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley dns_rdatacallbacks_init(&callbacks);
7829fad4093f2c1985b1efb7cea00287ff015d2bckb result = dns_db_beginload(db, &callbacks);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley return (result);
e174044290953a2499f574e35cc9c22ba126a303Mark Andrews result = dns_master_loadfile2(filename, &db->origin, &db->origin,
e174044290953a2499f574e35cc9c22ba126a303Mark Andrews db->rdclass, options,
e174044290953a2499f574e35cc9c22ba126a303Mark Andrews &callbacks, db->mctx, format);
7829fad4093f2c1985b1efb7cea00287ff015d2bckb eresult = dns_db_endload(db, &callbacks);
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley /*
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley * We always call dns_db_endload(), but we only want to return its
27ffc5a69779c3c7224580a89aa2bf0a3ff8c16dBob Halley * result if dns_master_loadfile() succeeded. If dns_master_loadfile()
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley * failed, we want to return the result code it gave us.
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley */
86529bb6979dbe3ffd7bc2df078fac21cb339953Mark Andrews if (eresult != ISC_R_SUCCESS &&
86529bb6979dbe3ffd7bc2df078fac21cb339953Mark Andrews (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE))
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley result = eresult;
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley
7d44d8aacda98eb2b526af34757a6bbcc97cd388Bob Halley return (result);
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley}
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley
8e6b386ab7e2d1bd8efedecbb8f4efb6b572a866Tinderbox Userisc_result_t
7829fad4093f2c1985b1efb7cea00287ff015d2bckbdns_db_serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file) {
7829fad4093f2c1985b1efb7cea00287ff015d2bckb REQUIRE(DNS_DB_VALID(db));
7829fad4093f2c1985b1efb7cea00287ff015d2bckb if (db->methods->serialize == NULL)
7829fad4093f2c1985b1efb7cea00287ff015d2bckb return (ISC_R_NOTIMPLEMENTED);
7829fad4093f2c1985b1efb7cea00287ff015d2bckb return ((db->methods->serialize)(db, version, file));
7829fad4093f2c1985b1efb7cea00287ff015d2bckb}
7829fad4093f2c1985b1efb7cea00287ff015d2bckb
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
bad8294771671374e811afac79a20cc6927e3e2fBob Halleydns_db_dump(dns_db_t *db, dns_dbversion_t *version, const char *filename) {
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews return ((db->methods->dump)(db, version, filename,
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews dns_masterformat_text));
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews}
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsisc_result_t
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrewsdns_db_dump2(dns_db_t *db, dns_dbversion_t *version, const char *filename,
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews dns_masterformat_t masterformat) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson /*
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * Dump 'db' into master file 'filename' in the 'masterformat' format.
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * XXXJT: is it okay to modify the interface to the existing "dump"
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews * method?
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson REQUIRE(DNS_DB_VALID(db));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
a903095bf4512dae561c7f6fc7854a51bebf334aMark Andrews return ((db->methods->dump)(db, version, filename, masterformat));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson}
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley/***
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley *** Version Methods
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ***/
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyvoid
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Open the current version for reading.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(versionp != NULL && *versionp == NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley (db->methods->currentversion)(db, versionp);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Open a new version for reading and writing.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(versionp != NULL && *versionp == NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley return ((db->methods->newversion)(db, versionp));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
b8862d5130b88e7b1a257997d7909f769716d51cBob Halleyvoid
b8862d5130b88e7b1a257997d7909f769716d51cBob Halleydns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley dns_dbversion_t **targetp)
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley{
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley /*
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley * Attach '*targetp' to 'source'.
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley */
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley REQUIRE(DNS_DB_VALID(db));
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley REQUIRE(source != NULL);
e8d86192fc424f49e43df9cee439ca5c793e6000Mark Andrews REQUIRE(targetp != NULL && *targetp == NULL);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley (db->methods->attachversion)(db, source, targetp);
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley ENSURE(*targetp != NULL);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence}
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyvoid
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleydns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley isc_boolean_t commit)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley{
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki dns_dbonupdatelistener_t *listener;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Close version '*versionp'.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
0e3ad060581e366d3e682caf2dd5d9ea2e0f4893Bob Halley REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(versionp != NULL && *versionp != NULL);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley (db->methods->closeversion)(db, versionp, commit);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki if (commit == ISC_TRUE) {
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki for (listener = ISC_LIST_HEAD(db->update_listeners);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener != NULL;
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener = ISC_LIST_NEXT(listener, link))
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener->onupdate(db, listener->onupdate_arg);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki }
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ENSURE(*versionp == NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley/***
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley *** Node Methods
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ***/
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_findnode(dns_db_t *db, dns_name_t *name,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley isc_boolean_t create, dns_dbnode_t **nodep)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley{
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Find the node with name 'name'.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(nodep != NULL && *nodep == NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if (db->methods->findnode != NULL)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt return ((db->methods->findnode)(db, name, create, nodep));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt else
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt return ((db->methods->findnodeext)(db, name, create,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, NULL, nodep));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt}
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntisc_result_t
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntdns_db_findnodeext(dns_db_t *db, dns_name_t *name,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt isc_boolean_t create, dns_clientinfomethods_t *methods,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_clientinfo_t *clientinfo, dns_dbnode_t **nodep)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt{
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt /*
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * Find the node with name 'name', passing 'arg' to the database
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * implementation.
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(DNS_DB_VALID(db));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(nodep != NULL && *nodep == NULL);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if (db->methods->findnodeext != NULL)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt return ((db->methods->findnodeext)(db, name, create,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt methods, clientinfo, nodep));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt else
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt return ((db->methods->findnode)(db, name, create, nodep));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsisc_result_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsdns_db_findnsec3node(dns_db_t *db, dns_name_t *name,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_boolean_t create, dns_dbnode_t **nodep)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews{
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews /*
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * Find the node with name 'name'.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews */
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews REQUIRE(DNS_DB_VALID(db));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews REQUIRE(nodep != NULL && *nodep == NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return ((db->methods->findnsec3node)(db, name, create, nodep));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halleydns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
63e6086ef99eca768a4cd69871038181251905bbBob Halley dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley dns_dbnode_t **nodep, dns_name_t *foundname,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
d2615909402705135d0560ad9d11f4302053c17cBob Halley{
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley /*
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley * Find the best match for 'name' and 'type' in version 'version'
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley * of 'db'.
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley */
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley REQUIRE(DNS_DB_VALID(db));
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews REQUIRE(type != dns_rdatatype_rrsig);
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
739ccd81b011ec3f7b8029000704b1a925df7e65Bob Halley REQUIRE(dns_name_hasbuffer(foundname));
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley REQUIRE(rdataset == NULL ||
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence (DNS_RDATASET_VALID(rdataset) &&
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence ! dns_rdataset_isassociated(rdataset)));
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley REQUIRE(sigrdataset == NULL ||
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley (DNS_RDATASET_VALID(sigrdataset) &&
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence ! dns_rdataset_isassociated(sigrdataset)));
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if (db->methods->find != NULL)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt return ((db->methods->find)(db, name, version, type,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt options, now, nodep, foundname,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt rdataset, sigrdataset));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt else
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt return ((db->methods->findext)(db, name, version, type,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt options, now, nodep, foundname,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt NULL, NULL,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt rdataset, sigrdataset));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt}
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntisc_result_t
793814f80703afdd69b59ade91e63efa81ae4178Evan Huntdns_db_findext(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_dbnode_t **nodep, dns_name_t *foundname,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt{
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt /*
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * Find the best match for 'name' and 'type' in version 'version'
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * of 'db', passing in 'arg'.
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(DNS_DB_VALID(db));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(type != dns_rdatatype_rrsig);
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(dns_name_hasbuffer(foundname));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(rdataset == NULL ||
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt (DNS_RDATASET_VALID(rdataset) &&
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt ! dns_rdataset_isassociated(rdataset)));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt REQUIRE(sigrdataset == NULL ||
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt (DNS_RDATASET_VALID(sigrdataset) &&
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt ! dns_rdataset_isassociated(sigrdataset)));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt if (db->methods->findext != NULL)
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt return ((db->methods->findext)(db, name, version, type,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt options, now, nodep, foundname,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt methods, clientinfo,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt rdataset, sigrdataset));
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt else
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt return ((db->methods->find)(db, name, version, type,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt options, now, nodep, foundname,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt rdataset, sigrdataset));
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley}
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halleydns_db_findzonecut(dns_db_t *db, dns_name_t *name,
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley unsigned int options, isc_stdtime_t now,
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley dns_dbnode_t **nodep, dns_name_t *foundname,
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley{
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley /*
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley * Find the deepest known zonecut which encloses 'name' in 'db'.
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley */
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley REQUIRE(DNS_DB_VALID(db));
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley REQUIRE(dns_name_hasbuffer(foundname));
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley REQUIRE(sigrdataset == NULL ||
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley (DNS_RDATASET_VALID(sigrdataset) &&
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence ! dns_rdataset_isassociated(sigrdataset)));
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley return ((db->methods->findzonecut)(db, name, options, now, nodep,
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley foundname, rdataset, sigrdataset));
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley}
9acbfdb6a2f70d84107ccd99b24a2e523a48259bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyvoid
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Attach *targetp to source.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(source != NULL);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(targetp != NULL && *targetp == NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley (db->methods->attachnode)(db, source, targetp);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyvoid
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Detach *nodep from its node.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(nodep != NULL && *nodep != NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley (db->methods->detachnode)(db, nodep);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ENSURE(*nodep == NULL);
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
a56f5ada432128085e4a06815328023ee0c9610dMark Andrewsvoid
a56f5ada432128085e4a06815328023ee0c9610dMark Andrewsdns_db_transfernode(dns_db_t *db, dns_dbnode_t **sourcep,
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews dns_dbnode_t **targetp)
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews{
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews REQUIRE(DNS_DB_VALID(db));
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews REQUIRE(targetp != NULL && *targetp == NULL);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews /*
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews * This doesn't check the implementation magic. If we find that
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews * we need such checks in future then this will be done in the
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews * method.
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews */
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews REQUIRE(sourcep != NULL && *sourcep != NULL);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews UNUSED(db);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews if (db->methods->transfernode == NULL) {
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater *targetp = *sourcep;
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater *sourcep = NULL;
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews } else
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater (db->methods->transfernode)(db, sourcep, targetp);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews ENSURE(*sourcep == NULL);
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews}
a56f5ada432128085e4a06815328023ee0c9610dMark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halleydns_db_expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) {
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley /*
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley * Mark as stale all records at 'node' which expire at or before 'now'.
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley */
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley REQUIRE(DNS_DB_VALID(db));
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley REQUIRE(node != NULL);
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley return ((db->methods->expirenode)(db, node, now));
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley}
6e8ec359a45b7e991d7bcc97ed8547eac725a506Bob Halley
097c31fdea44383b7ce95345a66489040ad5e333Bob Halleyvoid
097c31fdea44383b7ce95345a66489040ad5e333Bob Halleydns_db_printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) {
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley /*
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley * Print a textual representation of the contents of the node to
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley * 'out'.
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley */
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley REQUIRE(DNS_DB_VALID(db));
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley REQUIRE(node != NULL);
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley (db->methods->printnode)(db, node, out);
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley}
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley/***
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley *** DB Iterator Creation
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley ***/
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsdns_db_createiterator(dns_db_t *db, unsigned int flags,
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley dns_dbiterator_t **iteratorp)
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley{
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley /*
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley * Create an iterator for version 'version' of 'db'.
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley */
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley REQUIRE(DNS_DB_VALID(db));
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley REQUIRE(iteratorp != NULL && *iteratorp == NULL);
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (db->methods->createiterator(db, flags, iteratorp));
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley}
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley/***
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley *** Rdataset Methods
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley ***/
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley dns_rdatatype_t type, dns_rdatatype_t covers,
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley isc_stdtime_t now, dns_rdataset_t *rdataset,
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley dns_rdataset_t *sigrdataset)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley{
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(node != NULL);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence REQUIRE(! dns_rdataset_isassociated(rdataset));
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews REQUIRE(covers == 0 || type == dns_rdatatype_rrsig);
732e0731dec1922747bb3b3147cf2c3d16b22eaaBob Halley REQUIRE(type != dns_rdatatype_any);
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley REQUIRE(sigrdataset == NULL ||
0b157747b398ab59f42f584adc70a6c97d771abeBob Halley (DNS_RDATASET_VALID(sigrdataset) &&
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence ! dns_rdataset_isassociated(sigrdataset)));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt return ((db->methods->findrdataset)(db, node, version, type,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt covers, now, rdataset,
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt sigrdataset));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halleydns_db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
63e6086ef99eca768a4cd69871038181251905bbBob Halley isc_stdtime_t now, dns_rdatasetiter_t **iteratorp)
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley{
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley /*
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley * Make '*iteratorp' an rdataset iteratator for all rdatasets at
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley * 'node' in version 'version' of 'db'.
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley */
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley REQUIRE(DNS_DB_VALID(db));
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley REQUIRE(iteratorp != NULL && *iteratorp == NULL);
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley
63e6086ef99eca768a4cd69871038181251905bbBob Halley return ((db->methods->allrdatasets)(db, node, version, now,
63e6086ef99eca768a4cd69871038181251905bbBob Halley iteratorp));
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley}
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
7f705ac9a20e82264113e561a515d54dde5bcea3Bob Halley isc_stdtime_t now, dns_rdataset_t *rdataset,
64e829fffb8d95e7507079767ef68327b4a7b4caBob Halley unsigned int options, dns_rdataset_t *addedrdataset)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley{
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Add 'rdataset' to 'node' in version 'version' of 'db'.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(node != NULL);
5c6d49484bf5600e3c2bcb3165e168bd058d167bBob Halley REQUIRE(((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL)||
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley ((db->attributes & DNS_DBATTR_CACHE) != 0 &&
64e829fffb8d95e7507079767ef68327b4a7b4caBob Halley version == NULL && (options & DNS_DBADD_MERGE) == 0));
012c6d0b9114a2eacd3ec5e61f5cab47993a4d15Mark Andrews REQUIRE((options & DNS_DBADD_EXACT) == 0 ||
012c6d0b9114a2eacd3ec5e61f5cab47993a4d15Mark Andrews (options & DNS_DBADD_MERGE) != 0);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence REQUIRE(dns_rdataset_isassociated(rdataset));
302d9bebb54ad8c5a3e2108698215a0e98e06a32Bob Halley REQUIRE(rdataset->rdclass == db->rdclass);
7f705ac9a20e82264113e561a515d54dde5bcea3Bob Halley REQUIRE(addedrdataset == NULL ||
7f705ac9a20e82264113e561a515d54dde5bcea3Bob Halley (DNS_RDATASET_VALID(addedrdataset) &&
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence ! dns_rdataset_isassociated(addedrdataset)));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
7f705ac9a20e82264113e561a515d54dde5bcea3Bob Halley return ((db->methods->addrdataset)(db, node, version, now, rdataset,
64e829fffb8d95e7507079767ef68327b4a7b4caBob Halley options, addedrdataset));
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley}
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halleydns_db_subtractrdataset(dns_db_t *db, dns_dbnode_t *node,
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley dns_dbversion_t *version, dns_rdataset_t *rdataset,
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews unsigned int options, dns_rdataset_t *newrdataset)
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley{
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley /*
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley * Remove any rdata in 'rdataset' from 'node' in version 'version' of
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley * 'db'.
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley */
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley REQUIRE(DNS_DB_VALID(db));
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley REQUIRE(node != NULL);
b687c057fbd8b88738300a5038538e589677fe18Bob Halley REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL);
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley REQUIRE(DNS_RDATASET_VALID(rdataset));
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence REQUIRE(dns_rdataset_isassociated(rdataset));
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley REQUIRE(rdataset->rdclass == db->rdclass);
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley REQUIRE(newrdataset == NULL ||
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley (DNS_RDATASET_VALID(newrdataset) &&
b77f76be2d114ad1abecf7e6e6c1414a4ade44c1David Lawrence ! dns_rdataset_isassociated(newrdataset)));
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley
a7e185ff3f7db73e282bf53b9f84a95ff8f8cb27Bob Halley return ((db->methods->subtractrdataset)(db, node, version, rdataset,
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews options, newrdataset));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
1ccbfca64ae86ace521053773001cb995352f96fBob Halleydns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
6cac2e0f7a1ab207a64127bef11bb93404523c15Brian Wellington dns_dbversion_t *version, dns_rdatatype_t type,
6cac2e0f7a1ab207a64127bef11bb93404523c15Brian Wellington dns_rdatatype_t covers)
1ccbfca64ae86ace521053773001cb995352f96fBob Halley{
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley /*
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Make it so that no rdataset of type 'type' exists at 'node' in
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * version version 'version' of 'db'.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley */
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley
1ccbfca64ae86ace521053773001cb995352f96fBob Halley REQUIRE(DNS_DB_VALID(db));
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley REQUIRE(node != NULL);
a3e2ec2dfec1a8171eaf584bb957b80c04de1e0bBob Halley REQUIRE(((db->attributes & DNS_DBATTR_CACHE) == 0 && version != NULL)||
a3e2ec2dfec1a8171eaf584bb957b80c04de1e0bBob Halley ((db->attributes & DNS_DBATTR_CACHE) != 0 && version == NULL));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence return ((db->methods->deleterdataset)(db, node, version,
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence type, covers));
1ccbfca64ae86ace521053773001cb995352f96fBob Halley}
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updatervoid
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrewsdns_db_overmem(dns_db_t *db, isc_boolean_t overmem) {
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews REQUIRE(DNS_DB_VALID(db));
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews (db->methods->overmem)(db, overmem);
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews}
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graffisc_result_t
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graffdns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, isc_uint32_t *serialp)
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff{
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff isc_result_t result;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff dns_dbnode_t *node = NULL;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff dns_rdataset_t rdataset;
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews dns_rdata_t rdata = DNS_RDATA_INIT;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff isc_buffer_t buffer;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff
a6733246eafeb43755ce6d7ec3627ac4209cbccbMark Andrews REQUIRE(dns_db_iszone(db) || dns_db_isstub(db));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff result = dns_db_findnode(db, dns_db_origin(db), ISC_FALSE, &node);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff if (result != ISC_R_SUCCESS)
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff return (result);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff dns_rdataset_init(&rdataset);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff result = dns_db_findrdataset(db, node, ver, dns_rdatatype_soa, 0,
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff (isc_stdtime_t)0, &rdataset, NULL);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater if (result != ISC_R_SUCCESS)
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff goto freenode;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff result = dns_rdataset_first(&rdataset);
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater if (result != ISC_R_SUCCESS)
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff goto freerdataset;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff dns_rdataset_current(&rdataset, &rdata);
c03bb27f0675a6e60ceea66b451548e8481bc05cMark Andrews result = dns_rdataset_next(&rdataset);
f604b5ab0bd90515230a334503b7c51dcbca0c53David Lawrence INSIST(result == ISC_R_NOMORE);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff INSIST(rdata.length > 20);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff isc_buffer_init(&buffer, rdata.data, rdata.length);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff isc_buffer_add(&buffer, rdata.length);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff isc_buffer_forward(&buffer, rdata.length - 20);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff *serialp = isc_buffer_getuint32(&buffer);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff result = ISC_R_SUCCESS;
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff freerdataset:
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff dns_rdataset_disassociate(&rdataset);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff freenode:
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff dns_db_detachnode(db, &node);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff return (result);
341323e0e7ef69f7c425cd3462afe06d0930c528Michael Graff}
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellingtonunsigned int
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellingtondns_db_nodecount(dns_db_t *db) {
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington REQUIRE(DNS_DB_VALID(db));
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington return ((db->methods->nodecount)(db));
83e6eb0dfe7d3525dcf093f440e04e8971c4c5d2Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
5d79b60fc5e4dad4f04da39570517d20a2425f8bMukund Sivaramansize_t
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntdns_db_hashsize(dns_db_t *db) {
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt REQUIRE(DNS_DB_VALID(db));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt if (db->methods->hashsize == NULL)
5d79b60fc5e4dad4f04da39570517d20a2425f8bMukund Sivaraman return (0);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt return ((db->methods->hashsize)(db));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt}
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrewsvoid
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrewsdns_db_settask(dns_db_t *db, isc_task_t *task) {
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews REQUIRE(DNS_DB_VALID(db));
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews (db->methods->settask)(db, task);
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews}
a03848252fa85734ca75beae3d0b01bb503c0a8bMark Andrews
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonisc_result_t
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtondns_db_register(const char *name, dns_dbcreatefunc_t create, void *driverarg,
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_t *mctx, dns_dbimplementation_t **dbimp)
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington{
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_dbimplementation_t *imp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(name != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(dbimp != NULL && *dbimp == NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
a1014b72b0340a071f4c59c153b02c538bfd6b9fBrian Wellington RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
a1014b72b0340a071f4c59c153b02c538bfd6b9fBrian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RWLOCK(&implock, isc_rwlocktype_write);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp = impfind(name);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (imp != NULL) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RWUNLOCK(&implock, isc_rwlocktype_write);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (ISC_R_EXISTS);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp = isc_mem_get(mctx, sizeof(dns_dbimplementation_t));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (imp == NULL) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RWUNLOCK(&implock, isc_rwlocktype_write);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (ISC_R_NOMEMORY);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington }
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->name = name;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->create = create;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->mctx = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp->driverarg = driverarg;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_attach(mctx, &imp->mctx);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LINK_INIT(imp, link);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LIST_APPEND(implementations, imp, link);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RWUNLOCK(&implock, isc_rwlocktype_write);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington *dbimp = imp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington return (ISC_R_SUCCESS);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonvoid
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtondns_db_unregister(dns_dbimplementation_t **dbimp) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington dns_dbimplementation_t *imp;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_t *mctx;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington REQUIRE(dbimp != NULL && *dbimp != NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington
a1014b72b0340a071f4c59c153b02c538bfd6b9fBrian Wellington RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
a1014b72b0340a071f4c59c153b02c538bfd6b9fBrian Wellington
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington imp = *dbimp;
f030c715007053e4ceb557c78ad5c8cfdedb4240Mark Andrews *dbimp = NULL;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RWLOCK(&implock, isc_rwlocktype_write);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington ISC_LIST_UNLINK(implementations, imp, link);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington mctx = imp->mctx;
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_put(mctx, imp, sizeof(dns_dbimplementation_t));
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington isc_mem_detach(&mctx);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington RWUNLOCK(&implock, isc_rwlocktype_write);
f030c715007053e4ceb557c78ad5c8cfdedb4240Mark Andrews ENSURE(*dbimp == NULL);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington}
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉isc_result_t
982e072a5000bfc072aee8b34f64112cf54369a5Mark Andrewsdns_db_getoriginnode(dns_db_t *db, dns_dbnode_t **nodep) {
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(DNS_DB_VALID(db));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(dns_db_iszone(db) == ISC_TRUE);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 REQUIRE(nodep != NULL && *nodep == NULL);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
982e072a5000bfc072aee8b34f64112cf54369a5Mark Andrews if (db->methods->getoriginnode != NULL)
982e072a5000bfc072aee8b34f64112cf54369a5Mark Andrews return ((db->methods->getoriginnode)(db, nodep));
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 return (ISC_R_NOTFOUND);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉}
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrewsdns_stats_t *
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrewsdns_db_getrrsetstats(dns_db_t *db) {
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews REQUIRE(DNS_DB_VALID(db));
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews if (db->methods->getrrsetstats != NULL)
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews return ((db->methods->getrrsetstats)(db));
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews return (NULL);
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews}
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntisc_result_t
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntdns_db_setcachestats(dns_db_t *db, isc_stats_t *stats) {
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt REQUIRE(DNS_DB_VALID(db));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt if (db->methods->setcachestats != NULL)
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt return ((db->methods->setcachestats)(db, stats));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt return (ISC_R_NOTIMPLEMENTED);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt}
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsisc_result_t
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrewsdns_db_getnsec3parameters(dns_db_t *db, dns_dbversion_t *version,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews dns_hash_t *hash, isc_uint8_t *flags,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews isc_uint16_t *iterations,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews unsigned char *salt, size_t *salt_length)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews{
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews REQUIRE(DNS_DB_VALID(db));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews REQUIRE(dns_db_iszone(db) == ISC_TRUE);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews if (db->methods->getnsec3parameters != NULL)
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return ((db->methods->getnsec3parameters)(db, version, hash,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews flags, iterations,
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews salt, salt_length));
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews return (ISC_R_NOTFOUND);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews}
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrewsisc_result_t
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrewsdns_db_getsize(dns_db_t *db, dns_dbversion_t *version, isc_uint64_t *records,
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews isc_uint64_t *bytes)
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews{
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews REQUIRE(DNS_DB_VALID(db));
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews REQUIRE(dns_db_iszone(db) == ISC_TRUE);
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews if (db->methods->getsize != NULL)
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews return ((db->methods->getsize)(db, version, records, bytes));
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews return (ISC_R_NOTFOUND);
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews}
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrewsisc_result_t
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrewsdns_db_setsigningtime(dns_db_t *db, dns_rdataset_t *rdataset,
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews isc_stdtime_t resign)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews{
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if (db->methods->setsigningtime != NULL)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews return ((db->methods->setsigningtime)(db, rdataset, resign));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews return (ISC_R_NOTIMPLEMENTED);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews}
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrewsisc_result_t
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrewsdns_db_getsigningtime(dns_db_t *db, dns_rdataset_t *rdataset, dns_name_t *name)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews{
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if (db->methods->getsigningtime != NULL)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews return ((db->methods->getsigningtime)(db, rdataset, name));
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews return (ISC_R_NOTFOUND);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews}
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrewsvoid
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrewsdns_db_resigned(dns_db_t *db, dns_rdataset_t *rdataset,
28479307225582ad0b2e11441d85fcf5169551d0Mark Andrews dns_dbversion_t *version)
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews{
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews if (db->methods->resigned != NULL)
2391def77980f6107b2c5bdd8b74e225b604b3baMark Andrews (db->methods->resigned)(db, rdataset, version);
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt/*
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt * Attach a database to policy zone databases.
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt * This should only happen when the caller has already ensured that
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt * it is dealing with a database that understands response policy zones.
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsvoid
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntdns_db_rpz_attach(dns_db_t *db, dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num) {
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt REQUIRE(db->methods->rpz_attach != NULL);
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt (db->methods->rpz_attach)(db, rpzs, rpz_num);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt/*
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt * Finish loading a response policy zone.
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt */
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntisc_result_t
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntdns_db_rpz_ready(dns_db_t *db) {
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt if (db->methods->rpz_ready == NULL)
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt return (ISC_R_SUCCESS);
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt return ((db->methods->rpz_ready)(db));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki/**
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki * Attach a notify-on-update function the database
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki */
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecickiisc_result_t
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecickidns_db_updatenotify_register(dns_db_t *db,
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki dns_dbupdate_callback_t fn,
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki void *fn_arg)
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki{
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki dns_dbonupdatelistener_t *listener;
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki REQUIRE(db != NULL);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki REQUIRE(fn != NULL);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener = isc_mem_get(db->mctx, sizeof(dns_dbonupdatelistener_t));
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki if (listener == NULL)
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki return (ISC_R_NOMEMORY);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener->onupdate = fn;
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener->onupdate_arg = fn_arg;
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki ISC_LINK_INIT(listener, link);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki ISC_LIST_APPEND(db->update_listeners, listener, link);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki return (ISC_R_SUCCESS);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki}
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecickiisc_result_t
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecickidns_db_updatenotify_unregister(dns_db_t *db,
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki dns_dbupdate_callback_t fn,
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki void *fn_arg)
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki{
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki dns_dbonupdatelistener_t *listener;
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki REQUIRE(db != NULL);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki for (listener = ISC_LIST_HEAD(db->update_listeners);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener != NULL;
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki listener = ISC_LIST_NEXT(listener, link))
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki {
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki if ((listener->onupdate == fn) &&
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki (listener->onupdate_arg == fn_arg))
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki {
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki ISC_LIST_UNLINK(db->update_listeners, listener, link);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki isc_mem_put(db->mctx, listener,
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki sizeof(dns_dbonupdatelistener_t));
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki return (ISC_R_SUCCESS);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki }
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki }
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki return (ISC_R_NOTFOUND);
7a00d69909ace5dc11bcff9c1e07c311f92a7f8eWitold Krecicki}
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrewsisc_result_t
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrewsdns_db_nodefullname(dns_db_t *db, dns_dbnode_t *node, dns_name_t *name) {
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews REQUIRE(db != NULL);
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews REQUIRE(node != NULL);
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews REQUIRE(name != NULL);
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews if (db->methods->nodefullname == NULL)
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews return (ISC_R_NOTIMPLEMENTED);
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews return ((db->methods->nodefullname)(db, node, name));
b4bbf494183e4158b417d9200297ff0764af2f9dMark Andrews}