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