2 * Copyright (C) 2004-2006 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.91.18.9 2006/03/09 23:38:21 marka Exp $ */
31 * A "view" is a DNS namespace, together with an optional resolver and a
32 * forwarding policy. A "DNS namespace" is a (possibly empty) set of
33 * authoritative zones together with an optional cache and optional
34 * "hints" information.
36 * Views start out "unfrozen". In this state, core attributes like
37 * the cache, set of zones, and forwarding policy may be set. While
38 * "unfrozen", the caller (e.g. nameserver configuration loading
39 * code), must ensure exclusive access to the view. When the view is
40 * "frozen", the core attributes become immutable, and the view module
41 * will ensure synchronization. Freezing allows the view's core attributes
42 * to be accessed without locking.
45 *\li Before the view is frozen, the caller must ensure synchronization.
47 *\li After the view is frozen, the module guarantees appropriate
48 * synchronization of any data structures it creates and manipulates.
51 *\li No anticipated impact.
57 *\li No anticipated impact.
66 #include <isc/magic.h>
67 #include <isc/event.h>
68 #include <isc/mutex.h>
70 #include <isc/refcount.h>
71 #include <isc/rwlock.h>
72 #include <isc/stdtime.h>
75 #include <dns/fixedname.h>
76 #include <dns/types.h>
84 dns_rdataclass_t rdclass;
87 dns_dlzdb_t * dlzdatabase;
88 dns_resolver_t * resolver;
90 dns_requestmgr_t * requestmgr;
91 dns_acache_t * acache;
95 dns_keytable_t * secroots;
96 dns_keytable_t * trustedkeys;
100 isc_event_t resevent;
101 isc_event_t adbevent;
102 isc_event_t reqevent;
103 /* Configurable data. */
104 dns_tsig_keyring_t * statickeys;
105 dns_tsig_keyring_t * dynamickeys;
106 dns_peerlist_t * peers;
108 dns_fwdtable_t * fwdtable;
109 isc_boolean_t recursion;
110 isc_boolean_t auth_nxdomain;
111 isc_boolean_t additionalfromcache;
112 isc_boolean_t additionalfromauth;
113 isc_boolean_t minimalresponses;
114 isc_boolean_t enablednssec;
115 isc_boolean_t enablevalidation;
116 isc_boolean_t acceptexpired;
117 dns_transfer_format_t transfer_format;
118 dns_acl_t * queryacl;
119 dns_acl_t * recursionacl;
120 dns_acl_t * sortlist;
121 isc_boolean_t requestixfr;
122 isc_boolean_t provideixfr;
123 dns_ttl_t maxcachettl;
124 dns_ttl_t maxncachettl;
127 dns_rdatatype_t preferred_glue;
129 dns_namelist_t * delonly;
130 isc_boolean_t rootdelonly;
131 dns_namelist_t * rootexclude;
132 isc_boolean_t checknames;
134 dns_fixedname_t dlv_fixed;
138 * Configurable data for server use only,
139 * locked by server configuration lock.
141 dns_acl_t * matchclients;
142 dns_acl_t * matchdestinations;
143 isc_boolean_t matchrecursiveonly;
145 /* Locked by themselves. */
146 isc_refcount_t references;
148 /* Locked by lock. */
149 unsigned int weakrefs;
150 unsigned int attributes;
151 /* Under owner's locking control. */
152 ISC_LINK(struct dns_view) link;
155 #define DNS_VIEW_MAGIC ISC_MAGIC('V','i','e','w')
156 #define DNS_VIEW_VALID(view) ISC_MAGIC_VALID(view, DNS_VIEW_MAGIC)
158 #define DNS_VIEWATTR_RESSHUTDOWN 0x01
159 #define DNS_VIEWATTR_ADBSHUTDOWN 0x02
160 #define DNS_VIEWATTR_REQSHUTDOWN 0x04
163 dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
164 const char *name, dns_view_t **viewp);
170 *\li The newly created view has no cache, no resolver, and an empty
171 * zone table. The view is not frozen.
175 *\li 'mctx' is a valid memory context.
177 *\li 'rdclass' is a valid class.
179 *\li 'name' is a valid C string.
181 *\li viewp != NULL && *viewp == NULL
188 *\li Other errors are possible.
192 dns_view_attach(dns_view_t *source, dns_view_t **targetp);
194 * Attach '*targetp' to 'source'.
198 *\li 'source' is a valid, frozen view.
200 *\li 'targetp' points to a NULL dns_view_t *.
204 *\li *targetp is attached to source.
206 *\li While *targetp is attached, the view will not shut down.
210 dns_view_detach(dns_view_t **viewp);
212 * Detach '*viewp' from its view.
216 *\li 'viewp' points to a valid dns_view_t *
224 dns_view_flushanddetach(dns_view_t **viewp);
226 * Detach '*viewp' from its view. If this was the last reference
227 * uncommited changed in zones will be flushed to disk.
231 *\li 'viewp' points to a valid dns_view_t *
239 dns_view_weakattach(dns_view_t *source, dns_view_t **targetp);
241 * Weakly attach '*targetp' to 'source'.
245 *\li 'source' is a valid, frozen view.
247 *\li 'targetp' points to a NULL dns_view_t *.
251 *\li *targetp is attached to source.
253 * \li While *targetp is attached, the view will not be freed.
257 dns_view_weakdetach(dns_view_t **targetp);
259 * Detach '*viewp' from its view.
263 *\li 'viewp' points to a valid dns_view_t *.
271 dns_view_createresolver(dns_view_t *view,
272 isc_taskmgr_t *taskmgr, unsigned int ntasks,
273 isc_socketmgr_t *socketmgr,
274 isc_timermgr_t *timermgr,
275 unsigned int options,
276 dns_dispatchmgr_t *dispatchmgr,
277 dns_dispatch_t *dispatchv4,
278 dns_dispatch_t *dispatchv6);
280 * Create a resolver and address database for the view.
284 *\li 'view' is a valid, unfrozen view.
286 *\li 'view' does not have a resolver already.
288 *\li The requirements of dns_resolver_create() apply to 'taskmgr',
289 * 'ntasks', 'socketmgr', 'timermgr', 'options', 'dispatchv4', and
296 *\li Any error that dns_resolver_create() can return.
300 dns_view_setcache(dns_view_t *view, dns_cache_t *cache);
302 * Set the view's cache database.
306 *\li 'view' is a valid, unfrozen view.
308 *\li 'cache' is a valid cache.
312 * \li The cache of 'view' is 'cached.
314 *\li If this is not the first call to dns_view_setcache() for this
315 * view, then previously set cache is detached.
319 dns_view_sethints(dns_view_t *view, dns_db_t *hints);
321 * Set the view's hints database.
325 *\li 'view' is a valid, unfrozen view, whose hints database has not been
328 *\li 'hints' is a valid zone database.
332 * \li The hints database of 'view' is 'hints'.
336 dns_view_setkeyring(dns_view_t *view, dns_tsig_keyring_t *ring);
338 * Set the view's static TSIG keys
342 * \li 'view' is a valid, unfrozen view, whose static TSIG keyring has not
345 *\li 'ring' is a valid TSIG keyring
349 *\li The static TSIG keyring of 'view' is 'ring'.
353 dns_view_setdstport(dns_view_t *view, in_port_t dstport);
355 * Set the view's destination port. This is the port to
356 * which outgoing queries are sent. The default is 53,
357 * the standard DNS port.
361 *\li 'view' is a valid view.
363 *\li 'dstport' is a valid TCP/UDP port number.
366 *\li External name servers will be assumed to be listning
367 * on 'dstport'. For servers whose address has already
368 * obtained obtained at the time of the call, the view may
369 * continue to use the previously set port until the address
370 * times out from the view's address database.
375 dns_view_addzone(dns_view_t *view, dns_zone_t *zone);
377 * Add zone 'zone' to 'view'.
381 *\li 'view' is a valid, unfrozen view.
383 *\li 'zone' is a valid zone.
387 dns_view_freeze(dns_view_t *view);
393 *\li 'view' is a valid, unfrozen view.
397 *\li 'view' is frozen.
401 dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
402 isc_stdtime_t now, unsigned int options, isc_boolean_t use_hints,
403 dns_db_t **dbp, dns_dbnode_t **nodep, dns_name_t *foundname,
404 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
406 * Find an rdataset whose owner name is 'name', and whose type is
411 *\li See the description of dns_db_find() for information about 'options'.
412 * If the caller sets #DNS_DBFIND_GLUEOK, it must ensure that 'name'
413 * and 'type' are appropriate for glue retrieval.
415 *\li If 'now' is zero, then the current time will be used.
417 *\li If 'use_hints' is ISC_TRUE, and the view has a hints database, then
418 * it will be searched last. If the answer is found in the hints
419 * database, the result code will be DNS_R_HINT. If the name is found
420 * in the hints database but not the type, the result code will be
421 * #DNS_R_HINTNXRRSET.
423 *\li 'foundname' must meet the requirements of dns_db_find().
425 *\li If 'sigrdataset' is not NULL, and there is a SIG rdataset which
426 * covers 'type', then 'sigrdataset' will be bound to it.
430 *\li 'view' is a valid, frozen view.
432 *\li 'name' is valid name.
434 *\li 'type' is a valid dns_rdatatype_t, and is not a meta query type
435 * except dns_rdatatype_any.
437 *\li dbp == NULL || *dbp == NULL
439 *\li nodep == NULL || *nodep == NULL. If nodep != NULL, dbp != NULL.
441 *\li 'foundname' is a valid name with a dedicated buffer or NULL.
443 *\li 'rdataset' is a valid, disassociated rdataset.
445 *\li 'sigrdataset' is NULL, or is a valid, disassociated rdataset.
449 *\li In successful cases, 'rdataset', and possibly 'sigrdataset', are
450 * bound to the found data.
452 *\li If dbp != NULL, it points to the database containing the data.
454 *\li If nodep != NULL, it points to the database node containing the data.
456 *\li If foundname != NULL, it contains the full name of the found data.
460 *\li Any result that dns_db_find() can return, with the exception of
465 dns_view_simplefind(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
466 isc_stdtime_t now, unsigned int options,
467 isc_boolean_t use_hints,
468 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
470 * Find an rdataset whose owner name is 'name', and whose type is
475 *\li This routine is appropriate for simple, exact-match queries of the
476 * view. 'name' must be a canonical name; there is no DNAME or CNAME
479 *\li See the description of dns_db_find() for information about 'options'.
480 * If the caller sets DNS_DBFIND_GLUEOK, it must ensure that 'name'
481 * and 'type' are appropriate for glue retrieval.
483 *\li If 'now' is zero, then the current time will be used.
485 *\li If 'use_hints' is ISC_TRUE, and the view has a hints database, then
486 * it will be searched last. If the answer is found in the hints
487 * database, the result code will be DNS_R_HINT. If the name is found
488 * in the hints database but not the type, the result code will be
491 *\li If 'sigrdataset' is not NULL, and there is a SIG rdataset which
492 * covers 'type', then 'sigrdataset' will be bound to it.
496 *\li 'view' is a valid, frozen view.
498 *\li 'name' is valid name.
500 *\li 'type' is a valid dns_rdatatype_t, and is not a meta query type
501 * (e.g. dns_rdatatype_any), or dns_rdatatype_rrsig.
503 *\li 'rdataset' is a valid, disassociated rdataset.
505 *\li 'sigrdataset' is NULL, or is a valid, disassociated rdataset.
509 *\li In successful cases, 'rdataset', and possibly 'sigrdataset', are
510 * bound to the found data.
514 *\li #ISC_R_SUCCESS Success; result is desired type.
515 *\li DNS_R_GLUE Success; result is glue.
516 *\li DNS_R_HINT Success; result is a hint.
517 *\li DNS_R_NCACHENXDOMAIN Success; result is a ncache entry.
518 *\li DNS_R_NCACHENXRRSET Success; result is a ncache entry.
519 *\li DNS_R_NXDOMAIN The name does not exist.
520 *\li DNS_R_NXRRSET The rrset does not exist.
521 *\li #ISC_R_NOTFOUND No matching data found,
522 * or an error occurred.
525 /*% See dns_view_findzonecut2() */
527 dns_view_findzonecut(dns_view_t *view, dns_name_t *name, dns_name_t *fname,
528 isc_stdtime_t now, unsigned int options,
529 isc_boolean_t use_hints,
530 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
533 dns_view_findzonecut2(dns_view_t *view, dns_name_t *name, dns_name_t *fname,
534 isc_stdtime_t now, unsigned int options,
535 isc_boolean_t use_hints, isc_boolean_t use_cache,
536 dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
538 * Find the best known zonecut containing 'name'.
540 * This uses local authority, cache, and optionally hints data.
541 * No external queries are performed.
545 *\li If 'now' is zero, then the current time will be used.
547 *\li If 'use_hints' is ISC_TRUE, and the view has a hints database, then
548 * it will be searched last.
550 *\li If 'use_cache' is ISC_TRUE, and the view has a cache, then it will be
553 *\li If 'sigrdataset' is not NULL, and there is a SIG rdataset which
554 * covers 'type', then 'sigrdataset' will be bound to it.
556 *\li If the DNS_DBFIND_NOEXACT option is set, then the zonecut returned
557 * (if any) will be the deepest known ancestor of 'name'.
561 *\li 'view' is a valid, frozen view.
563 *\li 'name' is valid name.
565 *\li 'rdataset' is a valid, disassociated rdataset.
567 *\li 'sigrdataset' is NULL, or is a valid, disassociated rdataset.
571 *\li #ISC_R_SUCCESS Success.
573 *\li Many other results are possible.
577 dns_viewlist_find(dns_viewlist_t *list, const char *name,
578 dns_rdataclass_t rdclass, dns_view_t **viewp);
580 * Search for a view with name 'name' and class 'rdclass' in 'list'.
581 * If found, '*viewp' is (strongly) attached to it.
585 *\li 'viewp' points to a NULL dns_view_t *.
589 *\li #ISC_R_SUCCESS A matching view was found.
590 *\li #ISC_R_NOTFOUND No matching view was found.
594 dns_view_findzone(dns_view_t *view, dns_name_t *name, dns_zone_t **zonep);
596 * Search for the zone 'name' in the zone table of 'view'.
597 * If found, 'zonep' is (strongly) attached to it. There
598 * are no partial matches.
602 *\li 'zonep' points to a NULL dns_zone_t *.
605 *\li #ISC_R_SUCCESS A matching zone was found.
606 *\li #ISC_R_NOTFOUND No matching zone was found.
607 *\li others An error occurred.
611 dns_view_load(dns_view_t *view, isc_boolean_t stop);
614 dns_view_loadnew(dns_view_t *view, isc_boolean_t stop);
616 * Load zones attached to this view. dns_view_load() loads
617 * all zones whose master file has changed since the last
618 * load; dns_view_loadnew() loads only zones that have never
621 * If 'stop' is ISC_TRUE, stop on the first error and return it.
622 * If 'stop' is ISC_FALSE, ignore errors.
626 *\li 'view' is valid.
630 dns_view_gettsig(dns_view_t *view, dns_name_t *keyname,
631 dns_tsigkey_t **keyp);
633 * Find the TSIG key configured in 'view' with name 'keyname',
637 *\li keyp points to a NULL dns_tsigkey_t *.
640 *\li #ISC_R_SUCCESS A key was found and '*keyp' now points to it.
641 *\li #ISC_R_NOTFOUND No key was found.
642 *\li others An error occurred.
646 dns_view_getpeertsig(dns_view_t *view, isc_netaddr_t *peeraddr,
647 dns_tsigkey_t **keyp);
649 * Find the TSIG key configured in 'view' for the server whose
650 * address is 'peeraddr', if any.
653 * keyp points to a NULL dns_tsigkey_t *.
656 *\li #ISC_R_SUCCESS A key was found and '*keyp' now points to it.
657 *\li #ISC_R_NOTFOUND No key was found.
658 *\li others An error occurred.
662 dns_view_checksig(dns_view_t *view, isc_buffer_t *source, dns_message_t *msg);
664 * Verifies the signature of a message.
668 *\li 'view' is a valid view.
669 *\li 'source' is a valid buffer containing the message
670 *\li 'msg' is a valid message
673 *\li see dns_tsig_verify()
677 dns_view_dialup(dns_view_t *view);
679 * Perform dialup-time maintenance on the zones of 'view'.
683 dns_view_dumpdbtostream(dns_view_t *view, FILE *fp);
685 * Dump the current state of the view 'view' to the stream 'fp'
686 * for purposes of analysis or debugging.
688 * Currently the dumped state includes the view's cache; in the future
689 * it may also include other state such as the address database.
690 * It will not not include authoritative data since it is voluminous and
691 * easily obtainable by other means.
695 *\li 'view' is valid.
697 *\li 'fp' refers to a file open for writing.
700 * \li ISC_R_SUCCESS The cache was successfully dumped.
701 * \li others An error occurred (see dns_master_dump)
705 dns_view_flushcache(dns_view_t *view);
707 * Flush the view's cache (and ADB).
712 * No other tasks are executing.
720 dns_view_flushname(dns_view_t *view, dns_name_t *);
722 * Flush the given name from the view's cache (and ADB).
725 *\li 'view' is valid.
726 *\li 'name' is valid.
730 * other returns are failures.
734 dns_view_adddelegationonly(dns_view_t *view, dns_name_t *name);
736 * Add the given name to the delegation only table.
740 *\li 'view' is valid.
741 *\li 'name' is valid.
749 dns_view_excludedelegationonly(dns_view_t *view, dns_name_t *name);
751 * Add the given name to be excluded from the root-delegation-only.
755 *\li 'view' is valid.
756 *\li 'name' is valid.
764 dns_view_isdelegationonly(dns_view_t *view, dns_name_t *name);
766 * Check if 'name' is in the delegation only table or if
767 * rootdelonly is set that name is not being excluded.
770 *\li 'view' is valid.
771 *\li 'name' is valid.
774 *\li #ISC_TRUE if the name is is the table.
775 *\li #ISC_FALSE othewise.
779 dns_view_setrootdelonly(dns_view_t *view, isc_boolean_t value);
781 * Set the root delegation only flag.
784 *\li 'view' is valid.
788 dns_view_getrootdelonly(dns_view_t *view);
790 * Get the root delegation only flag.
793 *\li 'view' is valid.
797 dns_view_freezezones(dns_view_t *view, isc_boolean_t freeze);
799 * Freeze/thaw updates to master zones.
802 * \li 'view' is valid.
804 #endif /* DNS_VIEW_H */