Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / dns / include / dns / view.h
blobbb64bb610534545a6b8fde810536309c43b8716b
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
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.
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.
18 /* $Id: view.h,v 1.73.2.8 2004/03/09 06:11:24 marka Exp $ */
20 #ifndef DNS_VIEW_H
21 #define DNS_VIEW_H 1
23 /*****
24 ***** Module Info
25 *****/
28 * DNS View
30 * A "view" is a DNS namespace, together with an optional resolver and a
31 * forwarding policy. A "DNS namespace" is a (possibly empty) set of
32 * authoritative zones together with an optional cache and optional
33 * "hints" information.
35 * Views start out "unfrozen". In this state, core attributes like
36 * the cache, set of zones, and forwarding policy may be set. While
37 * "unfrozen", the caller (e.g. nameserver configuration loading
38 * code), must ensure exclusive access to the view. When the view is
39 * "frozen", the core attributes become immutable, and the view module
40 * will ensure synchronization. Freezing allows the view's core attributes
41 * to be accessed without locking.
43 * MP:
44 * Before the view is frozen, the caller must ensure synchronization.
46 * After the view is frozen, the module guarantees appropriate
47 * synchronization of any data structures it creates and manipulates.
49 * Reliability:
50 * No anticipated impact.
52 * Resources:
53 * <TBS>
55 * Security:
56 * No anticipated impact.
58 * Standards:
59 * None.
62 #include <stdio.h>
64 #include <isc/lang.h>
65 #include <isc/magic.h>
66 #include <isc/event.h>
67 #include <isc/mutex.h>
68 #include <isc/net.h>
69 #include <isc/refcount.h>
70 #include <isc/rwlock.h>
71 #include <isc/stdtime.h>
73 #include <dns/acl.h>
74 #include <dns/types.h>
76 ISC_LANG_BEGINDECLS
78 struct dns_view {
79 /* Unlocked. */
80 unsigned int magic;
81 isc_mem_t * mctx;
82 dns_rdataclass_t rdclass;
83 char * name;
84 dns_zt_t * zonetable;
85 dns_resolver_t * resolver;
86 dns_adb_t * adb;
87 dns_requestmgr_t * requestmgr;
88 dns_cache_t * cache;
89 dns_db_t * cachedb;
90 dns_db_t * hints;
91 dns_keytable_t * secroots;
92 dns_keytable_t * trustedkeys;
93 isc_mutex_t lock;
94 isc_boolean_t frozen;
95 isc_task_t * task;
96 isc_event_t resevent;
97 isc_event_t adbevent;
98 isc_event_t reqevent;
99 /* Configurable data. */
100 dns_tsig_keyring_t * statickeys;
101 dns_tsig_keyring_t * dynamickeys;
102 dns_peerlist_t * peers;
103 dns_fwdtable_t * fwdtable;
104 isc_boolean_t recursion;
105 isc_boolean_t auth_nxdomain;
106 isc_boolean_t additionalfromcache;
107 isc_boolean_t additionalfromauth;
108 isc_boolean_t minimalresponses;
109 dns_transfer_format_t transfer_format;
110 dns_acl_t * queryacl;
111 dns_acl_t * recursionacl;
112 dns_acl_t * v6synthesisacl;
113 dns_acl_t * sortlist;
114 isc_boolean_t requestixfr;
115 isc_boolean_t provideixfr;
116 dns_ttl_t maxcachettl;
117 dns_ttl_t maxncachettl;
118 in_port_t dstport;
119 dns_aclenv_t aclenv;
120 isc_boolean_t flush;
121 dns_namelist_t * delonly;
122 isc_boolean_t rootdelonly;
123 dns_namelist_t * rootexclude;
126 * Configurable data for server use only,
127 * locked by server configuration lock.
129 dns_acl_t * matchclients;
130 dns_acl_t * matchdestinations;
131 isc_boolean_t matchrecursiveonly;
133 /* Locked by themselves. */
134 isc_refcount_t references;
136 /* Locked by lock. */
137 unsigned int weakrefs;
138 unsigned int attributes;
139 /* Under owner's locking control. */
140 ISC_LINK(struct dns_view) link;
143 #define DNS_VIEW_MAGIC ISC_MAGIC('V','i','e','w')
144 #define DNS_VIEW_VALID(view) ISC_MAGIC_VALID(view, DNS_VIEW_MAGIC)
146 #define DNS_VIEWATTR_RESSHUTDOWN 0x01
147 #define DNS_VIEWATTR_ADBSHUTDOWN 0x02
148 #define DNS_VIEWATTR_REQSHUTDOWN 0x04
150 isc_result_t
151 dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
152 const char *name, dns_view_t **viewp);
154 * Create a view.
156 * Notes:
158 * The newly created view has no cache, no resolver, and an empty
159 * zone table. The view is not frozen.
161 * Requires:
163 * 'mctx' is a valid memory context.
165 * 'rdclass' is a valid class.
167 * 'name' is a valid C string.
169 * viewp != NULL && *viewp == NULL
171 * Returns:
173 * ISC_R_SUCCESS
174 * ISC_R_NOMEMORY
176 * Other errors are possible.
179 void
180 dns_view_attach(dns_view_t *source, dns_view_t **targetp);
182 * Attach '*targetp' to 'source'.
184 * Requires:
186 * 'source' is a valid, frozen view.
188 * 'targetp' points to a NULL dns_view_t *.
190 * Ensures:
192 * *targetp is attached to source.
194 * While *targetp is attached, the view will not shut down.
197 void
198 dns_view_detach(dns_view_t **viewp);
200 * Detach '*viewp' from its view.
202 * Requires:
204 * 'viewp' points to a valid dns_view_t *
206 * Ensures:
208 * *viewp is NULL.
211 void
212 dns_view_flushanddetach(dns_view_t **viewp);
214 * Detach '*viewp' from its view. If this was the last reference
215 * uncommited changed in zones will be flushed to disk.
217 * Requires:
219 * 'viewp' points to a valid dns_view_t *
221 * Ensures:
223 * *viewp is NULL.
226 void
227 dns_view_weakattach(dns_view_t *source, dns_view_t **targetp);
229 * Weakly attach '*targetp' to 'source'.
231 * Requires:
233 * 'source' is a valid, frozen view.
235 * 'targetp' points to a NULL dns_view_t *.
237 * Ensures:
239 * *targetp is attached to source.
241 * While *targetp is attached, the view will not be freed.
244 void
245 dns_view_weakdetach(dns_view_t **targetp);
247 * Detach '*viewp' from its view.
249 * Requires:
251 * 'viewp' points to a valid dns_view_t *.
253 * Ensures:
255 * *viewp is NULL.
258 isc_result_t
259 dns_view_createresolver(dns_view_t *view,
260 isc_taskmgr_t *taskmgr, unsigned int ntasks,
261 isc_socketmgr_t *socketmgr,
262 isc_timermgr_t *timermgr,
263 unsigned int options,
264 dns_dispatchmgr_t *dispatchmgr,
265 dns_dispatch_t *dispatchv4,
266 dns_dispatch_t *dispatchv6);
268 * Create a resolver and address database for the view.
270 * Requires:
272 * 'view' is a valid, unfrozen view.
274 * 'view' does not have a resolver already.
276 * The requirements of dns_resolver_create() apply to 'taskmgr',
277 * 'ntasks', 'socketmgr', 'timermgr', 'options', 'dispatchv4', and
278 * 'dispatchv6'.
280 * Returns:
282 * ISC_R_SUCCESS
284 * Any error that dns_resolver_create() can return.
287 void
288 dns_view_setcache(dns_view_t *view, dns_cache_t *cache);
290 * Set the view's cache database.
292 * Requires:
294 * 'view' is a valid, unfrozen view.
296 * 'cache' is a valid cache.
298 * Ensures:
300 * The cache of 'view' is 'cached.
302 * If this is not the first call to dns_view_setcache() for this
303 * view, then previously set cache is detached.
306 void
307 dns_view_sethints(dns_view_t *view, dns_db_t *hints);
309 * Set the view's hints database.
311 * Requires:
313 * 'view' is a valid, unfrozen view, whose hints database has not been
314 * set.
316 * 'hints' is a valid zone database.
318 * Ensures:
320 * The hints database of 'view' is 'hints'.
323 void
324 dns_view_setkeyring(dns_view_t *view, dns_tsig_keyring_t *ring);
326 * Set the view's static TSIG keys
328 * Requires:
330 * 'view' is a valid, unfrozen view, whose static TSIG keyring has not
331 * been set.
333 * 'ring' is a valid TSIG keyring
335 * Ensures:
337 * The static TSIG keyring of 'view' is 'ring'.
340 void
341 dns_view_setdstport(dns_view_t *view, in_port_t dstport);
343 * Set the view's destination port. This is the port to
344 * which outgoing queries are sent. The default is 53,
345 * the standard DNS port.
347 * Requires:
349 * 'view' is a valid view.
351 * 'dstport' is a valid TCP/UDP port number.
353 * Ensures:
354 * External name servers will be assumed to be listning
355 * on 'dstport'. For servers whose address has already
356 * obtained obtained at the time of the call, the view may
357 * continue to use the previously set port until the address
358 * times out from the view's address database.
362 isc_result_t
363 dns_view_addzone(dns_view_t *view, dns_zone_t *zone);
365 * Add zone 'zone' to 'view'.
367 * Requires:
369 * 'view' is a valid, unfrozen view.
371 * 'zone' is a valid zone.
374 void
375 dns_view_freeze(dns_view_t *view);
377 * Freeze view.
379 * Requires:
381 * 'view' is a valid, unfrozen view.
383 * Ensures:
385 * 'view' is frozen.
388 isc_result_t
389 dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
390 isc_stdtime_t now, unsigned int options, isc_boolean_t use_hints,
391 dns_db_t **dbp, dns_dbnode_t **nodep, dns_name_t *foundname,
392 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
394 * Find an rdataset whose owner name is 'name', and whose type is
395 * 'type'.
397 * Notes:
399 * See the description of dns_db_find() for information about 'options'.
400 * If the caller sets DNS_DBFIND_GLUEOK, it must ensure that 'name'
401 * and 'type' are appropriate for glue retrieval.
403 * If 'now' is zero, then the current time will be used.
405 * If 'use_hints' is ISC_TRUE, and the view has a hints database, then
406 * it will be searched last. If the answer is found in the hints
407 * database, the result code will be DNS_R_HINT. If the name is found
408 * in the hints database but not the type, the result code will be
409 * DNS_R_HINTNXRRSET.
411 * 'foundname' must meet the requirements of dns_db_find().
413 * If 'sigrdataset' is not NULL, and there is a SIG rdataset which
414 * covers 'type', then 'sigrdataset' will be bound to it.
416 * Requires:
418 * 'view' is a valid, frozen view.
420 * 'name' is valid name.
422 * 'type' is a valid dns_rdatatype_t, and is not a meta query type
423 * except dns_rdatatype_any.
425 * dbp == NULL || *dbp == NULL
427 * nodep == NULL || *nodep == NULL. If nodep != NULL, dbp != NULL.
429 * 'foundname' is a valid name with a dedicated buffer or NULL.
431 * 'rdataset' is a valid, disassociated rdataset.
433 * 'sigrdataset' is NULL, or is a valid, disassociated rdataset.
435 * Ensures:
437 * In successful cases, 'rdataset', and possibly 'sigrdataset', are
438 * bound to the found data.
440 * If dbp != NULL, it points to the database containing the data.
442 * If nodep != NULL, it points to the database node containing the data.
444 * If foundname != NULL, it contains the full name of the found data.
446 * Returns:
448 * Any result that dns_db_find() can return, with the exception of
449 * DNS_R_DELEGATION.
452 isc_result_t
453 dns_view_simplefind(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
454 isc_stdtime_t now, unsigned int options,
455 isc_boolean_t use_hints,
456 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
458 * Find an rdataset whose owner name is 'name', and whose type is
459 * 'type'.
461 * Notes:
463 * This routine is appropriate for simple, exact-match queries of the
464 * view. 'name' must be a canonical name; there is no DNAME or CNAME
465 * processing.
467 * See the description of dns_db_find() for information about 'options'.
468 * If the caller sets DNS_DBFIND_GLUEOK, it must ensure that 'name'
469 * and 'type' are appropriate for glue retrieval.
471 * If 'now' is zero, then the current time will be used.
473 * If 'use_hints' is ISC_TRUE, and the view has a hints database, then
474 * it will be searched last. If the answer is found in the hints
475 * database, the result code will be DNS_R_HINT. If the name is found
476 * in the hints database but not the type, the result code will be
477 * DNS_R_HINTNXRRSET.
479 * If 'sigrdataset' is not NULL, and there is a SIG rdataset which
480 * covers 'type', then 'sigrdataset' will be bound to it.
482 * Requires:
484 * 'view' is a valid, frozen view.
486 * 'name' is valid name.
488 * 'type' is a valid dns_rdatatype_t, and is not a meta query type
489 * (e.g. dns_rdatatype_any), or dns_rdatatype_sig.
491 * 'rdataset' is a valid, disassociated rdataset.
493 * 'sigrdataset' is NULL, or is a valid, disassociated rdataset.
495 * Ensures:
497 * In successful cases, 'rdataset', and possibly 'sigrdataset', are
498 * bound to the found data.
500 * Returns:
502 * ISC_R_SUCCESS Success; result is desired type.
503 * DNS_R_GLUE Success; result is glue.
504 * DNS_R_HINT Success; result is a hint.
505 * DNS_R_NCACHENXDOMAIN Success; result is a ncache entry.
506 * DNS_R_NCACHENXRRSET Success; result is a ncache entry.
507 * DNS_R_NXDOMAIN The name does not exist.
508 * DNS_R_NXRRSET The rrset does not exist.
509 * ISC_R_NOTFOUND No matching data found,
510 * or an error occurred.
513 isc_result_t
514 dns_view_findzonecut(dns_view_t *view, dns_name_t *name, dns_name_t *fname,
515 isc_stdtime_t now, unsigned int options,
516 isc_boolean_t use_hints,
517 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
519 isc_result_t
520 dns_view_findzonecut2(dns_view_t *view, dns_name_t *name, dns_name_t *fname,
521 isc_stdtime_t now, unsigned int options,
522 isc_boolean_t use_hints, isc_boolean_t use_cache,
523 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
525 * Find the best known zonecut containing 'name'.
527 * This uses local authority, cache, and optionally hints data.
528 * No external queries are performed.
530 * Notes:
532 * If 'now' is zero, then the current time will be used.
534 * If 'use_hints' is ISC_TRUE, and the view has a hints database, then
535 * it will be searched last.
537 * If 'use_cache' is ISC_TRUE, and the view has a cache, then it will be
538 * searched.
540 * If 'sigrdataset' is not NULL, and there is a SIG rdataset which
541 * covers 'type', then 'sigrdataset' will be bound to it.
543 * If the DNS_DBFIND_NOEXACT option is set, then the zonecut returned
544 * (if any) will be the deepest known ancestor of 'name'.
546 * Requires:
548 * 'view' is a valid, frozen view.
550 * 'name' is valid name.
552 * 'rdataset' is a valid, disassociated rdataset.
554 * 'sigrdataset' is NULL, or is a valid, disassociated rdataset.
556 * Returns:
558 * ISC_R_SUCCESS Success.
560 * Many other results are possible.
563 isc_result_t
564 dns_viewlist_find(dns_viewlist_t *list, const char *name,
565 dns_rdataclass_t rdclass, dns_view_t **viewp);
567 * Search for a view with name 'name' and class 'rdclass' in 'list'.
568 * If found, '*viewp' is (strongly) attached to it.
570 * Requires:
572 * 'viewp' points to a NULL dns_view_t *.
574 * Returns:
576 * ISC_R_SUCCESS A matching view was found.
577 * ISC_R_NOTFOUND No matching view was found.
580 isc_result_t
581 dns_view_findzone(dns_view_t *view, dns_name_t *name, dns_zone_t **zonep);
583 * Search for the zone 'name' in the zone table of 'view'.
584 * If found, 'zonep' is (strongly) attached to it. There
585 * are no partial matches.
587 * Requires:
589 * 'zonep' points to a NULL dns_zone_t *.
591 * Returns:
592 * ISC_R_SUCCESS A matching zone was found.
593 * ISC_R_NOTFOUND No matching zone was found.
594 * others An error occurred.
597 isc_result_t
598 dns_view_load(dns_view_t *view, isc_boolean_t stop);
600 isc_result_t
601 dns_view_loadnew(dns_view_t *view, isc_boolean_t stop);
603 * Load zones attached to this view. dns_view_load() loads
604 * all zones whose master file has changed since the last
605 * load; dns_view_loadnew() loads only zones that have never
606 * been loaded.
608 * If 'stop' is ISC_TRUE, stop on the first error and return it.
609 * If 'stop' is ISC_FALSE, ignore errors.
611 * Requires:
613 * 'view' is valid.
616 isc_result_t
617 dns_view_gettsig(dns_view_t *view, dns_name_t *keyname,
618 dns_tsigkey_t **keyp);
620 * Find the TSIG key configured in 'view' with name 'keyname',
621 * if any.
623 * Reqires:
624 * keyp points to a NULL dns_tsigkey_t *.
626 * Returns:
627 * ISC_R_SUCCESS A key was found and '*keyp' now points to it.
628 * ISC_R_NOTFOUND No key was found.
629 * others An error occurred.
632 isc_result_t
633 dns_view_getpeertsig(dns_view_t *view, isc_netaddr_t *peeraddr,
634 dns_tsigkey_t **keyp);
636 * Find the TSIG key configured in 'view' for the server whose
637 * address is 'peeraddr', if any.
639 * Reqires:
640 * keyp points to a NULL dns_tsigkey_t *.
642 * Returns:
643 * ISC_R_SUCCESS A key was found and '*keyp' now points to it.
644 * ISC_R_NOTFOUND No key was found.
645 * others An error occurred.
648 isc_result_t
649 dns_view_checksig(dns_view_t *view, isc_buffer_t *source, dns_message_t *msg);
651 * Verifies the signature of a message.
653 * Requires:
655 * 'view' is a valid view.
656 * 'source' is a valid buffer containing the message
657 * 'msg' is a valid message
659 * Returns:
660 * see dns_tsig_verify()
663 void
664 dns_view_dialup(dns_view_t *view);
666 * Perform dialup-time maintenance on the zones of 'view'.
669 isc_result_t
670 dns_view_dumpdbtostream(dns_view_t *view, FILE *fp);
672 * Dump the current state of the view 'view' to the stream 'fp'
673 * for purposes of analysis or debugging.
675 * Currently the dumped state includes the view's cache; in the future
676 * it may also include other state such as the address database.
677 * It will not not include authoritative data since it is voluminous and
678 * easily obtainable by other means.
680 * Requires:
682 * 'view' is valid.
684 * 'fp' refers to a file open for writing.
686 * Returns:
687 * ISC_R_SUCCESS The cache was successfully dumped.
688 * others An error occurred (see dns_master_dump)
691 isc_result_t
692 dns_view_flushcache(dns_view_t *view);
694 * Flush the view's cache (and ADB).
696 * Requires:
697 * 'view' is valid.
699 * No other tasks are executing.
701 * Returns:
702 * ISC_R_SUCCESS
703 * ISC_R_NOMEMORY
706 isc_result_t
707 dns_view_adddelegationonly(dns_view_t *view, dns_name_t *name);
709 * Add the given name to the delegation only table.
712 * Requires:
713 * 'view' is valid.
714 * 'name' is valid.
716 * Returns:
717 * ISC_R_SUCCESS
718 * ISC_R_NOMEMORY
721 isc_result_t
722 dns_view_excludedelegationonly(dns_view_t *view, dns_name_t *name);
724 * Add the given name to be excluded from the root-delegation-only.
727 * Requires:
728 * 'view' is valid.
729 * 'name' is valid.
731 * Returns:
732 * ISC_R_SUCCESS
733 * ISC_R_NOMEMORY
736 isc_boolean_t
737 dns_view_isdelegationonly(dns_view_t *view, dns_name_t *name);
739 * Check if 'name' is in the delegation only table or if
740 * rootdelonly is set that name is not being excluded.
742 * Requires:
743 * 'view' is valid.
744 * 'name' is valid.
746 * Returns:
747 * ISC_TRUE if the name is is the table.
748 * ISC_FALSE othewise.
751 void
752 dns_view_setrootdelonly(dns_view_t *view, isc_boolean_t value);
754 * Set the root delegation only flag.
756 * Requires:
757 * 'view' is valid.
760 isc_boolean_t
761 dns_view_getrootdelonly(dns_view_t *view);
763 * Get the root delegation only flag.
765 * Requires:
766 * 'view' is valid.
769 #endif /* DNS_VIEW_H */