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