2 * Copyright (C) 2004-2009, 2011, 2012 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
29 * The DNS DB interface allows named rdatasets to be stored and retrieved.
31 * The dns_db_t type is like a "virtual class". To actually use
32 * DBs, an implementation of the class is required.
37 * \li The module ensures appropriate synchronization of data structures it
38 * creates and manipulates.
41 * \li No anticipated impact.
47 * \li No anticipated impact.
58 #include <isc/magic.h>
59 #include <isc/ondestroy.h>
60 #include <isc/stdtime.h>
62 #include <dns/fixedname.h>
64 #include <dns/rdata.h>
65 #include <dns/rdataset.h>
67 #include <dns/types.h>
75 typedef struct dns_dbmethods {
76 void (*attach)(dns_db_t *source, dns_db_t **targetp);
77 void (*detach)(dns_db_t **dbp);
78 isc_result_t (*beginload)(dns_db_t *db, dns_addrdatasetfunc_t *addp,
79 dns_dbload_t **dbloadp);
80 isc_result_t (*endload)(dns_db_t *db, dns_dbload_t **dbloadp);
81 isc_result_t (*dump)(dns_db_t *db, dns_dbversion_t *version,
83 dns_masterformat_t masterformat);
84 void (*currentversion)(dns_db_t *db,
85 dns_dbversion_t **versionp);
86 isc_result_t (*newversion)(dns_db_t *db,
87 dns_dbversion_t **versionp);
88 void (*attachversion)(dns_db_t *db, dns_dbversion_t *source,
89 dns_dbversion_t **targetp);
90 void (*closeversion)(dns_db_t *db,
91 dns_dbversion_t **versionp,
92 isc_boolean_t commit);
93 isc_result_t (*findnode)(dns_db_t *db, dns_name_t *name,
95 dns_dbnode_t **nodep);
96 isc_result_t (*find)(dns_db_t *db, dns_name_t *name,
97 dns_dbversion_t *version,
98 dns_rdatatype_t type, unsigned int options,
100 dns_dbnode_t **nodep, dns_name_t *foundname,
101 dns_rdataset_t *rdataset,
102 dns_rdataset_t *sigrdataset);
103 isc_result_t (*findzonecut)(dns_db_t *db, dns_name_t *name,
104 unsigned int options, isc_stdtime_t now,
105 dns_dbnode_t **nodep,
106 dns_name_t *foundname,
107 dns_rdataset_t *rdataset,
108 dns_rdataset_t *sigrdataset);
109 void (*attachnode)(dns_db_t *db,
110 dns_dbnode_t *source,
111 dns_dbnode_t **targetp);
112 void (*detachnode)(dns_db_t *db,
113 dns_dbnode_t **targetp);
114 isc_result_t (*expirenode)(dns_db_t *db, dns_dbnode_t *node,
116 void (*printnode)(dns_db_t *db, dns_dbnode_t *node,
118 isc_result_t (*createiterator)(dns_db_t *db, unsigned int options,
119 dns_dbiterator_t **iteratorp);
120 isc_result_t (*findrdataset)(dns_db_t *db, dns_dbnode_t *node,
121 dns_dbversion_t *version,
122 dns_rdatatype_t type,
123 dns_rdatatype_t covers,
125 dns_rdataset_t *rdataset,
126 dns_rdataset_t *sigrdataset);
127 isc_result_t (*allrdatasets)(dns_db_t *db, dns_dbnode_t *node,
128 dns_dbversion_t *version,
130 dns_rdatasetiter_t **iteratorp);
131 isc_result_t (*addrdataset)(dns_db_t *db, dns_dbnode_t *node,
132 dns_dbversion_t *version,
134 dns_rdataset_t *rdataset,
135 unsigned int options,
136 dns_rdataset_t *addedrdataset);
137 isc_result_t (*subtractrdataset)(dns_db_t *db, dns_dbnode_t *node,
138 dns_dbversion_t *version,
139 dns_rdataset_t *rdataset,
140 unsigned int options,
141 dns_rdataset_t *newrdataset);
142 isc_result_t (*deleterdataset)(dns_db_t *db, dns_dbnode_t *node,
143 dns_dbversion_t *version,
144 dns_rdatatype_t type,
145 dns_rdatatype_t covers);
146 isc_boolean_t (*issecure)(dns_db_t *db);
147 unsigned int (*nodecount)(dns_db_t *db);
148 isc_boolean_t (*ispersistent)(dns_db_t *db);
149 void (*overmem)(dns_db_t *db, isc_boolean_t overmem);
150 void (*settask)(dns_db_t *db, isc_task_t *);
151 isc_result_t (*getoriginnode)(dns_db_t *db, dns_dbnode_t **nodep);
152 void (*transfernode)(dns_db_t *db, dns_dbnode_t **sourcep,
153 dns_dbnode_t **targetp);
154 isc_result_t (*getnsec3parameters)(dns_db_t *db,
155 dns_dbversion_t *version,
158 isc_uint16_t *iterations,
161 isc_result_t (*findnsec3node)(dns_db_t *db, dns_name_t *name,
162 isc_boolean_t create,
163 dns_dbnode_t **nodep);
164 isc_result_t (*setsigningtime)(dns_db_t *db,
165 dns_rdataset_t *rdataset,
166 isc_stdtime_t resign);
167 isc_result_t (*getsigningtime)(dns_db_t *db,
168 dns_rdataset_t *rdataset,
170 void (*resigned)(dns_db_t *db, dns_rdataset_t *rdataset,
171 dns_dbversion_t *version);
172 isc_boolean_t (*isdnssec)(dns_db_t *db);
173 dns_stats_t *(*getrrsetstats)(dns_db_t *db);
174 void (*rpz_enabled)(dns_db_t *db, dns_rpz_st_t *st);
175 isc_result_t (*rpz_findips)(dns_rpz_zone_t *rpz,
176 dns_rpz_type_t rpz_type,
177 dns_zone_t *zone, dns_db_t *db,
178 dns_dbversion_t *version,
179 dns_rdataset_t *ardataset,
181 dns_name_t *query_qname);
185 (*dns_dbcreatefunc_t)(isc_mem_t *mctx, dns_name_t *name,
186 dns_dbtype_t type, dns_rdataclass_t rdclass,
187 unsigned int argc, char *argv[], void *driverarg,
190 #define DNS_DB_MAGIC ISC_MAGIC('D','N','S','D')
191 #define DNS_DB_VALID(db) ISC_MAGIC_VALID(db, DNS_DB_MAGIC)
194 * This structure is actually just the common prefix of a DNS db
195 * implementation's version of a dns_db_t.
197 * Direct use of this structure by clients is forbidden. DB implementations
198 * may change the structure. 'magic' must be DNS_DB_MAGIC for any of the
199 * dns_db_ routines to work. DB implementations must maintain all DB
204 unsigned int impmagic;
205 dns_dbmethods_t * methods;
206 isc_uint16_t attributes;
207 dns_rdataclass_t rdclass;
209 isc_ondestroy_t ondest;
213 #define DNS_DBATTR_CACHE 0x01
214 #define DNS_DBATTR_STUB 0x02
218 * Options that can be specified for dns_db_find().
220 #define DNS_DBFIND_GLUEOK 0x0001
221 #define DNS_DBFIND_VALIDATEGLUE 0x0002
222 #define DNS_DBFIND_NOWILD 0x0004
223 #define DNS_DBFIND_PENDINGOK 0x0008
224 #define DNS_DBFIND_NOEXACT 0x0010
225 #define DNS_DBFIND_FORCENSEC 0x0020
226 #define DNS_DBFIND_COVERINGNSEC 0x0040
227 #define DNS_DBFIND_FORCENSEC3 0x0080
228 #define DNS_DBFIND_ADDITIONALOK 0x0100
233 * Options that can be specified for dns_db_addrdataset().
235 #define DNS_DBADD_MERGE 0x01
236 #define DNS_DBADD_FORCE 0x02
237 #define DNS_DBADD_EXACT 0x04
238 #define DNS_DBADD_EXACTTTL 0x08
242 * Options that can be specified for dns_db_subtractrdataset().
244 #define DNS_DBSUB_EXACT 0x01
250 #define DNS_DB_RELATIVENAMES 0x1
251 #define DNS_DB_NSEC3ONLY 0x2
252 #define DNS_DB_NONSEC3 0x4
264 dns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin,
265 dns_dbtype_t type, dns_rdataclass_t rdclass,
266 unsigned int argc, char *argv[], dns_db_t **dbp);
268 * Create a new database using implementation 'db_type'.
271 * \li All names in the database must be subdomains of 'origin' and in class
272 * 'rdclass'. The database makes its own copy of the origin, so the
273 * caller may do whatever they like with 'origin' and its storage once the
276 * \li DB implementation-specific parameters are passed using argc and argv.
280 * \li dbp != NULL and *dbp == NULL
282 * \li 'origin' is a valid absolute domain name.
284 * \li mctx is a valid memory context
288 * \li A copy of 'origin' has been made for the databases use, and the
289 * caller is free to do whatever they want with the name and storage
290 * associated with 'origin'.
295 * \li #ISC_R_NOMEMORY
296 * \li #ISC_R_NOTFOUND db_type not found
298 * \li Many other errors are possible, depending on what db_type was
303 dns_db_attach(dns_db_t *source, dns_db_t **targetp);
305 * Attach *targetp to source.
309 * \li 'source' is a valid database.
311 * \li 'targetp' points to a NULL dns_db_t *.
315 * \li *targetp is attached to source.
319 dns_db_detach(dns_db_t **dbp);
321 * Detach *dbp from its database.
325 * \li 'dbp' points to a valid database.
331 * \li If '*dbp' is the last reference to the database,
332 * all resources used by the database will be freed
336 dns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp);
338 * Causes 'eventp' to be sent to be sent to 'task' when the database is
341 * Note; ownership of the eventp is taken from the caller (and *eventp is
342 * set to NULL). The sender field of the event is set to 'db' before it is
347 dns_db_iscache(dns_db_t *db);
349 * Does 'db' have cache semantics?
353 * \li 'db' is a valid database.
356 * \li #ISC_TRUE 'db' has cache semantics
357 * \li #ISC_FALSE otherwise
361 dns_db_iszone(dns_db_t *db);
363 * Does 'db' have zone semantics?
367 * \li 'db' is a valid database.
370 * \li #ISC_TRUE 'db' has zone semantics
371 * \li #ISC_FALSE otherwise
375 dns_db_isstub(dns_db_t *db);
377 * Does 'db' have stub semantics?
381 * \li 'db' is a valid database.
384 * \li #ISC_TRUE 'db' has zone semantics
385 * \li #ISC_FALSE otherwise
389 dns_db_issecure(dns_db_t *db);
395 * \li 'db' is a valid database with zone semantics.
398 * \li #ISC_TRUE 'db' is secure.
399 * \li #ISC_FALSE 'db' is not secure.
403 dns_db_isdnssec(dns_db_t *db);
405 * Is 'db' secure or partially secure?
409 * \li 'db' is a valid database with zone semantics.
412 * \li #ISC_TRUE 'db' is secure or is partially.
413 * \li #ISC_FALSE 'db' is not secure.
417 dns_db_origin(dns_db_t *db);
419 * The origin of the database.
421 * Note: caller must not try to change this name.
425 * \li 'db' is a valid database.
429 * \li The origin of the database.
433 dns_db_class(dns_db_t *db);
435 * The class of the database.
439 * \li 'db' is a valid database.
443 * \li The class of the database.
447 dns_db_beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp,
448 dns_dbload_t **dbloadp);
450 * Begin loading 'db'.
454 * \li 'db' is a valid database.
456 * \li This is the first attempt to load 'db'.
458 * \li addp != NULL && *addp == NULL
460 * \li dbloadp != NULL && *dbloadp == NULL
464 * \li On success, *addp will be a valid dns_addrdatasetfunc_t suitable
465 * for loading 'db'. *dbloadp will be a valid DB load context which
466 * should be used as 'arg' when *addp is called.
471 * \li #ISC_R_NOMEMORY
473 * \li Other results are possible, depending upon the database
474 * implementation used, syntax errors in the master file, etc.
478 dns_db_endload(dns_db_t *db, dns_dbload_t **dbloadp);
480 * Finish loading 'db'.
484 * \li 'db' is a valid database that is being loaded.
486 * \li dbloadp != NULL and *dbloadp is a valid database load context.
490 * \li *dbloadp == NULL
495 * \li #ISC_R_NOMEMORY
497 * \li Other results are possible, depending upon the database
498 * implementation used, syntax errors in the master file, etc.
502 dns_db_load(dns_db_t *db, const char *filename);
505 dns_db_load2(dns_db_t *db, const char *filename, dns_masterformat_t format);
508 dns_db_load3(dns_db_t *db, const char *filename, dns_masterformat_t format,
509 unsigned int options);
511 * Load master file 'filename' into 'db'.
514 * \li This routine is equivalent to calling
517 * dns_db_beginload();
518 * dns_master_loadfile();
524 * \li 'db' is a valid database.
526 * \li This is the first attempt to load 'db'.
531 * \li #ISC_R_NOMEMORY
533 * \li Other results are possible, depending upon the database
534 * implementation used, syntax errors in the master file, etc.
538 dns_db_dump(dns_db_t *db, dns_dbversion_t *version, const char *filename);
541 dns_db_dump2(dns_db_t *db, dns_dbversion_t *version, const char *filename,
542 dns_masterformat_t masterformat);
544 * Dump version 'version' of 'db' to master file 'filename'.
548 * \li 'db' is a valid database.
550 * \li 'version' is a valid version.
555 * \li #ISC_R_NOMEMORY
557 * \li Other results are possible, depending upon the database
558 * implementation used, OS file errors, etc.
566 dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp);
568 * Open the current version for reading.
572 * \li 'db' is a valid database with zone semantics.
574 * \li versionp != NULL && *verisonp == NULL
578 * \li On success, '*versionp' is attached to the current version.
583 dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp);
585 * Open a new version for reading and writing.
589 * \li 'db' is a valid database with zone semantics.
591 * \li versionp != NULL && *verisonp == NULL
595 * \li On success, '*versionp' is attached to the current version.
600 * \li #ISC_R_NOMEMORY
602 * \li Other results are possible, depending upon the database
603 * implementation used.
607 dns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
608 dns_dbversion_t **targetp);
610 * Attach '*targetp' to 'source'.
614 * \li 'db' is a valid database with zone semantics.
616 * \li source is a valid open version
618 * \li targetp != NULL && *targetp == NULL
622 * \li '*targetp' is attached to source.
626 dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
627 isc_boolean_t commit);
629 * Close version '*versionp'.
631 * Note: if '*versionp' is a read-write version and 'commit' is ISC_TRUE,
632 * then all changes made in the version will take effect, otherwise they
633 * will be rolled back. The value of 'commit' is ignored for read-only
638 * \li 'db' is a valid database with zone semantics.
640 * \li '*versionp' refers to a valid version.
642 * \li If committing a writable version, then there must be no other
643 * outstanding references to the version (e.g. an active rdataset
648 * \li *versionp == NULL
650 * \li If *versionp is a read-write version, and commit is ISC_TRUE, then
651 * the version will become the current version. If !commit, then all
652 * changes made in the version will be undone, and the version will
653 * not become the current version.
661 dns_db_findnode(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
662 dns_dbnode_t **nodep);
664 * Find the node with name 'name'.
667 * \li If 'create' is ISC_TRUE and no node with name 'name' exists, then
668 * such a node will be created.
670 * \li This routine is for finding or creating a node with the specified
671 * name. There are no partial matches. It is not suitable for use
672 * in building responses to ordinary DNS queries; clients which wish
673 * to do that should use dns_db_find() instead.
677 * \li 'db' is a valid database.
679 * \li 'name' is a valid, non-empty, absolute name.
681 * \li nodep != NULL && *nodep == NULL
685 * \li On success, *nodep is attached to the node with name 'name'.
690 * \li #ISC_R_NOTFOUND If !create and name not found.
691 * \li #ISC_R_NOMEMORY Can only happen if create is ISC_TRUE.
693 * \li Other results are possible, depending upon the database
694 * implementation used.
698 dns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
699 dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
700 dns_dbnode_t **nodep, dns_name_t *foundname,
701 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
703 * Find the best match for 'name' and 'type' in version 'version' of 'db'.
707 * \li If type == dns_rdataset_any, then rdataset will not be bound.
709 * \li If 'options' does not have #DNS_DBFIND_GLUEOK set, then no glue will
710 * be returned. For zone databases, glue is as defined in RFC2181.
711 * For cache databases, glue is any rdataset with a trust of
714 * \li If 'options' does not have #DNS_DBFIND_ADDITIONALOK set, then no
715 * additional records will be returned. Only caches can have
716 * rdataset with trust dns_trust_additional.
718 * \li If 'options' does not have #DNS_DBFIND_PENDINGOK set, then no
719 * pending data will be returned. This option is only meaningful for
722 * \li If the #DNS_DBFIND_NOWILD option is set, then wildcard matching will
723 * be disabled. This option is only meaningful for zone databases.
725 * \li If the #DNS_DBFIND_FORCENSEC option is set, the database is assumed to
726 * have NSEC records, and these will be returned when appropriate. This
727 * is only necessary when querying a database that was not secure
730 * \li If the DNS_DBFIND_COVERINGNSEC option is set, then look for a
731 * NSEC record that potentially covers 'name' if a answer cannot
732 * be found. Note the returned NSEC needs to be checked to ensure
733 * that it is correct. This only affects answers returned from the
736 * \li To respond to a query for SIG records, the caller should create a
737 * rdataset iterator and extract the signatures from each rdataset.
739 * \li Making queries of type ANY with #DNS_DBFIND_GLUEOK is not recommended,
740 * because the burden of determining whether a given rdataset is valid
741 * glue or not falls upon the caller.
743 * \li The 'now' field is ignored if 'db' is a zone database. If 'db' is a
744 * cache database, an rdataset will not be found unless it expires after
745 * 'now'. Any ANY query will not match unless at least one rdataset at
746 * the node expires after 'now'. If 'now' is zero, then the current time
751 * \li 'db' is a valid database.
753 * \li 'type' is not SIG, or a meta-RR type other than 'ANY' (e.g. 'OPT').
755 * \li 'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
757 * \li 'foundname' is a valid name with a dedicated buffer.
759 * \li 'rdataset' is NULL, or is a valid unassociated rdataset.
762 * on a non-error completion:
764 * \li If nodep != NULL, then it is bound to the found node.
766 * \li If foundname != NULL, then it contains the full name of the
769 * \li If rdataset != NULL and type != dns_rdatatype_any, then
770 * rdataset is bound to the found rdataset.
772 * Non-error results are:
774 * \li #ISC_R_SUCCESS The desired node and type were
777 * \li #DNS_R_WILDCARD The desired node and type were
778 * found after performing
779 * wildcard matching. This is
780 * only returned if the
781 * #DNS_DBFIND_INDICATEWILD
782 * option is set; otherwise
783 * #ISC_R_SUCCESS is returned.
785 * \li #DNS_R_GLUE The desired node and type were
786 * found, but are glue. This
787 * result can only occur if
788 * the DNS_DBFIND_GLUEOK option
789 * is set. This result can only
790 * occur if 'db' is a zone
791 * database. If type ==
792 * dns_rdatatype_any, then the
793 * node returned may contain, or
794 * consist entirely of invalid
795 * glue (i.e. data occluded by a
796 * zone cut). The caller must
797 * take care not to return invalid
800 * \li #DNS_R_DELEGATION The data requested is beneath
801 * a zone cut. node, foundname,
802 * and rdataset reference the
803 * NS RRset of the zone cut.
804 * If 'db' is a cache database,
805 * then this is the deepest known
808 * \li #DNS_R_ZONECUT type == dns_rdatatype_any, and
809 * the desired node is a zonecut.
810 * The caller must take care not
811 * to return inappropriate glue
812 * to a client. This result can
813 * only occur if 'db' is a zone
814 * database and DNS_DBFIND_GLUEOK
817 * \li #DNS_R_DNAME The data requested is beneath
818 * a DNAME. node, foundname,
819 * and rdataset reference the
822 * \li #DNS_R_CNAME The rdataset requested was not
823 * found, but there is a CNAME
824 * at the desired name. node,
825 * foundname, and rdataset
826 * reference the CNAME RRset.
828 * \li #DNS_R_NXDOMAIN The desired name does not
831 * \li #DNS_R_NXRRSET The desired name exists, but
832 * the desired type does not.
834 * \li #ISC_R_NOTFOUND The desired name does not
835 * exist, and no delegation could
836 * be found. This result can only
837 * occur if 'db' is a cache
838 * database. The caller should
839 * use its nameserver(s) of last
840 * resort (e.g. root hints).
842 * \li #DNS_R_NCACHENXDOMAIN The desired name does not
843 * exist. 'node' is bound to the
844 * cache node with the desired
845 * name, and 'rdataset' contains
846 * the negative caching proof.
848 * \li #DNS_R_NCACHENXRRSET The desired type does not
849 * exist. 'node' is bound to the
850 * cache node with the desired
851 * name, and 'rdataset' contains
852 * the negative caching proof.
854 * \li #DNS_R_EMPTYNAME The name exists but there is
855 * no data at the name.
857 * \li #DNS_R_COVERINGNSEC The returned data is a NSEC
858 * that potentially covers 'name'.
860 * \li #DNS_R_EMPTYWILD The name is a wildcard without
865 * \li #ISC_R_NOMEMORY
867 * \li #DNS_R_BADDB Data that is required to be
868 * present in the DB, e.g. an NSEC
869 * record in a secure zone, is not
872 * \li Other results are possible, and should all be treated as
877 dns_db_findzonecut(dns_db_t *db, dns_name_t *name,
878 unsigned int options, isc_stdtime_t now,
879 dns_dbnode_t **nodep, dns_name_t *foundname,
880 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
882 * Find the deepest known zonecut which encloses 'name' in 'db'.
886 * \li If the #DNS_DBFIND_NOEXACT option is set, then the zonecut returned
887 * (if any) will be the deepest known ancestor of 'name'.
889 * \li If 'now' is zero, then the current time will be used.
893 * \li 'db' is a valid database with cache semantics.
895 * \li 'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
897 * \li 'foundname' is a valid name with a dedicated buffer.
899 * \li 'rdataset' is NULL, or is a valid unassociated rdataset.
901 * Ensures, on a non-error completion:
903 * \li If nodep != NULL, then it is bound to the found node.
905 * \li If foundname != NULL, then it contains the full name of the
908 * \li If rdataset != NULL and type != dns_rdatatype_any, then
909 * rdataset is bound to the found rdataset.
911 * Non-error results are:
915 * \li #ISC_R_NOTFOUND
917 * \li Other results are possible, and should all be treated as
922 dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp);
924 * Attach *targetp to source.
928 * \li 'db' is a valid database.
930 * \li 'source' is a valid node.
932 * \li 'targetp' points to a NULL dns_dbnode_t *.
936 * \li *targetp is attached to source.
940 dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep);
942 * Detach *nodep from its node.
946 * \li 'db' is a valid database.
948 * \li 'nodep' points to a valid node.
952 * \li *nodep is NULL.
956 dns_db_transfernode(dns_db_t *db, dns_dbnode_t **sourcep,
957 dns_dbnode_t **targetp);
959 * Transfer a node between pointer.
961 * This is equivalent to calling dns_db_attachnode() then dns_db_detachnode().
965 * \li 'db' is a valid database.
967 * \li '*sourcep' is a valid node.
969 * \li 'targetp' points to a NULL dns_dbnode_t *.
973 * \li '*sourcep' is NULL.
977 dns_db_expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now);
979 * Mark as stale all records at 'node' which expire at or before 'now'.
981 * Note: if 'now' is zero, then the current time will be used.
985 * \li 'db' is a valid cache database.
987 * \li 'node' is a valid node.
991 dns_db_printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out);
993 * Print a textual representation of the contents of the node to
996 * Note: this function is intended for debugging, not general use.
1000 * \li 'db' is a valid database.
1002 * \li 'node' is a valid node.
1006 *** DB Iterator Creation
1010 dns_db_createiterator(dns_db_t *db, unsigned int options,
1011 dns_dbiterator_t **iteratorp);
1013 * Create an iterator for version 'version' of 'db'.
1017 * \li One or more of the following options can be set.
1018 * #DNS_DB_RELATIVENAMES
1024 * \li 'db' is a valid database.
1026 * \li iteratorp != NULL && *iteratorp == NULL
1030 * \li On success, *iteratorp will be a valid database iterator.
1034 * \li #ISC_R_SUCCESS
1035 * \li #ISC_R_NOMEMORY
1039 *** Rdataset Methods
1043 * XXXRTH Should we check for glue and pending data in dns_db_findrdataset()?
1047 dns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
1048 dns_rdatatype_t type, dns_rdatatype_t covers,
1049 isc_stdtime_t now, dns_rdataset_t *rdataset,
1050 dns_rdataset_t *sigrdataset);
1052 * Search for an rdataset of type 'type' at 'node' that are in version
1053 * 'version' of 'db'. If found, make 'rdataset' refer to it.
1057 * \li If 'version' is NULL, then the current version will be used.
1059 * \li Care must be used when using this routine to build a DNS response:
1060 * 'node' should have been found with dns_db_find(), not
1061 * dns_db_findnode(). No glue checking is done. No checking for
1062 * pending data is done.
1064 * \li The 'now' field is ignored if 'db' is a zone database. If 'db' is a
1065 * cache database, an rdataset will not be found unless it expires after
1066 * 'now'. If 'now' is zero, then the current time will be used.
1070 * \li 'db' is a valid database.
1072 * \li 'node' is a valid node.
1074 * \li 'rdataset' is a valid, disassociated rdataset.
1076 * \li 'sigrdataset' is a valid, disassociated rdataset, or it is NULL.
1078 * \li If 'covers' != 0, 'type' must be SIG.
1080 * \li 'type' is not a meta-RR type such as 'ANY' or 'OPT'.
1084 * \li On success, 'rdataset' is associated with the found rdataset.
1088 * \li #ISC_R_SUCCESS
1089 * \li #ISC_R_NOTFOUND
1091 * \li Other results are possible, depending upon the database
1092 * implementation used.
1096 dns_db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
1097 isc_stdtime_t now, dns_rdatasetiter_t **iteratorp);
1099 * Make '*iteratorp' an rdataset iterator for all rdatasets at 'node' in
1100 * version 'version' of 'db'.
1104 * \li If 'version' is NULL, then the current version will be used.
1106 * \li The 'now' field is ignored if 'db' is a zone database. If 'db' is a
1107 * cache database, an rdataset will not be found unless it expires after
1108 * 'now'. Any ANY query will not match unless at least one rdataset at
1109 * the node expires after 'now'. If 'now' is zero, then the current time
1114 * \li 'db' is a valid database.
1116 * \li 'node' is a valid node.
1118 * \li iteratorp != NULL && *iteratorp == NULL
1122 * \li On success, '*iteratorp' is a valid rdataset iterator.
1126 * \li #ISC_R_SUCCESS
1127 * \li #ISC_R_NOTFOUND
1129 * \li Other results are possible, depending upon the database
1130 * implementation used.
1134 dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
1135 isc_stdtime_t now, dns_rdataset_t *rdataset,
1136 unsigned int options, dns_rdataset_t *addedrdataset);
1138 * Add 'rdataset' to 'node' in version 'version' of 'db'.
1142 * \li If the database has zone semantics, the #DNS_DBADD_MERGE option is set,
1143 * and an rdataset of the same type as 'rdataset' already exists at
1144 * 'node' then the contents of 'rdataset' will be merged with the existing
1145 * rdataset. If the option is not set, then rdataset will replace any
1146 * existing rdataset of the same type. If not merging and the
1147 * #DNS_DBADD_FORCE option is set, then the data will update the database
1148 * without regard to trust levels. If not forcing the data, then the
1149 * rdataset will only be added if its trust level is >= the trust level of
1150 * any existing rdataset. Forcing is only meaningful for cache databases.
1151 * If #DNS_DBADD_EXACT is set then there must be no rdata in common between
1152 * the old and new rdata sets. If #DNS_DBADD_EXACTTTL is set then both
1153 * the old and new rdata sets must have the same ttl.
1155 * \li The 'now' field is ignored if 'db' is a zone database. If 'db' is
1156 * a cache database, then the added rdataset will expire no later than
1157 * now + rdataset->ttl.
1159 * \li If 'addedrdataset' is not NULL, then it will be attached to the
1160 * resulting new rdataset in the database, or to the existing data if
1161 * the existing data was better.
1165 * \li 'db' is a valid database.
1167 * \li 'node' is a valid node.
1169 * \li 'rdataset' is a valid, associated rdataset with the same class
1172 * \li 'addedrdataset' is NULL, or a valid, unassociated rdataset.
1174 * \li The database has zone semantics and 'version' is a valid
1175 * read-write version, or the database has cache semantics
1176 * and version is NULL.
1178 * \li If the database has cache semantics, the #DNS_DBADD_MERGE option must
1183 * \li #ISC_R_SUCCESS
1184 * \li #DNS_R_UNCHANGED The operation did not change anything.
1185 * \li #ISC_R_NOMEMORY
1186 * \li #DNS_R_NOTEXACT
1188 * \li Other results are possible, depending upon the database
1189 * implementation used.
1193 dns_db_subtractrdataset(dns_db_t *db, dns_dbnode_t *node,
1194 dns_dbversion_t *version, dns_rdataset_t *rdataset,
1195 unsigned int options, dns_rdataset_t *newrdataset);
1197 * Remove any rdata in 'rdataset' from 'node' in version 'version' of
1202 * \li If 'newrdataset' is not NULL, then it will be attached to the
1203 * resulting new rdataset in the database, unless the rdataset has
1204 * become nonexistent. If DNS_DBSUB_EXACT is set then all elements
1205 * of 'rdataset' must exist at 'node'.
1209 * \li 'db' is a valid database.
1211 * \li 'node' is a valid node.
1213 * \li 'rdataset' is a valid, associated rdataset with the same class
1216 * \li 'newrdataset' is NULL, or a valid, unassociated rdataset.
1218 * \li The database has zone semantics and 'version' is a valid
1219 * read-write version.
1223 * \li #ISC_R_SUCCESS
1224 * \li #DNS_R_UNCHANGED The operation did not change anything.
1225 * \li #DNS_R_NXRRSET All rdata of the same type as those
1226 * in 'rdataset' have been deleted.
1227 * \li #DNS_R_NOTEXACT Some part of 'rdataset' did not
1228 * exist and DNS_DBSUB_EXACT was set.
1230 * \li Other results are possible, depending upon the database
1231 * implementation used.
1235 dns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
1236 dns_dbversion_t *version, dns_rdatatype_t type,
1237 dns_rdatatype_t covers);
1239 * Make it so that no rdataset of type 'type' exists at 'node' in version
1240 * version 'version' of 'db'.
1244 * \li If 'type' is dns_rdatatype_any, then no rdatasets will exist in
1245 * 'version' (provided that the dns_db_deleterdataset() isn't followed
1246 * by one or more dns_db_addrdataset() calls).
1250 * \li 'db' is a valid database.
1252 * \li 'node' is a valid node.
1254 * \li The database has zone semantics and 'version' is a valid
1255 * read-write version, or the database has cache semantics
1256 * and version is NULL.
1258 * \li 'type' is not a meta-RR type, except for dns_rdatatype_any, which is
1261 * \li If 'covers' != 0, 'type' must be SIG.
1265 * \li #ISC_R_SUCCESS
1266 * \li #DNS_R_UNCHANGED No rdatasets of 'type' existed before
1267 * the operation was attempted.
1269 * \li Other results are possible, depending upon the database
1270 * implementation used.
1274 dns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, isc_uint32_t *serialp);
1276 * Get the current SOA serial number from a zone database.
1279 * \li 'db' is a valid database with zone semantics.
1280 * \li 'ver' is a valid version.
1284 dns_db_overmem(dns_db_t *db, isc_boolean_t overmem);
1286 * Enable / disable aggressive cache cleaning.
1290 dns_db_nodecount(dns_db_t *db);
1292 * Count the number of nodes in 'db'.
1296 * \li 'db' is a valid database.
1299 * \li The number of nodes in the database
1303 dns_db_settask(dns_db_t *db, isc_task_t *task);
1305 * If task is set then the final detach maybe performed asynchronously.
1308 * \li 'db' is a valid database.
1309 * \li 'task' to be valid or NULL.
1313 dns_db_ispersistent(dns_db_t *db);
1315 * Is 'db' persistent? A persistent database does not need to be loaded
1316 * from disk or written to disk.
1320 * \li 'db' is a valid database.
1323 * \li #ISC_TRUE 'db' is persistent.
1324 * \li #ISC_FALSE 'db' is not persistent.
1328 dns_db_register(const char *name, dns_dbcreatefunc_t create, void *driverarg,
1329 isc_mem_t *mctx, dns_dbimplementation_t **dbimp);
1332 * Register a new database implementation and add it to the list of
1333 * supported implementations.
1337 * \li 'name' is not NULL
1338 * \li 'order' is a valid function pointer
1339 * \li 'mctx' is a valid memory context
1340 * \li dbimp != NULL && *dbimp == NULL
1343 * \li #ISC_R_SUCCESS The registration succeeded
1344 * \li #ISC_R_NOMEMORY Out of memory
1345 * \li #ISC_R_EXISTS A database implementation with the same name exists
1349 * \li *dbimp points to an opaque structure which must be passed to
1350 * dns_db_unregister().
1354 dns_db_unregister(dns_dbimplementation_t **dbimp);
1356 * Remove a database implementation from the list of supported
1357 * implementations. No databases of this type can be active when this
1361 * \li dbimp != NULL && *dbimp == NULL
1365 * \li Any memory allocated in *dbimp will be freed.
1369 dns_db_getoriginnode(dns_db_t *db, dns_dbnode_t **nodep);
1371 * Get the origin DB node corresponding to the DB's zone. This function
1372 * should typically succeed unless the underlying DB implementation doesn't
1373 * support the feature.
1377 * \li 'db' is a valid zone database.
1378 * \li 'nodep' != NULL && '*nodep' == NULL
1381 * \li On success, '*nodep' will point to the DB node of the zone's origin.
1384 * \li #ISC_R_SUCCESS
1385 * \li #ISC_R_NOTFOUND - the DB implementation does not support this feature.
1389 dns_db_getnsec3parameters(dns_db_t *db, dns_dbversion_t *version,
1390 dns_hash_t *hash, isc_uint8_t *flags,
1391 isc_uint16_t *interations,
1392 unsigned char *salt, size_t *salt_length);
1394 * Get the NSEC3 parameters that are associated with this zone.
1397 * \li 'db' is a valid zone database.
1400 * \li #ISC_R_SUCCESS
1401 * \li #ISC_R_NOTFOUND - the DB implementation does not support this feature
1402 * or this zone does not have NSEC3 records.
1406 dns_db_findnsec3node(dns_db_t *db, dns_name_t *name,
1407 isc_boolean_t create, dns_dbnode_t **nodep);
1409 * Find the NSEC3 node with name 'name'.
1412 * \li If 'create' is ISC_TRUE and no node with name 'name' exists, then
1413 * such a node will be created.
1417 * \li 'db' is a valid database.
1419 * \li 'name' is a valid, non-empty, absolute name.
1421 * \li nodep != NULL && *nodep == NULL
1425 * \li On success, *nodep is attached to the node with name 'name'.
1429 * \li #ISC_R_SUCCESS
1430 * \li #ISC_R_NOTFOUND If !create and name not found.
1431 * \li #ISC_R_NOMEMORY Can only happen if create is ISC_TRUE.
1433 * \li Other results are possible, depending upon the database
1434 * implementation used.
1438 dns_db_setsigningtime(dns_db_t *db, dns_rdataset_t *rdataset,
1439 isc_stdtime_t resign);
1441 * Sets the re-signing time associated with 'rdataset' to 'resign'.
1444 * \li 'db' is a valid zone database.
1445 * \li 'rdataset' is or is to be associated with 'db'.
1446 * \li 'rdataset' is not pending removed from the heap via an
1447 * uncommitted call to dns_db_resigned().
1450 * \li #ISC_R_SUCCESS
1451 * \li #ISC_R_NOMEMORY
1452 * \li #ISC_R_NOTIMPLEMENTED - Not supported by this DB implementation.
1456 dns_db_getsigningtime(dns_db_t *db, dns_rdataset_t *rdataset, dns_name_t *name);
1458 * Return the rdataset with the earliest signing time in the zone.
1459 * Note: the rdataset is version agnostic.
1462 * \li 'db' is a valid zone database.
1463 * \li 'rdataset' to be initialized but not associated.
1464 * \li 'name' to be NULL or have a buffer associated with it.
1467 * \li #ISC_R_SUCCESS
1468 * \li #ISC_R_NOTFOUND - No dataset exists.
1472 dns_db_resigned(dns_db_t *db, dns_rdataset_t *rdataset,
1473 dns_dbversion_t *version);
1475 * Mark 'rdataset' as not being available to be returned by
1476 * dns_db_getsigningtime(). If the changes associated with 'version'
1477 * are committed this will be permanent. If the version is not committed
1478 * this change will be rolled back when the version is closed. Until
1479 * 'version' is either committed or rolled back, 'rdataset' can no longer
1480 * be acted upon by dns_db_setsigningtime().
1483 * \li 'db' is a valid zone database.
1484 * \li 'rdataset' to be associated with 'db'.
1485 * \li 'version' to be open for writing.
1489 dns_db_getrrsetstats(dns_db_t *db);
1491 * Get statistics information counting RRsets stored in the DB, when available.
1492 * The statistics may not be available depending on the DB implementation.
1496 * \li 'db' is a valid database (zone or cache).
1499 * \li when available, a pointer to a statistics object created by
1500 * dns_rdatasetstats_create(); otherwise NULL.
1504 dns_db_rpz_enabled(dns_db_t *db, dns_rpz_st_t *st);
1506 * See if a policy database has DNS_RPZ_TYPE_IP, DNS_RPZ_TYPE_NSIP, or
1507 * DNS_RPZ_TYPE_NSDNAME records.
1511 dns_db_rpz_findips(dns_rpz_zone_t *rpz, dns_rpz_type_t rpz_type,
1512 dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *version,
1513 dns_rdataset_t *ardataset, dns_rpz_st_t *st,
1514 dns_name_t *query_qname);
1516 * Search the CDIR block tree of a response policy tree of trees for the best
1517 * match to any of the IP addresses in an A or AAAA rdataset.
1520 * \li search in policy zone 'rpz' for a match of 'rpz_type' either
1521 * DNS_RPZ_TYPE_IP or DNS_RPZ_TYPE_NSIP
1522 * \li 'zone' and 'db' are the database corresponding to 'rpz'
1523 * \li 'version' is the required version of the database
1524 * \li 'ardataset' is an A or AAAA rdataset of addresses to check
1525 * \li 'found' specifies the previous best match if any or
1526 * or NULL, an empty name, 0, DNS_RPZ_POLICY_MISS, and 0
1529 * \li #ISC_R_SUCCESS
1530 * \li #ISC_R_UNEXPECTED
1535 #endif /* DNS_DB_H */