unsigned int resolver_param;
dns_ntatable_t *ntatable = NULL;
const char *qminmode = NULL;
+ dns_adb_t *adb = NULL;
REQUIRE(DNS_VIEW_VALID(view));
{
max_adb_size = MAX_ADB_SIZE_FOR_CACHESHARE;
if (!nsc->adbsizeadjusted) {
- dns_adb_setadbsize(nsc->primaryview->adb,
- MAX_ADB_SIZE_FOR_CACHESHARE);
- nsc->adbsizeadjusted = true;
+ dns_view_getadb(nsc->primaryview, &adb);
+ if (adb != NULL) {
+ dns_adb_setadbsize(
+ adb,
+ MAX_ADB_SIZE_FOR_CACHESHARE);
+ nsc->adbsizeadjusted = true;
+ dns_adb_detach(&adb);
+ }
}
}
}
- dns_adb_setadbsize(view->adb, max_adb_size);
+ dns_view_getadb(view, &adb);
+ if (adb != NULL) {
+ dns_adb_setadbsize(adb, max_adb_size);
+ dns_adb_detach(&adb);
+ }
/*
* Set up ADB quotas
obj2 = cfg_tuple_get(obj, "discount");
discount = (double)cfg_obj_asfixedpoint(obj2) / 100.0;
- dns_adb_setquota(view->adb, fps, freq, low, high, discount);
+ dns_view_getadb(view, &adb);
+ if (adb != NULL) {
+ dns_adb_setquota(adb, fps, freq, low, high, discount);
+ dns_adb_detach(&adb);
+ }
}
/*
if (dctx->cache != NULL) {
if (dctx->dumpadb) {
- dns_adb_dump(dctx->view->view->adb, dctx->fp);
+ dns_adb_t *adb = NULL;
+ dns_view_getadb(dctx->view->view, &adb);
+ if (adb != NULL) {
+ dns_adb_dump(adb, dctx->fp);
+ dns_adb_detach(&adb);
+ }
}
if (dctx->dumpbad) {
dns_resolver_printbadcache(dctx->view->view->resolver,
dns_view_t *view = NULL;
char *ptr = NULL, *viewname = NULL;
bool first = true;
+ dns_adb_t *adb = NULL;
REQUIRE(text != NULL);
continue;
}
- if (view->adb == NULL) {
+ dns_view_getadb(view, &adb);
+ if (adb == NULL) {
continue;
}
CHECK(putstr(text, "Rate limited servers, view "));
CHECK(putstr(text, view->name));
- dns_adb_getquota(view->adb, &val, NULL, NULL, NULL, NULL);
+ dns_adb_getquota(adb, &val, NULL, NULL, NULL, NULL);
s = snprintf(tbuf, sizeof(tbuf),
" (fetches-per-server %u):", val);
if (s < 0 || (unsigned int)s > sizeof(tbuf)) {
- return (ISC_R_NOSPACE);
+ CHECK(ISC_R_NOSPACE);
}
first = false;
CHECK(putstr(text, tbuf));
used = isc_buffer_usedlength(*text);
- CHECK(dns_adb_dumpquota(view->adb, text));
+ CHECK(dns_adb_dumpquota(adb, text));
if (used == isc_buffer_usedlength(*text)) {
CHECK(putstr(text, "\n None."));
}
s = snprintf(tbuf, sizeof(tbuf),
" (fetches-per-zone %u):", val);
if (s < 0 || (unsigned int)s > sizeof(tbuf)) {
- return (ISC_R_NOSPACE);
+ CHECK(ISC_R_NOSPACE);
}
CHECK(putstr(text, tbuf));
used = isc_buffer_usedlength(*text);
if (used == isc_buffer_usedlength(*text)) {
CHECK(putstr(text, "\n None."));
}
+ dns_adb_detach(&adb);
}
-
cleanup:
+ if (adb != NULL) {
+ dns_adb_detach(&adb);
+ }
if (isc_buffer_usedlength(*text) > 0) {
(void)putnull(text);
}
{
isc_stats_t *istats = NULL;
dns_stats_t *dstats = NULL;
+ dns_adb_t *adb = NULL;
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "view"));
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "name",
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters"));
TRY0(xmlTextWriterWriteAttribute(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR "adbstat"));
- CHECK(dump_stats(
- dns_adb_getstats(view->adb), isc_statsformat_xml,
- writer, NULL, adbstats_xmldesc, dns_adbstats_max,
- adbstats_index, adbstat_values, ISC_STATSDUMP_VERBOSE));
+ dns_view_getadb(view, &adb);
+ if (adb != NULL) {
+ result = dump_stats(dns_adb_getstats(adb),
+ isc_statsformat_xml, writer, NULL,
+ adbstats_xmldesc, dns_adbstats_max,
+ adbstats_index, adbstat_values,
+ ISC_STATSDUMP_VERBOSE);
+ dns_adb_detach(&adb);
+ CHECK(result);
+ }
TRY0(xmlTextWriterEndElement(writer)); /* </adbstats> */
/* <cachestats> */
view = ISC_LIST_HEAD(server->viewlist);
while (view != NULL) {
json_object *za, *v = json_object_new_object();
+ dns_adb_t *adb = NULL;
CHECKMEM(v);
json_object_object_add(viewlist, view->name, v);
json_object_object_add(res, "cachestats",
counters);
- istats = dns_adb_getstats(view->adb);
+ dns_view_getadb(view, &adb);
+ if (adb != NULL) {
+ istats = dns_adb_getstats(adb);
+ dns_adb_detach(&adb);
+ }
if (istats != NULL) {
counters = json_object_new_object();
CHECKMEM(counters);
for (view = ISC_LIST_HEAD(server->viewlist); view != NULL;
view = ISC_LIST_NEXT(view, link))
{
- isc_stats_t *adbstats = dns_adb_getstats(view->adb);
+ dns_adb_t *adb = NULL;
+ isc_stats_t *adbstats = NULL;
+ dns_view_getadb(view, &adb);
+ if (adb != NULL) {
+ adbstats = dns_adb_getstats(adb);
+ dns_adb_detach(&adb);
+ }
if (adbstats == NULL) {
continue;
}
* Add a DNSSEC trusted key to a view of class 'IN'. 'rdtype' is the type
* of the RR data for the key, either DNSKEY or DS. 'keyname' is the DNS
* name of the key, and 'databuf' stores the RR data.
-
+ *
* Requires:
*
*\li 'view' is a valid view.
-
+ *
*\li 'view' is class 'IN'.
*
*\li 'keyname' is a valid name.
* \li ISC_R_SHUTTINGDOWN if the view is in the process of shutting down.
*/
+void
+dns_view_getadb(dns_view_t *view, dns_adb_t **adbp);
+/*%<
+ * Get the view's adb if it exist.
+ *
+ * Requires:
+ *
+ *\li 'view' is a valid view.
+ *\li 'adbp' is non-NULL and '*adbp' is NULL.
+ */
+
ISC_LANG_ENDDECLS
* Attach to the view's cache and adb.
*/
dns_db_attach(res->view->cachedb, &fctx->cache);
- dns_adb_attach(res->view->adb, &fctx->adb);
+ dns_view_getadb(res->view, &fctx->adb);
ISC_LIST_INIT(fctx->resps);
ISC_LINK_INIT(fctx, link);
if (view->resolver != NULL) {
dns_resolver_shutdown(view->resolver);
}
- if (view->adb != NULL) {
- dns_adb_shutdown(view->adb);
+
+ rcu_read_lock();
+ adb = rcu_dereference(view->adb);
+ if (adb != NULL) {
+ dns_adb_shutdown(adb);
}
+ rcu_read_unlock();
+
if (view->requestmgr != NULL) {
dns_requestmgr_shutdown(view->requestmgr);
}
/* Swap the pointers under the lock */
LOCK(&view->lock);
+ if (view->resolver != NULL) {
+ resolver = view->resolver;
+ view->resolver = NULL;
+ }
+
rcu_read_lock();
zonetable = rcu_xchg_pointer(&view->zonetable, NULL);
if (zonetable != NULL) {
dns_zt_flush(zonetable);
}
}
+ adb = rcu_xchg_pointer(&view->adb, NULL);
rcu_read_unlock();
- if (view->resolver != NULL) {
- resolver = view->resolver;
- view->resolver = NULL;
- }
-
- if (view->adb != NULL) {
- adb = view->adb;
- view->adb = NULL;
- }
-
if (view->requestmgr != NULL) {
requestmgr = view->requestmgr;
view->requestmgr = NULL;
if (resolver != NULL) {
dns_resolver_detach(&resolver);
}
- if (adb != NULL) {
- dns_adb_detach(&adb);
+ if (adb != NULL || zonetable != NULL) {
+ synchronize_rcu();
+ if (adb != NULL) {
+ dns_adb_detach(&adb);
+ }
+ if (zonetable != NULL) {
+ dns_zt_detach(&zonetable);
+ }
}
if (requestmgr != NULL) {
dns_requestmgr_detach(&requestmgr);
}
-
- if (zonetable != NULL) {
- synchronize_rcu();
- dns_zt_detach(&zonetable);
- }
if (mkzone != NULL) {
dns_zone_detach(&mkzone);
}
isc_result_t
dns_view_flushcache(dns_view_t *view, bool fixuponly) {
isc_result_t result;
+ dns_adb_t *adb = NULL;
REQUIRE(DNS_VIEW_VALID(view));
dns_badcache_flush(view->failcache);
}
- if (view->adb) {
- dns_adb_flush(view->adb);
+ rcu_read_lock();
+ adb = rcu_dereference(view->adb);
+ if (adb != NULL) {
+ dns_adb_flush(adb);
}
+ rcu_read_unlock();
return (ISC_R_SUCCESS);
}
isc_result_t
dns_view_flushnode(dns_view_t *view, const dns_name_t *name, bool tree) {
isc_result_t result = ISC_R_SUCCESS;
+ dns_adb_t *adb = NULL;
REQUIRE(DNS_VIEW_VALID(view));
if (tree) {
- if (view->adb != NULL) {
- dns_adb_flushnames(view->adb, name);
+ rcu_read_lock();
+ adb = rcu_dereference(view->adb);
+ if (adb != NULL) {
+ dns_adb_flushnames(adb, name);
}
+ rcu_read_unlock();
if (view->resolver != NULL) {
dns_resolver_flushbadnames(view->resolver, name);
}
dns_badcache_flushtree(view->failcache, name);
}
} else {
- if (view->adb != NULL) {
- dns_adb_flushname(view->adb, name);
+ rcu_read_lock();
+ adb = rcu_dereference(view->adb);
+ if (adb != NULL) {
+ dns_adb_flushname(adb, name);
}
+ rcu_read_unlock();
if (view->resolver != NULL) {
dns_resolver_flushbadcache(view->resolver, name);
}
rcu_read_unlock();
return (result);
}
+
+void
+dns_view_getadb(dns_view_t *view, dns_adb_t **adbp) {
+ dns_adb_t *adb = NULL;
+
+ REQUIRE(DNS_VIEW_VALID(view));
+ REQUIRE(adbp != NULL && *adbp == NULL);
+
+ rcu_read_lock();
+ adb = rcu_dereference(view->adb);
+ if (adb != NULL) {
+ dns_adb_attach(adb, adbp);
+ }
+ rcu_read_unlock();
+}
zone_maintenance(dns_zone_t *zone) {
isc_time_t now;
isc_result_t result;
- bool load_pending, exiting, dumping, viewok, notify;
+ bool load_pending, exiting, dumping, viewok = false, notify;
bool refreshkeys, sign, resign, rekey, chain, warn_expire;
REQUIRE(DNS_ZONE_VALID(zone));
LOCK_ZONE(zone);
load_pending = DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADPENDING);
exiting = DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING);
- viewok = (zone->view != NULL && zone->view->adb != NULL);
+ if (!load_pending && !exiting && zone->view != NULL) {
+ dns_adb_t *adb = NULL;
+ dns_view_getadb(zone->view, &adb);
+ if (adb != NULL) {
+ dns_adb_detach(&adb);
+ viewok = true;
+ }
+ }
UNLOCK_ZONE(zone);
if (load_pending || exiting || !viewok) {
notify_find_address(dns_notify_t *notify) {
isc_result_t result;
unsigned int options;
+ dns_adb_t *adb = NULL;
REQUIRE(DNS_NOTIFY_VALID(notify));
options = DNS_ADBFIND_WANTEVENT | DNS_ADBFIND_INET | DNS_ADBFIND_INET6 |
DNS_ADBFIND_RETURNLAME;
- if (notify->zone->view->adb == NULL) {
+ dns_view_getadb(notify->zone->view, &adb);
+ if (adb == NULL) {
goto destroy;
}
- result = dns_adb_createfind(notify->zone->view->adb, notify->zone->loop,
- process_notify_adb_event, notify,
- ¬ify->ns, dns_rootname, 0, options, 0,
- NULL, notify->zone->view->dstport, 0, NULL,
- ¬ify->find);
+ result = dns_adb_createfind(
+ adb, notify->zone->loop, process_notify_adb_event, notify,
+ ¬ify->ns, dns_rootname, 0, options, 0, NULL,
+ notify->zone->view->dstport, 0, NULL, ¬ify->find);
+ dns_adb_detach(&adb);
/* Something failed? */
if (result != ISC_R_SUCCESS) {
checkds_find_address(dns_checkds_t *checkds) {
isc_result_t result;
unsigned int options;
+ dns_adb_t *adb = NULL;
REQUIRE(DNS_CHECKDS_VALID(checkds));
options = DNS_ADBFIND_WANTEVENT | DNS_ADBFIND_INET | DNS_ADBFIND_INET6 |
DNS_ADBFIND_RETURNLAME;
- if (checkds->zone->view->adb == NULL) {
+ dns_view_getadb(checkds->zone->view, &adb);
+ if (adb == NULL) {
goto destroy;
}
result = dns_adb_createfind(
- checkds->zone->view->adb, checkds->zone->loop,
- process_checkds_adb_event, checkds, &checkds->ns, dns_rootname,
- 0, options, 0, NULL, checkds->zone->view->dstport, 0, NULL,
- &checkds->find);
+ adb, checkds->zone->loop, process_checkds_adb_event, checkds,
+ &checkds->ns, dns_rootname, 0, options, 0, NULL,
+ checkds->zone->view->dstport, 0, NULL, &checkds->find);
+ dns_adb_detach(&adb);
/* Something failed? */
if (result != ISC_R_SUCCESS) {
if (client->view != NULL) {
#ifdef ENABLE_AFL
if (client->manager->sctx->fuzztype == isc_fuzz_resolver) {
- dns_adb_flush(client->view->adb);
+ dns_adb_t *adb = NULL;
+ dns_view_getadb(client->view, &adb);
+ if (adb != NULL) {
+ dns_adb_flush(adb);
+ dns_adb_detach(&adb);
+ }
}
#endif /* ifdef ENABLE_AFL */
dns_view_detach(&client->view);