db.c revision 7a00d69909ace5dc11bcff9c1e07c311f92a7f8e
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2004, 2005, 2007-2009, 2011-2013, 2015 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2001, 2003 Internet Software Consortium.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Permission to use, copy, modify, and/or distribute this software for any
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * purpose with or without fee is hereby granted, provided that the above
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrence *** Private Types
71811653336a000f6c61d26d4b2a0c0d2cec9c25Danny Mayer const char * name;
3489d64bde03af5c7950661b083b530bd285ec27Mark Andrews *** Supported DB Implementations Registry
71811653336a000f6c61d26d4b2a0c0d2cec9c25Danny Mayer * Built in database implementations are registered here.
03a0fca86dd9db6a40743107ec9dea7c33e46a7aDavid Lawrencestatic ISC_LIST(dns_dbimplementation_t) implementations;
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RUNTIME_CHECK(isc_rwlock_init(&implock, 0, 0) == ISC_R_SUCCESS);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ISC_LIST_APPEND(implementations, &rbtimp, link);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff ISC_LIST_APPEND(implementations, &rbt64imp, link);
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff *** Basic DB Methods
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graffdns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin,
d736db6dc53e615e3f2d66d1ddbe28473694d107Michael Graff unsigned int argc, char *argv[], dns_db_t **dbp)
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Create a new database using implementation 'db_type'.
c1cfd8ef05f47f2ccb5db80639e9501c9f16864cMichael Graff result = ((impinfo->create)(mctx, origin, type,
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffdns_db_attach(dns_db_t *source, dns_db_t **targetp) {
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Attach *targetp to source.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graff * Detach *dbp from its database.
64bed6c54393c2d213db83e9b171fb7c318cfc8eMichael Graffdns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp)
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence return (isc_ondestroy_register(&db->ondest, task, eventp));
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence * Does 'db' have cache semantics?
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington if ((db->attributes & DNS_DBATTR_CACHE) != 0)
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson * Does 'db' have zone semantics?
5b34d8267e8228b4615b9eae4e32d9ad1f308179Andreas Gustafsson if ((db->attributes & (DNS_DBATTR_CACHE|DNS_DBATTR_STUB)) == 0)
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * Does 'db' have stub semantics?
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington if ((db->attributes & DNS_DBATTR_STUB) != 0)
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff * Is 'db' secure or partially secure?
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff * Is 'db' secure?
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * Is 'db' persistent?
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson * The origin of the database.
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * The class of the database.
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtondns_db_beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington * Begin loading 'db'.
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson return ((db->methods->beginload)(db, callbacks));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssondns_db_endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
5733d25b06b46067b3751d10436d82aef09cd705Brian Wellington * Finish loading 'db'.
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington for (listener = ISC_LIST_HEAD(db->update_listeners);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington listener->onupdate(db, listener->onupdate_arg);
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington return ((db->methods->endload)(db, callbacks));
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellingtondns_db_load(dns_db_t *db, const char *filename) {
8f80322fb58bac39c84bb76cb2bc82406bd6a9ecBrian Wellington return (dns_db_load3(db, filename, dns_masterformat_text, 0));
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafssondns_db_load2(dns_db_t *db, const char *filename, dns_masterformat_t format) {
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson return (dns_db_load3(db, filename, format, 0));
01933e930208da3291de3722cb0d0787636b1e4fMichael Graffdns_db_load3(dns_db_t *db, const char *filename, dns_masterformat_t format,
7dbf5a0b64237aa3052f04f4c8f7d56be8ec5d79Michael Graff unsigned int options)
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff * Load master file 'filename' into 'db'.
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence if ((db->attributes & DNS_DBATTR_CACHE) != 0)
74cf566d92d610c2dc090a0dc7f77651c0fb0635David Lawrence result = dns_master_loadfile2(filename, &db->origin, &db->origin,
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson eresult = dns_db_endload(db, &callbacks);
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson * We always call dns_db_endload(), but we only want to return its
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff * result if dns_master_loadfile() succeeded. If dns_master_loadfile()
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graff * failed, we want to return the result code it gave us.
7bee275ebe250b5e1705a997e2ee3e685d146fbdAndreas Gustafsson (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE))
b91bbaf50cf6d0c2cad7323720495165595e413bMichael Graffdns_db_serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file) {
8cd870e3f5e3db9808a4a0d6f98db3d1a5348e40Michael Graff return ((db->methods->serialize)(db, version, file));
sigrdataset));
iteratorp));
return (result);
goto freenode;
goto freerdataset;
return (result);
return (ISC_R_EXISTS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (NULL);
return (ISC_R_NOTIMPLEMENTED);
return (ISC_R_NOTFOUND);
return (ISC_R_NOTIMPLEMENTED);
return (ISC_R_NOTFOUND);
return (ISC_R_SUCCESS);
void *fn_arg)
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
void *fn_arg)
sizeof(dns_dbonupdatelistener_t));
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);