]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/bind9/lib/dns/include/dns/view.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / bind9 / lib / dns / include / dns / view.h
1 /*
2  * Copyright (C) 2004-2012  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$ */
19
20 #ifndef DNS_VIEW_H
21 #define DNS_VIEW_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*! \file dns/view.h
28  * \brief
29  * DNS View
30  *
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.
35  *
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.
43  *
44  * MP:
45  *\li   Before the view is frozen, the caller must ensure synchronization.
46  *
47  *\li   After the view is frozen, the module guarantees appropriate
48  *      synchronization of any data structures it creates and manipulates.
49  *
50  * Reliability:
51  *\li   No anticipated impact.
52  *
53  * Resources:
54  *\li   TBS
55  *
56  * Security:
57  *\li   No anticipated impact.
58  *
59  * Standards:
60  *\li   None.
61  */
62
63 #include <stdio.h>
64
65 #include <isc/lang.h>
66 #include <isc/magic.h>
67 #include <isc/event.h>
68 #include <isc/mutex.h>
69 #include <isc/net.h>
70 #include <isc/refcount.h>
71 #include <isc/rwlock.h>
72 #include <isc/stdtime.h>
73
74 #include <dns/acl.h>
75 #include <dns/fixedname.h>
76 #include <dns/rdatastruct.h>
77 #include <dns/rpz.h>
78 #include <dns/types.h>
79
80 ISC_LANG_BEGINDECLS
81
82 struct dns_view {
83         /* Unlocked. */
84         unsigned int                    magic;
85         isc_mem_t *                     mctx;
86         dns_rdataclass_t                rdclass;
87         char *                          name;
88         dns_zt_t *                      zonetable;
89         dns_dlzdb_t *                   dlzdatabase;
90         dns_resolver_t *                resolver;
91         dns_adb_t *                     adb;
92         dns_requestmgr_t *              requestmgr;
93         dns_acache_t *                  acache;
94         dns_cache_t *                   cache;
95         dns_db_t *                      cachedb;
96         dns_db_t *                      hints;
97
98         /*
99          * security roots.
100          * internal use only; access via * dns_view_getsecroots()
101          */
102         dns_keytable_t *                secroots_priv;
103
104         isc_mutex_t                     lock;
105         isc_boolean_t                   frozen;
106         isc_task_t *                    task;
107         isc_event_t                     resevent;
108         isc_event_t                     adbevent;
109         isc_event_t                     reqevent;
110         isc_stats_t *                   resstats;
111         dns_stats_t *                   resquerystats;
112         isc_boolean_t                   cacheshared;
113
114         /* Configurable data. */
115         dns_tsig_keyring_t *            statickeys;
116         dns_tsig_keyring_t *            dynamickeys;
117         dns_peerlist_t *                peers;
118         dns_order_t *                   order;
119         dns_fwdtable_t *                fwdtable;
120         isc_boolean_t                   recursion;
121         isc_boolean_t                   auth_nxdomain;
122         isc_boolean_t                   additionalfromcache;
123         isc_boolean_t                   additionalfromauth;
124         isc_boolean_t                   minimalresponses;
125         isc_boolean_t                   enablednssec;
126         isc_boolean_t                   enablevalidation;
127         isc_boolean_t                   acceptexpired;
128         dns_transfer_format_t           transfer_format;
129         dns_acl_t *                     cacheacl;
130         dns_acl_t *                     cacheonacl;
131         dns_acl_t *                     queryacl;
132         dns_acl_t *                     queryonacl;
133         dns_acl_t *                     recursionacl;
134         dns_acl_t *                     recursiononacl;
135         dns_acl_t *                     sortlist;
136         dns_acl_t *                     notifyacl;
137         dns_acl_t *                     transferacl;
138         dns_acl_t *                     updateacl;
139         dns_acl_t *                     upfwdacl;
140         dns_acl_t *                     denyansweracl;
141         dns_rbt_t *                     answeracl_exclude;
142         dns_rbt_t *                     denyanswernames;
143         dns_rbt_t *                     answernames_exclude;
144         isc_boolean_t                   requestixfr;
145         isc_boolean_t                   provideixfr;
146         isc_boolean_t                   requestnsid;
147         dns_ttl_t                       maxcachettl;
148         dns_ttl_t                       maxncachettl;
149         in_port_t                       dstport;
150         dns_aclenv_t                    aclenv;
151         dns_rdatatype_t                 preferred_glue;
152         isc_boolean_t                   flush;
153         dns_namelist_t *                delonly;
154         isc_boolean_t                   rootdelonly;
155         dns_namelist_t *                rootexclude;
156         isc_boolean_t                   checknames;
157         dns_name_t *                    dlv;
158         dns_fixedname_t                 dlv_fixed;
159         isc_uint16_t                    maxudp;
160         dns_v4_aaaa_t                   v4_aaaa;
161         dns_acl_t *                     v4_aaaa_acl;
162         dns_dns64list_t                 dns64;
163         unsigned int                    dns64cnt;
164         ISC_LIST(dns_rpz_zone_t)        rpz_zones;
165         isc_boolean_t                   rpz_recursive_only;
166         isc_boolean_t                   rpz_break_dnssec;
167
168         /*
169          * Configurable data for server use only,
170          * locked by server configuration lock.
171          */
172         dns_acl_t *                     matchclients;
173         dns_acl_t *                     matchdestinations;
174         isc_boolean_t                   matchrecursiveonly;
175
176         /* Locked by themselves. */
177         isc_refcount_t                  references;
178
179         /* Locked by lock. */
180         unsigned int                    weakrefs;
181         unsigned int                    attributes;
182         /* Under owner's locking control. */
183         ISC_LINK(struct dns_view)       link;
184         dns_viewlist_t *                viewlist;
185
186         dns_zone_t *                    managed_keys;
187
188 #ifdef BIND9
189         /* File in which to store configuration for newly added zones */
190         char *                          new_zone_file;
191
192         void *                          new_zone_config;
193         void                            (*cfg_destroy)(void **);
194 #endif
195 };
196
197 #define DNS_VIEW_MAGIC                  ISC_MAGIC('V','i','e','w')
198 #define DNS_VIEW_VALID(view)            ISC_MAGIC_VALID(view, DNS_VIEW_MAGIC)
199
200 #define DNS_VIEWATTR_RESSHUTDOWN        0x01
201 #define DNS_VIEWATTR_ADBSHUTDOWN        0x02
202 #define DNS_VIEWATTR_REQSHUTDOWN        0x04
203
204 isc_result_t
205 dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass,
206                 const char *name, dns_view_t **viewp);
207 /*%<
208  * Create a view.
209  *
210  * Notes:
211  *
212  *\li   The newly created view has no cache, no resolver, and an empty
213  *      zone table.  The view is not frozen.
214  *
215  * Requires:
216  *
217  *\li   'mctx' is a valid memory context.
218  *
219  *\li   'rdclass' is a valid class.
220  *
221  *\li   'name' is a valid C string.
222  *
223  *\li   viewp != NULL && *viewp == NULL
224  *
225  * Returns:
226  *
227  *\li   #ISC_R_SUCCESS
228  *\li   #ISC_R_NOMEMORY
229  *
230  *\li   Other errors are possible.
231  */
232
233 void
234 dns_view_attach(dns_view_t *source, dns_view_t **targetp);
235 /*%<
236  * Attach '*targetp' to 'source'.
237  *
238  * Requires:
239  *
240  *\li   'source' is a valid, frozen view.
241  *
242  *\li   'targetp' points to a NULL dns_view_t *.
243  *
244  * Ensures:
245  *
246  *\li   *targetp is attached to source.
247  *
248  *\li   While *targetp is attached, the view will not shut down.
249  */
250
251 void
252 dns_view_detach(dns_view_t **viewp);
253 /*%<
254  * Detach '*viewp' from its view.
255  *
256  * Requires:
257  *
258  *\li   'viewp' points to a valid dns_view_t *
259  *
260  * Ensures:
261  *
262  *\li   *viewp is NULL.
263  */
264
265 void
266 dns_view_flushanddetach(dns_view_t **viewp);
267 /*%<
268  * Detach '*viewp' from its view.  If this was the last reference
269  * uncommitted changed in zones will be flushed to disk.
270  *
271  * Requires:
272  *
273  *\li   'viewp' points to a valid dns_view_t *
274  *
275  * Ensures:
276  *
277  *\li   *viewp is NULL.
278  */
279
280 void
281 dns_view_weakattach(dns_view_t *source, dns_view_t **targetp);
282 /*%<
283  * Weakly attach '*targetp' to 'source'.
284  *
285  * Requires:
286  *
287  *\li   'source' is a valid, frozen view.
288  *
289  *\li   'targetp' points to a NULL dns_view_t *.
290  *
291  * Ensures:
292  *
293  *\li   *targetp is attached to source.
294  *
295  * \li  While *targetp is attached, the view will not be freed.
296  */
297
298 void
299 dns_view_weakdetach(dns_view_t **targetp);
300 /*%<
301  * Detach '*viewp' from its view.
302  *
303  * Requires:
304  *
305  *\li   'viewp' points to a valid dns_view_t *.
306  *
307  * Ensures:
308  *
309  *\li   *viewp is NULL.
310  */
311
312 isc_result_t
313 dns_view_createresolver(dns_view_t *view,
314                         isc_taskmgr_t *taskmgr, unsigned int ntasks,
315                         isc_socketmgr_t *socketmgr,
316                         isc_timermgr_t *timermgr,
317                         unsigned int options,
318                         dns_dispatchmgr_t *dispatchmgr,
319                         dns_dispatch_t *dispatchv4,
320                         dns_dispatch_t *dispatchv6);
321 /*%<
322  * Create a resolver and address database for the view.
323  *
324  * Requires:
325  *
326  *\li   'view' is a valid, unfrozen view.
327  *
328  *\li   'view' does not have a resolver already.
329  *
330  *\li   The requirements of dns_resolver_create() apply to 'taskmgr',
331  *      'ntasks', 'socketmgr', 'timermgr', 'options', 'dispatchv4', and
332  *      'dispatchv6'.
333  *
334  * Returns:
335  *
336  *\li           #ISC_R_SUCCESS
337  *
338  *\li   Any error that dns_resolver_create() can return.
339  */
340
341 void
342 dns_view_setcache(dns_view_t *view, dns_cache_t *cache);
343 void
344 dns_view_setcache2(dns_view_t *view, dns_cache_t *cache, isc_boolean_t shared);
345 /*%<
346  * Set the view's cache database.  If 'shared' is true, this means the cache
347  * is created by another view and is shared with that view.  dns_view_setcache()
348  * is a backward compatible version equivalent to setcache2(..., ISC_FALSE).
349  *
350  * Requires:
351  *
352  *\li   'view' is a valid, unfrozen view.
353  *
354  *\li   'cache' is a valid cache.
355  *
356  * Ensures:
357  *
358  * \li          The cache of 'view' is 'cached.
359  *
360  *\li   If this is not the first call to dns_view_setcache() for this
361  *      view, then previously set cache is detached.
362  */
363
364 void
365 dns_view_sethints(dns_view_t *view, dns_db_t *hints);
366 /*%<
367  * Set the view's hints database.
368  *
369  * Requires:
370  *
371  *\li   'view' is a valid, unfrozen view, whose hints database has not been
372  *      set.
373  *
374  *\li   'hints' is a valid zone database.
375  *
376  * Ensures:
377  *
378  * \li          The hints database of 'view' is 'hints'.
379  */
380
381 void
382 dns_view_setkeyring(dns_view_t *view, dns_tsig_keyring_t *ring);
383 void
384 dns_view_setdynamickeyring(dns_view_t *view, dns_tsig_keyring_t *ring);
385 /*%<
386  * Set the view's static TSIG keys
387  *
388  * Requires:
389  *
390  *   \li   'view' is a valid, unfrozen view, whose static TSIG keyring has not
391  *      been set.
392  *
393  *\li      'ring' is a valid TSIG keyring
394  *
395  * Ensures:
396  *
397  *\li      The static TSIG keyring of 'view' is 'ring'.
398  */
399
400 void
401 dns_view_getdynamickeyring(dns_view_t *view, dns_tsig_keyring_t **ringp);
402 /*%<
403  * Return the views dynamic keys.
404  *
405  *   \li  'view' is a valid, unfrozen view.
406  *   \li  'ringp' != NULL && ringp == NULL.
407  */
408
409 void
410 dns_view_setdstport(dns_view_t *view, in_port_t dstport);
411 /*%<
412  * Set the view's destination port.  This is the port to
413  * which outgoing queries are sent.  The default is 53,
414  * the standard DNS port.
415  *
416  * Requires:
417  *
418  *\li      'view' is a valid view.
419  *
420  *\li      'dstport' is a valid TCP/UDP port number.
421  *
422  * Ensures:
423  *\li   External name servers will be assumed to be listening
424  *      on 'dstport'.  For servers whose address has already
425  *      obtained obtained at the time of the call, the view may
426  *      continue to use the previously set port until the address
427  *      times out from the view's address database.
428  */
429
430
431 isc_result_t
432 dns_view_addzone(dns_view_t *view, dns_zone_t *zone);
433 /*%<
434  * Add zone 'zone' to 'view'.
435  *
436  * Requires:
437  *
438  *\li   'view' is a valid, unfrozen view.
439  *
440  *\li   'zone' is a valid zone.
441  */
442
443 void
444 dns_view_freeze(dns_view_t *view);
445 /*%<
446  * Freeze view.  No changes can be made to view configuration while frozen.
447  *
448  * Requires:
449  *
450  *\li   'view' is a valid, unfrozen view.
451  *
452  * Ensures:
453  *
454  *\li   'view' is frozen.
455  */
456
457 void
458 dns_view_thaw(dns_view_t *view);
459 /*%<
460  * Thaw view.  This allows zones to be added or removed at runtime.  This is
461  * NOT thread-safe; the caller MUST have run isc_task_exclusive() prior to
462  * thawing the view.
463  *
464  * Requires:
465  *
466  *\li   'view' is a valid, frozen view.
467  *
468  * Ensures:
469  *
470  *\li   'view' is no longer frozen.
471  */
472 isc_result_t
473 dns_view_find(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
474               isc_stdtime_t now, unsigned int options, isc_boolean_t use_hints,
475               dns_db_t **dbp, dns_dbnode_t **nodep, dns_name_t *foundname,
476               dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
477 isc_result_t
478 dns_view_find2(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
479                isc_stdtime_t now, unsigned int options,
480                isc_boolean_t use_hints, isc_boolean_t use_static_stub,
481                dns_db_t **dbp, dns_dbnode_t **nodep, dns_name_t *foundname,
482                dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
483 /*%<
484  * Find an rdataset whose owner name is 'name', and whose type is
485  * 'type'.
486  * In general, this function first searches view's zone and cache DBs for the
487  * best match data against 'name'.  If nothing found there, and if 'use_hints'
488  * is ISC_TRUE, the view's hint DB (if configured) is searched.
489  * If the view is configured with a static-stub zone which gives the longest
490  * match for 'name' among the zones, however, the cache DB is not consulted
491  * unless 'use_static_stub' is ISC_FALSE (see below about this argument).
492  *
493  * dns_view_find() is a backward compatible version equivalent to
494  * dns_view_find2() with use_static_stub argument being ISC_FALSE.
495  *
496  * Notes:
497  *
498  *\li   See the description of dns_db_find() for information about 'options'.
499  *      If the caller sets #DNS_DBFIND_GLUEOK, it must ensure that 'name'
500  *      and 'type' are appropriate for glue retrieval.
501  *
502  *\li   If 'now' is zero, then the current time will be used.
503  *
504  *\li   If 'use_hints' is ISC_TRUE, and the view has a hints database, then
505  *      it will be searched last.  If the answer is found in the hints
506  *      database, the result code will be DNS_R_HINT.  If the name is found
507  *      in the hints database but not the type, the result code will be
508  *      #DNS_R_HINTNXRRSET.
509  *
510  *\li   If 'use_static_stub' is ISC_FALSE and the longest match zone for 'name'
511  *      is a static-stub zone, it's ignored and the cache and/or hints will be
512  *      searched.  In the majority of the cases this argument should be
513  *      ISC_FALSE.  The only known usage of this argument being ISC_TRUE is
514  *      if this search is for a "bailiwick" glue A or AAAA RRset that may
515  *      best match a static-stub zone.  Consider the following example:
516  *      this view is configured with a static-stub zone "example.com",
517  *      and an attempt of recursive resolution needs to send a query for the
518  *      zone.  In this case it's quite likely that the resolver is trying to
519  *      find A/AAAA RRs for the apex name "example.com".  And, to honor the
520  *      static-stub configuration it needs to return the glue RRs in the
521  *      static-stub zone even if that exact RRs coming from the authoritative
522  *      zone has been cached.
523  *      In other general cases, the requested data is better to be
524  *      authoritative, either locally configured or retrieved from an external
525  *      server, and the data in the static-stub zone should better be ignored.
526  *
527  *\li   'foundname' must meet the requirements of dns_db_find().
528  *
529  *\li   If 'sigrdataset' is not NULL, and there is a SIG rdataset which
530  *      covers 'type', then 'sigrdataset' will be bound to it.
531  *
532  * Requires:
533  *
534  *\li   'view' is a valid, frozen view.
535  *
536  *\li   'name' is valid name.
537  *
538  *\li   'type' is a valid dns_rdatatype_t, and is not a meta query type
539  *      except dns_rdatatype_any.
540  *
541  *\li   dbp == NULL || *dbp == NULL
542  *
543  *\li   nodep == NULL || *nodep == NULL.  If nodep != NULL, dbp != NULL.
544  *
545  *\li   'foundname' is a valid name with a dedicated buffer or NULL.
546  *
547  *\li   'rdataset' is a valid, disassociated rdataset.
548  *
549  *\li   'sigrdataset' is NULL, or is a valid, disassociated rdataset.
550  *
551  * Ensures:
552  *
553  *\li   In successful cases, 'rdataset', and possibly 'sigrdataset', are
554  *      bound to the found data.
555  *
556  *\li   If dbp != NULL, it points to the database containing the data.
557  *
558  *\li   If nodep != NULL, it points to the database node containing the data.
559  *
560  *\li   If foundname != NULL, it contains the full name of the found data.
561  *
562  * Returns:
563  *
564  *\li   Any result that dns_db_find() can return, with the exception of
565  *      #DNS_R_DELEGATION.
566  */
567
568 isc_result_t
569 dns_view_simplefind(dns_view_t *view, dns_name_t *name, dns_rdatatype_t type,
570                     isc_stdtime_t now, unsigned int options,
571                     isc_boolean_t use_hints,
572                     dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
573 /*%<
574  * Find an rdataset whose owner name is 'name', and whose type is
575  * 'type'.
576  *
577  * Notes:
578  *
579  *\li   This routine is appropriate for simple, exact-match queries of the
580  *      view.  'name' must be a canonical name; there is no DNAME or CNAME
581  *      processing.
582  *
583  *\li   See the description of dns_db_find() for information about 'options'.
584  *      If the caller sets DNS_DBFIND_GLUEOK, it must ensure that 'name'
585  *      and 'type' are appropriate for glue retrieval.
586  *
587  *\li   If 'now' is zero, then the current time will be used.
588  *
589  *\li   If 'use_hints' is ISC_TRUE, and the view has a hints database, then
590  *      it will be searched last.  If the answer is found in the hints
591  *      database, the result code will be DNS_R_HINT.  If the name is found
592  *      in the hints database but not the type, the result code will be
593  *      DNS_R_HINTNXRRSET.
594  *
595  *\li   If 'sigrdataset' is not NULL, and there is a SIG rdataset which
596  *      covers 'type', then 'sigrdataset' will be bound to it.
597  *
598  * Requires:
599  *
600  *\li   'view' is a valid, frozen view.
601  *
602  *\li   'name' is valid name.
603  *
604  *\li   'type' is a valid dns_rdatatype_t, and is not a meta query type
605  *      (e.g. dns_rdatatype_any), or dns_rdatatype_rrsig.
606  *
607  *\li   'rdataset' is a valid, disassociated rdataset.
608  *
609  *\li   'sigrdataset' is NULL, or is a valid, disassociated rdataset.
610  *
611  * Ensures:
612  *
613  *\li   In successful cases, 'rdataset', and possibly 'sigrdataset', are
614  *      bound to the found data.
615  *
616  * Returns:
617  *
618  *\li   #ISC_R_SUCCESS                  Success; result is desired type.
619  *\li   DNS_R_GLUE                      Success; result is glue.
620  *\li   DNS_R_HINT                      Success; result is a hint.
621  *\li   DNS_R_NCACHENXDOMAIN            Success; result is a ncache entry.
622  *\li   DNS_R_NCACHENXRRSET             Success; result is a ncache entry.
623  *\li   DNS_R_NXDOMAIN                  The name does not exist.
624  *\li   DNS_R_NXRRSET                   The rrset does not exist.
625  *\li   #ISC_R_NOTFOUND                 No matching data found,
626  *                                      or an error occurred.
627  */
628
629 /*% See dns_view_findzonecut2() */
630 isc_result_t
631 dns_view_findzonecut(dns_view_t *view, dns_name_t *name, dns_name_t *fname,
632                      isc_stdtime_t now, unsigned int options,
633                      isc_boolean_t use_hints,
634                      dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
635
636 isc_result_t
637 dns_view_findzonecut2(dns_view_t *view, dns_name_t *name, dns_name_t *fname,
638                       isc_stdtime_t now, unsigned int options,
639                       isc_boolean_t use_hints, isc_boolean_t use_cache,
640                       dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset);
641 /*%<
642  * Find the best known zonecut containing 'name'.
643  *
644  * This uses local authority, cache, and optionally hints data.
645  * No external queries are performed.
646  *
647  * Notes:
648  *
649  *\li   If 'now' is zero, then the current time will be used.
650  *
651  *\li   If 'use_hints' is ISC_TRUE, and the view has a hints database, then
652  *      it will be searched last.
653  *
654  *\li   If 'use_cache' is ISC_TRUE, and the view has a cache, then it will be
655  *      searched.
656  *
657  *\li   If 'sigrdataset' is not NULL, and there is a SIG rdataset which
658  *      covers 'type', then 'sigrdataset' will be bound to it.
659  *
660  *\li   If the DNS_DBFIND_NOEXACT option is set, then the zonecut returned
661  *      (if any) will be the deepest known ancestor of 'name'.
662  *
663  * Requires:
664  *
665  *\li   'view' is a valid, frozen view.
666  *
667  *\li   'name' is valid name.
668  *
669  *\li   'rdataset' is a valid, disassociated rdataset.
670  *
671  *\li   'sigrdataset' is NULL, or is a valid, disassociated rdataset.
672  *
673  * Returns:
674  *
675  *\li   #ISC_R_SUCCESS                          Success.
676  *
677  *\li   Many other results are possible.
678  */
679
680 isc_result_t
681 dns_viewlist_find(dns_viewlist_t *list, const char *name,
682                   dns_rdataclass_t rdclass, dns_view_t **viewp);
683 /*%<
684  * Search for a view with name 'name' and class 'rdclass' in 'list'.
685  * If found, '*viewp' is (strongly) attached to it.
686  *
687  * Requires:
688  *
689  *\li   'viewp' points to a NULL dns_view_t *.
690  *
691  * Returns:
692  *
693  *\li   #ISC_R_SUCCESS          A matching view was found.
694  *\li   #ISC_R_NOTFOUND         No matching view was found.
695  */
696
697 isc_result_t
698 dns_viewlist_findzone(dns_viewlist_t *list, dns_name_t *name, isc_boolean_t allclasses,
699                       dns_rdataclass_t rdclass, dns_zone_t **zonep);
700
701 /*%<
702  * Search zone with 'name' in view with 'rdclass' in viewlist 'list'
703  * If found, zone is returned in *zonep. If allclasses is set rdclass is ignored
704  *
705  * Returns:
706  *\li   #ISC_R_SUCCESS          A matching zone was found.
707  *\li   #ISC_R_NOTFOUND         No matching zone was found.
708  */
709
710 isc_result_t
711 dns_view_findzone(dns_view_t *view, dns_name_t *name, dns_zone_t **zonep);
712 /*%<
713  * Search for the zone 'name' in the zone table of 'view'.
714  * If found, 'zonep' is (strongly) attached to it.  There
715  * are no partial matches.
716  *
717  * Requires:
718  *
719  *\li   'zonep' points to a NULL dns_zone_t *.
720  *
721  * Returns:
722  *\li   #ISC_R_SUCCESS          A matching zone was found.
723  *\li   #ISC_R_NOTFOUND         No matching zone was found.
724  *\li   others                  An error occurred.
725  */
726
727 isc_result_t
728 dns_view_load(dns_view_t *view, isc_boolean_t stop);
729
730 isc_result_t
731 dns_view_loadnew(dns_view_t *view, isc_boolean_t stop);
732 /*%<
733  * Load zones attached to this view.  dns_view_load() loads
734  * all zones whose master file has changed since the last
735  * load; dns_view_loadnew() loads only zones that have never
736  * been loaded.
737  *
738  * If 'stop' is ISC_TRUE, stop on the first error and return it.
739  * If 'stop' is ISC_FALSE, ignore errors.
740  *
741  * Requires:
742  *
743  *\li   'view' is valid.
744  */
745
746 isc_result_t
747 dns_view_gettsig(dns_view_t *view, dns_name_t *keyname,
748                  dns_tsigkey_t **keyp);
749 /*%<
750  * Find the TSIG key configured in 'view' with name 'keyname',
751  * if any.
752  *
753  * Requires:
754  *\li   keyp points to a NULL dns_tsigkey_t *.
755  *
756  * Returns:
757  *\li   #ISC_R_SUCCESS  A key was found and '*keyp' now points to it.
758  *\li   #ISC_R_NOTFOUND No key was found.
759  *\li   others          An error occurred.
760  */
761
762 isc_result_t
763 dns_view_getpeertsig(dns_view_t *view, isc_netaddr_t *peeraddr,
764                      dns_tsigkey_t **keyp);
765 /*%<
766  * Find the TSIG key configured in 'view' for the server whose
767  * address is 'peeraddr', if any.
768  *
769  * Requires:
770  *      keyp points to a NULL dns_tsigkey_t *.
771  *
772  * Returns:
773  *\li   #ISC_R_SUCCESS  A key was found and '*keyp' now points to it.
774  *\li   #ISC_R_NOTFOUND No key was found.
775  *\li   others          An error occurred.
776  */
777
778 isc_result_t
779 dns_view_checksig(dns_view_t *view, isc_buffer_t *source, dns_message_t *msg);
780 /*%<
781  * Verifies the signature of a message.
782  *
783  * Requires:
784  *
785  *\li   'view' is a valid view.
786  *\li   'source' is a valid buffer containing the message
787  *\li   'msg' is a valid message
788  *
789  * Returns:
790  *\li   see dns_tsig_verify()
791  */
792
793 void
794 dns_view_dialup(dns_view_t *view);
795 /*%<
796  * Perform dialup-time maintenance on the zones of 'view'.
797  */
798
799 isc_result_t
800 dns_view_dumpdbtostream(dns_view_t *view, FILE *fp);
801 /*%<
802  * Dump the current state of the view 'view' to the stream 'fp'
803  * for purposes of analysis or debugging.
804  *
805  * Currently the dumped state includes the view's cache; in the future
806  * it may also include other state such as the address database.
807  * It will not not include authoritative data since it is voluminous and
808  * easily obtainable by other means.
809  *
810  * Requires:
811  *
812  *\li   'view' is valid.
813  *
814  *\li   'fp' refers to a file open for writing.
815  *
816  * Returns:
817  * \li  ISC_R_SUCCESS   The cache was successfully dumped.
818  * \li  others          An error occurred (see dns_master_dump)
819  */
820
821 isc_result_t
822 dns_view_flushcache(dns_view_t *view);
823 isc_result_t
824 dns_view_flushcache2(dns_view_t *view, isc_boolean_t fixuponly);
825 /*%<
826  * Flush the view's cache (and ADB).  If 'fixuponly' is true, it only updates
827  * the internal reference to the cache DB with omitting actual flush operation.
828  * 'fixuponly' is intended to be used for a view that shares a cache with
829  * a different view.  dns_view_flushcache() is a backward compatible version
830  * that always sets fixuponly to false.
831  *
832  * Requires:
833  *      'view' is valid.
834  *
835  *      No other tasks are executing.
836  *
837  * Returns:
838  *\li   #ISC_R_SUCCESS
839  *\li   #ISC_R_NOMEMORY
840  */
841
842 isc_result_t
843 dns_view_flushname(dns_view_t *view, dns_name_t *);
844 /*%<
845  * Flush the given name from the view's cache (and ADB).
846  *
847  * Requires:
848  *\li   'view' is valid.
849  *\li   'name' is valid.
850  *
851  * Returns:
852  *\li   #ISC_R_SUCCESS
853  *      other returns are failures.
854  */
855
856 isc_result_t
857 dns_view_adddelegationonly(dns_view_t *view, dns_name_t *name);
858 /*%<
859  * Add the given name to the delegation only table.
860  *
861  *
862  * Requires:
863  *\li   'view' is valid.
864  *\li   'name' is valid.
865  *
866  * Returns:
867  *\li   #ISC_R_SUCCESS
868  *\li   #ISC_R_NOMEMORY
869  */
870
871 isc_result_t
872 dns_view_excludedelegationonly(dns_view_t *view, dns_name_t *name);
873 /*%<
874  * Add the given name to be excluded from the root-delegation-only.
875  *
876  *
877  * Requires:
878  *\li   'view' is valid.
879  *\li   'name' is valid.
880  *
881  * Returns:
882  *\li   #ISC_R_SUCCESS
883  *\li   #ISC_R_NOMEMORY
884  */
885
886 isc_boolean_t
887 dns_view_isdelegationonly(dns_view_t *view, dns_name_t *name);
888 /*%<
889  * Check if 'name' is in the delegation only table or if
890  * rootdelonly is set that name is not being excluded.
891  *
892  * Requires:
893  *\li   'view' is valid.
894  *\li   'name' is valid.
895  *
896  * Returns:
897  *\li   #ISC_TRUE if the name is the table.
898  *\li   #ISC_FALSE otherwise.
899  */
900
901 void
902 dns_view_setrootdelonly(dns_view_t *view, isc_boolean_t value);
903 /*%<
904  * Set the root delegation only flag.
905  *
906  * Requires:
907  *\li   'view' is valid.
908  */
909
910 isc_boolean_t
911 dns_view_getrootdelonly(dns_view_t *view);
912 /*%<
913  * Get the root delegation only flag.
914  *
915  * Requires:
916  *\li   'view' is valid.
917  */
918
919 isc_result_t
920 dns_view_freezezones(dns_view_t *view, isc_boolean_t freeze);
921 /*%<
922  * Freeze/thaw updates to master zones.
923  *
924  * Requires:
925  * \li  'view' is valid.
926  */
927
928 void
929 dns_view_setresstats(dns_view_t *view, isc_stats_t *stats);
930 /*%<
931  * Set a general resolver statistics counter set 'stats' for 'view'.
932  *
933  * Requires:
934  * \li  'view' is valid and is not frozen.
935  *
936  *\li   stats is a valid statistics supporting resolver statistics counters
937  *      (see dns/stats.h).
938  */
939
940 void
941 dns_view_getresstats(dns_view_t *view, isc_stats_t **statsp);
942 /*%<
943  * Get the general statistics counter set for 'view'.  If a statistics set is
944  * set '*statsp' will be attached to the set; otherwise, '*statsp' will be
945  * untouched.
946  *
947  * Requires:
948  * \li  'view' is valid and is not frozen.
949  *
950  *\li   'statsp' != NULL && '*statsp' != NULL
951  */
952
953 void
954 dns_view_setresquerystats(dns_view_t *view, dns_stats_t *stats);
955 /*%<
956  * Set a statistics counter set of rdata type, 'stats', for 'view'.  Once the
957  * statistic set is installed, view's resolver will count outgoing queries
958  * per rdata type.
959  *
960  * Requires:
961  * \li  'view' is valid and is not frozen.
962  *
963  *\li   stats is a valid statistics created by dns_rdatatypestats_create().
964  */
965
966 void
967 dns_view_getresquerystats(dns_view_t *view, dns_stats_t **statsp);
968 /*%<
969  * Get the rdatatype statistics counter set for 'view'.  If a statistics set is
970  * set '*statsp' will be attached to the set; otherwise, '*statsp' will be
971  * untouched.
972  *
973  * Requires:
974  * \li  'view' is valid and is not frozen.
975  *
976  *\li   'statsp' != NULL && '*statsp' != NULL
977  */
978
979 isc_boolean_t
980 dns_view_iscacheshared(dns_view_t *view);
981 /*%<
982  * Check if the view shares the cache created by another view.
983  *
984  * Requires:
985  * \li  'view' is valid.
986  *
987  * Returns:
988  *\li   #ISC_TRUE if the cache is shared.
989  *\li   #ISC_FALSE otherwise.
990  */
991
992 isc_result_t
993 dns_view_initsecroots(dns_view_t *view, isc_mem_t *mctx);
994 /*%<
995  * Initialize security roots for the view.  (Note that secroots is
996  * NULL until this function is called, so any function using
997  * secroots must check its validity first.  One way to do this is
998  * use dns_view_getsecroots() and check its return value.)
999  *
1000  * Requires:
1001  * \li  'view' is valid.
1002  * \li  'view->secroots' is NULL.
1003  *
1004  * Returns:
1005  *\li   ISC_R_SUCCESS
1006  *\li   Any other result indicates failure
1007  */
1008
1009 isc_result_t
1010 dns_view_getsecroots(dns_view_t *view, dns_keytable_t **ktp);
1011 /*%<
1012  * Get the security roots for this view.  Returns ISC_R_NOTFOUND if
1013  * the security roots keytable has not been initialized for the view.
1014  *
1015  * '*ktp' is attached on success; the caller is responsible for
1016  * detaching it with dns_keytable_detach().
1017  *
1018  * Requires:
1019  * \li  'view' is valid.
1020  * \li  'ktp' is not NULL and '*ktp' is NULL.
1021  *
1022  * Returns:
1023  *\li   ISC_R_SUCCESS
1024  *\li   ISC_R_NOTFOUND
1025  */
1026
1027 isc_result_t
1028 dns_view_issecuredomain(dns_view_t *view, dns_name_t *name,
1029                          isc_boolean_t *secure_domain);
1030 /*%<
1031  * Is 'name' at or beneath a trusted key?  Put answer in
1032  * '*secure_domain'.
1033  *
1034  * Requires:
1035  * \li  'view' is valid.
1036  *
1037  * Returns:
1038  *\li   ISC_R_SUCCESS
1039  *\li   Any other value indicates failure
1040  */
1041
1042 void
1043 dns_view_untrust(dns_view_t *view, dns_name_t *keyname,
1044                  dns_rdata_dnskey_t *dnskey, isc_mem_t *mctx);
1045 /*%<
1046  * Remove keys that match 'keyname' and 'dnskey' from the views trust
1047  * anchors.
1048  *
1049  * Requires:
1050  * \li  'view' is valid.
1051  * \li  'keyname' is valid.
1052  * \li  'mctx' is valid.
1053  * \li  'dnskey' is valid.
1054  */
1055
1056 void
1057 dns_view_setnewzones(dns_view_t *view, isc_boolean_t allow, void *cfgctx,
1058                      void (*cfg_destroy)(void **));
1059 /*%<
1060  * Set whether or not to allow zones to be created or deleted at runtime.
1061  *
1062  * If 'allow' is ISC_TRUE, determines the filename into which new zone
1063  * configuration will be written.  Preserves the configuration context
1064  * (a pointer to which is passed in 'cfgctx') for use when parsing new
1065  * zone configuration.  'cfg_destroy' points to a callback routine to
1066  * destroy the configuration context when the view is destroyed.  (This
1067  * roundabout method is used in order to avoid libdns having a dependency
1068  * on libisccfg and libbind9.)
1069  *
1070  * If 'allow' is ISC_FALSE, removes any existing references to
1071  * configuration context and frees any memory.
1072  *
1073  * Requires:
1074  * \li 'view' is valid.
1075  */
1076
1077 void
1078 dns_view_restorekeyring(dns_view_t *view);
1079
1080 ISC_LANG_ENDDECLS
1081
1082 #endif /* DNS_VIEW_H */