4 * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: view.c,v 1.159 2009/11/28 15:57:37 vjs Exp */
27 #include <isc/stats.h>
28 #include <isc/string.h> /* Required for HP/UX (and others?) */
32 #include <dns/acache.h>
35 #include <dns/cache.h>
38 #include <dns/events.h>
39 #include <dns/forward.h>
40 #include <dns/keytable.h>
41 #include <dns/master.h>
42 #include <dns/masterdump.h>
43 #include <dns/order.h>
46 #include <dns/rdataset.h>
47 #include <dns/request.h>
48 #include <dns/resolver.h>
49 #include <dns/result.h>
50 #include <dns/stats.h>
55 #define RESSHUTDOWN(v) (((v)->attributes & DNS_VIEWATTR_RESSHUTDOWN) != 0)
56 #define ADBSHUTDOWN(v) (((v)->attributes & DNS_VIEWATTR_ADBSHUTDOWN) != 0)
57 #define REQSHUTDOWN(v) (((v)->attributes & DNS_VIEWATTR_REQSHUTDOWN) != 0)
59 #define DNS_VIEW_DELONLYHASH 111
61 static void resolver_shutdown(isc_task_t
*task
, isc_event_t
*event
);
62 static void adb_shutdown(isc_task_t
*task
, isc_event_t
*event
);
63 static void req_shutdown(isc_task_t
*task
, isc_event_t
*event
);
66 dns_view_create(isc_mem_t
*mctx
, dns_rdataclass_t rdclass
,
67 const char *name
, dns_view_t
**viewp
)
76 REQUIRE(name
!= NULL
);
77 REQUIRE(viewp
!= NULL
&& *viewp
== NULL
);
79 view
= isc_mem_get(mctx
, sizeof(*view
));
81 return (ISC_R_NOMEMORY
);
82 view
->name
= isc_mem_strdup(mctx
, name
);
83 if (view
->name
== NULL
) {
84 result
= ISC_R_NOMEMORY
;
87 result
= isc_mutex_init(&view
->lock
);
88 if (result
!= ISC_R_SUCCESS
)
92 view
->zonetable
= NULL
;
93 result
= dns_zt_create(mctx
, rdclass
, &view
->zonetable
);
94 if (result
!= ISC_R_SUCCESS
) {
95 UNEXPECTED_ERROR(__FILE__
, __LINE__
,
96 "dns_zt_create() failed: %s",
97 isc_result_totext(result
));
98 result
= ISC_R_UNEXPECTED
;
102 view
->secroots_priv
= NULL
;
103 view
->fwdtable
= NULL
;
104 result
= dns_fwdtable_create(mctx
, &view
->fwdtable
);
105 if (result
!= ISC_R_SUCCESS
) {
106 UNEXPECTED_ERROR(__FILE__
, __LINE__
,
107 "dns_fwdtable_create() failed: %s",
108 isc_result_totext(result
));
109 result
= ISC_R_UNEXPECTED
;
115 view
->cachedb
= NULL
;
116 view
->dlzdatabase
= NULL
;
118 view
->resolver
= NULL
;
120 view
->requestmgr
= NULL
;
122 view
->rdclass
= rdclass
;
123 view
->frozen
= ISC_FALSE
;
125 result
= isc_refcount_init(&view
->references
, 1);
126 if (result
!= ISC_R_SUCCESS
)
127 goto cleanup_fwdtable
;
129 view
->attributes
= (DNS_VIEWATTR_RESSHUTDOWN
|DNS_VIEWATTR_ADBSHUTDOWN
|
130 DNS_VIEWATTR_REQSHUTDOWN
);
131 view
->statickeys
= NULL
;
132 view
->dynamickeys
= NULL
;
133 view
->matchclients
= NULL
;
134 view
->matchdestinations
= NULL
;
135 view
->matchrecursiveonly
= ISC_FALSE
;
136 result
= dns_tsigkeyring_create(view
->mctx
, &view
->dynamickeys
);
137 if (result
!= ISC_R_SUCCESS
)
138 goto cleanup_references
;
141 view
->delonly
= NULL
;
142 view
->rootdelonly
= ISC_FALSE
;
143 view
->rootexclude
= NULL
;
144 view
->resstats
= NULL
;
145 view
->resquerystats
= NULL
;
146 view
->cacheshared
= ISC_FALSE
;
149 * Initialize configuration data with default values.
151 view
->recursion
= ISC_TRUE
;
152 view
->auth_nxdomain
= ISC_FALSE
; /* Was true in BIND 8 */
153 view
->additionalfromcache
= ISC_TRUE
;
154 view
->additionalfromauth
= ISC_TRUE
;
155 view
->enablednssec
= ISC_TRUE
;
156 view
->enablevalidation
= ISC_TRUE
;
157 view
->acceptexpired
= ISC_FALSE
;
158 view
->minimalresponses
= ISC_FALSE
;
159 view
->transfer_format
= dns_one_answer
;
160 view
->queryacl
= NULL
;
161 view
->queryonacl
= NULL
;
162 view
->recursionacl
= NULL
;
163 view
->recursiononacl
= NULL
;
164 view
->sortlist
= NULL
;
165 view
->transferacl
= NULL
;
166 view
->notifyacl
= NULL
;
167 view
->updateacl
= NULL
;
168 view
->upfwdacl
= NULL
;
169 view
->denyansweracl
= NULL
;
170 view
->answeracl_exclude
= NULL
;
171 view
->denyanswernames
= NULL
;
172 view
->answernames_exclude
= NULL
;
173 view
->requestixfr
= ISC_TRUE
;
174 view
->provideixfr
= ISC_TRUE
;
175 view
->maxcachettl
= 7 * 24 * 3600;
176 view
->maxncachettl
= 3 * 3600;
178 view
->preferred_glue
= 0;
179 view
->flush
= ISC_FALSE
;
182 #ifdef ALLOW_FILTER_AAAA_ON_V4
183 view
->v4_aaaa
= dns_v4_aaaa_ok
;
185 dns_fixedname_init(&view
->dlv_fixed
);
188 result
= dns_order_create(view
->mctx
, &view
->order
);
189 if (result
!= ISC_R_SUCCESS
)
190 goto cleanup_dynkeys
;
193 result
= dns_peerlist_new(view
->mctx
, &view
->peers
);
194 if (result
!= ISC_R_SUCCESS
)
197 result
= dns_aclenv_init(view
->mctx
, &view
->aclenv
);
198 if (result
!= ISC_R_SUCCESS
)
199 goto cleanup_peerlist
;
201 ISC_LINK_INIT(view
, link
);
202 ISC_EVENT_INIT(&view
->resevent
, sizeof(view
->resevent
), 0, NULL
,
203 DNS_EVENT_VIEWRESSHUTDOWN
, resolver_shutdown
,
204 view
, NULL
, NULL
, NULL
);
205 ISC_EVENT_INIT(&view
->adbevent
, sizeof(view
->adbevent
), 0, NULL
,
206 DNS_EVENT_VIEWADBSHUTDOWN
, adb_shutdown
,
207 view
, NULL
, NULL
, NULL
);
208 ISC_EVENT_INIT(&view
->reqevent
, sizeof(view
->reqevent
), 0, NULL
,
209 DNS_EVENT_VIEWREQSHUTDOWN
, req_shutdown
,
210 view
, NULL
, NULL
, NULL
);
211 view
->magic
= DNS_VIEW_MAGIC
;
215 return (ISC_R_SUCCESS
);
218 dns_peerlist_detach(&view
->peers
);
222 dns_order_detach(&view
->order
);
226 dns_tsigkeyring_destroy(&view
->dynamickeys
);
229 isc_refcount_destroy(&view
->references
);
232 dns_fwdtable_destroy(&view
->fwdtable
);
236 dns_zt_detach(&view
->zonetable
);
240 DESTROYLOCK(&view
->lock
);
243 isc_mem_free(mctx
, view
->name
);
246 isc_mem_put(mctx
, view
, sizeof(*view
));
252 destroy(dns_view_t
*view
) {
253 REQUIRE(!ISC_LINK_LINKED(view
, link
));
254 REQUIRE(isc_refcount_current(&view
->references
) == 0);
255 REQUIRE(view
->weakrefs
== 0);
256 REQUIRE(RESSHUTDOWN(view
));
257 REQUIRE(ADBSHUTDOWN(view
));
258 REQUIRE(REQSHUTDOWN(view
));
261 if (view
->order
!= NULL
)
262 dns_order_detach(&view
->order
);
264 if (view
->peers
!= NULL
)
265 dns_peerlist_detach(&view
->peers
);
266 if (view
->dynamickeys
!= NULL
)
267 dns_tsigkeyring_destroy(&view
->dynamickeys
);
268 if (view
->statickeys
!= NULL
)
269 dns_tsigkeyring_destroy(&view
->statickeys
);
270 if (view
->adb
!= NULL
)
271 dns_adb_detach(&view
->adb
);
272 if (view
->resolver
!= NULL
)
273 dns_resolver_detach(&view
->resolver
);
275 if (view
->acache
!= NULL
) {
276 if (view
->cachedb
!= NULL
)
277 dns_acache_putdb(view
->acache
, view
->cachedb
);
278 dns_acache_detach(&view
->acache
);
281 if (view
->requestmgr
!= NULL
)
282 dns_requestmgr_detach(&view
->requestmgr
);
283 if (view
->task
!= NULL
)
284 isc_task_detach(&view
->task
);
285 if (view
->hints
!= NULL
)
286 dns_db_detach(&view
->hints
);
287 if (view
->dlzdatabase
!= NULL
)
288 dns_dlzdestroy(&view
->dlzdatabase
);
289 if (view
->cachedb
!= NULL
)
290 dns_db_detach(&view
->cachedb
);
291 if (view
->cache
!= NULL
)
292 dns_cache_detach(&view
->cache
);
293 if (view
->matchclients
!= NULL
)
294 dns_acl_detach(&view
->matchclients
);
295 if (view
->matchdestinations
!= NULL
)
296 dns_acl_detach(&view
->matchdestinations
);
297 if (view
->queryacl
!= NULL
)
298 dns_acl_detach(&view
->queryacl
);
299 if (view
->queryonacl
!= NULL
)
300 dns_acl_detach(&view
->queryonacl
);
301 if (view
->recursionacl
!= NULL
)
302 dns_acl_detach(&view
->recursionacl
);
303 if (view
->recursiononacl
!= NULL
)
304 dns_acl_detach(&view
->recursiononacl
);
305 if (view
->sortlist
!= NULL
)
306 dns_acl_detach(&view
->sortlist
);
307 if (view
->transferacl
!= NULL
)
308 dns_acl_detach(&view
->transferacl
);
309 if (view
->notifyacl
!= NULL
)
310 dns_acl_detach(&view
->notifyacl
);
311 if (view
->updateacl
!= NULL
)
312 dns_acl_detach(&view
->updateacl
);
313 if (view
->upfwdacl
!= NULL
)
314 dns_acl_detach(&view
->upfwdacl
);
315 if (view
->denyansweracl
!= NULL
)
316 dns_acl_detach(&view
->denyansweracl
);
317 if (view
->answeracl_exclude
!= NULL
)
318 dns_rbt_destroy(&view
->answeracl_exclude
);
319 if (view
->denyanswernames
!= NULL
)
320 dns_rbt_destroy(&view
->denyanswernames
);
321 if (view
->answernames_exclude
!= NULL
)
322 dns_rbt_destroy(&view
->answernames_exclude
);
323 if (view
->delonly
!= NULL
) {
327 for (i
= 0; i
< DNS_VIEW_DELONLYHASH
; i
++) {
328 name
= ISC_LIST_HEAD(view
->delonly
[i
]);
329 while (name
!= NULL
) {
330 ISC_LIST_UNLINK(view
->delonly
[i
], name
, link
);
331 dns_name_free(name
, view
->mctx
);
332 isc_mem_put(view
->mctx
, name
, sizeof(*name
));
333 name
= ISC_LIST_HEAD(view
->delonly
[i
]);
336 isc_mem_put(view
->mctx
, view
->delonly
, sizeof(dns_namelist_t
) *
337 DNS_VIEW_DELONLYHASH
);
338 view
->delonly
= NULL
;
340 if (view
->rootexclude
!= NULL
) {
344 for (i
= 0; i
< DNS_VIEW_DELONLYHASH
; i
++) {
345 name
= ISC_LIST_HEAD(view
->rootexclude
[i
]);
346 while (name
!= NULL
) {
347 ISC_LIST_UNLINK(view
->rootexclude
[i
],
349 dns_name_free(name
, view
->mctx
);
350 isc_mem_put(view
->mctx
, name
, sizeof(*name
));
351 name
= ISC_LIST_HEAD(view
->rootexclude
[i
]);
354 isc_mem_put(view
->mctx
, view
->rootexclude
,
355 sizeof(dns_namelist_t
) * DNS_VIEW_DELONLYHASH
);
356 view
->rootexclude
= NULL
;
358 if (view
->resstats
!= NULL
)
359 isc_stats_detach(&view
->resstats
);
360 if (view
->resquerystats
!= NULL
)
361 dns_stats_detach(&view
->resquerystats
);
362 if (view
->secroots_priv
!= NULL
)
363 dns_keytable_detach(&view
->secroots_priv
);
364 dns_fwdtable_destroy(&view
->fwdtable
);
365 dns_aclenv_destroy(&view
->aclenv
);
366 DESTROYLOCK(&view
->lock
);
367 isc_refcount_destroy(&view
->references
);
368 isc_mem_free(view
->mctx
, view
->name
);
369 isc_mem_put(view
->mctx
, view
, sizeof(*view
));
373 * Return true iff 'view' may be freed.
374 * The caller must be holding the view lock.
377 all_done(dns_view_t
*view
) {
379 if (isc_refcount_current(&view
->references
) == 0 &&
380 view
->weakrefs
== 0 &&
381 RESSHUTDOWN(view
) && ADBSHUTDOWN(view
) && REQSHUTDOWN(view
))
388 dns_view_attach(dns_view_t
*source
, dns_view_t
**targetp
) {
390 REQUIRE(DNS_VIEW_VALID(source
));
391 REQUIRE(targetp
!= NULL
&& *targetp
== NULL
);
393 isc_refcount_increment(&source
->references
, NULL
);
399 view_flushanddetach(dns_view_t
**viewp
, isc_boolean_t flush
) {
402 isc_boolean_t done
= ISC_FALSE
;
404 REQUIRE(viewp
!= NULL
);
406 REQUIRE(DNS_VIEW_VALID(view
));
409 view
->flush
= ISC_TRUE
;
410 isc_refcount_decrement(&view
->references
, &refs
);
413 if (!RESSHUTDOWN(view
))
414 dns_resolver_shutdown(view
->resolver
);
415 if (!ADBSHUTDOWN(view
))
416 dns_adb_shutdown(view
->adb
);
417 if (!REQSHUTDOWN(view
))
418 dns_requestmgr_shutdown(view
->requestmgr
);
420 if (view
->acache
!= NULL
)
421 dns_acache_shutdown(view
->acache
);
423 dns_zt_flushanddetach(&view
->zonetable
);
425 dns_zt_detach(&view
->zonetable
);
427 done
= all_done(view
);
438 dns_view_flushanddetach(dns_view_t
**viewp
) {
439 view_flushanddetach(viewp
, ISC_TRUE
);
443 dns_view_detach(dns_view_t
**viewp
) {
444 view_flushanddetach(viewp
, ISC_FALSE
);
449 dialup(dns_zone_t
*zone
, void *dummy
) {
451 dns_zone_dialup(zone
);
452 return (ISC_R_SUCCESS
);
456 dns_view_dialup(dns_view_t
*view
) {
457 REQUIRE(DNS_VIEW_VALID(view
));
458 (void)dns_zt_apply(view
->zonetable
, ISC_FALSE
, dialup
, NULL
);
463 dns_view_weakattach(dns_view_t
*source
, dns_view_t
**targetp
) {
465 REQUIRE(DNS_VIEW_VALID(source
));
466 REQUIRE(targetp
!= NULL
&& *targetp
== NULL
);
470 UNLOCK(&source
->lock
);
476 dns_view_weakdetach(dns_view_t
**viewp
) {
478 isc_boolean_t done
= ISC_FALSE
;
480 REQUIRE(viewp
!= NULL
);
482 REQUIRE(DNS_VIEW_VALID(view
));
486 INSIST(view
->weakrefs
> 0);
488 done
= all_done(view
);
499 resolver_shutdown(isc_task_t
*task
, isc_event_t
*event
) {
500 dns_view_t
*view
= event
->ev_arg
;
503 REQUIRE(event
->ev_type
== DNS_EVENT_VIEWRESSHUTDOWN
);
504 REQUIRE(DNS_VIEW_VALID(view
));
505 REQUIRE(view
->task
== task
);
511 view
->attributes
|= DNS_VIEWATTR_RESSHUTDOWN
;
512 done
= all_done(view
);
516 isc_event_free(&event
);
523 adb_shutdown(isc_task_t
*task
, isc_event_t
*event
) {
524 dns_view_t
*view
= event
->ev_arg
;
527 REQUIRE(event
->ev_type
== DNS_EVENT_VIEWADBSHUTDOWN
);
528 REQUIRE(DNS_VIEW_VALID(view
));
529 REQUIRE(view
->task
== task
);
535 view
->attributes
|= DNS_VIEWATTR_ADBSHUTDOWN
;
536 done
= all_done(view
);
540 isc_event_free(&event
);
547 req_shutdown(isc_task_t
*task
, isc_event_t
*event
) {
548 dns_view_t
*view
= event
->ev_arg
;
551 REQUIRE(event
->ev_type
== DNS_EVENT_VIEWREQSHUTDOWN
);
552 REQUIRE(DNS_VIEW_VALID(view
));
553 REQUIRE(view
->task
== task
);
559 view
->attributes
|= DNS_VIEWATTR_REQSHUTDOWN
;
560 done
= all_done(view
);
564 isc_event_free(&event
);
571 dns_view_createresolver(dns_view_t
*view
,
572 isc_taskmgr_t
*taskmgr
, unsigned int ntasks
,
573 isc_socketmgr_t
*socketmgr
,
574 isc_timermgr_t
*timermgr
,
575 unsigned int options
,
576 dns_dispatchmgr_t
*dispatchmgr
,
577 dns_dispatch_t
*dispatchv4
,
578 dns_dispatch_t
*dispatchv6
)
582 isc_mem_t
*mctx
= NULL
;
584 REQUIRE(DNS_VIEW_VALID(view
));
585 REQUIRE(!view
->frozen
);
586 REQUIRE(view
->resolver
== NULL
);
588 result
= isc_task_create(taskmgr
, 0, &view
->task
);
589 if (result
!= ISC_R_SUCCESS
)
591 isc_task_setname(view
->task
, "view", view
);
593 result
= dns_resolver_create(view
, taskmgr
, ntasks
, socketmgr
,
594 timermgr
, options
, dispatchmgr
,
595 dispatchv4
, dispatchv6
,
597 if (result
!= ISC_R_SUCCESS
) {
598 isc_task_detach(&view
->task
);
601 event
= &view
->resevent
;
602 dns_resolver_whenshutdown(view
->resolver
, view
->task
, &event
);
603 view
->attributes
&= ~DNS_VIEWATTR_RESSHUTDOWN
;
605 result
= isc_mem_create(0, 0, &mctx
);
606 if (result
!= ISC_R_SUCCESS
) {
607 dns_resolver_shutdown(view
->resolver
);
611 result
= dns_adb_create(mctx
, view
, timermgr
, taskmgr
, &view
->adb
);
612 isc_mem_setname(mctx
, "ADB", NULL
);
613 isc_mem_detach(&mctx
);
614 if (result
!= ISC_R_SUCCESS
) {
615 dns_resolver_shutdown(view
->resolver
);
618 event
= &view
->adbevent
;
619 dns_adb_whenshutdown(view
->adb
, view
->task
, &event
);
620 view
->attributes
&= ~DNS_VIEWATTR_ADBSHUTDOWN
;
622 result
= dns_requestmgr_create(view
->mctx
, timermgr
, socketmgr
,
623 dns_resolver_taskmgr(view
->resolver
),
624 dns_resolver_dispatchmgr(view
->resolver
),
625 dns_resolver_dispatchv4(view
->resolver
),
626 dns_resolver_dispatchv6(view
->resolver
),
628 if (result
!= ISC_R_SUCCESS
) {
629 dns_adb_shutdown(view
->adb
);
630 dns_resolver_shutdown(view
->resolver
);
633 event
= &view
->reqevent
;
634 dns_requestmgr_whenshutdown(view
->requestmgr
, view
->task
, &event
);
635 view
->attributes
&= ~DNS_VIEWATTR_REQSHUTDOWN
;
637 return (ISC_R_SUCCESS
);
641 dns_view_setcache(dns_view_t
*view
, dns_cache_t
*cache
) {
642 dns_view_setcache2(view
, cache
, ISC_FALSE
);
646 dns_view_setcache2(dns_view_t
*view
, dns_cache_t
*cache
, isc_boolean_t shared
) {
647 REQUIRE(DNS_VIEW_VALID(view
));
648 REQUIRE(!view
->frozen
);
650 view
->cacheshared
= shared
;
651 if (view
->cache
!= NULL
) {
653 if (view
->acache
!= NULL
)
654 dns_acache_putdb(view
->acache
, view
->cachedb
);
656 dns_db_detach(&view
->cachedb
);
657 dns_cache_detach(&view
->cache
);
659 dns_cache_attach(cache
, &view
->cache
);
660 dns_cache_attachdb(cache
, &view
->cachedb
);
661 INSIST(DNS_DB_VALID(view
->cachedb
));
664 if (view
->acache
!= NULL
)
665 dns_acache_setdb(view
->acache
, view
->cachedb
);
670 dns_view_iscacheshared(dns_view_t
*view
) {
671 REQUIRE(DNS_VIEW_VALID(view
));
673 return (view
->cacheshared
);
677 dns_view_sethints(dns_view_t
*view
, dns_db_t
*hints
) {
678 REQUIRE(DNS_VIEW_VALID(view
));
679 REQUIRE(!view
->frozen
);
680 REQUIRE(view
->hints
== NULL
);
681 REQUIRE(dns_db_iszone(hints
));
683 dns_db_attach(hints
, &view
->hints
);
687 dns_view_setkeyring(dns_view_t
*view
, dns_tsig_keyring_t
*ring
) {
688 REQUIRE(DNS_VIEW_VALID(view
));
689 REQUIRE(ring
!= NULL
);
690 if (view
->statickeys
!= NULL
)
691 dns_tsigkeyring_destroy(&view
->statickeys
);
692 view
->statickeys
= ring
;
696 dns_view_setdstport(dns_view_t
*view
, in_port_t dstport
) {
697 REQUIRE(DNS_VIEW_VALID(view
));
698 view
->dstport
= dstport
;
703 dns_view_addzone(dns_view_t
*view
, dns_zone_t
*zone
) {
706 REQUIRE(DNS_VIEW_VALID(view
));
707 REQUIRE(!view
->frozen
);
709 result
= dns_zt_mount(view
->zonetable
, zone
);
716 dns_view_freeze(dns_view_t
*view
) {
717 REQUIRE(DNS_VIEW_VALID(view
));
718 REQUIRE(!view
->frozen
);
720 if (view
->resolver
!= NULL
) {
721 INSIST(view
->cachedb
!= NULL
);
722 dns_resolver_freeze(view
->resolver
);
724 view
->frozen
= ISC_TRUE
;
729 dns_view_findzone(dns_view_t
*view
, dns_name_t
*name
, dns_zone_t
**zonep
) {
732 REQUIRE(DNS_VIEW_VALID(view
));
734 result
= dns_zt_find(view
->zonetable
, name
, 0, NULL
, zonep
);
735 if (result
== DNS_R_PARTIALMATCH
) {
736 dns_zone_detach(zonep
);
737 result
= ISC_R_NOTFOUND
;
745 dns_view_find(dns_view_t
*view
, dns_name_t
*name
, dns_rdatatype_t type
,
746 isc_stdtime_t now
, unsigned int options
, isc_boolean_t use_hints
,
747 dns_db_t
**dbp
, dns_dbnode_t
**nodep
, dns_name_t
*foundname
,
748 dns_rdataset_t
*rdataset
, dns_rdataset_t
*sigrdataset
)
752 dns_dbnode_t
*node
, *znode
;
753 isc_boolean_t is_cache
;
754 dns_rdataset_t zrdataset
, zsigrdataset
;
762 * Find an rdataset whose owner name is 'name', and whose type is
766 REQUIRE(DNS_VIEW_VALID(view
));
767 REQUIRE(view
->frozen
);
768 REQUIRE(type
!= dns_rdatatype_rrsig
);
769 REQUIRE(rdataset
!= NULL
); /* XXXBEW - remove this */
770 REQUIRE(nodep
== NULL
|| *nodep
== NULL
);
775 dns_rdataset_init(&zrdataset
);
776 dns_rdataset_init(&zsigrdataset
);
781 * Find a database to answer the query.
787 result
= dns_zt_find(view
->zonetable
, name
, 0, NULL
, &zone
);
788 if (result
== ISC_R_SUCCESS
|| result
== DNS_R_PARTIALMATCH
) {
789 result
= dns_zone_getdb(zone
, &db
);
790 if (result
!= ISC_R_SUCCESS
&& view
->cachedb
!= NULL
)
791 dns_db_attach(view
->cachedb
, &db
);
792 else if (result
!= ISC_R_SUCCESS
)
794 } else if (result
== ISC_R_NOTFOUND
&& view
->cachedb
!= NULL
)
795 dns_db_attach(view
->cachedb
, &db
);
797 result
= ISC_R_NOTFOUND
;
798 if (view
->cachedb
!= NULL
)
799 dns_db_attach(view
->cachedb
, &db
);
804 is_cache
= dns_db_iscache(db
);
808 * Now look for an answer in the database.
810 result
= dns_db_find(db
, name
, NULL
, type
, options
,
811 now
, &node
, foundname
, rdataset
, sigrdataset
);
813 if (result
== DNS_R_DELEGATION
||
814 result
== ISC_R_NOTFOUND
) {
815 if (dns_rdataset_isassociated(rdataset
))
816 dns_rdataset_disassociate(rdataset
);
817 if (sigrdataset
!= NULL
&&
818 dns_rdataset_isassociated(sigrdataset
))
819 dns_rdataset_disassociate(sigrdataset
);
821 dns_db_detachnode(db
, &node
);
824 if (view
->cachedb
!= NULL
) {
826 * Either the answer is in the cache, or we
830 dns_db_attach(view
->cachedb
, &db
);
835 * We don't have the data in the cache. If we've got
836 * glue from the zone, use it.
838 if (dns_rdataset_isassociated(&zrdataset
)) {
839 dns_rdataset_clone(&zrdataset
, rdataset
);
840 if (sigrdataset
!= NULL
&&
841 dns_rdataset_isassociated(&zsigrdataset
))
842 dns_rdataset_clone(&zsigrdataset
,
847 dns_db_attach(zdb
, &db
);
848 dns_db_attachnode(db
, znode
, &node
);
853 * We don't know the answer.
855 result
= ISC_R_NOTFOUND
;
856 } else if (result
== DNS_R_GLUE
) {
857 if (view
->cachedb
!= NULL
) {
859 * We found an answer, but the cache may be better.
860 * Remember what we've got and go look in the cache.
863 dns_rdataset_clone(rdataset
, &zrdataset
);
864 dns_rdataset_disassociate(rdataset
);
865 if (sigrdataset
!= NULL
&&
866 dns_rdataset_isassociated(sigrdataset
)) {
867 dns_rdataset_clone(sigrdataset
, &zsigrdataset
);
868 dns_rdataset_disassociate(sigrdataset
);
870 dns_db_attach(db
, &zdb
);
871 dns_db_attachnode(zdb
, node
, &znode
);
872 dns_db_detachnode(db
, &node
);
874 dns_db_attach(view
->cachedb
, &db
);
878 * Otherwise, the glue is the best answer.
880 result
= ISC_R_SUCCESS
;
884 if (result
== ISC_R_NOTFOUND
&& use_hints
&& view
->hints
!= NULL
) {
885 if (dns_rdataset_isassociated(rdataset
))
886 dns_rdataset_disassociate(rdataset
);
887 if (sigrdataset
!= NULL
&&
888 dns_rdataset_isassociated(sigrdataset
))
889 dns_rdataset_disassociate(sigrdataset
);
892 dns_db_detachnode(db
, &node
);
895 result
= dns_db_find(view
->hints
, name
, NULL
, type
, options
,
896 now
, &node
, foundname
,
897 rdataset
, sigrdataset
);
898 if (result
== ISC_R_SUCCESS
|| result
== DNS_R_GLUE
) {
900 * We just used a hint. Let the resolver know it
901 * should consider priming.
903 dns_resolver_prime(view
->resolver
);
904 dns_db_attach(view
->hints
, &db
);
906 } else if (result
== DNS_R_NXRRSET
) {
907 dns_db_attach(view
->hints
, &db
);
908 result
= DNS_R_HINTNXRRSET
;
909 } else if (result
== DNS_R_NXDOMAIN
)
910 result
= ISC_R_NOTFOUND
;
913 * Cleanup if non-standard hints are used.
915 if (db
== NULL
&& node
!= NULL
)
916 dns_db_detachnode(view
->hints
, &node
);
921 if (dns_rdataset_isassociated(&zrdataset
)) {
922 dns_rdataset_disassociate(&zrdataset
);
923 if (dns_rdataset_isassociated(&zsigrdataset
))
924 dns_rdataset_disassociate(&zsigrdataset
);
929 dns_db_detachnode(zdb
, &znode
);
938 dns_db_detachnode(db
, &node
);
945 INSIST(node
== NULL
);
949 dns_zone_detach(&zone
);
956 dns_view_simplefind(dns_view_t
*view
, dns_name_t
*name
, dns_rdatatype_t type
,
957 isc_stdtime_t now
, unsigned int options
,
958 isc_boolean_t use_hints
,
959 dns_rdataset_t
*rdataset
, dns_rdataset_t
*sigrdataset
)
962 dns_fixedname_t foundname
;
964 dns_fixedname_init(&foundname
);
965 result
= dns_view_find(view
, name
, type
, now
, options
, use_hints
,
966 NULL
, NULL
, dns_fixedname_name(&foundname
),
967 rdataset
, sigrdataset
);
968 if (result
== DNS_R_NXDOMAIN
) {
970 * The rdataset and sigrdataset of the relevant NSEC record
971 * may be returned, but the caller cannot use them because
972 * foundname is not returned by this simplified API. We
973 * disassociate them here to prevent any misuse by the caller.
975 if (dns_rdataset_isassociated(rdataset
))
976 dns_rdataset_disassociate(rdataset
);
977 if (sigrdataset
!= NULL
&&
978 dns_rdataset_isassociated(sigrdataset
))
979 dns_rdataset_disassociate(sigrdataset
);
980 } else if (result
!= ISC_R_SUCCESS
&&
981 result
!= DNS_R_GLUE
&&
982 result
!= DNS_R_HINT
&&
983 result
!= DNS_R_NCACHENXDOMAIN
&&
984 result
!= DNS_R_NCACHENXRRSET
&&
985 result
!= DNS_R_NXRRSET
&&
986 result
!= DNS_R_HINTNXRRSET
&&
987 result
!= ISC_R_NOTFOUND
) {
988 if (dns_rdataset_isassociated(rdataset
))
989 dns_rdataset_disassociate(rdataset
);
990 if (sigrdataset
!= NULL
&&
991 dns_rdataset_isassociated(sigrdataset
))
992 dns_rdataset_disassociate(sigrdataset
);
993 result
= ISC_R_NOTFOUND
;
1000 dns_view_findzonecut(dns_view_t
*view
, dns_name_t
*name
, dns_name_t
*fname
,
1001 isc_stdtime_t now
, unsigned int options
,
1002 isc_boolean_t use_hints
,
1003 dns_rdataset_t
*rdataset
, dns_rdataset_t
*sigrdataset
)
1005 return(dns_view_findzonecut2(view
, name
, fname
, now
, options
,
1006 use_hints
, ISC_TRUE
,
1007 rdataset
, sigrdataset
));
1011 dns_view_findzonecut2(dns_view_t
*view
, dns_name_t
*name
, dns_name_t
*fname
,
1012 isc_stdtime_t now
, unsigned int options
,
1013 isc_boolean_t use_hints
, isc_boolean_t use_cache
,
1014 dns_rdataset_t
*rdataset
, dns_rdataset_t
*sigrdataset
)
1016 isc_result_t result
;
1018 isc_boolean_t is_cache
, use_zone
, try_hints
;
1021 dns_rdataset_t zrdataset
, zsigrdataset
;
1022 dns_fixedname_t zfixedname
;
1024 REQUIRE(DNS_VIEW_VALID(view
));
1025 REQUIRE(view
->frozen
);
1029 use_zone
= ISC_FALSE
;
1030 try_hints
= ISC_FALSE
;
1036 dns_fixedname_init(&zfixedname
);
1037 dns_rdataset_init(&zrdataset
);
1038 dns_rdataset_init(&zsigrdataset
);
1041 * Find the right database.
1044 result
= dns_zt_find(view
->zonetable
, name
, 0, NULL
, &zone
);
1045 if (result
== ISC_R_SUCCESS
|| result
== DNS_R_PARTIALMATCH
)
1046 result
= dns_zone_getdb(zone
, &db
);
1048 result
= ISC_R_NOTFOUND
;
1050 if (result
== ISC_R_NOTFOUND
) {
1052 * We're not directly authoritative for this query name, nor
1053 * is it a subdomain of any zone for which we're
1056 if (use_cache
&& view
->cachedb
!= NULL
) {
1058 * We have a cache; try it.
1060 dns_db_attach(view
->cachedb
, &db
);
1063 * Maybe we have hints...
1065 try_hints
= ISC_TRUE
;
1068 } else if (result
!= ISC_R_SUCCESS
) {
1070 * Something is broken.
1074 is_cache
= dns_db_iscache(db
);
1078 * Look for the zonecut.
1081 result
= dns_db_find(db
, name
, NULL
, dns_rdatatype_ns
, options
,
1082 now
, NULL
, fname
, rdataset
, sigrdataset
);
1083 if (result
== DNS_R_DELEGATION
)
1084 result
= ISC_R_SUCCESS
;
1085 else if (result
!= ISC_R_SUCCESS
)
1087 if (use_cache
&& view
->cachedb
!= NULL
&& db
!= view
->hints
) {
1089 * We found an answer, but the cache may be better.
1091 zfname
= dns_fixedname_name(&zfixedname
);
1092 result
= dns_name_copy(fname
, zfname
, NULL
);
1093 if (result
!= ISC_R_SUCCESS
)
1095 dns_rdataset_clone(rdataset
, &zrdataset
);
1096 dns_rdataset_disassociate(rdataset
);
1097 if (sigrdataset
!= NULL
&&
1098 dns_rdataset_isassociated(sigrdataset
)) {
1099 dns_rdataset_clone(sigrdataset
, &zsigrdataset
);
1100 dns_rdataset_disassociate(sigrdataset
);
1103 dns_db_attach(view
->cachedb
, &db
);
1104 is_cache
= ISC_TRUE
;
1108 result
= dns_db_findzonecut(db
, name
, options
, now
, NULL
,
1109 fname
, rdataset
, sigrdataset
);
1110 if (result
== ISC_R_SUCCESS
) {
1111 if (zfname
!= NULL
&&
1112 !dns_name_issubdomain(fname
, zfname
)) {
1114 * We found a zonecut in the cache, but our
1115 * zone delegation is better.
1117 use_zone
= ISC_TRUE
;
1119 } else if (result
== ISC_R_NOTFOUND
) {
1120 if (zfname
!= NULL
) {
1122 * We didn't find anything in the cache, but we
1123 * have a zone delegation, so use it.
1125 use_zone
= ISC_TRUE
;
1128 * Maybe we have hints...
1130 try_hints
= ISC_TRUE
;
1134 * Something bad happened.
1142 if (dns_rdataset_isassociated(rdataset
)) {
1143 dns_rdataset_disassociate(rdataset
);
1144 if (sigrdataset
!= NULL
&&
1145 dns_rdataset_isassociated(sigrdataset
))
1146 dns_rdataset_disassociate(sigrdataset
);
1148 result
= dns_name_copy(zfname
, fname
, NULL
);
1149 if (result
!= ISC_R_SUCCESS
)
1151 dns_rdataset_clone(&zrdataset
, rdataset
);
1152 if (sigrdataset
!= NULL
&&
1153 dns_rdataset_isassociated(&zrdataset
))
1154 dns_rdataset_clone(&zsigrdataset
, sigrdataset
);
1155 } else if (try_hints
&& use_hints
&& view
->hints
!= NULL
) {
1157 * We've found nothing so far, but we have hints.
1159 result
= dns_db_find(view
->hints
, dns_rootname
, NULL
,
1160 dns_rdatatype_ns
, 0, now
, NULL
, fname
,
1162 if (result
!= ISC_R_SUCCESS
) {
1164 * We can't even find the hints for the root
1167 if (dns_rdataset_isassociated(rdataset
))
1168 dns_rdataset_disassociate(rdataset
);
1169 result
= ISC_R_NOTFOUND
;
1174 if (dns_rdataset_isassociated(&zrdataset
)) {
1175 dns_rdataset_disassociate(&zrdataset
);
1176 if (dns_rdataset_isassociated(&zsigrdataset
))
1177 dns_rdataset_disassociate(&zsigrdataset
);
1183 dns_zone_detach(&zone
);
1190 dns_viewlist_find(dns_viewlist_t
*list
, const char *name
,
1191 dns_rdataclass_t rdclass
, dns_view_t
**viewp
)
1195 REQUIRE(list
!= NULL
);
1197 for (view
= ISC_LIST_HEAD(*list
);
1199 view
= ISC_LIST_NEXT(view
, link
)) {
1200 if (strcmp(view
->name
, name
) == 0 && view
->rdclass
== rdclass
)
1204 return (ISC_R_NOTFOUND
);
1206 dns_view_attach(view
, viewp
);
1208 return (ISC_R_SUCCESS
);
1213 dns_viewlist_findzone(dns_viewlist_t
*list
, dns_name_t
*name
,
1214 isc_boolean_t allclasses
, dns_rdataclass_t rdclass
,
1218 isc_result_t result
;
1219 dns_zone_t
*zone1
= NULL
, *zone2
= NULL
;
1220 dns_zone_t
**zp
= NULL
;;
1222 REQUIRE(list
!= NULL
);
1223 for (view
= ISC_LIST_HEAD(*list
);
1225 view
= ISC_LIST_NEXT(view
, link
)) {
1226 if (allclasses
== ISC_FALSE
&& view
->rdclass
!= rdclass
)
1230 * If the zone is defined in more than one view,
1231 * treat it as not found.
1233 zp
= (zone1
== NULL
) ? &zone1
: &zone2
;
1234 result
= dns_zt_find(view
->zonetable
, name
, 0, NULL
, zp
);
1235 INSIST(result
== ISC_R_SUCCESS
||
1236 result
== ISC_R_NOTFOUND
||
1237 result
== DNS_R_PARTIALMATCH
);
1239 /* Treat a partial match as no match */
1240 if (result
== DNS_R_PARTIALMATCH
) {
1241 dns_zone_detach(zp
);
1242 result
= ISC_R_NOTFOUND
;
1245 if (zone2
!= NULL
) {
1246 dns_zone_detach(&zone1
);
1247 dns_zone_detach(&zone2
);
1248 return (ISC_R_NOTFOUND
);
1252 if (zone1
!= NULL
) {
1253 dns_zone_attach(zone1
, zonep
);
1254 dns_zone_detach(&zone1
);
1255 return (ISC_R_SUCCESS
);
1258 return (ISC_R_NOTFOUND
);
1262 dns_view_load(dns_view_t
*view
, isc_boolean_t stop
) {
1264 REQUIRE(DNS_VIEW_VALID(view
));
1266 return (dns_zt_load(view
->zonetable
, stop
));
1270 dns_view_loadnew(dns_view_t
*view
, isc_boolean_t stop
) {
1272 REQUIRE(DNS_VIEW_VALID(view
));
1274 return (dns_zt_loadnew(view
->zonetable
, stop
));
1279 dns_view_gettsig(dns_view_t
*view
, dns_name_t
*keyname
, dns_tsigkey_t
**keyp
)
1281 isc_result_t result
;
1282 REQUIRE(keyp
!= NULL
&& *keyp
== NULL
);
1284 result
= dns_tsigkey_find(keyp
, keyname
, NULL
,
1286 if (result
== ISC_R_NOTFOUND
)
1287 result
= dns_tsigkey_find(keyp
, keyname
, NULL
,
1293 dns_view_getpeertsig(dns_view_t
*view
, isc_netaddr_t
*peeraddr
,
1294 dns_tsigkey_t
**keyp
)
1296 isc_result_t result
;
1297 dns_name_t
*keyname
= NULL
;
1298 dns_peer_t
*peer
= NULL
;
1300 result
= dns_peerlist_peerbyaddr(view
->peers
, peeraddr
, &peer
);
1301 if (result
!= ISC_R_SUCCESS
)
1304 result
= dns_peer_getkey(peer
, &keyname
);
1305 if (result
!= ISC_R_SUCCESS
)
1308 result
= dns_view_gettsig(view
, keyname
, keyp
);
1309 return ((result
== ISC_R_NOTFOUND
) ? ISC_R_FAILURE
: result
);
1313 dns_view_checksig(dns_view_t
*view
, isc_buffer_t
*source
, dns_message_t
*msg
) {
1314 REQUIRE(DNS_VIEW_VALID(view
));
1315 REQUIRE(source
!= NULL
);
1317 return (dns_tsig_verify(source
, msg
, view
->statickeys
,
1318 view
->dynamickeys
));
1323 dns_view_dumpdbtostream(dns_view_t
*view
, FILE *fp
) {
1324 isc_result_t result
;
1326 REQUIRE(DNS_VIEW_VALID(view
));
1328 (void)fprintf(fp
, ";\n; Cache dump of view '%s'\n;\n", view
->name
);
1329 result
= dns_master_dumptostream(view
->mctx
, view
->cachedb
, NULL
,
1330 &dns_master_style_cache
, fp
);
1331 if (result
!= ISC_R_SUCCESS
)
1333 dns_adb_dump(view
->adb
, fp
);
1334 return (ISC_R_SUCCESS
);
1339 dns_view_flushcache(dns_view_t
*view
) {
1340 return (dns_view_flushcache2(view
, ISC_FALSE
));
1344 dns_view_flushcache2(dns_view_t
*view
, isc_boolean_t fixuponly
) {
1345 isc_result_t result
;
1347 REQUIRE(DNS_VIEW_VALID(view
));
1349 if (view
->cachedb
== NULL
)
1350 return (ISC_R_SUCCESS
);
1352 result
= dns_cache_flush(view
->cache
);
1353 if (result
!= ISC_R_SUCCESS
)
1357 if (view
->acache
!= NULL
)
1358 dns_acache_putdb(view
->acache
, view
->cachedb
);
1360 dns_db_detach(&view
->cachedb
);
1361 dns_cache_attachdb(view
->cache
, &view
->cachedb
);
1363 if (view
->acache
!= NULL
)
1364 dns_acache_setdb(view
->acache
, view
->cachedb
);
1367 dns_adb_flush(view
->adb
);
1368 return (ISC_R_SUCCESS
);
1372 dns_view_flushname(dns_view_t
*view
, dns_name_t
*name
) {
1374 REQUIRE(DNS_VIEW_VALID(view
));
1376 if (view
->adb
!= NULL
)
1377 dns_adb_flushname(view
->adb
, name
);
1378 if (view
->cache
== NULL
)
1379 return (ISC_R_SUCCESS
);
1380 return (dns_cache_flushname(view
->cache
, name
));
1384 dns_view_adddelegationonly(dns_view_t
*view
, dns_name_t
*name
) {
1385 isc_result_t result
;
1389 REQUIRE(DNS_VIEW_VALID(view
));
1391 if (view
->delonly
== NULL
) {
1392 view
->delonly
= isc_mem_get(view
->mctx
,
1393 sizeof(dns_namelist_t
) *
1394 DNS_VIEW_DELONLYHASH
);
1395 if (view
->delonly
== NULL
)
1396 return (ISC_R_NOMEMORY
);
1397 for (hash
= 0; hash
< DNS_VIEW_DELONLYHASH
; hash
++)
1398 ISC_LIST_INIT(view
->delonly
[hash
]);
1400 hash
= dns_name_hash(name
, ISC_FALSE
) % DNS_VIEW_DELONLYHASH
;
1401 new = ISC_LIST_HEAD(view
->delonly
[hash
]);
1402 while (new != NULL
&& !dns_name_equal(new, name
))
1403 new = ISC_LIST_NEXT(new, link
);
1405 return (ISC_R_SUCCESS
);
1406 new = isc_mem_get(view
->mctx
, sizeof(*new));
1408 return (ISC_R_NOMEMORY
);
1409 dns_name_init(new, NULL
);
1410 result
= dns_name_dup(name
, view
->mctx
, new);
1411 if (result
== ISC_R_SUCCESS
)
1412 ISC_LIST_APPEND(view
->delonly
[hash
], new, link
);
1414 isc_mem_put(view
->mctx
, new, sizeof(*new));
1419 dns_view_excludedelegationonly(dns_view_t
*view
, dns_name_t
*name
) {
1420 isc_result_t result
;
1424 REQUIRE(DNS_VIEW_VALID(view
));
1426 if (view
->rootexclude
== NULL
) {
1427 view
->rootexclude
= isc_mem_get(view
->mctx
,
1428 sizeof(dns_namelist_t
) *
1429 DNS_VIEW_DELONLYHASH
);
1430 if (view
->rootexclude
== NULL
)
1431 return (ISC_R_NOMEMORY
);
1432 for (hash
= 0; hash
< DNS_VIEW_DELONLYHASH
; hash
++)
1433 ISC_LIST_INIT(view
->rootexclude
[hash
]);
1435 hash
= dns_name_hash(name
, ISC_FALSE
) % DNS_VIEW_DELONLYHASH
;
1436 new = ISC_LIST_HEAD(view
->rootexclude
[hash
]);
1437 while (new != NULL
&& !dns_name_equal(new, name
))
1438 new = ISC_LIST_NEXT(new, link
);
1440 return (ISC_R_SUCCESS
);
1441 new = isc_mem_get(view
->mctx
, sizeof(*new));
1443 return (ISC_R_NOMEMORY
);
1444 dns_name_init(new, NULL
);
1445 result
= dns_name_dup(name
, view
->mctx
, new);
1446 if (result
== ISC_R_SUCCESS
)
1447 ISC_LIST_APPEND(view
->rootexclude
[hash
], new, link
);
1449 isc_mem_put(view
->mctx
, new, sizeof(*new));
1454 dns_view_isdelegationonly(dns_view_t
*view
, dns_name_t
*name
) {
1458 REQUIRE(DNS_VIEW_VALID(view
));
1460 if (!view
->rootdelonly
&& view
->delonly
== NULL
)
1463 hash
= dns_name_hash(name
, ISC_FALSE
) % DNS_VIEW_DELONLYHASH
;
1464 if (view
->rootdelonly
&& dns_name_countlabels(name
) <= 2) {
1465 if (view
->rootexclude
== NULL
)
1467 new = ISC_LIST_HEAD(view
->rootexclude
[hash
]);
1468 while (new != NULL
&& !dns_name_equal(new, name
))
1469 new = ISC_LIST_NEXT(new, link
);
1474 if (view
->delonly
== NULL
)
1477 new = ISC_LIST_HEAD(view
->delonly
[hash
]);
1478 while (new != NULL
&& !dns_name_equal(new, name
))
1479 new = ISC_LIST_NEXT(new, link
);
1486 dns_view_setrootdelonly(dns_view_t
*view
, isc_boolean_t value
) {
1487 REQUIRE(DNS_VIEW_VALID(view
));
1488 view
->rootdelonly
= value
;
1492 dns_view_getrootdelonly(dns_view_t
*view
) {
1493 REQUIRE(DNS_VIEW_VALID(view
));
1494 return (view
->rootdelonly
);
1499 dns_view_freezezones(dns_view_t
*view
, isc_boolean_t value
) {
1500 REQUIRE(DNS_VIEW_VALID(view
));
1501 return (dns_zt_freezezones(view
->zonetable
, value
));
1506 dns_view_setresstats(dns_view_t
*view
, isc_stats_t
*stats
) {
1507 REQUIRE(DNS_VIEW_VALID(view
));
1508 REQUIRE(!view
->frozen
);
1509 REQUIRE(view
->resstats
== NULL
);
1511 isc_stats_attach(stats
, &view
->resstats
);
1515 dns_view_getresstats(dns_view_t
*view
, isc_stats_t
**statsp
) {
1516 REQUIRE(DNS_VIEW_VALID(view
));
1517 REQUIRE(statsp
!= NULL
&& *statsp
== NULL
);
1519 if (view
->resstats
!= NULL
)
1520 isc_stats_attach(view
->resstats
, statsp
);
1524 dns_view_setresquerystats(dns_view_t
*view
, dns_stats_t
*stats
) {
1525 REQUIRE(DNS_VIEW_VALID(view
));
1526 REQUIRE(!view
->frozen
);
1527 REQUIRE(view
->resquerystats
== NULL
);
1529 dns_stats_attach(stats
, &view
->resquerystats
);
1533 dns_view_getresquerystats(dns_view_t
*view
, dns_stats_t
**statsp
) {
1534 REQUIRE(DNS_VIEW_VALID(view
));
1535 REQUIRE(statsp
!= NULL
&& *statsp
== NULL
);
1537 if (view
->resquerystats
!= NULL
)
1538 dns_stats_attach(view
->resquerystats
, statsp
);
1542 dns_view_initsecroots(dns_view_t
*view
, isc_mem_t
*mctx
) {
1543 REQUIRE(DNS_VIEW_VALID(view
));
1544 if (view
->secroots_priv
!= NULL
)
1545 dns_keytable_detach(&view
->secroots_priv
);
1546 return (dns_keytable_create(mctx
, &view
->secroots_priv
));
1550 dns_view_getsecroots(dns_view_t
*view
, dns_keytable_t
**ktp
) {
1551 REQUIRE(DNS_VIEW_VALID(view
));
1552 REQUIRE(ktp
!= NULL
&& *ktp
== NULL
);
1553 if (view
->secroots_priv
== NULL
)
1554 return (ISC_R_NOTFOUND
);
1555 dns_keytable_attach(view
->secroots_priv
, ktp
);
1556 return (ISC_R_SUCCESS
);
1560 dns_view_issecuredomain(dns_view_t
*view
, dns_name_t
*name
,
1561 isc_boolean_t
*secure_domain
) {
1562 REQUIRE(DNS_VIEW_VALID(view
));
1563 return (dns_keytable_issecuredomain(view
->secroots_priv
, name
,