]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - contrib/bind9/lib/dns/include/dns/db.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / contrib / bind9 / lib / dns / include / dns / db.h
1 /*
2  * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2003  Internet Software Consortium.
4  *
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.
8  *
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.
16  */
17
18 /* $Id: db.h,v 1.76.18.10 2007/08/28 07:20:05 tbox Exp $ */
19
20 #ifndef DNS_DB_H
21 #define DNS_DB_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*! \file
28  * \brief
29  * The DNS DB interface allows named rdatasets to be stored and retrieved.
30  *
31  * The dns_db_t type is like a "virtual class".  To actually use
32  * DBs, an implementation of the class is required.
33  *
34  * XXX more XXX
35  *
36  * MP:
37  * \li  The module ensures appropriate synchronization of data structures it
38  *      creates and manipulates.
39  *
40  * Reliability:
41  * \li  No anticipated impact.
42  *
43  * Resources:
44  * \li  TBS
45  *
46  * Security:
47  * \li  No anticipated impact.
48  *
49  * Standards:
50  * \li  None.
51  */
52
53 /*****
54  ***** Imports
55  *****/
56
57 #include <isc/lang.h>
58 #include <isc/magic.h>
59 #include <isc/ondestroy.h>
60 #include <isc/stdtime.h>
61
62 #include <dns/name.h>
63 #include <dns/types.h>
64
65 ISC_LANG_BEGINDECLS
66
67 /*****
68  ***** Types
69  *****/
70
71 typedef struct dns_dbmethods {
72         void            (*attach)(dns_db_t *source, dns_db_t **targetp);
73         void            (*detach)(dns_db_t **dbp);
74         isc_result_t    (*beginload)(dns_db_t *db, dns_addrdatasetfunc_t *addp,
75                                      dns_dbload_t **dbloadp);
76         isc_result_t    (*endload)(dns_db_t *db, dns_dbload_t **dbloadp);
77         isc_result_t    (*dump)(dns_db_t *db, dns_dbversion_t *version,
78                                 const char *filename,
79                                 dns_masterformat_t masterformat);
80         void            (*currentversion)(dns_db_t *db,
81                                           dns_dbversion_t **versionp);
82         isc_result_t    (*newversion)(dns_db_t *db,
83                                       dns_dbversion_t **versionp);
84         void            (*attachversion)(dns_db_t *db, dns_dbversion_t *source,
85                                          dns_dbversion_t **targetp);
86         void            (*closeversion)(dns_db_t *db,
87                                         dns_dbversion_t **versionp,
88                                         isc_boolean_t commit);
89         isc_result_t    (*findnode)(dns_db_t *db, dns_name_t *name,
90                                     isc_boolean_t create,
91                                     dns_dbnode_t **nodep);
92         isc_result_t    (*find)(dns_db_t *db, dns_name_t *name,
93                                 dns_dbversion_t *version,
94                                 dns_rdatatype_t type, unsigned int options,
95                                 isc_stdtime_t now,
96                                 dns_dbnode_t **nodep, dns_name_t *foundname,
97                                 dns_rdataset_t *rdataset,
98                                 dns_rdataset_t *sigrdataset);
99         isc_result_t    (*findzonecut)(dns_db_t *db, dns_name_t *name,
100                                        unsigned int options, isc_stdtime_t now,
101                                        dns_dbnode_t **nodep,
102                                        dns_name_t *foundname,
103                                        dns_rdataset_t *rdataset,
104                                        dns_rdataset_t *sigrdataset);
105         void            (*attachnode)(dns_db_t *db,
106                                       dns_dbnode_t *source,
107                                       dns_dbnode_t **targetp);
108         void            (*detachnode)(dns_db_t *db,
109                                       dns_dbnode_t **targetp);
110         isc_result_t    (*expirenode)(dns_db_t *db, dns_dbnode_t *node,
111                                       isc_stdtime_t now);
112         void            (*printnode)(dns_db_t *db, dns_dbnode_t *node,
113                                      FILE *out);
114         isc_result_t    (*createiterator)(dns_db_t *db,
115                                           isc_boolean_t relative_names,
116                                           dns_dbiterator_t **iteratorp);
117         isc_result_t    (*findrdataset)(dns_db_t *db, dns_dbnode_t *node,
118                                         dns_dbversion_t *version,
119                                         dns_rdatatype_t type,
120                                         dns_rdatatype_t covers,
121                                         isc_stdtime_t now,
122                                         dns_rdataset_t *rdataset,
123                                         dns_rdataset_t *sigrdataset);
124         isc_result_t    (*allrdatasets)(dns_db_t *db, dns_dbnode_t *node,
125                                         dns_dbversion_t *version,
126                                         isc_stdtime_t now,
127                                         dns_rdatasetiter_t **iteratorp);
128         isc_result_t    (*addrdataset)(dns_db_t *db, dns_dbnode_t *node,
129                                        dns_dbversion_t *version,
130                                        isc_stdtime_t now,
131                                        dns_rdataset_t *rdataset,
132                                        unsigned int options,
133                                        dns_rdataset_t *addedrdataset);
134         isc_result_t    (*subtractrdataset)(dns_db_t *db, dns_dbnode_t *node,
135                                             dns_dbversion_t *version,
136                                             dns_rdataset_t *rdataset,
137                                             unsigned int options,
138                                             dns_rdataset_t *newrdataset);
139         isc_result_t    (*deleterdataset)(dns_db_t *db, dns_dbnode_t *node,
140                                           dns_dbversion_t *version,
141                                           dns_rdatatype_t type,
142                                           dns_rdatatype_t covers);
143         isc_boolean_t   (*issecure)(dns_db_t *db);
144         unsigned int    (*nodecount)(dns_db_t *db);
145         isc_boolean_t   (*ispersistent)(dns_db_t *db);
146         void            (*overmem)(dns_db_t *db, isc_boolean_t overmem);
147         void            (*settask)(dns_db_t *db, isc_task_t *);
148         isc_result_t    (*getoriginnode)(dns_db_t *db, dns_dbnode_t **nodep);
149 } dns_dbmethods_t;
150
151 typedef isc_result_t
152 (*dns_dbcreatefunc_t)(isc_mem_t *mctx, dns_name_t *name,
153                       dns_dbtype_t type, dns_rdataclass_t rdclass,
154                       unsigned int argc, char *argv[], void *driverarg,
155                       dns_db_t **dbp);
156                                         
157 #define DNS_DB_MAGIC            ISC_MAGIC('D','N','S','D')
158 #define DNS_DB_VALID(db)        ISC_MAGIC_VALID(db, DNS_DB_MAGIC)
159
160 /*%
161  * This structure is actually just the common prefix of a DNS db
162  * implementation's version of a dns_db_t.
163  * \brief
164  * Direct use of this structure by clients is forbidden.  DB implementations
165  * may change the structure.  'magic' must be DNS_DB_MAGIC for any of the
166  * dns_db_ routines to work.  DB implementations must maintain all DB
167  * invariants.
168  */
169 struct dns_db {
170         unsigned int                    magic;
171         unsigned int                    impmagic;
172         dns_dbmethods_t *               methods;
173         isc_uint16_t                    attributes;
174         dns_rdataclass_t                rdclass;
175         dns_name_t                      origin;
176         isc_ondestroy_t                 ondest;
177         isc_mem_t *                     mctx;
178 };
179
180 #define DNS_DBATTR_CACHE                0x01
181 #define DNS_DBATTR_STUB                 0x02
182
183 /*@{*/
184 /*%
185  * Options that can be specified for dns_db_find().
186  */
187 #define DNS_DBFIND_GLUEOK               0x01
188 #define DNS_DBFIND_VALIDATEGLUE         0x02
189 #define DNS_DBFIND_NOWILD               0x04
190 #define DNS_DBFIND_PENDINGOK            0x08
191 #define DNS_DBFIND_NOEXACT              0x10
192 #define DNS_DBFIND_FORCENSEC            0x20
193 #define DNS_DBFIND_COVERINGNSEC         0x40
194 /*@}*/
195
196 /*@{*/
197 /*%
198  * Options that can be specified for dns_db_addrdataset().
199  */
200 #define DNS_DBADD_MERGE                 0x01
201 #define DNS_DBADD_FORCE                 0x02
202 #define DNS_DBADD_EXACT                 0x04
203 #define DNS_DBADD_EXACTTTL              0x08
204 /*@}*/
205
206 /*%
207  * Options that can be specified for dns_db_subtractrdataset().
208  */
209 #define DNS_DBSUB_EXACT                 0x01
210
211 /*****
212  ***** Methods
213  *****/
214
215 /***
216  *** Basic DB Methods
217  ***/
218
219 isc_result_t
220 dns_db_create(isc_mem_t *mctx, const char *db_type, dns_name_t *origin,
221               dns_dbtype_t type, dns_rdataclass_t rdclass,
222               unsigned int argc, char *argv[], dns_db_t **dbp);
223 /*%<
224  * Create a new database using implementation 'db_type'.
225  *
226  * Notes:
227  * \li  All names in the database must be subdomains of 'origin' and in class
228  *      'rdclass'.  The database makes its own copy of the origin, so the
229  *      caller may do whatever they like with 'origin' and its storage once the
230  *      call returns.
231  *
232  * \li  DB implementation-specific parameters are passed using argc and argv.
233  *
234  * Requires:
235  *
236  * \li  dbp != NULL and *dbp == NULL
237  *
238  * \li  'origin' is a valid absolute domain name.
239  *
240  * \li  mctx is a valid memory context
241  *
242  * Ensures:
243  *
244  * \li  A copy of 'origin' has been made for the databases use, and the
245  *      caller is free to do whatever they want with the name and storage
246  *      associated with 'origin'.
247  *
248  * Returns:
249  *
250  * \li  #ISC_R_SUCCESS
251  * \li  #ISC_R_NOMEMORY
252  * \li  #ISC_R_NOTFOUND                         db_type not found
253  *
254  * \li  Many other errors are possible, depending on what db_type was
255  *      specified.
256  */
257
258 void
259 dns_db_attach(dns_db_t *source, dns_db_t **targetp);
260 /*%<
261  * Attach *targetp to source.
262  *
263  * Requires:
264  *
265  * \li  'source' is a valid database.
266  *
267  * \li  'targetp' points to a NULL dns_db_t *.
268  *
269  * Ensures:
270  *
271  * \li  *targetp is attached to source.
272  */
273
274 void
275 dns_db_detach(dns_db_t **dbp);
276 /*%<
277  * Detach *dbp from its database.
278  *
279  * Requires:
280  *
281  * \li  'dbp' points to a valid database.
282  *
283  * Ensures:
284  *
285  * \li  *dbp is NULL.
286  *
287  * \li  If '*dbp' is the last reference to the database,
288  *              all resources used by the database will be freed
289  */
290
291 isc_result_t
292 dns_db_ondestroy(dns_db_t *db, isc_task_t *task, isc_event_t **eventp);
293 /*%<
294  * Causes 'eventp' to be sent to be sent to 'task' when the database is
295  * destroyed.
296  *
297  * Note; ownership of the eventp is taken from the caller (and *eventp is
298  * set to NULL). The sender field of the event is set to 'db' before it is
299  * sent to the task.
300  */
301
302 isc_boolean_t
303 dns_db_iscache(dns_db_t *db);
304 /*%<
305  * Does 'db' have cache semantics?
306  *
307  * Requires:
308  *
309  * \li  'db' is a valid database.
310  *
311  * Returns:
312  * \li  #ISC_TRUE       'db' has cache semantics
313  * \li  #ISC_FALSE      otherwise
314  */
315
316 isc_boolean_t
317 dns_db_iszone(dns_db_t *db);
318 /*%<
319  * Does 'db' have zone semantics?
320  *
321  * Requires:
322  *
323  * \li  'db' is a valid database.
324  *
325  * Returns:
326  * \li  #ISC_TRUE       'db' has zone semantics
327  * \li  #ISC_FALSE      otherwise
328  */
329
330 isc_boolean_t
331 dns_db_isstub(dns_db_t *db);
332 /*%<
333  * Does 'db' have stub semantics?
334  *
335  * Requires:
336  *
337  * \li  'db' is a valid database.
338  *
339  * Returns:
340  * \li  #ISC_TRUE       'db' has zone semantics
341  * \li  #ISC_FALSE      otherwise
342  */
343
344 isc_boolean_t
345 dns_db_issecure(dns_db_t *db);
346 /*%<
347  * Is 'db' secure?
348  *
349  * Requires:
350  *
351  * \li  'db' is a valid database with zone semantics.
352  *
353  * Returns:
354  * \li  #ISC_TRUE       'db' is secure.
355  * \li  #ISC_FALSE      'db' is not secure.
356  */
357
358 dns_name_t *
359 dns_db_origin(dns_db_t *db);
360 /*%<
361  * The origin of the database.
362  *
363  * Note: caller must not try to change this name.
364  *
365  * Requires:
366  *
367  * \li  'db' is a valid database.
368  *
369  * Returns:
370  *
371  * \li  The origin of the database.
372  */
373
374 dns_rdataclass_t
375 dns_db_class(dns_db_t *db);
376 /*%<
377  * The class of the database.
378  *
379  * Requires:
380  *
381  * \li  'db' is a valid database.
382  *
383  * Returns:
384  *
385  * \li  The class of the database.
386  */
387
388 isc_result_t
389 dns_db_beginload(dns_db_t *db, dns_addrdatasetfunc_t *addp,
390                  dns_dbload_t **dbloadp);
391 /*%<
392  * Begin loading 'db'.
393  *
394  * Requires:
395  *
396  * \li  'db' is a valid database.
397  *
398  * \li  This is the first attempt to load 'db'.
399  *
400  * \li  addp != NULL && *addp == NULL
401  *
402  * \li  dbloadp != NULL && *dbloadp == NULL
403  *
404  * Ensures:
405  *
406  * \li  On success, *addp will be a valid dns_addrdatasetfunc_t suitable
407  *      for loading 'db'.  *dbloadp will be a valid DB load context which
408  *      should be used as 'arg' when *addp is called.
409  *
410  * Returns:
411  *
412  * \li  #ISC_R_SUCCESS
413  * \li  #ISC_R_NOMEMORY
414  *
415  * \li  Other results are possible, depending upon the database
416  *      implementation used, syntax errors in the master file, etc.
417  */
418
419 isc_result_t
420 dns_db_endload(dns_db_t *db, dns_dbload_t **dbloadp);
421 /*%<
422  * Finish loading 'db'.
423  *
424  * Requires:
425  *
426  * \li  'db' is a valid database that is being loaded.
427  *
428  * \li  dbloadp != NULL and *dbloadp is a valid database load context.
429  *
430  * Ensures:
431  *
432  * \li  *dbloadp == NULL
433  *
434  * Returns:
435  *
436  * \li  #ISC_R_SUCCESS
437  * \li  #ISC_R_NOMEMORY
438  *
439  * \li  Other results are possible, depending upon the database
440  *      implementation used, syntax errors in the master file, etc.
441  */
442
443 isc_result_t
444 dns_db_load(dns_db_t *db, const char *filename);
445
446 isc_result_t
447 dns_db_load2(dns_db_t *db, const char *filename, dns_masterformat_t format);
448 /*%<
449  * Load master file 'filename' into 'db'.
450  *
451  * Notes:
452  * \li  This routine is equivalent to calling
453  *
454  *\code
455  *              dns_db_beginload();
456  *              dns_master_loadfile();
457  *              dns_db_endload();
458  *\endcode
459  *
460  * Requires:
461  *
462  * \li  'db' is a valid database.
463  *
464  * \li  This is the first attempt to load 'db'.
465  *
466  * Returns:
467  *
468  * \li  #ISC_R_SUCCESS
469  * \li  #ISC_R_NOMEMORY
470  *
471  * \li  Other results are possible, depending upon the database
472  *      implementation used, syntax errors in the master file, etc.
473  */
474
475 isc_result_t
476 dns_db_dump(dns_db_t *db, dns_dbversion_t *version, const char *filename);
477
478 isc_result_t
479 dns_db_dump2(dns_db_t *db, dns_dbversion_t *version, const char *filename,
480              dns_masterformat_t masterformat);
481 /*%<
482  * Dump version 'version' of 'db' to master file 'filename'.
483  *
484  * Requires:
485  *
486  * \li  'db' is a valid database.
487  *
488  * \li  'version' is a valid version.
489  *
490  * Returns:
491  *
492  * \li  #ISC_R_SUCCESS
493  * \li  #ISC_R_NOMEMORY
494  *
495  * \li  Other results are possible, depending upon the database
496  *      implementation used, OS file errors, etc.
497  */
498
499 /***
500  *** Version Methods
501  ***/
502
503 void
504 dns_db_currentversion(dns_db_t *db, dns_dbversion_t **versionp);
505 /*%<
506  * Open the current version for reading.
507  *
508  * Requires:
509  *
510  * \li  'db' is a valid database with zone semantics.
511  *
512  * \li  versionp != NULL && *verisonp == NULL
513  *
514  * Ensures:
515  *
516  * \li  On success, '*versionp' is attached to the current version.
517  *
518  */
519
520 isc_result_t
521 dns_db_newversion(dns_db_t *db, dns_dbversion_t **versionp);
522 /*%<
523  * Open a new version for reading and writing.
524  *
525  * Requires:
526  *
527  * \li  'db' is a valid database with zone semantics.
528  *
529  * \li  versionp != NULL && *verisonp == NULL
530  *
531  * Ensures:
532  *
533  * \li  On success, '*versionp' is attached to the current version.
534  *
535  * Returns:
536  *
537  * \li  #ISC_R_SUCCESS
538  * \li  #ISC_R_NOMEMORY
539  *
540  * \li  Other results are possible, depending upon the database
541  *      implementation used.
542  */
543
544 void
545 dns_db_attachversion(dns_db_t *db, dns_dbversion_t *source,
546                      dns_dbversion_t **targetp);
547 /*%<
548  * Attach '*targetp' to 'source'.
549  *
550  * Requires:
551  *
552  * \li  'db' is a valid database with zone semantics.
553  *
554  * \li  source is a valid open version
555  *
556  * \li  targetp != NULL && *targetp == NULL
557  *
558  * Ensures:
559  *
560  * \li  '*targetp' is attached to source.
561  */
562
563 void
564 dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp,
565                     isc_boolean_t commit);
566 /*%<
567  * Close version '*versionp'.
568  *
569  * Note: if '*versionp' is a read-write version and 'commit' is ISC_TRUE,
570  * then all changes made in the version will take effect, otherwise they
571  * will be rolled back.  The value if 'commit' is ignored for read-only
572  * versions.
573  *
574  * Requires:
575  *
576  * \li  'db' is a valid database with zone semantics.
577  *
578  * \li  '*versionp' refers to a valid version.
579  *
580  * \li  If committing a writable version, then there must be no other
581  *      outstanding references to the version (e.g. an active rdataset
582  *      iterator).
583  *
584  * Ensures:
585  *
586  * \li  *versionp == NULL
587  *
588  * \li  If *versionp is a read-write version, and commit is ISC_TRUE, then
589  *      the version will become the current version.  If !commit, then all
590  *      changes made in the version will be undone, and the version will
591  *      not become the current version.
592  */
593
594 /***
595  *** Node Methods
596  ***/
597
598 isc_result_t
599 dns_db_findnode(dns_db_t *db, dns_name_t *name, isc_boolean_t create,
600                 dns_dbnode_t **nodep);
601 /*%<
602  * Find the node with name 'name'.
603  *
604  * Notes:
605  * \li  If 'create' is ISC_TRUE and no node with name 'name' exists, then
606  *      such a node will be created.
607  *
608  * \li  This routine is for finding or creating a node with the specified
609  *      name.  There are no partial matches.  It is not suitable for use
610  *      in building responses to ordinary DNS queries; clients which wish
611  *      to do that should use dns_db_find() instead.
612  *
613  * Requires:
614  *
615  * \li  'db' is a valid database.
616  *
617  * \li  'name' is a valid, non-empty, absolute name.
618  *
619  * \li  nodep != NULL && *nodep == NULL
620  *
621  * Ensures:
622  *
623  * \li  On success, *nodep is attached to the node with name 'name'.
624  *
625  * Returns:
626  *
627  * \li  #ISC_R_SUCCESS
628  * \li  #ISC_R_NOTFOUND                 If !create and name not found.
629  * \li  #ISC_R_NOMEMORY                 Can only happen if create is ISC_TRUE.
630  *
631  * \li  Other results are possible, depending upon the database
632  *      implementation used.
633  */
634
635 isc_result_t
636 dns_db_find(dns_db_t *db, dns_name_t *name, dns_dbversion_t *version,
637             dns_rdatatype_t type, unsigned int options, isc_stdtime_t now,
638             dns_dbnode_t **nodep, dns_name_t *foundname,
639             dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
640 /*%<
641  * Find the best match for 'name' and 'type' in version 'version' of 'db'.
642  *
643  * Notes:
644  *
645  * \li  If type == dns_rdataset_any, then rdataset will not be bound.
646  *
647  * \li  If 'options' does not have #DNS_DBFIND_GLUEOK set, then no glue will
648  *      be returned.  For zone databases, glue is as defined in RFC2181.
649  *      For cache databases, glue is any rdataset with a trust of
650  *      dns_trust_glue.
651  *
652  * \li  If 'options' does not have #DNS_DBFIND_PENDINGOK set, then no
653  *      pending data will be returned.  This option is only meaningful for
654  *      cache databases.
655  *
656  * \li  If the #DNS_DBFIND_NOWILD option is set, then wildcard matching will
657  *      be disabled.  This option is only meaningful for zone databases.
658  *
659  * \li  If the #DNS_DBFIND_FORCENSEC option is set, the database is assumed to
660  *      have NSEC records, and these will be returned when appropriate.  This
661  *      is only necessary when querying a database that was not secure
662  *      when created.
663  *
664  * \li  If the DNS_DBFIND_COVERINGNSEC option is set, then look for a
665  *      NSEC record that potentially covers 'name' if a answer cannot
666  *      be found.  Note the returned NSEC needs to be checked to ensure
667  *      that it is correct.  This only affects answers returned from the
668  *      cache.
669  *
670  * \li  To respond to a query for SIG records, the caller should create a
671  *      rdataset iterator and extract the signatures from each rdataset.
672  *
673  * \li  Making queries of type ANY with #DNS_DBFIND_GLUEOK is not recommended,
674  *      because the burden of determining whether a given rdataset is valid
675  *      glue or not falls upon the caller.
676  *
677  * \li  The 'now' field is ignored if 'db' is a zone database.  If 'db' is a
678  *      cache database, an rdataset will not be found unless it expires after
679  *      'now'.  Any ANY query will not match unless at least one rdataset at
680  *      the node expires after 'now'.  If 'now' is zero, then the current time
681  *      will be used.
682  *
683  * Requires:
684  *
685  * \li  'db' is a valid database.
686  *
687  * \li  'type' is not SIG, or a meta-RR type other than 'ANY' (e.g. 'OPT').
688  *
689  * \li  'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
690  *
691  * \li  'foundname' is a valid name with a dedicated buffer.
692  *
693  * \li  'rdataset' is NULL, or is a valid unassociated rdataset.
694  *
695  * Ensures,
696  *      on a non-error completion:
697  *
698  *      \li     If nodep != NULL, then it is bound to the found node.
699  *
700  *      \li     If foundname != NULL, then it contains the full name of the
701  *              found node.
702  *
703  *      \li     If rdataset != NULL and type != dns_rdatatype_any, then
704  *              rdataset is bound to the found rdataset.
705  *
706  *      Non-error results are:
707  *
708  *      \li     #ISC_R_SUCCESS                  The desired node and type were
709  *                                              found.
710  *
711  *      \li     #DNS_R_WILDCARD                 The desired node and type were
712  *                                              found after performing
713  *                                              wildcard matching.  This is
714  *                                              only returned if the
715  *                                              #DNS_DBFIND_INDICATEWILD
716  *                                              option is set; otherwise
717  *                                              #ISC_R_SUCCESS is returned.
718  *
719  *      \li     #DNS_R_GLUE                     The desired node and type were
720  *                                              found, but are glue.  This
721  *                                              result can only occur if
722  *                                              the DNS_DBFIND_GLUEOK option
723  *                                              is set.  This result can only
724  *                                              occur if 'db' is a zone
725  *                                              database.  If type ==
726  *                                              dns_rdatatype_any, then the
727  *                                              node returned may contain, or
728  *                                              consist entirely of invalid
729  *                                              glue (i.e. data occluded by a
730  *                                              zone cut).  The caller must
731  *                                              take care not to return invalid
732  *                                              glue to a client.
733  *
734  *      \li     #DNS_R_DELEGATION               The data requested is beneath
735  *                                              a zone cut.  node, foundname,
736  *                                              and rdataset reference the
737  *                                              NS RRset of the zone cut.
738  *                                              If 'db' is a cache database,
739  *                                              then this is the deepest known
740  *                                              delegation.
741  *
742  *      \li     #DNS_R_ZONECUT                  type == dns_rdatatype_any, and
743  *                                              the desired node is a zonecut.
744  *                                              The caller must take care not
745  *                                              to return inappropriate glue
746  *                                              to a client.  This result can
747  *                                              only occur if 'db' is a zone
748  *                                              database and DNS_DBFIND_GLUEOK
749  *                                              is set.
750  *
751  *      \li     #DNS_R_DNAME                    The data requested is beneath
752  *                                              a DNAME.  node, foundname,
753  *                                              and rdataset reference the
754  *                                              DNAME RRset.
755  *
756  *      \li     #DNS_R_CNAME                    The rdataset requested was not
757  *                                              found, but there is a CNAME
758  *                                              at the desired name.  node,
759  *                                              foundname, and rdataset
760  *                                              reference the CNAME RRset.
761  *
762  *      \li     #DNS_R_NXDOMAIN                 The desired name does not
763  *                                              exist.
764  *
765  *      \li     #DNS_R_NXRRSET                  The desired name exists, but
766  *                                              the desired type does not.
767  *
768  *      \li     #ISC_R_NOTFOUND                 The desired name does not
769  *                                              exist, and no delegation could
770  *                                              be found.  This result can only
771  *                                              occur if 'db' is a cache
772  *                                              database.  The caller should
773  *                                              use its nameserver(s) of last
774  *                                              resort (e.g. root hints).
775  *
776  *      \li     #DNS_R_NCACHENXDOMAIN           The desired name does not
777  *                                              exist.  'node' is bound to the
778  *                                              cache node with the desired
779  *                                              name, and 'rdataset' contains
780  *                                              the negative caching proof.
781  *
782  *      \li     #DNS_R_NCACHENXRRSET            The desired type does not
783  *                                              exist.  'node' is bound to the
784  *                                              cache node with the desired
785  *                                              name, and 'rdataset' contains
786  *                                              the negative caching proof.
787  *
788  *      \li     #DNS_R_EMPTYNAME                        The name exists but there is
789  *                                              no data at the name. 
790  *
791  *      \li     #DNS_R_COVERINGNSEC             The returned data is a NSEC
792  *                                              that potentially covers 'name'.
793  *
794  *      Error results:
795  *
796  *      \li     #ISC_R_NOMEMORY
797  *
798  *      \li     #DNS_R_BADDB                    Data that is required to be
799  *                                              present in the DB, e.g. an NSEC
800  *                                              record in a secure zone, is not
801  *                                              present.
802  *
803  *      \li     Other results are possible, and should all be treated as
804  *              errors.
805  */
806
807 isc_result_t
808 dns_db_findzonecut(dns_db_t *db, dns_name_t *name,
809                    unsigned int options, isc_stdtime_t now,
810                    dns_dbnode_t **nodep, dns_name_t *foundname,
811                    dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
812 /*%<
813  * Find the deepest known zonecut which encloses 'name' in 'db'.
814  *
815  * Notes:
816  *
817  * \li  If the #DNS_DBFIND_NOEXACT option is set, then the zonecut returned
818  *      (if any) will be the deepest known ancestor of 'name'.
819  *
820  * \li  If 'now' is zero, then the current time will be used.
821  *
822  * Requires:
823  *
824  * \li  'db' is a valid database with cache semantics.
825  *
826  * \li  'nodep' is NULL, or nodep is a valid pointer and *nodep == NULL.
827  *
828  * \li  'foundname' is a valid name with a dedicated buffer.
829  *
830  * \li  'rdataset' is NULL, or is a valid unassociated rdataset.
831  *
832  * Ensures, on a non-error completion:
833  *
834  * \li  If nodep != NULL, then it is bound to the found node.
835  *
836  * \li  If foundname != NULL, then it contains the full name of the
837  *      found node.
838  *
839  * \li  If rdataset != NULL and type != dns_rdatatype_any, then
840  *      rdataset is bound to the found rdataset.
841  *
842  * Non-error results are:
843  *
844  * \li  #ISC_R_SUCCESS
845  *
846  * \li  #ISC_R_NOTFOUND
847  *
848  * \li  Other results are possible, and should all be treated as
849  *      errors.
850  */
851
852 void
853 dns_db_attachnode(dns_db_t *db, dns_dbnode_t *source, dns_dbnode_t **targetp);
854 /*%<
855  * Attach *targetp to source.
856  *
857  * Requires:
858  *
859  * \li  'db' is a valid database.
860  *
861  * \li  'source' is a valid node.
862  *
863  * \li  'targetp' points to a NULL dns_dbnode_t *.
864  *
865  * Ensures:
866  *
867  * \li  *targetp is attached to source.
868  */
869
870 void
871 dns_db_detachnode(dns_db_t *db, dns_dbnode_t **nodep);
872 /*%<
873  * Detach *nodep from its node.
874  *
875  * Requires:
876  *
877  * \li  'db' is a valid database.
878  *
879  * \li  'nodep' points to a valid node.
880  *
881  * Ensures:
882  *
883  * \li  *nodep is NULL.
884  */
885
886 isc_result_t
887 dns_db_expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now);
888 /*%<
889  * Mark as stale all records at 'node' which expire at or before 'now'.
890  *
891  * Note: if 'now' is zero, then the current time will be used.
892  *
893  * Requires:
894  *
895  * \li  'db' is a valid cache database.
896  *
897  * \li  'node' is a valid node.
898  */
899
900 void
901 dns_db_printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out);
902 /*%<
903  * Print a textual representation of the contents of the node to
904  * 'out'.
905  *
906  * Note: this function is intended for debugging, not general use.
907  *
908  * Requires:
909  *
910  * \li  'db' is a valid database.
911  *
912  * \li  'node' is a valid node.
913  */
914
915 /***
916  *** DB Iterator Creation
917  ***/
918
919 isc_result_t
920 dns_db_createiterator(dns_db_t *db, isc_boolean_t relative_names,
921                       dns_dbiterator_t **iteratorp);
922 /*%<
923  * Create an iterator for version 'version' of 'db'.
924  *
925  * Notes:
926  *
927  * \li  If 'relative_names' is ISC_TRUE, then node names returned by the
928  *      iterator will be relative to the iterator's current origin.  If
929  *      #ISC_FALSE, then the node names will be absolute.
930  *
931  * Requires:
932  *
933  * \li  'db' is a valid database.
934  *
935  * \li  iteratorp != NULL && *iteratorp == NULL
936  *
937  * Ensures:
938  *
939  * \li  On success, *iteratorp will be a valid database iterator.
940  *
941  * Returns:
942  *
943  * \li  #ISC_R_SUCCESS
944  * \li  #ISC_R_NOMEMORY
945  */
946
947 /***
948  *** Rdataset Methods
949  ***/
950
951 /*
952  * XXXRTH  Should we check for glue and pending data in dns_db_findrdataset()?
953  */
954
955 isc_result_t
956 dns_db_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
957                     dns_rdatatype_t type, dns_rdatatype_t covers,
958                     isc_stdtime_t now, dns_rdataset_t *rdataset,
959                     dns_rdataset_t *sigrdataset);
960 /*%<
961  * Search for an rdataset of type 'type' at 'node' that are in version
962  * 'version' of 'db'.  If found, make 'rdataset' refer to it.
963  *
964  * Notes:
965  *
966  * \li  If 'version' is NULL, then the current version will be used.
967  *
968  * \li  Care must be used when using this routine to build a DNS response:
969  *      'node' should have been found with dns_db_find(), not
970  *      dns_db_findnode().  No glue checking is done.  No checking for
971  *      pending data is done.
972  *
973  * \li  The 'now' field is ignored if 'db' is a zone database.  If 'db' is a
974  *      cache database, an rdataset will not be found unless it expires after
975  *      'now'.  If 'now' is zero, then the current time will be used.
976  *
977  * Requires:
978  *
979  * \li  'db' is a valid database.
980  *
981  * \li  'node' is a valid node.
982  *
983  * \li  'rdataset' is a valid, disassociated rdataset.
984  *
985  * \li  'sigrdataset' is a valid, disassociated rdataset, or it is NULL.
986  *
987  * \li  If 'covers' != 0, 'type' must be SIG.
988  *
989  * \li  'type' is not a meta-RR type such as 'ANY' or 'OPT'.
990  *
991  * Ensures:
992  *
993  * \li  On success, 'rdataset' is associated with the found rdataset.
994  *
995  * Returns:
996  *
997  * \li  #ISC_R_SUCCESS
998  * \li  #ISC_R_NOTFOUND
999  *
1000  * \li  Other results are possible, depending upon the database
1001  *      implementation used.
1002  */
1003
1004 isc_result_t
1005 dns_db_allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
1006                     isc_stdtime_t now, dns_rdatasetiter_t **iteratorp);
1007 /*%<
1008  * Make '*iteratorp' an rdataset iteratator for all rdatasets at 'node' in
1009  * version 'version' of 'db'.
1010  *
1011  * Notes:
1012  *
1013  * \li  If 'version' is NULL, then the current version will be used.
1014  *
1015  * \li  The 'now' field is ignored if 'db' is a zone database.  If 'db' is a
1016  *      cache database, an rdataset will not be found unless it expires after
1017  *      'now'.  Any ANY query will not match unless at least one rdataset at
1018  *      the node expires after 'now'.  If 'now' is zero, then the current time
1019  *      will be used.
1020  *
1021  * Requires:
1022  *
1023  * \li  'db' is a valid database.
1024  *
1025  * \li  'node' is a valid node.
1026  *
1027  * \li  iteratorp != NULL && *iteratorp == NULL
1028  *
1029  * Ensures:
1030  *
1031  * \li  On success, '*iteratorp' is a valid rdataset iterator.
1032  *
1033  * Returns:
1034  *
1035  * \li  #ISC_R_SUCCESS
1036  * \li  #ISC_R_NOTFOUND
1037  *
1038  * \li  Other results are possible, depending upon the database
1039  *      implementation used.
1040  */
1041
1042 isc_result_t
1043 dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
1044                    isc_stdtime_t now, dns_rdataset_t *rdataset,
1045                    unsigned int options, dns_rdataset_t *addedrdataset);
1046 /*%<
1047  * Add 'rdataset' to 'node' in version 'version' of 'db'.
1048  *
1049  * Notes:
1050  *
1051  * \li  If the database has zone semantics, the #DNS_DBADD_MERGE option is set,
1052  *      and an rdataset of the same type as 'rdataset' already exists at
1053  *      'node' then the contents of 'rdataset' will be merged with the existing
1054  *      rdataset.  If the option is not set, then rdataset will replace any
1055  *      existing rdataset of the same type.  If not merging and the
1056  *      #DNS_DBADD_FORCE option is set, then the data will update the database
1057  *      without regard to trust levels.  If not forcing the data, then the
1058  *      rdataset will only be added if its trust level is >= the trust level of
1059  *      any existing rdataset.  Forcing is only meaningful for cache databases.
1060  *      If #DNS_DBADD_EXACT is set then there must be no rdata in common between
1061  *      the old and new rdata sets.  If #DNS_DBADD_EXACTTTL is set then both
1062  *      the old and new rdata sets must have the same ttl.
1063  *
1064  * \li  The 'now' field is ignored if 'db' is a zone database.  If 'db' is
1065  *      a cache database, then the added rdataset will expire no later than
1066  *      now + rdataset->ttl.
1067  *
1068  * \li  If 'addedrdataset' is not NULL, then it will be attached to the
1069  *      resulting new rdataset in the database, or to the existing data if
1070  *      the existing data was better.
1071  *
1072  * Requires:
1073  *
1074  * \li  'db' is a valid database.
1075  *
1076  * \li  'node' is a valid node.
1077  *
1078  * \li  'rdataset' is a valid, associated rdataset with the same class
1079  *      as 'db'.
1080  *
1081  * \li  'addedrdataset' is NULL, or a valid, unassociated rdataset.
1082  *
1083  * \li  The database has zone semantics and 'version' is a valid
1084  *      read-write version, or the database has cache semantics
1085  *      and version is NULL.
1086  *
1087  * \li  If the database has cache semantics, the #DNS_DBADD_MERGE option must
1088  *      not be set.
1089  *
1090  * Returns:
1091  *
1092  * \li  #ISC_R_SUCCESS
1093  * \li  #DNS_R_UNCHANGED                        The operation did not change anything.
1094  * \li  #ISC_R_NOMEMORY
1095  * \li  #DNS_R_NOTEXACT
1096  *
1097  * \li  Other results are possible, depending upon the database
1098  *      implementation used.
1099  */
1100
1101 isc_result_t
1102 dns_db_subtractrdataset(dns_db_t *db, dns_dbnode_t *node,
1103                         dns_dbversion_t *version, dns_rdataset_t *rdataset,
1104                         unsigned int options, dns_rdataset_t *newrdataset);
1105 /*%<
1106  * Remove any rdata in 'rdataset' from 'node' in version 'version' of
1107  * 'db'.
1108  *
1109  * Notes:
1110  *
1111  * \li  If 'newrdataset' is not NULL, then it will be attached to the
1112  *      resulting new rdataset in the database, unless the rdataset has
1113  *      become nonexistent.  If DNS_DBSUB_EXACT is set then all elements
1114  *      of 'rdataset' must exist at 'node'.
1115  *
1116  * Requires:
1117  *
1118  * \li  'db' is a valid database.
1119  *
1120  * \li  'node' is a valid node.
1121  *
1122  * \li  'rdataset' is a valid, associated rdataset with the same class
1123  *      as 'db'.
1124  *
1125  * \li  'newrdataset' is NULL, or a valid, unassociated rdataset.
1126  *
1127  * \li  The database has zone semantics and 'version' is a valid
1128  *      read-write version.
1129  *
1130  * Returns:
1131  *
1132  * \li  #ISC_R_SUCCESS
1133  * \li  #DNS_R_UNCHANGED                        The operation did not change anything.
1134  * \li  #DNS_R_NXRRSET                  All rdata of the same type as those
1135  *                                      in 'rdataset' have been deleted.
1136  * \li  #DNS_R_NOTEXACT                 Some part of 'rdataset' did not
1137  *                                      exist and DNS_DBSUB_EXACT was set.
1138  *
1139  * \li  Other results are possible, depending upon the database
1140  *      implementation used.
1141  */
1142
1143 isc_result_t
1144 dns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node,
1145                       dns_dbversion_t *version, dns_rdatatype_t type,
1146                       dns_rdatatype_t covers);
1147 /*%<
1148  * Make it so that no rdataset of type 'type' exists at 'node' in version
1149  * version 'version' of 'db'.
1150  *
1151  * Notes:
1152  *
1153  * \li  If 'type' is dns_rdatatype_any, then no rdatasets will exist in
1154  *      'version' (provided that the dns_db_deleterdataset() isn't followed
1155  *      by one or more dns_db_addrdataset() calls).
1156  *
1157  * Requires:
1158  *
1159  * \li  'db' is a valid database.
1160  *
1161  * \li  'node' is a valid node.
1162  *
1163  * \li  The database has zone semantics and 'version' is a valid
1164  *      read-write version, or the database has cache semantics
1165  *      and version is NULL.
1166  *
1167  * \li  'type' is not a meta-RR type, except for dns_rdatatype_any, which is
1168  *      allowed.
1169  *
1170  * \li  If 'covers' != 0, 'type' must be SIG.
1171  *
1172  * Returns:
1173  *
1174  * \li  #ISC_R_SUCCESS
1175  * \li  #DNS_R_UNCHANGED                        No rdatasets of 'type' existed before
1176  *                                      the operation was attempted.
1177  *
1178  * \li  Other results are possible, depending upon the database
1179  *      implementation used.
1180  */
1181
1182 isc_result_t
1183 dns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, isc_uint32_t *serialp);
1184 /*%<
1185  * Get the current SOA serial number from a zone database.
1186  *
1187  * Requires:
1188  * \li  'db' is a valid database with zone semantics.
1189  * \li  'ver' is a valid version.
1190  */
1191
1192 void
1193 dns_db_overmem(dns_db_t *db, isc_boolean_t overmem);
1194 /*%<
1195  * Enable / disable agressive cache cleaning.
1196  */
1197
1198 unsigned int
1199 dns_db_nodecount(dns_db_t *db);
1200 /*%<
1201  * Count the number of nodes in 'db'.
1202  *
1203  * Requires:
1204  *
1205  * \li  'db' is a valid database.
1206  *
1207  * Returns:
1208  * \li  The number of nodes in the database
1209  */
1210
1211 void
1212 dns_db_settask(dns_db_t *db, isc_task_t *task);
1213 /*%<
1214  * If task is set then the final detach maybe performed asynchronously.
1215  *
1216  * Requires:
1217  * \li  'db' is a valid database.
1218  * \li  'task' to be valid or NULL.
1219  */
1220
1221 isc_boolean_t
1222 dns_db_ispersistent(dns_db_t *db);
1223 /*%<
1224  * Is 'db' persistent?  A persistent database does not need to be loaded
1225  * from disk or written to disk.
1226  *
1227  * Requires:
1228  *
1229  * \li  'db' is a valid database.
1230  *
1231  * Returns:
1232  * \li  #ISC_TRUE       'db' is persistent.
1233  * \li  #ISC_FALSE      'db' is not persistent.
1234  */
1235
1236 isc_result_t
1237 dns_db_register(const char *name, dns_dbcreatefunc_t create, void *driverarg,
1238                 isc_mem_t *mctx, dns_dbimplementation_t **dbimp);
1239
1240 /*%<
1241  * Register a new database implementation and add it to the list of
1242  * supported implementations.
1243  *
1244  * Requires:
1245  *
1246  * \li  'name' is not NULL
1247  * \li  'order' is a valid function pointer
1248  * \li  'mctx' is a valid memory context
1249  * \li  dbimp != NULL && *dbimp == NULL
1250  *
1251  * Returns:
1252  * \li  #ISC_R_SUCCESS  The registration succeeded
1253  * \li  #ISC_R_NOMEMORY Out of memory
1254  * \li  #ISC_R_EXISTS   A database implementation with the same name exists
1255  *
1256  * Ensures:
1257  *
1258  * \li  *dbimp points to an opaque structure which must be passed to
1259  *      dns_db_unregister().
1260  */
1261
1262 void
1263 dns_db_unregister(dns_dbimplementation_t **dbimp);
1264 /*%<
1265  * Remove a database implementation from the the list of supported
1266  * implementations.  No databases of this type can be active when this
1267  * is called.
1268  *
1269  * Requires:
1270  * \li  dbimp != NULL && *dbimp == NULL
1271  *
1272  * Ensures:
1273  *
1274  * \li  Any memory allocated in *dbimp will be freed.
1275  */
1276
1277 isc_result_t
1278 dns_db_getoriginnode(dns_db_t *db, dns_dbnode_t **nodep);
1279 /*%<
1280  * Get the origin DB node corresponding to the DB's zone.  This function
1281  * should typically succeed unless the underlying DB implementation doesn't
1282  * support the feature.
1283  *
1284  * Requires:
1285  *
1286  * \li  'db' is a valid zone database.
1287  * \li  'nodep' != NULL && '*nodep' == NULL
1288  *
1289  * Ensures:
1290  * \li  On success, '*nodep' will point to the DB node of the zone's origin.
1291  *
1292  * Returns:
1293  * \li  #ISC_R_SUCCESS
1294  * \li  #ISC_R_NOTFOUND - the DB implementation does not support this feature.
1295  */
1296
1297 ISC_LANG_ENDDECLS
1298
1299 #endif /* DNS_DB_H */