* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
* The DNS DB interface allows named rdatasets to be stored and retrieved.
* The dns_db_t type is like a "virtual class". To actually use
* DBs, an implementation of the class is required.
* \li The module ensures appropriate synchronization of data structures it
* creates and manipulates.
* \li No anticipated impact.
* \li No anticipated impact.
#include <isc/deprecated.h>
#include <isc/ondestroy.h>
#include <dns/clientinfo.h>
#include <dns/fixedname.h>
#include <dns/rdataset.h>
typedef struct dns_dbmethods {
void (*attach)(dns_db_t *source, dns_db_t **targetp);
void (*detach)(dns_db_t **dbp);
isc_result_t (*beginload)(dns_db_t *db,
dns_rdatacallbacks_t *callbacks);
isc_result_t (*endload)(dns_db_t *db,
dns_rdatacallbacks_t *callbacks);
isc_result_t (*serialize)(dns_db_t *db,
dns_dbversion_t *version, FILE *file);
isc_result_t (*dump)(dns_db_t *db, dns_dbversion_t *version,
dns_masterformat_t masterformat);
void (*currentversion)(dns_db_t *db,
dns_dbversion_t **versionp);
isc_result_t (*newversion)(dns_db_t *db,
dns_dbversion_t **versionp);
void (*attachversion)(dns_db_t *db, dns_dbversion_t *source,
dns_dbversion_t **targetp);
void (*closeversion)(dns_db_t *db,
dns_dbversion_t **versionp,
isc_result_t (*findnode)(dns_db_t *db, dns_name_t *name,
isc_result_t (*find)(dns_db_t *db, dns_name_t *name,
dns_dbversion_t *version,
dns_rdatatype_t type, unsigned int options,
dns_dbnode_t **nodep, dns_name_t *foundname,
dns_rdataset_t *rdataset,
dns_rdataset_t *sigrdataset);
isc_result_t (*findzonecut)(dns_db_t *db, dns_name_t *name,
unsigned int options, isc_stdtime_t now,
dns_rdataset_t *rdataset,
dns_rdataset_t *sigrdataset);
void (*attachnode)(dns_db_t *db,
void (*detachnode)(dns_db_t *db,
isc_result_t (*expirenode)(dns_db_t *db, dns_dbnode_t *node,
void (*printnode)(dns_db_t *db, dns_dbnode_t *node,
isc_result_t (*createiterator)(dns_db_t *db, unsigned int options,
dns_dbiterator_t **iteratorp);
isc_result_t (*findrdataset)(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version,
dns_rdataset_t *rdataset,
dns_rdataset_t *sigrdataset);
isc_result_t (*allrdatasets)(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version,
dns_rdatasetiter_t **iteratorp);
isc_result_t (*addrdataset)(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version,
dns_rdataset_t *rdataset,
dns_rdataset_t *addedrdataset);
isc_result_t (*subtractrdataset)(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version,
dns_rdataset_t *rdataset,
dns_rdataset_t *newrdataset);
isc_result_t (*deleterdataset)(dns_db_t *db, dns_dbnode_t *node,
dns_dbversion_t *version,
bool (*issecure)(dns_db_t *db);
unsigned int (*nodecount)(dns_db_t *db);
bool (*ispersistent)(dns_db_t *db);
void (*overmem)(dns_db_t *db, bool overmem);
void (*settask)(dns_db_t *db, isc_task_t *);
isc_result_t (*getoriginnode)(dns_db_t *db, dns_dbnode_t **nodep);
void (*transfernode)(dns_db_t *db, dns_dbnode_t **sourcep,
isc_result_t (*getnsec3parameters)(dns_db_t *db,
dns_dbversion_t *version,
isc_result_t (*findnsec3node)(dns_db_t *db, dns_name_t *name,
isc_result_t (*setsigningtime)(dns_db_t *db,
dns_rdataset_t *rdataset,
isc_result_t (*getsigningtime)(dns_db_t *db,
dns_rdataset_t *rdataset,
void (*resigned)(dns_db_t *db, dns_rdataset_t *rdataset,
dns_dbversion_t *version);
bool (*isdnssec)(dns_db_t *db);
dns_stats_t *(*getrrsetstats)(dns_db_t *db);
void (*rpz_attach)(dns_db_t *db, dns_rpz_zones_t *rpzs,
isc_result_t (*rpz_ready)(dns_db_t *db);
isc_result_t (*findnodeext)(dns_db_t *db, dns_name_t *name,
dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo,
isc_result_t (*findext)(dns_db_t *db, dns_name_t *name,
dns_dbversion_t *version,
dns_rdatatype_t type, unsigned int options,
dns_dbnode_t **nodep, dns_name_t *foundname,
dns_clientinfomethods_t *methods,
dns_clientinfo_t *clientinfo,
dns_rdataset_t *rdataset,
dns_rdataset_t *sigrdataset);
isc_result_t (*setcachestats)(dns_db_t *db, isc_stats_t *stats);
size_t (*hashsize)(dns_db_t *db);
isc_result_t (*nodefullname)(dns_db_t *db, dns_dbnode_t *node,
isc_result_t (*getsize)(dns_db_t *db, dns_dbversion_t *version,
uint64_t *records, uint64_t *bytes);
isc_result_t (*setservestalettl)(dns_db_t *db, dns_ttl_t ttl);
isc_result_t (*getservestalettl)(dns_db_t *db, dns_ttl_t *ttl);
(*dns_dbcreatefunc_t)(isc_mem_t *mctx, dns_name_t *name,
dns_dbtype_t type, dns_rdataclass_t rdclass,
unsigned int argc, char *argv[], void *driverarg,
(*dns_dbupdate_callback_t)(dns_db_t *db, void *fn_arg);
#define DNS_DB_MAGIC ISC_MAGIC('D','N','S','D')
#define DNS_DB_VALID(db) ISC_MAGIC_VALID(db, DNS_DB_MAGIC)
* This structure is actually just the common prefix of a DNS db
* implementation's version of a dns_db_t.
* Direct use of this structure by clients is forbidden. DB implementations
* may change the structure. 'magic' must be DNS_DB_MAGIC for any of the
* dns_db_ routines to work. DB implementations must maintain all DB
dns_dbmethods_t * methods;
dns_rdataclass_t rdclass;
ISC_LIST(dns_dbonupdatelistener_t) update_listeners;
#define DNS_DBATTR_CACHE 0x01
#define DNS_DBATTR_STUB 0x02
struct dns_dbonupdatelistener {
dns_dbupdate_callback_t onupdate;
ISC_LINK(dns_dbonupdatelistener_t) link;
* Options that can be specified for dns_db_find().
#define DNS_DBFIND_GLUEOK 0x0001
#define DNS_DBFIND_VALIDATEGLUE 0x0002
#define DNS_DBFIND_NOWILD 0x0004
#define DNS_DBFIND_PENDINGOK 0x0008
#define DNS_DBFIND_NOEXACT 0x0010
#define DNS_DBFIND_FORCENSEC 0x0020
#define DNS_DBFIND_COVERINGNSEC 0x0040
#define DNS_DBFIND_FORCENSEC3 0x0080
#define DNS_DBFIND_ADDITIONALOK 0x0100
#define DNS_DBFIND_NOZONECUT 0x0200
#define DNS_DBFIND_STALEOK 0x0400
* Options that can be specified for dns_db_addrdataset().
#define DNS_DBADD_MERGE 0x01
#define DNS_DBADD_FORCE 0x02
#define DNS_DBADD_EXACT 0x04
#define DNS_DBADD_EXACTTTL 0x08
#define DNS_DBADD_PREFETCH 0x10
* Options that can be specified for dns_db_subtractrdataset().
#define DNS_DBSUB_EXACT 0x01
#define DNS_DBSUB_WANTOLD 0x02
#define DNS_DB_RELATIVENAMES 0x1
#define DNS_DB_NSEC3ONLY 0x2
#define DNS_DB_NONSEC3 0x4
dns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin,
dns_dbtype_t type, dns_rdataclass_t rdclass,
unsigned int argc, char *argv[], dns_db_t **dbp);
* Create a new database using implementation 'db_type'.
* \li All names in the database must be subdomains of 'origin' and in class
* 'rdclass'. The database makes its own copy of the origin, so the
* caller may do whatever they like with 'origin' and its storage once the
* \li DB implementation-specific parameters are passed using argc and argv.
* \li dbp != NULL and *dbp == NULL
* \li 'origin' is a valid absolute domain name.
* \li mctx is a valid memory context
* \li A copy of 'origin' has been made for the databases use, and the
* caller is free to do whatever they want with the name and storage
* associated with 'origin'.
* \li #ISC_R_NOTFOUND db_type not found
* \li Many other errors are possible, depending on what db_type was
dns_db_attach(dns_db_t *source, dns_db_t **targetp);
* Attach *targetp to source.
* \li 'source' is a valid database.
* \li 'targetp' points to a NULL dns_db_t *.
* \li *targetp is attached to source.
dns_db_detach(dns_db_t **dbp);
* Detach *dbp from its database.
* \li 'dbp' points to a valid database.
* \li If '*dbp' is the last reference to the database,
* all resources used by the database will be freed
dns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp);
* Causes 'eventp' to be sent to be sent to 'task' when the database is
* Note; ownership of the eventp is taken from the caller (and *eventp is
* set to NULL). The sender field of the event is set to 'db' before it is
dns_db_iscache(dns_db_t *db);
* Does 'db' have cache semantics?
* \li 'db' is a valid database.
* \li #true 'db' has cache semantics
dns_db_iszone(dns_db_t *db);
* Does 'db' have zone semantics?
* \li 'db' is a valid database.
* \li #true 'db' has zone semantics
dns_db_isstub(dns_db_t *db);
* Does 'db' have stub semantics?
* \li 'db' is a valid database.
* \li #true 'db' has zone semantics
dns_db_issecure(dns_db_t *db);
* \li 'db' is a valid database with zone semantics.
* \li #true 'db' is secure.
* \li #false 'db' is not secure.
dns_db_isdnssec(dns_db_t *db);
* Is 'db' secure or partially secure?
* \li 'db' is a valid database with zone semantics.
* \li #true 'db' is secure or is partially.
* \li #false 'db' is not secure.
dns_db_origin(dns_db_t *db);
* The origin of the database.
* Note: caller must not try to change this name.
* \li 'db' is a valid database.
* \li The origin of the database.
dns_db_class(dns_db_t *db);
* The class of the database.
* \li 'db' is a valid database.
* \li The class of the database.
dns_db_beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks);
* \li 'db' is a valid database.
* \li This is the first attempt to load 'db'.
* \li 'callbacks' is a pointer to an initialized dns_rdatacallbacks_t
* \li On success, callbacks->add will be a valid dns_addrdatasetfunc_t
* suitable for loading records into 'db' from a raw or text zone
* file. callbacks->add_private will be a valid DB load context
* which should be used as 'arg' when callbacks->add is called.
* callbacks->deserialize will be a valid dns_deserialize_func_t
* suitable for loading 'db' from a map format zone file.