db.c revision 64e829fffb8d95e7507079767ef68327b4a7b4ca
ca41b452ede6feaa9d8739ec3cae19389a7b0d03Bob Halley * Copyright (C) 1999 Internet Software Consortium.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * Permission to use, copy, modify, and distribute this software for any
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * purpose with or without fee is hereby granted, provided that the above
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * copyright notice and this permission notice appear in all copies.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff *** Private Types
910df98b0efcbe8380b952887f4071051cc39a25Michael Grafftypedef struct {
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson isc_result_t (*create)(isc_mem_t *mctx, dns_name_t *name,
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff *** Supported DB Implementations Registry
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Supported database implementations must be registered here.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * It might be nice to generate this automatically some day.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff *** Basic DB Methods
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graffdns_db_create(isc_mem_t *mctx, char *db_type, dns_name_t *origin,
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff isc_boolean_t cache, dns_rdataclass_t rdclass,
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff unsigned int argc, char *argv[], dns_db_t **dbp)
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff * Create a new database using implementation 'db_type'.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff for (impinfo = implementations; impinfo->name != NULL; impinfo++)
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff return ((impinfo->create)(mctx, origin, cache, rdclass,
910df98b0efcbe8380b952887f4071051cc39a25Michael Graffdns_db_attach(dns_db_t *source, dns_db_t **targetp) {
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Attach *targetp to source.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Detach *dbp from its database.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Does 'db' have cache semantics?
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff * Does 'db' have zone semantics?
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Is 'db' secure?
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff * The origin of the database.
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff * The class of the database.
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffdns_db_beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp,
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff * Begin loading 'db'.
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson REQUIRE(dbloadp != NULL && *dbloadp == NULL);
fd15c8e32ed0c1cfd3ed737858a81966e7fbaeacAndreas Gustafsson return ((db->methods->beginload)(db, addp, dbloadp));
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffdns_db_endload(dns_db_t *db, dns_dbload_t **dbloadp) {
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff * Finish loading 'db'.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffdns_db_load(dns_db_t *db, const char *filename) {
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Load master file 'filename' into 'db'.
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff result = dns_db_beginload(db, &callbacks.add, &callbacks.add_private);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff result = dns_master_loadfile(filename, &db->origin, &db->origin,
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff eresult = dns_db_endload(db, &callbacks.add_private);
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * We always call dns_db_endload(), but we only want to return its
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * result if dns_master_loadfile() succeeded. If dns_master_loadfile()
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * failed, we want to return the result code it gave us.
1a0e33bc2044e1902493111db14cbf793083ac47Michael Graffdns_db_dump(dns_db_t *db, dns_dbversion_t *version, const char *filename) {
528829aa8ad69238e674cd81078bc14d4199691bMichael Graff * Dump 'db' into master file 'filename'.
c803787146cadcb2d7e10cbf4491f3be513dfa1aMichael Graff return ((db->methods->dump)(db, version, filename));
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff *** Version Methods
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graffdns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp) {
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Open the current version for reading.
da547174e2b7beb6d6119d58197ad0bc85b91179Michael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
da547174e2b7beb6d6119d58197ad0bc85b91179Michael Graff REQUIRE(versionp != NULL && *versionp == NULL);
f00d96a15cdd11e764437f9359e67328631caaeaMichael Graffdns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp) {
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Open a new version for reading and writing.
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff REQUIRE(versionp != NULL && *versionp == NULL);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff return ((db->methods->newversion)(db, versionp));
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffdns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff * Attach '*targetp' to 'source'.
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff (db->methods->attachversion)(db, source, targetp);
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graffdns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff * Close version '*versionp'.
ff9bb3fc5453bbf310b67c560fbf04a5c0fb60daMichael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graff REQUIRE(versionp != NULL && *versionp != NULL);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff (db->methods->closeversion)(db, versionp, commit);
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff *** Node Methods
efc8a09e19dfcfafa92fd2ad113073a4f5295e9bMichael Graffdns_db_findnode(dns_db_t *db, dns_name_t *name,
970cccf46e0f949a1a9edbcd8302dd2a112b43c2Michael Graff * Find the node with name 'name'.
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff REQUIRE(dns_name_issubdomain(name, &db->origin));
cebd4498636d3d480f6f2a7aa2eb72bd2ed64010Michael Graff return ((db->methods->findnode)(db, name, create, nodep));
528829aa8ad69238e674cd81078bc14d4199691bMichael Graffdns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff * Find the best match for 'name' and 'type' in version 'version'
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff (DNS_RDATASET_VALID(rdataset) && rdataset->methods == NULL));
f942258b6380ba1f2c2f057a79ffc37bc3436488Michael Graff return ((db->methods->find)(db, name, version, type, options, now,
29f28fe573d4b3b318b3b026d567c1eb86738015Michael Graffdns_db_findzonecut(dns_db_t *db, dns_name_t *name,
86944a4c8002e80ae9b6eb5a5e29b797879be45fMichael Graff dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset)
30251e07d1705d1a85b0e1d5a969496e1aed612eMichael Graff * Find the deepest known zonecut which encloses 'name' in 'db'.
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0);
1c3bc66ada38236cc81c41b7174a9f0a872c9ab6Michael Graff REQUIRE(nodep == NULL || (nodep != NULL && *nodep == NULL));
a9ece9973c35d4d780338e89e288fb6a59575324Michael Graff return ((db->methods->findzonecut)(db, name, options, now, nodep,
2bcb48cfcae36398454c98e40c563e2cde748e07Michael Graffdns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp) {
910df98b0efcbe8380b952887f4071051cc39a25Michael Graff * Attach *targetp to source.
iteratorp));
newrdataset));