1999-08-05 22:08:45 +00:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2000-08-01 01:33:37 +00:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2020-09-14 16:20:40 -07:00
|
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
1999-08-05 22:08:45 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-27 04:57:32 +00:00
|
|
|
/*! \file */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
#include <inttypes.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <limits.h>
|
2018-04-17 08:29:14 -07:00
|
|
|
#include <stdbool.h>
|
2018-03-28 20:57:20 +02:00
|
|
|
|
2016-07-21 11:13:03 -07:00
|
|
|
#ifdef HAVE_LMDB
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <lmdb.h>
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_LMDB */
|
2016-07-21 11:13:03 -07:00
|
|
|
|
2019-07-18 14:22:31 +02:00
|
|
|
#include <isc/atomic.h>
|
2021-06-10 08:14:57 +02:00
|
|
|
#include <isc/dir.h>
|
2011-01-10 05:32:04 +00:00
|
|
|
#include <isc/file.h>
|
2003-07-25 02:22:26 +00:00
|
|
|
#include <isc/hash.h>
|
2015-01-12 09:04:16 +05:30
|
|
|
#include <isc/lex.h>
|
2011-01-10 05:32:04 +00:00
|
|
|
#include <isc/print.h>
|
2021-10-04 17:14:53 +02:00
|
|
|
#include <isc/result.h>
|
2009-01-27 22:30:00 +00:00
|
|
|
#include <isc/stats.h>
|
2020-02-12 13:59:18 +01:00
|
|
|
#include <isc/string.h> /* Required for HP/UX (and others?) */
|
2006-12-21 06:03:37 +00:00
|
|
|
#include <isc/task.h>
|
1999-12-16 22:24:22 +00:00
|
|
|
#include <isc/util.h>
|
1999-08-05 22:08:45 +00:00
|
|
|
|
2000-04-06 00:19:44 +00:00
|
|
|
#include <dns/acl.h>
|
1999-10-28 19:52:10 +00:00
|
|
|
#include <dns/adb.h>
|
2014-09-03 23:28:14 -07:00
|
|
|
#include <dns/badcache.h>
|
1999-12-02 22:38:34 +00:00
|
|
|
#include <dns/cache.h>
|
1999-08-12 07:49:09 +00:00
|
|
|
#include <dns/db.h>
|
2012-04-27 16:07:24 -07:00
|
|
|
#include <dns/dispatch.h>
|
2005-09-05 00:12:29 +00:00
|
|
|
#include <dns/dlz.h>
|
2010-12-08 02:46:17 +00:00
|
|
|
#include <dns/dns64.h>
|
2010-05-14 04:38:52 +00:00
|
|
|
#include <dns/dnssec.h>
|
1999-11-22 19:53:51 +00:00
|
|
|
#include <dns/events.h>
|
2000-08-24 22:15:40 +00:00
|
|
|
#include <dns/forward.h>
|
2000-03-17 00:00:18 +00:00
|
|
|
#include <dns/keytable.h>
|
2010-05-14 04:38:52 +00:00
|
|
|
#include <dns/keyvalues.h>
|
2000-10-20 15:59:52 +00:00
|
|
|
#include <dns/master.h>
|
2000-12-12 21:33:21 +00:00
|
|
|
#include <dns/masterdump.h>
|
2014-05-29 22:22:53 -07:00
|
|
|
#include <dns/nta.h>
|
2002-03-07 13:46:41 +00:00
|
|
|
#include <dns/order.h>
|
2000-02-24 21:12:16 +00:00
|
|
|
#include <dns/peer.h>
|
2009-05-29 22:22:37 +00:00
|
|
|
#include <dns/rbt.h>
|
1999-09-22 19:35:47 +00:00
|
|
|
#include <dns/rdataset.h>
|
2000-04-18 11:43:46 +00:00
|
|
|
#include <dns/request.h>
|
2000-05-02 03:54:17 +00:00
|
|
|
#include <dns/resolver.h>
|
2011-01-13 01:59:28 +00:00
|
|
|
#include <dns/rpz.h>
|
2016-07-22 20:02:17 +10:00
|
|
|
#include <dns/rrl.h>
|
2008-04-03 05:55:52 +00:00
|
|
|
#include <dns/stats.h>
|
2015-01-12 09:04:16 +05:30
|
|
|
#include <dns/time.h>
|
2021-01-14 12:51:25 +01:00
|
|
|
#include <dns/transport.h>
|
2000-01-21 20:18:41 +00:00
|
|
|
#include <dns/tsig.h>
|
2000-01-20 01:07:16 +00:00
|
|
|
#include <dns/zone.h>
|
2000-01-20 00:46:45 +00:00
|
|
|
#include <dns/zt.h>
|
1999-08-05 22:08:45 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#define CHECK(op) \
|
|
|
|
do { \
|
|
|
|
result = (op); \
|
|
|
|
if (result != ISC_R_SUCCESS) \
|
|
|
|
goto cleanup; \
|
2015-01-12 09:04:16 +05:30
|
|
|
} while (0)
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
#define RESSHUTDOWN(v) \
|
|
|
|
((atomic_load(&(v)->attributes) & DNS_VIEWATTR_RESSHUTDOWN) != 0)
|
|
|
|
#define ADBSHUTDOWN(v) \
|
|
|
|
((atomic_load(&(v)->attributes) & DNS_VIEWATTR_ADBSHUTDOWN) != 0)
|
|
|
|
#define REQSHUTDOWN(v) \
|
|
|
|
((atomic_load(&(v)->attributes) & DNS_VIEWATTR_REQSHUTDOWN) != 0)
|
1999-11-22 19:53:51 +00:00
|
|
|
|
2020-02-13 14:44:37 -08:00
|
|
|
#define DNS_VIEW_DELONLYHASH 111
|
2014-09-03 23:28:14 -07:00
|
|
|
#define DNS_VIEW_FAILCACHESIZE 1021
|
2003-09-17 05:24:43 +00:00
|
|
|
|
2020-02-14 08:14:03 +01:00
|
|
|
static void
|
|
|
|
resolver_shutdown(isc_task_t *task, isc_event_t *event);
|
|
|
|
static void
|
|
|
|
adb_shutdown(isc_task_t *task, isc_event_t *event);
|
|
|
|
static void
|
|
|
|
req_shutdown(isc_task_t *task, isc_event_t *event);
|
1999-11-22 19:53:51 +00:00
|
|
|
|
1999-08-05 22:08:45 +00:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, const char *name,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_t **viewp) {
|
|
|
|
dns_view_t *view;
|
1999-08-05 22:08:45 +00:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
char buffer[1024];
|
1999-08-05 22:08:45 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a view.
|
|
|
|
*/
|
|
|
|
|
|
|
|
REQUIRE(name != NULL);
|
|
|
|
REQUIRE(viewp != NULL && *viewp == NULL);
|
|
|
|
|
2001-11-12 19:05:39 +00:00
|
|
|
view = isc_mem_get(mctx, sizeof(*view));
|
2013-03-08 14:38:03 +11:00
|
|
|
|
2015-01-12 09:04:16 +05:30
|
|
|
view->nta_file = NULL;
|
2013-03-08 14:38:03 +11:00
|
|
|
view->mctx = NULL;
|
|
|
|
isc_mem_attach(mctx, &view->mctx);
|
1999-08-05 22:08:45 +00:00
|
|
|
view->name = isc_mem_strdup(mctx, name);
|
2015-01-12 09:04:16 +05:30
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_file_sanitize(NULL, view->name, "nta", buffer,
|
|
|
|
sizeof(buffer));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2015-01-12 09:04:16 +05:30
|
|
|
goto cleanup_name;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
view->nta_file = isc_mem_strdup(mctx, buffer);
|
|
|
|
|
2018-11-16 15:33:22 +01:00
|
|
|
isc_mutex_init(&view->lock);
|
2005-07-12 01:00:20 +00:00
|
|
|
|
1999-10-13 23:17:32 +00:00
|
|
|
view->zonetable = NULL;
|
2018-10-03 17:56:50 -07:00
|
|
|
result = dns_zt_create(mctx, rdclass, &view->zonetable);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"dns_zt_create() failed: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
result = ISC_R_UNEXPECTED;
|
|
|
|
goto cleanup_mutex;
|
1999-08-05 22:08:45 +00:00
|
|
|
}
|
2018-10-03 17:56:50 -07:00
|
|
|
|
2009-10-27 22:46:13 +00:00
|
|
|
view->secroots_priv = NULL;
|
2014-05-29 22:22:53 -07:00
|
|
|
view->ntatable_priv = NULL;
|
2000-08-24 22:15:40 +00:00
|
|
|
view->fwdtable = NULL;
|
|
|
|
result = dns_fwdtable_create(mctx, &view->fwdtable);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"dns_fwdtable_create() failed: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
result = ISC_R_UNEXPECTED;
|
2009-06-30 02:53:46 +00:00
|
|
|
goto cleanup_zt;
|
2000-08-24 22:15:40 +00:00
|
|
|
}
|
1999-09-22 18:23:36 +00:00
|
|
|
|
1999-12-02 22:38:34 +00:00
|
|
|
view->cache = NULL;
|
1999-08-12 07:49:09 +00:00
|
|
|
view->cachedb = NULL;
|
2012-12-06 12:39:52 -08:00
|
|
|
ISC_LIST_INIT(view->dlz_searched);
|
|
|
|
ISC_LIST_INIT(view->dlz_unsearched);
|
1999-09-24 01:40:50 +00:00
|
|
|
view->hints = NULL;
|
1999-08-05 22:08:45 +00:00
|
|
|
view->resolver = NULL;
|
1999-10-28 19:52:10 +00:00
|
|
|
view->adb = NULL;
|
2000-04-18 11:43:46 +00:00
|
|
|
view->requestmgr = NULL;
|
1999-08-05 22:08:45 +00:00
|
|
|
view->rdclass = rdclass;
|
2018-04-17 08:29:14 -07:00
|
|
|
view->frozen = false;
|
1999-11-22 19:53:51 +00:00
|
|
|
view->task = NULL;
|
2018-08-01 11:46:11 +02:00
|
|
|
isc_refcount_init(&view->references, 1);
|
2019-08-06 12:40:04 +10:00
|
|
|
isc_refcount_init(&view->weakrefs, 1);
|
2020-02-12 13:59:18 +01:00
|
|
|
atomic_init(&view->attributes,
|
|
|
|
(DNS_VIEWATTR_RESSHUTDOWN | DNS_VIEWATTR_ADBSHUTDOWN |
|
|
|
|
DNS_VIEWATTR_REQSHUTDOWN));
|
2021-01-14 12:51:25 +01:00
|
|
|
view->transports = NULL;
|
2000-01-21 20:18:41 +00:00
|
|
|
view->statickeys = NULL;
|
|
|
|
view->dynamickeys = NULL;
|
2000-04-06 00:19:44 +00:00
|
|
|
view->matchclients = NULL;
|
2001-07-26 20:42:46 +00:00
|
|
|
view->matchdestinations = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
view->matchrecursiveonly = false;
|
2000-01-24 19:14:26 +00:00
|
|
|
result = dns_tsigkeyring_create(view->mctx, &view->dynamickeys);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2019-08-01 11:42:58 +02:00
|
|
|
goto cleanup_weakrefs;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-02-24 21:12:16 +00:00
|
|
|
view->peers = NULL;
|
2002-03-07 13:46:41 +00:00
|
|
|
view->order = NULL;
|
2003-09-17 05:24:43 +00:00
|
|
|
view->delonly = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
view->rootdelonly = false;
|
2003-09-19 13:17:21 +00:00
|
|
|
view->rootexclude = NULL;
|
2012-05-14 10:06:05 -07:00
|
|
|
view->adbstats = NULL;
|
2008-04-03 05:55:52 +00:00
|
|
|
view->resstats = NULL;
|
|
|
|
view->resquerystats = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
view->cacheshared = false;
|
2010-12-08 02:46:17 +00:00
|
|
|
ISC_LIST_INIT(view->dns64);
|
|
|
|
view->dns64cnt = 0;
|
2000-04-06 20:25:48 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Initialize configuration data with default values.
|
2000-08-01 01:33:37 +00:00
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
view->recursion = true;
|
|
|
|
view->qminimization = false;
|
|
|
|
view->qmin_strict = false;
|
|
|
|
view->auth_nxdomain = false; /* Was true in BIND 8 */
|
|
|
|
view->enablevalidation = true;
|
|
|
|
view->acceptexpired = false;
|
|
|
|
view->use_glue_cache = false;
|
|
|
|
view->minimal_any = false;
|
2016-08-12 10:48:51 +10:00
|
|
|
view->minimalresponses = dns_minimal_no;
|
2000-04-06 20:25:48 +00:00
|
|
|
view->transfer_format = dns_one_answer;
|
2010-09-24 05:09:03 +00:00
|
|
|
view->cacheacl = NULL;
|
|
|
|
view->cacheonacl = NULL;
|
2021-02-22 13:50:11 +01:00
|
|
|
view->checknames = false;
|
2000-04-06 23:59:19 +00:00
|
|
|
view->queryacl = NULL;
|
2007-03-29 06:36:31 +00:00
|
|
|
view->queryonacl = NULL;
|
2000-04-06 23:59:19 +00:00
|
|
|
view->recursionacl = NULL;
|
2007-03-29 06:36:31 +00:00
|
|
|
view->recursiononacl = NULL;
|
2000-11-10 03:16:26 +00:00
|
|
|
view->sortlist = NULL;
|
2008-05-21 23:17:21 +00:00
|
|
|
view->transferacl = NULL;
|
|
|
|
view->notifyacl = NULL;
|
|
|
|
view->updateacl = NULL;
|
|
|
|
view->upfwdacl = NULL;
|
2009-05-29 22:22:37 +00:00
|
|
|
view->denyansweracl = NULL;
|
2014-02-06 19:37:26 -08:00
|
|
|
view->nocasecompress = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
view->msgcompression = true;
|
2009-05-29 22:22:37 +00:00
|
|
|
view->answeracl_exclude = NULL;
|
|
|
|
view->denyanswernames = NULL;
|
|
|
|
view->answernames_exclude = NULL;
|
2013-02-25 10:49:30 -08:00
|
|
|
view->rrl = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
view->provideixfr = true;
|
2000-05-27 00:20:39 +00:00
|
|
|
view->maxcachettl = 7 * 24 * 3600;
|
|
|
|
view->maxncachettl = 3 * 3600;
|
2019-03-31 21:47:53 +11:00
|
|
|
view->mincachettl = 0;
|
|
|
|
view->minncachettl = 0;
|
2014-06-18 16:47:22 -07:00
|
|
|
view->nta_lifetime = 0;
|
|
|
|
view->nta_recheck = 0;
|
2014-04-13 18:50:34 -07:00
|
|
|
view->prefetch_eligible = 0;
|
|
|
|
view->prefetch_trigger = 0;
|
2000-06-01 00:30:58 +00:00
|
|
|
view->dstport = 53;
|
2002-04-26 00:40:37 +00:00
|
|
|
view->preferred_glue = 0;
|
2018-04-17 08:29:14 -07:00
|
|
|
view->flush = false;
|
2006-01-05 00:01:46 +00:00
|
|
|
view->maxudp = 0;
|
2017-09-06 09:58:29 +10:00
|
|
|
view->staleanswerttl = 1;
|
|
|
|
view->staleanswersok = dns_stale_answer_conf;
|
2018-04-17 08:29:14 -07:00
|
|
|
view->staleanswersenable = false;
|
2015-07-06 09:44:24 +10:00
|
|
|
view->nocookieudp = 0;
|
2017-01-04 09:16:30 -08:00
|
|
|
view->padding = 0;
|
|
|
|
view->pad_acl = NULL;
|
2012-06-14 15:44:20 +10:00
|
|
|
view->maxbits = 0;
|
2013-02-25 12:46:51 -08:00
|
|
|
view->rpzs = NULL;
|
2016-05-26 21:23:19 +02:00
|
|
|
view->catzs = NULL;
|
2010-05-14 04:48:28 +00:00
|
|
|
view->managed_keys = NULL;
|
2011-02-23 03:08:11 +00:00
|
|
|
view->redirect = NULL;
|
2015-04-23 16:57:15 +10:00
|
|
|
view->redirectzone = NULL;
|
|
|
|
dns_fixedname_init(&view->redirectfixed);
|
2018-04-17 08:29:14 -07:00
|
|
|
view->requestnsid = false;
|
|
|
|
view->sendcookie = true;
|
|
|
|
view->requireservercookie = false;
|
|
|
|
view->synthfromdnssec = true;
|
|
|
|
view->trust_anchor_telemetry = true;
|
|
|
|
view->root_key_sentinel = true;
|
2017-04-23 23:16:53 -07:00
|
|
|
view->new_zone_dir = NULL;
|
2010-08-11 18:14:20 +00:00
|
|
|
view->new_zone_file = NULL;
|
2016-07-21 11:13:03 -07:00
|
|
|
view->new_zone_db = NULL;
|
|
|
|
view->new_zone_dbenv = NULL;
|
2017-06-13 10:15:34 -07:00
|
|
|
view->new_zone_mapsize = 0ULL;
|
2010-08-11 18:14:20 +00:00
|
|
|
view->new_zone_config = NULL;
|
|
|
|
view->cfg_destroy = NULL;
|
2014-09-03 23:28:14 -07:00
|
|
|
view->fail_ttl = 0;
|
|
|
|
view->failcache = NULL;
|
2018-11-09 15:31:26 +11:00
|
|
|
result = dns_badcache_init(view->mctx, DNS_VIEW_FAILCACHESIZE,
|
2016-10-28 11:14:38 +11:00
|
|
|
&view->failcache);
|
2018-11-09 15:31:26 +11:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto cleanup_dynkeys;
|
|
|
|
}
|
2015-09-28 18:57:19 +10:00
|
|
|
view->v6bias = 0;
|
2015-10-02 12:32:42 -07:00
|
|
|
view->dtenv = NULL;
|
|
|
|
view->dttypes = 0;
|
2010-08-11 18:14:20 +00:00
|
|
|
|
2018-11-30 15:32:03 -08:00
|
|
|
view->plugins = NULL;
|
|
|
|
view->plugins_free = NULL;
|
2018-08-12 11:19:36 -07:00
|
|
|
view->hooktable = NULL;
|
|
|
|
view->hooktable_free = NULL;
|
|
|
|
|
2018-11-16 15:33:22 +01:00
|
|
|
isc_mutex_init(&view->new_zone_lock);
|
2016-10-28 11:14:38 +11:00
|
|
|
|
2018-10-03 17:56:50 -07:00
|
|
|
result = dns_order_create(view->mctx, &view->order);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
goto cleanup_new_zone_lock;
|
2013-04-10 13:49:57 -07:00
|
|
|
}
|
2001-03-26 21:33:07 +00:00
|
|
|
|
2002-03-07 13:46:41 +00:00
|
|
|
result = dns_peerlist_new(view->mctx, &view->peers);
|
2018-11-09 15:31:26 +11:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2002-03-07 13:46:41 +00:00
|
|
|
goto cleanup_order;
|
2018-11-09 15:31:26 +11:00
|
|
|
}
|
2002-03-07 13:46:41 +00:00
|
|
|
|
2021-05-22 18:12:11 +02:00
|
|
|
result = dns_aclenv_create(view->mctx, &view->aclenv);
|
2018-11-09 15:31:26 +11:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2001-03-26 21:33:07 +00:00
|
|
|
goto cleanup_peerlist;
|
2018-11-09 15:31:26 +11:00
|
|
|
}
|
2001-03-26 21:33:07 +00:00
|
|
|
|
1999-10-12 00:30:05 +00:00
|
|
|
ISC_LINK_INIT(view, link);
|
2001-11-12 19:05:39 +00:00
|
|
|
ISC_EVENT_INIT(&view->resevent, sizeof(view->resevent), 0, NULL,
|
2020-02-12 13:59:18 +01:00
|
|
|
DNS_EVENT_VIEWRESSHUTDOWN, resolver_shutdown, view, NULL,
|
|
|
|
NULL, NULL);
|
2001-11-12 19:05:39 +00:00
|
|
|
ISC_EVENT_INIT(&view->adbevent, sizeof(view->adbevent), 0, NULL,
|
2020-02-12 13:59:18 +01:00
|
|
|
DNS_EVENT_VIEWADBSHUTDOWN, adb_shutdown, view, NULL,
|
|
|
|
NULL, NULL);
|
2001-11-12 19:05:39 +00:00
|
|
|
ISC_EVENT_INIT(&view->reqevent, sizeof(view->reqevent), 0, NULL,
|
2020-02-12 13:59:18 +01:00
|
|
|
DNS_EVENT_VIEWREQSHUTDOWN, req_shutdown, view, NULL,
|
|
|
|
NULL, NULL);
|
2013-04-03 17:27:40 +11:00
|
|
|
view->viewlist = NULL;
|
1999-08-05 22:08:45 +00:00
|
|
|
view->magic = DNS_VIEW_MAGIC;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
1999-08-05 22:08:45 +00:00
|
|
|
*viewp = view;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_peerlist:
|
2018-11-09 15:31:26 +11:00
|
|
|
if (view->peers != NULL) {
|
2013-04-10 13:49:57 -07:00
|
|
|
dns_peerlist_detach(&view->peers);
|
2018-11-09 15:31:26 +11:00
|
|
|
}
|
2001-03-26 21:33:07 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_order:
|
2018-11-09 15:31:26 +11:00
|
|
|
if (view->order != NULL) {
|
2013-04-10 13:49:57 -07:00
|
|
|
dns_order_detach(&view->order);
|
2018-11-09 15:31:26 +11:00
|
|
|
}
|
2002-03-07 13:46:41 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_new_zone_lock:
|
2018-11-19 10:31:09 +00:00
|
|
|
isc_mutex_destroy(&view->new_zone_lock);
|
2016-10-28 11:14:38 +11:00
|
|
|
|
2018-11-09 15:31:26 +11:00
|
|
|
dns_badcache_destroy(&view->failcache);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_dynkeys:
|
2018-11-09 15:31:26 +11:00
|
|
|
if (view->dynamickeys != NULL) {
|
2013-04-10 13:49:57 -07:00
|
|
|
dns_tsigkeyring_detach(&view->dynamickeys);
|
2018-11-09 15:31:26 +11:00
|
|
|
}
|
2000-02-24 21:12:16 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_weakrefs:
|
2019-12-05 13:29:45 +11:00
|
|
|
isc_refcount_decrementz(&view->weakrefs);
|
2019-08-01 11:42:58 +02:00
|
|
|
isc_refcount_destroy(&view->weakrefs);
|
|
|
|
|
2019-12-05 13:29:45 +11:00
|
|
|
isc_refcount_decrementz(&view->references);
|
2005-07-12 01:00:20 +00:00
|
|
|
isc_refcount_destroy(&view->references);
|
|
|
|
|
2018-11-09 15:31:26 +11:00
|
|
|
if (view->fwdtable != NULL) {
|
2013-04-10 13:49:57 -07:00
|
|
|
dns_fwdtable_destroy(&view->fwdtable);
|
2018-11-09 15:31:26 +11:00
|
|
|
}
|
2000-08-24 22:15:40 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_zt:
|
2018-11-09 15:31:26 +11:00
|
|
|
if (view->zonetable != NULL) {
|
2013-04-10 13:49:57 -07:00
|
|
|
dns_zt_detach(&view->zonetable);
|
2018-11-09 15:31:26 +11:00
|
|
|
}
|
1999-10-11 19:13:17 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_mutex:
|
2018-11-19 10:31:09 +00:00
|
|
|
isc_mutex_destroy(&view->lock);
|
1999-08-05 22:08:45 +00:00
|
|
|
|
2018-11-09 15:31:26 +11:00
|
|
|
if (view->nta_file != NULL) {
|
2015-01-12 09:04:16 +05:30
|
|
|
isc_mem_free(mctx, view->nta_file);
|
2018-11-09 15:31:26 +11:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup_name:
|
1999-08-05 22:08:45 +00:00
|
|
|
isc_mem_free(mctx, view->name);
|
2013-03-08 14:38:03 +11:00
|
|
|
isc_mem_putanddetach(&view->mctx, view, sizeof(*view));
|
1999-08-05 22:08:45 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2020-02-13 14:44:37 -08:00
|
|
|
destroy(dns_view_t *view) {
|
2010-12-08 02:46:17 +00:00
|
|
|
dns_dns64_t *dns64;
|
2012-12-06 12:39:52 -08:00
|
|
|
dns_dlzdb_t *dlzdb;
|
2010-12-08 02:46:17 +00:00
|
|
|
|
1999-08-05 22:08:45 +00:00
|
|
|
REQUIRE(!ISC_LINK_LINKED(view, link));
|
1999-11-22 19:53:51 +00:00
|
|
|
REQUIRE(RESSHUTDOWN(view));
|
|
|
|
REQUIRE(ADBSHUTDOWN(view));
|
2000-04-18 11:43:46 +00:00
|
|
|
REQUIRE(REQSHUTDOWN(view));
|
1999-08-05 22:08:45 +00:00
|
|
|
|
2019-08-01 11:42:58 +02:00
|
|
|
isc_refcount_destroy(&view->references);
|
|
|
|
isc_refcount_destroy(&view->weakrefs);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->order != NULL) {
|
2002-03-07 13:46:41 +00:00
|
|
|
dns_order_detach(&view->order);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->peers != NULL) {
|
2000-02-24 21:12:16 +00:00
|
|
|
dns_peerlist_detach(&view->peers);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-01-10 05:32:04 +00:00
|
|
|
|
|
|
|
if (view->dynamickeys != NULL) {
|
|
|
|
isc_result_t result;
|
2018-03-28 22:11:22 +05:30
|
|
|
char template[PATH_MAX];
|
2020-02-13 14:44:37 -08:00
|
|
|
char keyfile[PATH_MAX];
|
2011-01-10 05:32:04 +00:00
|
|
|
FILE *fp = NULL;
|
2018-03-28 22:11:22 +05:30
|
|
|
|
|
|
|
result = isc_file_mktemplate(NULL, template, sizeof(template));
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
(void)isc_file_openuniqueprivate(template, &fp);
|
2011-01-10 05:32:04 +00:00
|
|
|
}
|
2018-03-28 22:11:22 +05:30
|
|
|
if (fp == NULL) {
|
2011-01-10 05:32:04 +00:00
|
|
|
dns_tsigkeyring_detach(&view->dynamickeys);
|
2018-03-28 22:11:22 +05:30
|
|
|
} else {
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_tsigkeyring_dumpanddetach(
|
|
|
|
&view->dynamickeys, fp);
|
2011-01-10 05:32:04 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2018-03-28 22:11:22 +05:30
|
|
|
if (fclose(fp) == 0) {
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_file_sanitize(
|
|
|
|
NULL, view->name, "tsigkeys",
|
|
|
|
keyfile, sizeof(keyfile));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_file_rename(
|
|
|
|
template, keyfile);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-03-28 22:11:22 +05:30
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2011-01-10 05:32:04 +00:00
|
|
|
(void)remove(template);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-01-10 05:32:04 +00:00
|
|
|
} else {
|
|
|
|
(void)fclose(fp);
|
|
|
|
(void)remove(template);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-14 12:51:25 +01:00
|
|
|
if (view->transports != NULL) {
|
|
|
|
dns_transport_list_detach(&view->transports);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->statickeys != NULL) {
|
2011-01-10 05:32:04 +00:00
|
|
|
dns_tsigkeyring_detach(&view->statickeys);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->adb != NULL) {
|
1999-10-28 19:52:10 +00:00
|
|
|
dns_adb_detach(&view->adb);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->resolver != NULL) {
|
1999-08-05 22:08:45 +00:00
|
|
|
dns_resolver_detach(&view->resolver);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-02-25 10:49:30 -08:00
|
|
|
dns_rrl_view_destroy(view);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->rpzs != NULL) {
|
2013-02-25 12:46:51 -08:00
|
|
|
dns_rpz_detach_rpzs(&view->rpzs);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->catzs != NULL) {
|
2016-05-26 21:23:19 +02:00
|
|
|
dns_catz_catzs_detach(&view->catzs);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
for (dlzdb = ISC_LIST_HEAD(view->dlz_searched); dlzdb != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dlzdb = ISC_LIST_HEAD(view->dlz_searched))
|
|
|
|
{
|
2012-12-06 12:39:52 -08:00
|
|
|
ISC_LIST_UNLINK(view->dlz_searched, dlzdb, link);
|
|
|
|
dns_dlzdestroy(&dlzdb);
|
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
for (dlzdb = ISC_LIST_HEAD(view->dlz_unsearched); dlzdb != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dlzdb = ISC_LIST_HEAD(view->dlz_unsearched))
|
|
|
|
{
|
2012-12-06 12:39:52 -08:00
|
|
|
ISC_LIST_UNLINK(view->dlz_unsearched, dlzdb, link);
|
|
|
|
dns_dlzdestroy(&dlzdb);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->requestmgr != NULL) {
|
2000-04-18 11:43:46 +00:00
|
|
|
dns_requestmgr_detach(&view->requestmgr);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->task != NULL) {
|
1999-11-22 19:53:51 +00:00
|
|
|
isc_task_detach(&view->task);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->hints != NULL) {
|
1999-09-24 01:40:50 +00:00
|
|
|
dns_db_detach(&view->hints);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->cachedb != NULL) {
|
1999-08-12 07:49:09 +00:00
|
|
|
dns_db_detach(&view->cachedb);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->cache != NULL) {
|
1999-12-02 22:38:34 +00:00
|
|
|
dns_cache_detach(&view->cache);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->nocasecompress != NULL) {
|
2014-02-06 19:37:26 -08:00
|
|
|
dns_acl_detach(&view->nocasecompress);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->matchclients != NULL) {
|
2000-04-06 00:19:44 +00:00
|
|
|
dns_acl_detach(&view->matchclients);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->matchdestinations != NULL) {
|
2001-07-26 20:42:46 +00:00
|
|
|
dns_acl_detach(&view->matchdestinations);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->cacheacl != NULL) {
|
2010-09-24 05:09:03 +00:00
|
|
|
dns_acl_detach(&view->cacheacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->cacheonacl != NULL) {
|
2010-09-24 05:09:03 +00:00
|
|
|
dns_acl_detach(&view->cacheonacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->queryacl != NULL) {
|
2000-04-06 23:59:19 +00:00
|
|
|
dns_acl_detach(&view->queryacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->queryonacl != NULL) {
|
2007-03-29 06:36:31 +00:00
|
|
|
dns_acl_detach(&view->queryonacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->recursionacl != NULL) {
|
2000-04-06 23:59:19 +00:00
|
|
|
dns_acl_detach(&view->recursionacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->recursiononacl != NULL) {
|
2007-03-29 06:36:31 +00:00
|
|
|
dns_acl_detach(&view->recursiononacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->sortlist != NULL) {
|
2000-11-10 03:16:26 +00:00
|
|
|
dns_acl_detach(&view->sortlist);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->transferacl != NULL) {
|
2008-05-21 23:17:21 +00:00
|
|
|
dns_acl_detach(&view->transferacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->notifyacl != NULL) {
|
2008-05-21 23:17:21 +00:00
|
|
|
dns_acl_detach(&view->notifyacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->updateacl != NULL) {
|
2008-05-21 23:17:21 +00:00
|
|
|
dns_acl_detach(&view->updateacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->upfwdacl != NULL) {
|
2008-05-21 23:17:21 +00:00
|
|
|
dns_acl_detach(&view->upfwdacl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->denyansweracl != NULL) {
|
2009-05-29 22:22:37 +00:00
|
|
|
dns_acl_detach(&view->denyansweracl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->pad_acl != NULL) {
|
2017-01-04 09:16:30 -08:00
|
|
|
dns_acl_detach(&view->pad_acl);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->answeracl_exclude != NULL) {
|
2009-05-29 22:22:37 +00:00
|
|
|
dns_rbt_destroy(&view->answeracl_exclude);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->denyanswernames != NULL) {
|
2009-05-29 22:22:37 +00:00
|
|
|
dns_rbt_destroy(&view->denyanswernames);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->answernames_exclude != NULL) {
|
2009-05-29 22:22:37 +00:00
|
|
|
dns_rbt_destroy(&view->answernames_exclude);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-09-17 05:24:43 +00:00
|
|
|
if (view->delonly != NULL) {
|
|
|
|
dns_name_t *name;
|
2020-02-13 14:44:37 -08:00
|
|
|
int i;
|
2003-09-17 05:24:43 +00:00
|
|
|
|
|
|
|
for (i = 0; i < DNS_VIEW_DELONLYHASH; i++) {
|
|
|
|
name = ISC_LIST_HEAD(view->delonly[i]);
|
|
|
|
while (name != NULL) {
|
|
|
|
ISC_LIST_UNLINK(view->delonly[i], name, link);
|
|
|
|
dns_name_free(name, view->mctx);
|
|
|
|
isc_mem_put(view->mctx, name, sizeof(*name));
|
|
|
|
name = ISC_LIST_HEAD(view->delonly[i]);
|
|
|
|
}
|
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_mem_put(view->mctx, view->delonly,
|
|
|
|
sizeof(dns_namelist_t) * DNS_VIEW_DELONLYHASH);
|
2003-09-17 05:24:43 +00:00
|
|
|
view->delonly = NULL;
|
|
|
|
}
|
2003-09-19 13:17:21 +00:00
|
|
|
if (view->rootexclude != NULL) {
|
|
|
|
dns_name_t *name;
|
2020-02-13 14:44:37 -08:00
|
|
|
int i;
|
2003-09-19 13:17:21 +00:00
|
|
|
|
|
|
|
for (i = 0; i < DNS_VIEW_DELONLYHASH; i++) {
|
|
|
|
name = ISC_LIST_HEAD(view->rootexclude[i]);
|
|
|
|
while (name != NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
ISC_LIST_UNLINK(view->rootexclude[i], name,
|
|
|
|
link);
|
2003-09-19 13:17:21 +00:00
|
|
|
dns_name_free(name, view->mctx);
|
|
|
|
isc_mem_put(view->mctx, name, sizeof(*name));
|
|
|
|
name = ISC_LIST_HEAD(view->rootexclude[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isc_mem_put(view->mctx, view->rootexclude,
|
|
|
|
sizeof(dns_namelist_t) * DNS_VIEW_DELONLYHASH);
|
|
|
|
view->rootexclude = NULL;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->adbstats != NULL) {
|
2012-05-14 10:06:05 -07:00
|
|
|
isc_stats_detach(&view->adbstats);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->resstats != NULL) {
|
2009-01-27 22:30:00 +00:00
|
|
|
isc_stats_detach(&view->resstats);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->resquerystats != NULL) {
|
2008-04-03 05:55:52 +00:00
|
|
|
dns_stats_detach(&view->resquerystats);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->secroots_priv != NULL) {
|
2009-10-27 22:46:13 +00:00
|
|
|
dns_keytable_detach(&view->secroots_priv);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->ntatable_priv != NULL) {
|
2014-05-29 22:22:53 -07:00
|
|
|
dns_ntatable_detach(&view->ntatable_priv);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
for (dns64 = ISC_LIST_HEAD(view->dns64); dns64 != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns64 = ISC_LIST_HEAD(view->dns64))
|
|
|
|
{
|
2010-12-08 02:46:17 +00:00
|
|
|
dns_dns64_unlink(&view->dns64, dns64);
|
|
|
|
dns_dns64_destroy(&dns64);
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->managed_keys != NULL) {
|
2010-05-14 04:48:28 +00:00
|
|
|
dns_zone_detach(&view->managed_keys);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->redirect != NULL) {
|
2011-02-23 03:08:11 +00:00
|
|
|
dns_zone_detach(&view->redirect);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
#ifdef HAVE_DNSTAP
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->dtenv != NULL) {
|
2015-10-02 12:32:42 -07:00
|
|
|
dns_dt_detach(&view->dtenv);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-10-02 12:32:42 -07:00
|
|
|
#endif /* HAVE_DNSTAP */
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_view_setnewzones(view, false, NULL, NULL, 0ULL);
|
2016-07-21 11:13:03 -07:00
|
|
|
if (view->new_zone_file != NULL) {
|
|
|
|
isc_mem_free(view->mctx, view->new_zone_file);
|
|
|
|
view->new_zone_file = NULL;
|
|
|
|
}
|
2017-04-23 23:16:53 -07:00
|
|
|
if (view->new_zone_dir != NULL) {
|
|
|
|
isc_mem_free(view->mctx, view->new_zone_dir);
|
|
|
|
view->new_zone_dir = NULL;
|
|
|
|
}
|
2016-07-21 11:13:03 -07:00
|
|
|
#ifdef HAVE_LMDB
|
2017-11-30 13:43:46 +01:00
|
|
|
if (view->new_zone_dbenv != NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
mdb_env_close((MDB_env *)view->new_zone_dbenv);
|
2017-11-30 13:43:46 +01:00
|
|
|
view->new_zone_dbenv = NULL;
|
|
|
|
}
|
2016-07-21 11:13:03 -07:00
|
|
|
if (view->new_zone_db != NULL) {
|
|
|
|
isc_mem_free(view->mctx, view->new_zone_db);
|
|
|
|
view->new_zone_db = NULL;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LMDB */
|
2000-08-24 22:15:40 +00:00
|
|
|
dns_fwdtable_destroy(&view->fwdtable);
|
2021-05-22 18:12:11 +02:00
|
|
|
dns_aclenv_detach(&view->aclenv);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->failcache != NULL) {
|
2016-10-28 11:14:38 +11:00
|
|
|
dns_badcache_destroy(&view->failcache);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-11-19 10:31:09 +00:00
|
|
|
isc_mutex_destroy(&view->new_zone_lock);
|
|
|
|
isc_mutex_destroy(&view->lock);
|
2019-08-01 11:42:58 +02:00
|
|
|
isc_refcount_destroy(&view->references);
|
|
|
|
isc_refcount_destroy(&view->weakrefs);
|
2015-01-12 09:04:16 +05:30
|
|
|
isc_mem_free(view->mctx, view->nta_file);
|
1999-08-05 22:08:45 +00:00
|
|
|
isc_mem_free(view->mctx, view->name);
|
2018-08-12 11:19:36 -07:00
|
|
|
if (view->hooktable != NULL && view->hooktable_free != NULL) {
|
|
|
|
view->hooktable_free(view->mctx, &view->hooktable);
|
|
|
|
}
|
2018-11-30 15:32:03 -08:00
|
|
|
if (view->plugins != NULL && view->plugins_free != NULL) {
|
|
|
|
view->plugins_free(view->mctx, &view->plugins);
|
2018-10-31 19:02:29 -07:00
|
|
|
}
|
2013-03-08 14:38:03 +11:00
|
|
|
isc_mem_putanddetach(&view->mctx, view, sizeof(*view));
|
1999-08-05 22:08:45 +00:00
|
|
|
}
|
|
|
|
|
2000-05-17 19:45:36 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_attach(dns_view_t *source, dns_view_t **targetp) {
|
2000-05-17 19:45:36 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(source));
|
|
|
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
|
|
|
|
2018-08-17 15:16:59 +02:00
|
|
|
isc_refcount_increment(&source->references);
|
2000-05-17 19:45:36 +00:00
|
|
|
|
|
|
|
*targetp = source;
|
|
|
|
}
|
|
|
|
|
2000-10-05 06:39:26 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
view_flushanddetach(dns_view_t **viewp, bool flush) {
|
2018-08-28 10:18:59 +02:00
|
|
|
REQUIRE(viewp != NULL && DNS_VIEW_VALID(*viewp));
|
|
|
|
dns_view_t *view = *viewp;
|
|
|
|
*viewp = NULL;
|
1999-08-05 22:08:45 +00:00
|
|
|
|
2018-08-28 10:18:59 +02:00
|
|
|
if (flush) {
|
|
|
|
view->flush = flush;
|
|
|
|
}
|
1999-08-05 22:08:45 +00:00
|
|
|
|
2018-08-17 15:16:59 +02:00
|
|
|
if (isc_refcount_decrement(&view->references) == 1) {
|
2012-10-23 22:04:06 -07:00
|
|
|
dns_zone_t *mkzone = NULL, *rdzone = NULL;
|
|
|
|
|
2018-08-28 10:18:59 +02:00
|
|
|
isc_refcount_destroy(&view->references);
|
2021-01-14 13:02:57 -08:00
|
|
|
|
2018-08-28 10:18:59 +02:00
|
|
|
if (!RESSHUTDOWN(view)) {
|
1999-11-22 19:53:51 +00:00
|
|
|
dns_resolver_shutdown(view->resolver);
|
2018-08-28 10:18:59 +02:00
|
|
|
}
|
|
|
|
if (!ADBSHUTDOWN(view)) {
|
1999-11-22 19:53:51 +00:00
|
|
|
dns_adb_shutdown(view->adb);
|
2018-08-28 10:18:59 +02:00
|
|
|
}
|
|
|
|
if (!REQSHUTDOWN(view)) {
|
2000-04-18 11:43:46 +00:00
|
|
|
dns_requestmgr_shutdown(view->requestmgr);
|
2018-08-28 10:18:59 +02:00
|
|
|
}
|
2021-01-14 13:02:57 -08:00
|
|
|
|
|
|
|
if (view->zonetable != NULL && view->flush) {
|
|
|
|
dns_zt_flushanddetach(&view->zonetable);
|
|
|
|
} else if (view->zonetable != NULL) {
|
|
|
|
dns_zt_detach(&view->zonetable);
|
2013-04-10 13:49:57 -07:00
|
|
|
}
|
2021-01-14 13:02:57 -08:00
|
|
|
|
|
|
|
LOCK(&view->lock);
|
2010-05-14 04:48:28 +00:00
|
|
|
if (view->managed_keys != NULL) {
|
2012-10-23 22:04:06 -07:00
|
|
|
mkzone = view->managed_keys;
|
|
|
|
view->managed_keys = NULL;
|
2018-08-28 10:18:59 +02:00
|
|
|
if (view->flush) {
|
2012-10-23 22:04:06 -07:00
|
|
|
dns_zone_flush(mkzone);
|
2018-08-28 10:18:59 +02:00
|
|
|
}
|
2010-05-14 04:48:28 +00:00
|
|
|
}
|
2011-02-23 03:08:11 +00:00
|
|
|
if (view->redirect != NULL) {
|
2012-10-23 22:04:06 -07:00
|
|
|
rdzone = view->redirect;
|
|
|
|
view->redirect = NULL;
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->flush) {
|
2012-10-23 22:04:06 -07:00
|
|
|
dns_zone_flush(rdzone);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-02-23 03:08:11 +00:00
|
|
|
}
|
2016-05-26 21:23:19 +02:00
|
|
|
if (view->catzs != NULL) {
|
|
|
|
dns_catz_catzs_detach(&view->catzs);
|
|
|
|
}
|
2020-08-07 18:00:41 +10:00
|
|
|
if (view->ntatable_priv != NULL) {
|
|
|
|
dns_ntatable_shutdown(view->ntatable_priv);
|
|
|
|
}
|
2001-01-30 02:50:51 +00:00
|
|
|
UNLOCK(&view->lock);
|
2012-10-23 22:04:06 -07:00
|
|
|
|
|
|
|
/* Need to detach zones outside view lock */
|
2018-08-28 10:18:59 +02:00
|
|
|
if (mkzone != NULL) {
|
2012-10-23 22:04:06 -07:00
|
|
|
dns_zone_detach(&mkzone);
|
2018-08-28 10:18:59 +02:00
|
|
|
}
|
2012-10-23 22:04:06 -07:00
|
|
|
|
2018-08-28 10:18:59 +02:00
|
|
|
if (rdzone != NULL) {
|
2012-10-23 22:04:06 -07:00
|
|
|
dns_zone_detach(&rdzone);
|
2018-08-28 10:18:59 +02:00
|
|
|
}
|
1999-08-05 22:08:45 +00:00
|
|
|
|
2019-08-06 12:40:04 +10:00
|
|
|
dns_view_weakdetach(&view);
|
2018-08-28 10:18:59 +02:00
|
|
|
}
|
1999-11-22 19:53:51 +00:00
|
|
|
}
|
|
|
|
|
2000-05-17 19:45:36 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_flushanddetach(dns_view_t **viewp) {
|
2018-04-17 08:29:14 -07:00
|
|
|
view_flushanddetach(viewp, true);
|
2000-10-05 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_detach(dns_view_t **viewp) {
|
2018-04-17 08:29:14 -07:00
|
|
|
view_flushanddetach(viewp, false);
|
2000-10-05 06:39:26 +00:00
|
|
|
}
|
|
|
|
|
2000-11-03 07:16:09 +00:00
|
|
|
static isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dialup(dns_zone_t *zone, void *dummy) {
|
2000-11-03 18:27:31 +00:00
|
|
|
UNUSED(dummy);
|
2000-11-03 07:16:09 +00:00
|
|
|
dns_zone_dialup(zone);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_dialup(dns_view_t *view) {
|
2000-11-03 07:16:09 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
2013-06-04 11:27:26 +10:00
|
|
|
REQUIRE(view->zonetable != NULL);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
(void)dns_zt_apply(view->zonetable, false, NULL, dialup, NULL);
|
2000-11-03 07:16:09 +00:00
|
|
|
}
|
|
|
|
|
2000-10-05 06:39:26 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_weakattach(dns_view_t *source, dns_view_t **targetp) {
|
2000-05-17 19:45:36 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(source));
|
|
|
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
|
|
|
|
2019-08-06 12:40:04 +10:00
|
|
|
isc_refcount_increment(&source->weakrefs);
|
2000-05-17 19:45:36 +00:00
|
|
|
|
|
|
|
*targetp = source;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_weakdetach(dns_view_t **viewp) {
|
2000-05-17 19:45:36 +00:00
|
|
|
dns_view_t *view;
|
|
|
|
|
|
|
|
REQUIRE(viewp != NULL);
|
|
|
|
view = *viewp;
|
|
|
|
*viewp = NULL;
|
2020-02-08 04:37:54 -08:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
2000-05-17 19:45:36 +00:00
|
|
|
|
2019-08-01 11:42:58 +02:00
|
|
|
if (isc_refcount_decrement(&view->weakrefs) == 1) {
|
2019-08-06 12:40:04 +10:00
|
|
|
destroy(view);
|
2019-08-01 11:42:58 +02:00
|
|
|
}
|
2000-05-17 19:45:36 +00:00
|
|
|
}
|
|
|
|
|
1999-11-22 19:53:51 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
resolver_shutdown(isc_task_t *task, isc_event_t *event) {
|
2000-04-17 19:22:44 +00:00
|
|
|
dns_view_t *view = event->ev_arg;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-04-17 19:22:44 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_VIEWRESSHUTDOWN);
|
1999-11-22 19:53:51 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(view->task == task);
|
|
|
|
|
2000-04-28 01:24:18 +00:00
|
|
|
UNUSED(task);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2014-08-05 16:58:23 +05:30
|
|
|
isc_event_free(&event);
|
|
|
|
|
2019-07-18 14:22:31 +02:00
|
|
|
atomic_fetch_or(&view->attributes, DNS_VIEWATTR_RESSHUTDOWN);
|
2019-08-06 12:40:04 +10:00
|
|
|
dns_view_weakdetach(&view);
|
1999-11-22 19:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
adb_shutdown(isc_task_t *task, isc_event_t *event) {
|
2000-04-17 19:22:44 +00:00
|
|
|
dns_view_t *view = event->ev_arg;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-04-17 19:22:44 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_VIEWADBSHUTDOWN);
|
1999-11-22 19:53:51 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(view->task == task);
|
|
|
|
|
2000-04-28 01:24:18 +00:00
|
|
|
UNUSED(task);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2014-08-05 16:58:23 +05:30
|
|
|
isc_event_free(&event);
|
|
|
|
|
2019-07-18 14:22:31 +02:00
|
|
|
atomic_fetch_or(&view->attributes, DNS_VIEWATTR_ADBSHUTDOWN);
|
1999-11-22 19:53:51 +00:00
|
|
|
|
2019-08-06 12:40:04 +10:00
|
|
|
dns_view_weakdetach(&view);
|
1999-08-05 22:08:45 +00:00
|
|
|
}
|
1999-09-22 18:23:36 +00:00
|
|
|
|
2000-04-18 11:43:46 +00:00
|
|
|
static void
|
2020-02-13 14:44:37 -08:00
|
|
|
req_shutdown(isc_task_t *task, isc_event_t *event) {
|
2000-04-18 11:43:46 +00:00
|
|
|
dns_view_t *view = event->ev_arg;
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2000-04-18 11:43:46 +00:00
|
|
|
REQUIRE(event->ev_type == DNS_EVENT_VIEWREQSHUTDOWN);
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(view->task == task);
|
|
|
|
|
2000-04-28 01:24:18 +00:00
|
|
|
UNUSED(task);
|
2000-08-01 01:33:37 +00:00
|
|
|
|
2014-08-05 16:58:23 +05:30
|
|
|
isc_event_free(&event);
|
|
|
|
|
2019-07-18 14:22:31 +02:00
|
|
|
atomic_fetch_or(&view->attributes, DNS_VIEWATTR_REQSHUTDOWN);
|
2000-04-18 11:43:46 +00:00
|
|
|
|
2019-08-06 12:40:04 +10:00
|
|
|
dns_view_weakdetach(&view);
|
2000-04-18 11:43:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-10 13:49:57 -07:00
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_createzonetable(dns_view_t *view) {
|
2013-04-10 13:49:57 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(!view->frozen);
|
|
|
|
REQUIRE(view->zonetable == NULL);
|
|
|
|
|
|
|
|
return (dns_zt_create(view->mctx, view->rdclass, &view->zonetable));
|
|
|
|
}
|
|
|
|
|
1999-09-24 01:40:50 +00:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
2021-01-14 13:02:57 -08:00
|
|
|
unsigned int ntasks, unsigned int ndisp, isc_nm_t *nm,
|
|
|
|
isc_timermgr_t *timermgr, unsigned int options,
|
|
|
|
dns_dispatchmgr_t *dispatchmgr,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_dispatch_t *dispatchv4,
|
|
|
|
dns_dispatch_t *dispatchv6) {
|
1999-10-28 19:52:10 +00:00
|
|
|
isc_result_t result;
|
1999-11-22 19:53:51 +00:00
|
|
|
isc_event_t *event;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_mem_t *mctx = NULL;
|
1999-10-28 19:52:10 +00:00
|
|
|
|
1999-09-22 18:23:36 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
1999-09-22 19:35:47 +00:00
|
|
|
REQUIRE(!view->frozen);
|
1999-09-22 18:23:36 +00:00
|
|
|
REQUIRE(view->resolver == NULL);
|
1999-11-22 19:53:51 +00:00
|
|
|
|
2000-04-12 01:41:21 +00:00
|
|
|
result = isc_task_create(taskmgr, 0, &view->task);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
1999-11-22 19:53:51 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-01-25 19:31:23 +00:00
|
|
|
isc_task_setname(view->task, "view", view);
|
1999-11-22 19:53:51 +00:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_resolver_create(view, taskmgr, ntasks, ndisp, nm, timermgr,
|
|
|
|
options, dispatchmgr, dispatchv4,
|
2020-02-12 13:59:18 +01:00
|
|
|
dispatchv6, &view->resolver);
|
1999-11-22 19:53:51 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
isc_task_detach(&view->task);
|
1999-10-28 19:52:10 +00:00
|
|
|
return (result);
|
1999-11-22 19:53:51 +00:00
|
|
|
}
|
|
|
|
event = &view->resevent;
|
|
|
|
dns_resolver_whenshutdown(view->resolver, view->task, &event);
|
2019-07-18 14:22:31 +02:00
|
|
|
atomic_fetch_and(&view->attributes, ~DNS_VIEWATTR_RESSHUTDOWN);
|
2019-08-06 12:40:04 +10:00
|
|
|
isc_refcount_increment(&view->weakrefs);
|
1999-11-22 19:53:51 +00:00
|
|
|
|
2019-09-05 18:40:57 +02:00
|
|
|
isc_mem_create(&mctx);
|
2021-12-14 13:02:50 +01:00
|
|
|
isc_mem_setname(mctx, "ADB");
|
2003-10-03 02:19:31 +00:00
|
|
|
|
2001-10-25 04:57:46 +00:00
|
|
|
result = dns_adb_create(mctx, view, timermgr, taskmgr, &view->adb);
|
|
|
|
isc_mem_detach(&mctx);
|
1999-11-22 19:53:51 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dns_resolver_shutdown(view->resolver);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
event = &view->adbevent;
|
|
|
|
dns_adb_whenshutdown(view->adb, view->task, &event);
|
2019-07-18 14:22:31 +02:00
|
|
|
atomic_fetch_and(&view->attributes, ~DNS_VIEWATTR_ADBSHUTDOWN);
|
2019-08-06 12:40:04 +10:00
|
|
|
isc_refcount_increment(&view->weakrefs);
|
1999-10-28 19:52:10 +00:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
result = dns_requestmgr_create(
|
|
|
|
view->mctx, dns_resolver_taskmgr(view->resolver),
|
|
|
|
dns_resolver_dispatchmgr(view->resolver), dispatchv4,
|
|
|
|
dispatchv6, &view->requestmgr);
|
2000-04-18 11:43:46 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
dns_adb_shutdown(view->adb);
|
|
|
|
dns_resolver_shutdown(view->resolver);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
event = &view->reqevent;
|
|
|
|
dns_requestmgr_whenshutdown(view->requestmgr, view->task, &event);
|
2019-07-18 14:22:31 +02:00
|
|
|
atomic_fetch_and(&view->attributes, ~DNS_VIEWATTR_REQSHUTDOWN);
|
2019-08-06 12:40:04 +10:00
|
|
|
isc_refcount_increment(&view->weakrefs);
|
2000-04-18 11:43:46 +00:00
|
|
|
|
1999-11-22 19:53:51 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-09-22 18:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setcache(dns_view_t *view, dns_cache_t *cache, bool shared) {
|
1999-09-22 18:23:36 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
1999-09-22 19:35:47 +00:00
|
|
|
REQUIRE(!view->frozen);
|
1999-09-22 18:23:36 +00:00
|
|
|
|
2009-01-09 22:24:37 +00:00
|
|
|
view->cacheshared = shared;
|
1999-12-02 22:38:34 +00:00
|
|
|
if (view->cache != NULL) {
|
1999-10-28 19:52:10 +00:00
|
|
|
dns_db_detach(&view->cachedb);
|
1999-12-02 22:38:34 +00:00
|
|
|
dns_cache_detach(&view->cache);
|
|
|
|
}
|
|
|
|
dns_cache_attach(cache, &view->cache);
|
|
|
|
dns_cache_attachdb(cache, &view->cachedb);
|
|
|
|
INSIST(DNS_DB_VALID(view->cachedb));
|
1999-09-22 18:23:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_iscacheshared(dns_view_t *view) {
|
2009-01-09 22:24:37 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
|
|
|
return (view->cacheshared);
|
|
|
|
}
|
|
|
|
|
1999-09-24 01:40:50 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_sethints(dns_view_t *view, dns_db_t *hints) {
|
1999-09-24 01:40:50 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(!view->frozen);
|
|
|
|
REQUIRE(view->hints == NULL);
|
|
|
|
REQUIRE(dns_db_iszone(hints));
|
|
|
|
|
|
|
|
dns_db_attach(hints, &view->hints);
|
|
|
|
}
|
|
|
|
|
2021-01-14 12:51:25 +01:00
|
|
|
void
|
|
|
|
dns_view_settransports(dns_view_t *view, dns_transport_list_t *list) {
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(list != NULL);
|
|
|
|
if (view->transports != NULL) {
|
|
|
|
dns_transport_list_detach(&view->transports);
|
|
|
|
}
|
|
|
|
dns_transport_list_attach(list, &view->transports);
|
|
|
|
}
|
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setkeyring(dns_view_t *view, dns_tsig_keyring_t *ring) {
|
2000-01-21 20:18:41 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(ring != NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->statickeys != NULL) {
|
2011-01-10 05:32:04 +00:00
|
|
|
dns_tsigkeyring_detach(&view->statickeys);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-01-10 05:32:04 +00:00
|
|
|
dns_tsigkeyring_attach(ring, &view->statickeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setdynamickeyring(dns_view_t *view, dns_tsig_keyring_t *ring) {
|
2011-01-10 05:32:04 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(ring != NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->dynamickeys != NULL) {
|
2011-01-10 05:32:04 +00:00
|
|
|
dns_tsigkeyring_detach(&view->dynamickeys);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-01-10 05:32:04 +00:00
|
|
|
dns_tsigkeyring_attach(ring, &view->dynamickeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_getdynamickeyring(dns_view_t *view, dns_tsig_keyring_t **ringp) {
|
2011-01-10 05:32:04 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(ringp != NULL && *ringp == NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->dynamickeys != NULL) {
|
2011-01-10 05:32:04 +00:00
|
|
|
dns_tsigkeyring_attach(view->dynamickeys, ringp);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-01-10 05:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_restorekeyring(dns_view_t *view) {
|
|
|
|
FILE *fp;
|
|
|
|
char keyfile[PATH_MAX];
|
2018-03-28 22:11:22 +05:30
|
|
|
isc_result_t result;
|
2011-01-10 05:32:04 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
|
|
|
if (view->dynamickeys != NULL) {
|
2018-03-28 22:11:22 +05:30
|
|
|
result = isc_file_sanitize(NULL, view->name, "tsigkeys",
|
|
|
|
keyfile, sizeof(keyfile));
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
2011-01-10 05:32:04 +00:00
|
|
|
fp = fopen(keyfile, "r");
|
|
|
|
if (fp != NULL) {
|
|
|
|
dns_keyring_restore(view->dynamickeys, fp);
|
|
|
|
(void)fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-01-21 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
2000-06-05 19:10:13 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setdstport(dns_view_t *view, in_port_t dstport) {
|
2000-06-05 19:10:13 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
view->dstport = dstport;
|
|
|
|
}
|
|
|
|
|
2010-07-11 00:12:57 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_freeze(dns_view_t *view) {
|
2010-07-11 00:12:57 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(!view->frozen);
|
|
|
|
|
|
|
|
if (view->resolver != NULL) {
|
|
|
|
INSIST(view->cachedb != NULL);
|
|
|
|
dns_resolver_freeze(view->resolver);
|
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
view->frozen = true;
|
2010-07-11 00:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_thaw(dns_view_t *view) {
|
2010-07-11 00:12:57 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(view->frozen);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
view->frozen = false;
|
2010-07-11 00:12:57 +00:00
|
|
|
}
|
|
|
|
|
1999-09-22 18:23:36 +00:00
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_addzone(dns_view_t *view, dns_zone_t *zone) {
|
1999-09-22 19:35:47 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
1999-09-22 18:23:36 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
1999-09-22 19:35:47 +00:00
|
|
|
REQUIRE(!view->frozen);
|
2013-04-10 13:49:57 -07:00
|
|
|
REQUIRE(view->zonetable != NULL);
|
1999-09-22 19:35:47 +00:00
|
|
|
|
1999-10-13 23:17:32 +00:00
|
|
|
result = dns_zt_mount(view->zonetable, zone);
|
1999-09-22 18:23:36 +00:00
|
|
|
|
1999-09-22 19:35:47 +00:00
|
|
|
return (result);
|
1999-09-22 18:23:36 +00:00
|
|
|
}
|
|
|
|
|
1999-10-13 23:17:32 +00:00
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_findzone(dns_view_t *view, const dns_name_t *name,
|
|
|
|
dns_zone_t **zonep) {
|
1999-10-13 23:17:32 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
2013-06-04 11:27:26 +10:00
|
|
|
LOCK(&view->lock);
|
2013-04-03 17:27:40 +11:00
|
|
|
if (view->zonetable != NULL) {
|
|
|
|
result = dns_zt_find(view->zonetable, name, 0, NULL, zonep);
|
|
|
|
if (result == DNS_R_PARTIALMATCH) {
|
|
|
|
dns_zone_detach(zonep);
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-04-06 22:03:35 +00:00
|
|
|
result = ISC_R_NOTFOUND;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-06-04 11:27:26 +10:00
|
|
|
UNLOCK(&view->lock);
|
1999-10-15 01:43:39 +00:00
|
|
|
|
1999-10-13 23:17:32 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-09-22 19:35:47 +00:00
|
|
|
isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_view_find(dns_view_t *view, const dns_name_t *name, dns_rdatatype_t type,
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_stdtime_t now, unsigned int options, bool use_hints,
|
|
|
|
bool use_static_stub, dns_db_t **dbp, dns_dbnode_t **nodep,
|
|
|
|
dns_name_t *foundname, dns_rdataset_t *rdataset,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *sigrdataset) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_db_t *db, *zdb;
|
|
|
|
dns_dbnode_t *node, *znode;
|
|
|
|
bool is_cache, is_staticstub_zone;
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_rdataset_t zrdataset, zsigrdataset;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_zone_t *zone;
|
1999-09-22 19:35:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find an rdataset whose owner name is 'name', and whose type is
|
|
|
|
* 'type'.
|
|
|
|
*/
|
|
|
|
|
1999-09-22 18:23:36 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
1999-09-22 19:35:47 +00:00
|
|
|
REQUIRE(view->frozen);
|
2003-09-30 06:00:40 +00:00
|
|
|
REQUIRE(type != dns_rdatatype_rrsig);
|
2020-02-12 13:59:18 +01:00
|
|
|
REQUIRE(rdataset != NULL); /* XXXBEW - remove this */
|
2007-03-06 00:38:58 +00:00
|
|
|
REQUIRE(nodep == NULL || *nodep == NULL);
|
1999-09-22 19:35:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize.
|
|
|
|
*/
|
|
|
|
dns_rdataset_init(&zrdataset);
|
|
|
|
dns_rdataset_init(&zsigrdataset);
|
2000-12-20 03:38:46 +00:00
|
|
|
zdb = NULL;
|
|
|
|
znode = NULL;
|
1999-09-22 19:35:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find a database to answer the query.
|
|
|
|
*/
|
|
|
|
db = NULL;
|
2000-12-20 03:38:46 +00:00
|
|
|
node = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
is_staticstub_zone = false;
|
2013-02-28 15:22:44 -08:00
|
|
|
zone = NULL;
|
2013-06-04 11:27:26 +10:00
|
|
|
LOCK(&view->lock);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->zonetable != NULL) {
|
2018-06-28 13:38:39 +02:00
|
|
|
result = dns_zt_find(view->zonetable, name, DNS_ZTFIND_MIRROR,
|
|
|
|
NULL, &zone);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2013-06-04 11:27:26 +10:00
|
|
|
result = ISC_R_NOTFOUND;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-06-04 11:27:26 +10:00
|
|
|
UNLOCK(&view->lock);
|
|
|
|
if (zone != NULL && dns_zone_gettype(zone) == dns_zone_staticstub &&
|
2020-02-13 14:44:37 -08:00
|
|
|
!use_static_stub)
|
|
|
|
{
|
2010-12-16 09:51:30 +00:00
|
|
|
result = ISC_R_NOTFOUND;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-13 23:17:32 +00:00
|
|
|
if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) {
|
|
|
|
result = dns_zone_getdb(zone, &db);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS && view->cachedb != NULL) {
|
1999-10-13 23:17:32 +00:00
|
|
|
dns_db_attach(view->cachedb, &db);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (result != ISC_R_SUCCESS) {
|
1999-10-13 23:17:32 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2010-12-16 09:51:30 +00:00
|
|
|
if (dns_zone_gettype(zone) == dns_zone_staticstub &&
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_equal(name, dns_zone_getorigin(zone)))
|
|
|
|
{
|
2018-04-17 08:29:14 -07:00
|
|
|
is_staticstub_zone = true;
|
2010-12-16 09:51:30 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (result == ISC_R_NOTFOUND && view->cachedb != NULL) {
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_db_attach(view->cachedb, &db);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
1999-09-22 19:35:47 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-22 19:35:47 +00:00
|
|
|
|
2000-06-07 02:38:41 +00:00
|
|
|
is_cache = dns_db_iscache(db);
|
1999-09-22 18:23:36 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
db_find:
|
1999-09-22 19:35:47 +00:00
|
|
|
/*
|
|
|
|
* Now look for an answer in the database.
|
|
|
|
*/
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_find(db, name, NULL, type, options, now, &node,
|
|
|
|
foundname, rdataset, sigrdataset);
|
1999-09-22 19:35:47 +00:00
|
|
|
|
2010-12-16 09:51:30 +00:00
|
|
|
if (result == DNS_R_DELEGATION || result == ISC_R_NOTFOUND) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_rdataset_isassociated(rdataset)) {
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_rdataset_disassociate(rdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-04-28 23:46:43 +00:00
|
|
|
if (sigrdataset != NULL &&
|
2020-02-13 21:48:23 +01:00
|
|
|
dns_rdataset_isassociated(sigrdataset)) {
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_rdataset_disassociate(sigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (node != NULL) {
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_detachnode(db, &node);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-06-07 02:38:41 +00:00
|
|
|
if (!is_cache) {
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_detach(&db);
|
2010-12-16 09:51:30 +00:00
|
|
|
if (view->cachedb != NULL && !is_staticstub_zone) {
|
1999-09-22 19:35:47 +00:00
|
|
|
/*
|
|
|
|
* Either the answer is in the cache, or we
|
|
|
|
* don't know it.
|
2010-12-16 09:51:30 +00:00
|
|
|
* Note that if the result comes from a
|
|
|
|
* static-stub zone we stop the search here
|
|
|
|
* (see the function description in view.h).
|
1999-09-22 19:35:47 +00:00
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
is_cache = true;
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_db_attach(view->cachedb, &db);
|
|
|
|
goto db_find;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We don't have the data in the cache. If we've got
|
|
|
|
* glue from the zone, use it.
|
|
|
|
*/
|
2000-04-28 23:46:43 +00:00
|
|
|
if (dns_rdataset_isassociated(&zrdataset)) {
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_rdataset_clone(&zrdataset, rdataset);
|
1999-10-27 00:43:56 +00:00
|
|
|
if (sigrdataset != NULL &&
|
2020-02-13 21:48:23 +01:00
|
|
|
dns_rdataset_isassociated(&zsigrdataset)) {
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_rdataset_clone(&zsigrdataset,
|
|
|
|
sigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-22 19:35:47 +00:00
|
|
|
result = DNS_R_GLUE;
|
2020-02-13 21:48:23 +01:00
|
|
|
if (db != NULL) {
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_detach(&db);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_attach(zdb, &db);
|
|
|
|
dns_db_attachnode(db, znode, &node);
|
1999-09-22 19:35:47 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We don't know the answer.
|
|
|
|
*/
|
2000-04-06 22:03:35 +00:00
|
|
|
result = ISC_R_NOTFOUND;
|
1999-09-22 19:35:47 +00:00
|
|
|
} else if (result == DNS_R_GLUE) {
|
2010-12-16 09:51:30 +00:00
|
|
|
if (view->cachedb != NULL && !is_staticstub_zone) {
|
1999-09-22 19:35:47 +00:00
|
|
|
/*
|
|
|
|
* We found an answer, but the cache may be better.
|
|
|
|
* Remember what we've got and go look in the cache.
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
is_cache = true;
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_rdataset_clone(rdataset, &zrdataset);
|
|
|
|
dns_rdataset_disassociate(rdataset);
|
1999-10-07 19:41:16 +00:00
|
|
|
if (sigrdataset != NULL &&
|
2000-04-28 23:46:43 +00:00
|
|
|
dns_rdataset_isassociated(sigrdataset)) {
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_rdataset_clone(sigrdataset, &zsigrdataset);
|
|
|
|
dns_rdataset_disassociate(sigrdataset);
|
|
|
|
}
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_attach(db, &zdb);
|
|
|
|
dns_db_attachnode(zdb, node, &znode);
|
|
|
|
dns_db_detachnode(db, &node);
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_db_detach(&db);
|
|
|
|
dns_db_attach(view->cachedb, &db);
|
|
|
|
goto db_find;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Otherwise, the glue is the best answer.
|
|
|
|
*/
|
|
|
|
result = ISC_R_SUCCESS;
|
1999-09-24 01:40:50 +00:00
|
|
|
}
|
|
|
|
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result == ISC_R_NOTFOUND && use_hints && view->hints != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_rdataset_isassociated(rdataset)) {
|
1999-09-24 01:40:50 +00:00
|
|
|
dns_rdataset_disassociate(rdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-04-28 23:46:43 +00:00
|
|
|
if (sigrdataset != NULL &&
|
2020-02-13 21:48:23 +01:00
|
|
|
dns_rdataset_isassociated(sigrdataset)) {
|
1999-09-24 01:40:50 +00:00
|
|
|
dns_rdataset_disassociate(sigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-20 03:38:46 +00:00
|
|
|
if (db != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (node != NULL) {
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_detachnode(db, &node);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_detach(&db);
|
|
|
|
}
|
1999-09-24 01:40:50 +00:00
|
|
|
result = dns_db_find(view->hints, name, NULL, type, options,
|
2020-02-12 13:59:18 +01:00
|
|
|
now, &node, foundname, rdataset,
|
|
|
|
sigrdataset);
|
2000-01-27 02:55:47 +00:00
|
|
|
if (result == ISC_R_SUCCESS || result == DNS_R_GLUE) {
|
|
|
|
/*
|
|
|
|
* We just used a hint. Let the resolver know it
|
|
|
|
* should consider priming.
|
|
|
|
*/
|
|
|
|
dns_resolver_prime(view->resolver);
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_attach(view->hints, &db);
|
1999-09-24 01:40:50 +00:00
|
|
|
result = DNS_R_HINT;
|
2000-12-20 23:31:11 +00:00
|
|
|
} else if (result == DNS_R_NXRRSET) {
|
|
|
|
dns_db_attach(view->hints, &db);
|
|
|
|
result = DNS_R_HINTNXRRSET;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (result == DNS_R_NXDOMAIN) {
|
2000-04-06 22:03:35 +00:00
|
|
|
result = ISC_R_NOTFOUND;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-08-27 06:10:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cleanup if non-standard hints are used.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (db == NULL && node != NULL) {
|
2001-08-27 06:10:17 +00:00
|
|
|
dns_db_detachnode(view->hints, &node);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-24 01:40:50 +00:00
|
|
|
}
|
1999-09-22 19:35:47 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2000-04-28 23:46:43 +00:00
|
|
|
if (dns_rdataset_isassociated(&zrdataset)) {
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_rdataset_disassociate(&zrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_rdataset_isassociated(&zsigrdataset)) {
|
1999-09-22 19:35:47 +00:00
|
|
|
dns_rdataset_disassociate(&zsigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-22 19:35:47 +00:00
|
|
|
}
|
2000-12-20 03:38:46 +00:00
|
|
|
|
|
|
|
if (zdb != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (znode != NULL) {
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_detachnode(zdb, &znode);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_detach(&zdb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (db != NULL) {
|
|
|
|
if (node != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (nodep != NULL) {
|
2000-12-20 03:38:46 +00:00
|
|
|
*nodep = node;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_detachnode(db, &node);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-20 03:38:46 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dbp != NULL) {
|
2000-12-20 03:38:46 +00:00
|
|
|
*dbp = db;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2000-12-20 03:38:46 +00:00
|
|
|
dns_db_detach(&db);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
} else {
|
2001-08-27 06:10:17 +00:00
|
|
|
INSIST(node == NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-20 03:38:46 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (zone != NULL) {
|
1999-10-13 23:17:32 +00:00
|
|
|
dns_zone_detach(&zone);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-09-22 19:35:47 +00:00
|
|
|
|
|
|
|
return (result);
|
1999-09-22 18:23:36 +00:00
|
|
|
}
|
1999-10-13 23:17:32 +00:00
|
|
|
|
2000-01-15 00:47:45 +00:00
|
|
|
isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_view_simplefind(dns_view_t *view, const dns_name_t *name,
|
|
|
|
dns_rdatatype_t type, isc_stdtime_t now,
|
2018-04-17 08:29:14 -07:00
|
|
|
unsigned int options, bool use_hints,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset) {
|
|
|
|
isc_result_t result;
|
2000-01-15 00:47:45 +00:00
|
|
|
dns_fixedname_t foundname;
|
|
|
|
|
|
|
|
dns_fixedname_init(&foundname);
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_view_find(view, name, type, now, options, use_hints, false,
|
|
|
|
NULL, NULL, dns_fixedname_name(&foundname),
|
|
|
|
rdataset, sigrdataset);
|
2000-02-12 02:19:20 +00:00
|
|
|
if (result == DNS_R_NXDOMAIN) {
|
|
|
|
/*
|
2003-09-30 06:00:40 +00:00
|
|
|
* The rdataset and sigrdataset of the relevant NSEC record
|
2000-02-12 02:19:20 +00:00
|
|
|
* may be returned, but the caller cannot use them because
|
|
|
|
* foundname is not returned by this simplified API. We
|
|
|
|
* disassociate them here to prevent any misuse by the caller.
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_rdataset_isassociated(rdataset)) {
|
2000-02-12 02:19:20 +00:00
|
|
|
dns_rdataset_disassociate(rdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-04-28 23:46:43 +00:00
|
|
|
if (sigrdataset != NULL &&
|
2020-02-13 21:48:23 +01:00
|
|
|
dns_rdataset_isassociated(sigrdataset)) {
|
2000-02-12 02:19:20 +00:00
|
|
|
dns_rdataset_disassociate(sigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
} else if (result != ISC_R_SUCCESS && result != DNS_R_GLUE &&
|
|
|
|
result != DNS_R_HINT && result != DNS_R_NCACHENXDOMAIN &&
|
|
|
|
result != DNS_R_NCACHENXRRSET && result != DNS_R_NXRRSET &&
|
2020-02-13 14:44:37 -08:00
|
|
|
result != DNS_R_HINTNXRRSET && result != ISC_R_NOTFOUND)
|
|
|
|
{
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_rdataset_isassociated(rdataset)) {
|
2000-01-15 00:47:45 +00:00
|
|
|
dns_rdataset_disassociate(rdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-04-28 23:46:43 +00:00
|
|
|
if (sigrdataset != NULL &&
|
2020-02-13 21:48:23 +01:00
|
|
|
dns_rdataset_isassociated(sigrdataset)) {
|
2000-01-15 00:47:45 +00:00
|
|
|
dns_rdataset_disassociate(sigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-04-06 22:03:35 +00:00
|
|
|
result = ISC_R_NOTFOUND;
|
2000-01-15 00:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-10-27 00:43:56 +00:00
|
|
|
isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_view_findzonecut(dns_view_t *view, const dns_name_t *name,
|
2018-06-13 09:29:40 +02:00
|
|
|
dns_name_t *fname, dns_name_t *dcname, isc_stdtime_t now,
|
2020-02-12 13:59:18 +01:00
|
|
|
unsigned int options, bool use_hints, bool use_cache,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_db_t *db;
|
|
|
|
bool is_cache, use_zone, try_hints;
|
|
|
|
dns_zone_t *zone;
|
|
|
|
dns_name_t *zfname;
|
|
|
|
dns_rdataset_t zrdataset, zsigrdataset;
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_fixedname_t zfixedname;
|
2020-02-13 14:44:37 -08:00
|
|
|
unsigned int ztoptions = DNS_ZTFIND_MIRROR;
|
1999-10-27 00:43:56 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(view->frozen);
|
|
|
|
|
|
|
|
db = NULL;
|
2018-04-17 08:29:14 -07:00
|
|
|
use_zone = false;
|
|
|
|
try_hints = false;
|
1999-10-27 00:43:56 +00:00
|
|
|
zfname = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize.
|
|
|
|
*/
|
|
|
|
dns_fixedname_init(&zfixedname);
|
|
|
|
dns_rdataset_init(&zrdataset);
|
|
|
|
dns_rdataset_init(&zsigrdataset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the right database.
|
|
|
|
*/
|
2013-02-28 15:22:44 -08:00
|
|
|
zone = NULL;
|
2013-06-04 11:27:26 +10:00
|
|
|
LOCK(&view->lock);
|
2014-08-22 16:32:19 +10:00
|
|
|
if (view->zonetable != NULL) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if ((options & DNS_DBFIND_NOEXACT) != 0) {
|
2014-08-22 16:32:19 +10:00
|
|
|
ztoptions |= DNS_ZTFIND_NOEXACT;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_zt_find(view->zonetable, name, ztoptions, NULL,
|
|
|
|
&zone);
|
2020-01-15 14:39:38 -03:00
|
|
|
} else {
|
2013-04-10 13:49:57 -07:00
|
|
|
result = ISC_R_NOTFOUND;
|
2020-01-15 14:39:38 -03:00
|
|
|
}
|
2013-06-04 11:27:26 +10:00
|
|
|
UNLOCK(&view->lock);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) {
|
1999-10-27 00:43:56 +00:00
|
|
|
result = dns_zone_getdb(zone, &db);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-27 00:43:56 +00:00
|
|
|
if (result == ISC_R_NOTFOUND) {
|
|
|
|
/*
|
|
|
|
* We're not directly authoritative for this query name, nor
|
|
|
|
* is it a subdomain of any zone for which we're
|
|
|
|
* authoritative.
|
|
|
|
*/
|
2003-02-26 22:54:29 +00:00
|
|
|
if (use_cache && view->cachedb != NULL) {
|
1999-10-27 00:43:56 +00:00
|
|
|
/*
|
|
|
|
* We have a cache; try it.
|
|
|
|
*/
|
|
|
|
dns_db_attach(view->cachedb, &db);
|
2020-01-15 14:39:38 -03:00
|
|
|
} else if (use_hints && view->hints != NULL) {
|
1999-10-27 00:43:56 +00:00
|
|
|
/*
|
|
|
|
* Maybe we have hints...
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
try_hints = true;
|
1999-10-27 00:43:56 +00:00
|
|
|
goto finish;
|
2020-01-15 14:39:38 -03:00
|
|
|
} else {
|
|
|
|
result = DNS_R_NXDOMAIN;
|
|
|
|
goto cleanup;
|
1999-10-27 00:43:56 +00:00
|
|
|
}
|
|
|
|
} else if (result != ISC_R_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* Something is broken.
|
|
|
|
*/
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2000-06-07 02:38:41 +00:00
|
|
|
is_cache = dns_db_iscache(db);
|
1999-10-27 00:43:56 +00:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
db_find:
|
1999-10-27 00:43:56 +00:00
|
|
|
/*
|
|
|
|
* Look for the zonecut.
|
|
|
|
*/
|
2000-06-07 02:38:41 +00:00
|
|
|
if (!is_cache) {
|
1999-10-27 00:43:56 +00:00
|
|
|
result = dns_db_find(db, name, NULL, dns_rdatatype_ns, options,
|
|
|
|
now, NULL, fname, rdataset, sigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result == DNS_R_DELEGATION) {
|
1999-10-27 00:43:56 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (result != ISC_R_SUCCESS) {
|
1999-10-27 00:43:56 +00:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-01-15 14:39:38 -03:00
|
|
|
|
2003-02-26 22:54:29 +00:00
|
|
|
if (use_cache && view->cachedb != NULL && db != view->hints) {
|
1999-10-27 00:43:56 +00:00
|
|
|
/*
|
|
|
|
* We found an answer, but the cache may be better.
|
|
|
|
*/
|
|
|
|
zfname = dns_fixedname_name(&zfixedname);
|
2021-05-21 17:20:44 -07:00
|
|
|
dns_name_copy(fname, zfname);
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_rdataset_clone(rdataset, &zrdataset);
|
|
|
|
dns_rdataset_disassociate(rdataset);
|
|
|
|
if (sigrdataset != NULL &&
|
2000-04-28 23:46:43 +00:00
|
|
|
dns_rdataset_isassociated(sigrdataset)) {
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_rdataset_clone(sigrdataset, &zsigrdataset);
|
|
|
|
dns_rdataset_disassociate(sigrdataset);
|
|
|
|
}
|
|
|
|
dns_db_detach(&db);
|
|
|
|
dns_db_attach(view->cachedb, &db);
|
2018-04-17 08:29:14 -07:00
|
|
|
is_cache = true;
|
1999-10-27 00:43:56 +00:00
|
|
|
goto db_find;
|
|
|
|
}
|
|
|
|
} else {
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_db_findzonecut(db, name, options, now, NULL, fname,
|
|
|
|
dcname, rdataset, sigrdataset);
|
1999-10-27 00:43:56 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
if (zfname != NULL &&
|
2010-12-16 09:51:30 +00:00
|
|
|
(!dns_name_issubdomain(fname, zfname) ||
|
2015-05-28 13:17:07 +10:00
|
|
|
(dns_zone_gettype(zone) == dns_zone_staticstub &&
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_equal(fname, zfname))))
|
|
|
|
{
|
1999-10-27 00:43:56 +00:00
|
|
|
/*
|
|
|
|
* We found a zonecut in the cache, but our
|
|
|
|
* zone delegation is better.
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
use_zone = true;
|
1999-10-27 00:43:56 +00:00
|
|
|
}
|
|
|
|
} else if (result == ISC_R_NOTFOUND) {
|
|
|
|
if (zfname != NULL) {
|
|
|
|
/*
|
|
|
|
* We didn't find anything in the cache, but we
|
|
|
|
* have a zone delegation, so use it.
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
use_zone = true;
|
2020-01-15 14:39:38 -03:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
} else if (use_hints && view->hints != NULL) {
|
1999-10-27 00:43:56 +00:00
|
|
|
/*
|
|
|
|
* Maybe we have hints...
|
|
|
|
*/
|
2018-04-17 08:29:14 -07:00
|
|
|
try_hints = true;
|
2020-01-15 14:39:38 -03:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
} else {
|
|
|
|
result = DNS_R_NXDOMAIN;
|
1999-10-27 00:43:56 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Something bad happened.
|
|
|
|
*/
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
finish:
|
1999-10-27 00:43:56 +00:00
|
|
|
if (use_zone) {
|
2000-04-28 23:46:43 +00:00
|
|
|
if (dns_rdataset_isassociated(rdataset)) {
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_rdataset_disassociate(rdataset);
|
|
|
|
if (sigrdataset != NULL &&
|
2020-02-13 21:48:23 +01:00
|
|
|
dns_rdataset_isassociated(sigrdataset)) {
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_rdataset_disassociate(sigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-27 00:43:56 +00:00
|
|
|
}
|
2021-05-21 17:20:44 -07:00
|
|
|
dns_name_copy(zfname, fname);
|
2018-06-13 09:29:40 +02:00
|
|
|
if (dcname != NULL) {
|
2021-05-21 17:20:44 -07:00
|
|
|
dns_name_copy(zfname, dcname);
|
2018-06-13 09:29:40 +02:00
|
|
|
}
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_rdataset_clone(&zrdataset, rdataset);
|
2000-04-28 23:46:43 +00:00
|
|
|
if (sigrdataset != NULL &&
|
2020-02-13 21:48:23 +01:00
|
|
|
dns_rdataset_isassociated(&zrdataset)) {
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_rdataset_clone(&zsigrdataset, sigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2020-01-15 14:39:38 -03:00
|
|
|
} else if (try_hints) {
|
1999-10-27 00:43:56 +00:00
|
|
|
/*
|
|
|
|
* We've found nothing so far, but we have hints.
|
|
|
|
*/
|
|
|
|
result = dns_db_find(view->hints, dns_rootname, NULL,
|
|
|
|
dns_rdatatype_ns, 0, now, NULL, fname,
|
|
|
|
rdataset, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* We can't even find the hints for the root
|
|
|
|
* nameservers!
|
|
|
|
*/
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_rdataset_isassociated(rdataset)) {
|
2001-08-27 17:20:10 +00:00
|
|
|
dns_rdataset_disassociate(rdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-27 00:43:56 +00:00
|
|
|
result = ISC_R_NOTFOUND;
|
2018-06-13 09:29:40 +02:00
|
|
|
} else if (dcname != NULL) {
|
2021-05-21 17:20:44 -07:00
|
|
|
dns_name_copy(fname, dcname);
|
1999-10-27 00:43:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2000-04-28 23:46:43 +00:00
|
|
|
if (dns_rdataset_isassociated(&zrdataset)) {
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_rdataset_disassociate(&zrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (dns_rdataset_isassociated(&zsigrdataset)) {
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_rdataset_disassociate(&zsigrdataset);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-27 00:43:56 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (db != NULL) {
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_db_detach(&db);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (zone != NULL) {
|
1999-10-27 00:43:56 +00:00
|
|
|
dns_zone_detach(&zone);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-27 00:43:56 +00:00
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-10-15 01:43:39 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_viewlist_find(dns_viewlist_t *list, const char *name,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdataclass_t rdclass, dns_view_t **viewp) {
|
1999-10-13 23:17:32 +00:00
|
|
|
dns_view_t *view;
|
|
|
|
|
|
|
|
REQUIRE(list != NULL);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
for (view = ISC_LIST_HEAD(*list); view != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
view = ISC_LIST_NEXT(view, link))
|
|
|
|
{
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strcmp(view->name, name) == 0 && view->rdclass == rdclass) {
|
1999-10-13 23:17:32 +00:00
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-13 23:17:32 +00:00
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view == NULL) {
|
1999-10-15 01:43:39 +00:00
|
|
|
return (ISC_R_NOTFOUND);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
1999-10-15 01:43:39 +00:00
|
|
|
|
|
|
|
dns_view_attach(view, viewp);
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
1999-10-13 23:17:32 +00:00
|
|
|
}
|
1999-10-25 13:38:00 +00:00
|
|
|
|
2007-05-15 02:38:34 +00:00
|
|
|
isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_viewlist_findzone(dns_viewlist_t *list, const dns_name_t *name,
|
2018-04-17 08:29:14 -07:00
|
|
|
bool allclasses, dns_rdataclass_t rdclass,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_zone_t **zonep) {
|
|
|
|
dns_view_t *view;
|
2007-05-15 02:38:34 +00:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_zone_t *zone1 = NULL, *zone2 = NULL;
|
2017-10-04 23:44:08 -07:00
|
|
|
dns_zone_t **zp = NULL;
|
2007-05-15 02:38:34 +00:00
|
|
|
|
|
|
|
REQUIRE(list != NULL);
|
2013-07-09 17:39:21 -07:00
|
|
|
REQUIRE(zonep != NULL && *zonep == NULL);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
for (view = ISC_LIST_HEAD(*list); view != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
view = ISC_LIST_NEXT(view, link))
|
|
|
|
{
|
2020-03-30 13:49:55 -07:00
|
|
|
if (!allclasses && view->rdclass != rdclass) {
|
2007-05-15 02:38:34 +00:00
|
|
|
continue;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-05-13 01:20:24 +00:00
|
|
|
|
|
|
|
/*
|
2008-05-13 23:47:01 +00:00
|
|
|
* If the zone is defined in more than one view,
|
2008-05-13 01:20:24 +00:00
|
|
|
* treat it as not found.
|
|
|
|
*/
|
|
|
|
zp = (zone1 == NULL) ? &zone1 : &zone2;
|
2013-06-04 11:27:26 +10:00
|
|
|
LOCK(&view->lock);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->zonetable != NULL) {
|
2020-02-13 14:44:37 -08:00
|
|
|
result = dns_zt_find(view->zonetable, name, 0, NULL,
|
|
|
|
zp);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2013-04-10 13:49:57 -07:00
|
|
|
result = ISC_R_NOTFOUND;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-06-04 11:27:26 +10:00
|
|
|
UNLOCK(&view->lock);
|
2020-02-12 13:59:18 +01:00
|
|
|
INSIST(result == ISC_R_SUCCESS || result == ISC_R_NOTFOUND ||
|
2008-05-13 01:20:24 +00:00
|
|
|
result == DNS_R_PARTIALMATCH);
|
|
|
|
|
|
|
|
/* Treat a partial match as no match */
|
|
|
|
if (result == DNS_R_PARTIALMATCH) {
|
|
|
|
dns_zone_detach(zp);
|
|
|
|
result = ISC_R_NOTFOUND;
|
2011-03-11 06:11:27 +00:00
|
|
|
POST(result);
|
2008-05-13 01:20:24 +00:00
|
|
|
}
|
|
|
|
|
2007-05-15 02:38:34 +00:00
|
|
|
if (zone2 != NULL) {
|
|
|
|
dns_zone_detach(&zone1);
|
|
|
|
dns_zone_detach(&zone2);
|
2014-08-02 14:43:26 +10:00
|
|
|
return (ISC_R_MULTIPLE);
|
2007-05-15 02:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zone1 != NULL) {
|
|
|
|
dns_zone_attach(zone1, zonep);
|
|
|
|
dns_zone_detach(&zone1);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
2000-01-22 01:36:34 +00:00
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_load(dns_view_t *view, bool stop, bool newonly) {
|
1999-10-25 13:38:00 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
2011-09-02 21:15:39 +00:00
|
|
|
REQUIRE(view->zonetable != NULL);
|
1999-10-25 13:38:00 +00:00
|
|
|
|
2018-07-10 18:43:55 +02:00
|
|
|
return (dns_zt_load(view->zonetable, stop, newonly));
|
1999-10-25 13:38:00 +00:00
|
|
|
}
|
2000-01-21 20:18:41 +00:00
|
|
|
|
2001-05-07 23:34:24 +00:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_view_asyncload(dns_view_t *view, bool newonly, dns_zt_allloaded_t callback,
|
2020-02-13 14:44:37 -08:00
|
|
|
void *arg) {
|
2011-09-02 21:15:39 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(view->zonetable != NULL);
|
|
|
|
|
2018-07-10 18:43:55 +02:00
|
|
|
return (dns_zt_asyncload(view->zonetable, newonly, callback, arg));
|
2011-09-02 21:15:39 +00:00
|
|
|
}
|
|
|
|
|
2000-08-17 00:18:12 +00:00
|
|
|
isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_view_gettsig(dns_view_t *view, const dns_name_t *keyname,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_tsigkey_t **keyp) {
|
2000-08-17 00:18:12 +00:00
|
|
|
isc_result_t result;
|
|
|
|
REQUIRE(keyp != NULL && *keyp == NULL);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_tsigkey_find(keyp, keyname, NULL, view->statickeys);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result == ISC_R_NOTFOUND) {
|
2000-08-17 00:18:12 +00:00
|
|
|
result = dns_tsigkey_find(keyp, keyname, NULL,
|
|
|
|
view->dynamickeys);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-17 00:18:12 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2021-01-14 12:51:25 +01:00
|
|
|
isc_result_t
|
|
|
|
dns_view_gettransport(dns_view_t *view, const dns_transport_type_t type,
|
|
|
|
const dns_name_t *name, dns_transport_t **transportp) {
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(transportp != NULL && *transportp == NULL);
|
|
|
|
|
|
|
|
dns_transport_t *transport = dns_transport_find(type, name,
|
|
|
|
view->transports);
|
|
|
|
if (transport == NULL) {
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
|
|
|
*transportp = transport;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2000-08-17 00:18:12 +00:00
|
|
|
isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_view_getpeertsig(dns_view_t *view, const isc_netaddr_t *peeraddr,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_tsigkey_t **keyp) {
|
2000-08-17 00:18:12 +00:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t *keyname = NULL;
|
|
|
|
dns_peer_t *peer = NULL;
|
2000-08-17 00:18:12 +00:00
|
|
|
|
|
|
|
result = dns_peerlist_peerbyaddr(view->peers, peeraddr, &peer);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-08-17 00:18:12 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-17 00:18:12 +00:00
|
|
|
|
|
|
|
result = dns_peer_getkey(peer, &keyname);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-08-17 00:18:12 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-08-17 00:18:12 +00:00
|
|
|
|
2009-11-12 23:30:36 +00:00
|
|
|
result = dns_view_gettsig(view, keyname, keyp);
|
|
|
|
return ((result == ISC_R_NOTFOUND) ? ISC_R_FAILURE : result);
|
2000-08-17 00:18:12 +00:00
|
|
|
}
|
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_checksig(dns_view_t *view, isc_buffer_t *source, dns_message_t *msg) {
|
2000-01-21 20:18:41 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(source != NULL);
|
|
|
|
|
2000-08-17 00:18:12 +00:00
|
|
|
return (dns_tsig_verify(source, msg, view->statickeys,
|
|
|
|
view->dynamickeys));
|
2000-01-21 20:18:41 +00:00
|
|
|
}
|
|
|
|
|
2000-12-12 21:33:21 +00:00
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_dumpdbtostream(dns_view_t *view, FILE *fp) {
|
2000-12-15 21:11:38 +00:00
|
|
|
isc_result_t result;
|
2000-12-12 21:33:21 +00:00
|
|
|
|
2000-12-15 21:11:38 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
2000-12-12 21:33:21 +00:00
|
|
|
|
2000-12-15 21:11:38 +00:00
|
|
|
(void)fprintf(fp, ";\n; Cache dump of view '%s'\n;\n", view->name);
|
|
|
|
result = dns_master_dumptostream(view->mctx, view->cachedb, NULL,
|
2018-04-03 13:09:55 +02:00
|
|
|
&dns_master_style_cache,
|
|
|
|
dns_masterformat_text, NULL, fp);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-12-15 21:11:38 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2000-12-15 21:11:38 +00:00
|
|
|
dns_adb_dump(view->adb, fp);
|
2010-02-25 04:39:13 +00:00
|
|
|
dns_resolver_printbadcache(view->resolver, fp);
|
2014-09-03 23:28:14 -07:00
|
|
|
dns_badcache_print(view->failcache, "SERVFAIL cache", fp);
|
2000-12-15 21:11:38 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2000-12-12 21:33:21 +00:00
|
|
|
}
|
2001-04-11 20:37:50 +00:00
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_flushcache(dns_view_t *view, bool fixuponly) {
|
2001-04-11 20:37:50 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->cachedb == NULL) {
|
2001-04-11 20:37:50 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-01-09 22:24:37 +00:00
|
|
|
if (!fixuponly) {
|
|
|
|
result = dns_cache_flush(view->cache);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2009-01-09 22:24:37 +00:00
|
|
|
return (result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-01-09 22:24:37 +00:00
|
|
|
}
|
2001-04-11 20:37:50 +00:00
|
|
|
dns_db_detach(&view->cachedb);
|
|
|
|
dns_cache_attachdb(view->cache, &view->cachedb);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->resolver != NULL) {
|
2010-02-25 04:39:13 +00:00
|
|
|
dns_resolver_flushbadcache(view->resolver, NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->failcache != NULL) {
|
2014-09-03 23:28:14 -07:00
|
|
|
dns_badcache_flush(view->failcache);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2001-04-11 20:37:50 +00:00
|
|
|
|
|
|
|
dns_adb_flush(view->adb);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
2001-11-27 04:06:17 +00:00
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_flushname(dns_view_t *view, const dns_name_t *name) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (dns_view_flushnode(view, name, false));
|
2011-08-02 20:36:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_flushnode(dns_view_t *view, const dns_name_t *name, bool tree) {
|
2013-06-30 18:53:48 -07:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
2001-11-27 04:06:17 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
2013-06-30 18:53:48 -07:00
|
|
|
if (tree) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->adb != NULL) {
|
2013-06-26 14:59:32 -07:00
|
|
|
dns_adb_flushnames(view->adb, name);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->resolver != NULL) {
|
2013-06-26 14:59:32 -07:00
|
|
|
dns_resolver_flushbadnames(view->resolver, name);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->failcache != NULL) {
|
2014-09-03 23:28:14 -07:00
|
|
|
dns_badcache_flushtree(view->failcache, name);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-06-30 18:53:48 -07:00
|
|
|
} else {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->adb != NULL) {
|
2011-08-02 20:36:13 +00:00
|
|
|
dns_adb_flushname(view->adb, name);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->resolver != NULL) {
|
2011-08-02 20:36:13 +00:00
|
|
|
dns_resolver_flushbadcache(view->resolver, name);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (view->failcache != NULL) {
|
2014-09-03 23:28:14 -07:00
|
|
|
dns_badcache_flushname(view->failcache, name);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2011-08-02 20:36:13 +00:00
|
|
|
}
|
2013-06-26 14:59:32 -07:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->cache != NULL) {
|
2013-06-30 18:53:48 -07:00
|
|
|
result = dns_cache_flushnode(view->cache, name, tree);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2013-06-30 18:53:48 -07:00
|
|
|
|
|
|
|
return (result);
|
2001-11-27 04:06:17 +00:00
|
|
|
}
|
2003-09-17 05:24:43 +00:00
|
|
|
|
2021-10-06 13:40:32 +02:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_adddelegationonly(dns_view_t *view, const dns_name_t *name) {
|
2017-07-21 11:52:24 +10:00
|
|
|
dns_name_t *item;
|
Fix the rbt hashtable and grow it when setting max-cache-size
There were several problems with rbt hashtable implementation:
1. Our internal hashing function returns uint64_t value, but it was
silently truncated to unsigned int in dns_name_hash() and
dns_name_fullhash() functions. As the SipHash 2-4 higher bits are
more random, we need to use the upper half of the return value.
2. The hashtable implementation in rbt.c was using modulo to pick the
slot number for the hash table. This has several problems because
modulo is: a) slow, b) oblivious to patterns in the input data. This
could lead to very uneven distribution of the hashed data in the
hashtable. Combined with the single-linked lists we use, it could
really hog-down the lookup and removal of the nodes from the rbt
tree[a]. The Fibonacci Hashing is much better fit for the hashtable
function here. For longer description, read "Fibonacci Hashing: The
Optimization that the World Forgot"[b] or just look at the Linux
kernel. Also this will make Diego very happy :).
3. The hashtable would rehash every time the number of nodes in the rbt
tree would exceed 3 * (hashtable size). The overcommit will make the
uneven distribution in the hashtable even worse, but the main problem
lies in the rehashing - every time the database grows beyond the
limit, each subsequent rehashing will be much slower. The mitigation
here is letting the rbt know how big the cache can grown and
pre-allocate the hashtable to be big enough to actually never need to
rehash. This will consume more memory at the start, but since the
size of the hashtable is capped to `1 << 32` (e.g. 4 mio entries), it
will only consume maximum of 32GB of memory for hashtable in the
worst case (and max-cache-size would need to be set to more than
4TB). Calling the dns_db_adjusthashsize() will also cap the maximum
size of the hashtable to the pre-computed number of bits, so it won't
try to consume more gigabytes of memory than available for the
database.
FIXME: What is the average size of the rbt node that gets hashed? I
chose the pagesize (4k) as initial value to precompute the size of
the hashtable, but the value is based on feeling and not any real
data.
For future work, there are more places where we use result of the hash
value modulo some small number and that would benefit from Fibonacci
Hashing to get better distribution.
Notes:
a. A doubly linked list should be used here to speedup the removal of
the entries from the hashtable.
b. https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/
2020-07-16 10:29:54 +02:00
|
|
|
unsigned int hash;
|
2003-09-17 05:24:43 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
|
|
|
if (view->delonly == NULL) {
|
2020-02-13 14:44:37 -08:00
|
|
|
view->delonly = isc_mem_get(view->mctx,
|
|
|
|
sizeof(dns_namelist_t) *
|
|
|
|
DNS_VIEW_DELONLYHASH);
|
2020-02-13 21:48:23 +01:00
|
|
|
for (hash = 0; hash < DNS_VIEW_DELONLYHASH; hash++) {
|
2003-09-17 05:24:43 +00:00
|
|
|
ISC_LIST_INIT(view->delonly[hash]);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-09-17 05:24:43 +00:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
hash = dns_name_hash(name, false) % DNS_VIEW_DELONLYHASH;
|
2017-07-21 11:52:24 +10:00
|
|
|
item = ISC_LIST_HEAD(view->delonly[hash]);
|
2020-02-13 21:48:23 +01:00
|
|
|
while (item != NULL && !dns_name_equal(item, name)) {
|
2017-07-21 11:52:24 +10:00
|
|
|
item = ISC_LIST_NEXT(item, link);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (item != NULL) {
|
2021-10-06 13:40:32 +02:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-07-21 11:52:24 +10:00
|
|
|
item = isc_mem_get(view->mctx, sizeof(*item));
|
|
|
|
dns_name_init(item, NULL);
|
2019-11-01 08:31:13 -05:00
|
|
|
dns_name_dup(name, view->mctx, item);
|
|
|
|
ISC_LIST_APPEND(view->delonly[hash], item, link);
|
2003-09-17 05:24:43 +00:00
|
|
|
}
|
|
|
|
|
2021-10-06 13:40:32 +02:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_excludedelegationonly(dns_view_t *view, const dns_name_t *name) {
|
2017-07-21 11:52:24 +10:00
|
|
|
dns_name_t *item;
|
Fix the rbt hashtable and grow it when setting max-cache-size
There were several problems with rbt hashtable implementation:
1. Our internal hashing function returns uint64_t value, but it was
silently truncated to unsigned int in dns_name_hash() and
dns_name_fullhash() functions. As the SipHash 2-4 higher bits are
more random, we need to use the upper half of the return value.
2. The hashtable implementation in rbt.c was using modulo to pick the
slot number for the hash table. This has several problems because
modulo is: a) slow, b) oblivious to patterns in the input data. This
could lead to very uneven distribution of the hashed data in the
hashtable. Combined with the single-linked lists we use, it could
really hog-down the lookup and removal of the nodes from the rbt
tree[a]. The Fibonacci Hashing is much better fit for the hashtable
function here. For longer description, read "Fibonacci Hashing: The
Optimization that the World Forgot"[b] or just look at the Linux
kernel. Also this will make Diego very happy :).
3. The hashtable would rehash every time the number of nodes in the rbt
tree would exceed 3 * (hashtable size). The overcommit will make the
uneven distribution in the hashtable even worse, but the main problem
lies in the rehashing - every time the database grows beyond the
limit, each subsequent rehashing will be much slower. The mitigation
here is letting the rbt know how big the cache can grown and
pre-allocate the hashtable to be big enough to actually never need to
rehash. This will consume more memory at the start, but since the
size of the hashtable is capped to `1 << 32` (e.g. 4 mio entries), it
will only consume maximum of 32GB of memory for hashtable in the
worst case (and max-cache-size would need to be set to more than
4TB). Calling the dns_db_adjusthashsize() will also cap the maximum
size of the hashtable to the pre-computed number of bits, so it won't
try to consume more gigabytes of memory than available for the
database.
FIXME: What is the average size of the rbt node that gets hashed? I
chose the pagesize (4k) as initial value to precompute the size of
the hashtable, but the value is based on feeling and not any real
data.
For future work, there are more places where we use result of the hash
value modulo some small number and that would benefit from Fibonacci
Hashing to get better distribution.
Notes:
a. A doubly linked list should be used here to speedup the removal of
the entries from the hashtable.
b. https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/
2020-07-16 10:29:54 +02:00
|
|
|
unsigned int hash;
|
2003-09-19 12:39:49 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
2003-09-19 13:17:21 +00:00
|
|
|
if (view->rootexclude == NULL) {
|
2020-02-13 14:44:37 -08:00
|
|
|
view->rootexclude = isc_mem_get(view->mctx,
|
|
|
|
sizeof(dns_namelist_t) *
|
2020-02-12 13:59:18 +01:00
|
|
|
DNS_VIEW_DELONLYHASH);
|
2020-02-13 21:48:23 +01:00
|
|
|
for (hash = 0; hash < DNS_VIEW_DELONLYHASH; hash++) {
|
2003-09-19 13:27:18 +00:00
|
|
|
ISC_LIST_INIT(view->rootexclude[hash]);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-09-19 12:39:49 +00:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
hash = dns_name_hash(name, false) % DNS_VIEW_DELONLYHASH;
|
2017-07-21 11:52:24 +10:00
|
|
|
item = ISC_LIST_HEAD(view->rootexclude[hash]);
|
2020-02-13 21:48:23 +01:00
|
|
|
while (item != NULL && !dns_name_equal(item, name)) {
|
2017-07-21 11:52:24 +10:00
|
|
|
item = ISC_LIST_NEXT(item, link);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (item != NULL) {
|
2021-10-06 13:40:32 +02:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-07-21 11:52:24 +10:00
|
|
|
item = isc_mem_get(view->mctx, sizeof(*item));
|
|
|
|
dns_name_init(item, NULL);
|
2019-11-01 08:31:13 -05:00
|
|
|
dns_name_dup(name, view->mctx, item);
|
|
|
|
ISC_LIST_APPEND(view->rootexclude[hash], item, link);
|
2003-09-19 12:39:49 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_isdelegationonly(dns_view_t *view, const dns_name_t *name) {
|
2017-07-21 11:52:24 +10:00
|
|
|
dns_name_t *item;
|
Fix the rbt hashtable and grow it when setting max-cache-size
There were several problems with rbt hashtable implementation:
1. Our internal hashing function returns uint64_t value, but it was
silently truncated to unsigned int in dns_name_hash() and
dns_name_fullhash() functions. As the SipHash 2-4 higher bits are
more random, we need to use the upper half of the return value.
2. The hashtable implementation in rbt.c was using modulo to pick the
slot number for the hash table. This has several problems because
modulo is: a) slow, b) oblivious to patterns in the input data. This
could lead to very uneven distribution of the hashed data in the
hashtable. Combined with the single-linked lists we use, it could
really hog-down the lookup and removal of the nodes from the rbt
tree[a]. The Fibonacci Hashing is much better fit for the hashtable
function here. For longer description, read "Fibonacci Hashing: The
Optimization that the World Forgot"[b] or just look at the Linux
kernel. Also this will make Diego very happy :).
3. The hashtable would rehash every time the number of nodes in the rbt
tree would exceed 3 * (hashtable size). The overcommit will make the
uneven distribution in the hashtable even worse, but the main problem
lies in the rehashing - every time the database grows beyond the
limit, each subsequent rehashing will be much slower. The mitigation
here is letting the rbt know how big the cache can grown and
pre-allocate the hashtable to be big enough to actually never need to
rehash. This will consume more memory at the start, but since the
size of the hashtable is capped to `1 << 32` (e.g. 4 mio entries), it
will only consume maximum of 32GB of memory for hashtable in the
worst case (and max-cache-size would need to be set to more than
4TB). Calling the dns_db_adjusthashsize() will also cap the maximum
size of the hashtable to the pre-computed number of bits, so it won't
try to consume more gigabytes of memory than available for the
database.
FIXME: What is the average size of the rbt node that gets hashed? I
chose the pagesize (4k) as initial value to precompute the size of
the hashtable, but the value is based on feeling and not any real
data.
For future work, there are more places where we use result of the hash
value modulo some small number and that would benefit from Fibonacci
Hashing to get better distribution.
Notes:
a. A doubly linked list should be used here to speedup the removal of
the entries from the hashtable.
b. https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/
2020-07-16 10:29:54 +02:00
|
|
|
unsigned int hash;
|
2003-09-17 05:24:43 +00:00
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (!view->rootdelonly && view->delonly == NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-09-17 05:24:43 +00:00
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
hash = dns_name_hash(name, false) % DNS_VIEW_DELONLYHASH;
|
2003-09-19 12:39:49 +00:00
|
|
|
if (view->rootdelonly && dns_name_countlabels(name) <= 2) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->rootexclude == NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2017-07-21 11:52:24 +10:00
|
|
|
item = ISC_LIST_HEAD(view->rootexclude[hash]);
|
2020-02-13 21:48:23 +01:00
|
|
|
while (item != NULL && !dns_name_equal(item, name)) {
|
2017-07-21 11:52:24 +10:00
|
|
|
item = ISC_LIST_NEXT(item, link);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (item == NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-09-19 12:39:49 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->delonly == NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2003-09-19 12:39:49 +00:00
|
|
|
|
2017-07-21 11:52:24 +10:00
|
|
|
item = ISC_LIST_HEAD(view->delonly[hash]);
|
2020-02-13 21:48:23 +01:00
|
|
|
while (item != NULL && !dns_name_equal(item, name)) {
|
2017-07-21 11:52:24 +10:00
|
|
|
item = ISC_LIST_NEXT(item, link);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
|
|
|
if (item == NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2003-09-17 05:24:43 +00:00
|
|
|
}
|
2003-09-19 12:39:49 +00:00
|
|
|
|
2008-04-01 23:47:10 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setrootdelonly(dns_view_t *view, bool value) {
|
2003-09-19 12:39:49 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
view->rootdelonly = value;
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_getrootdelonly(dns_view_t *view) {
|
2003-09-19 12:39:49 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
return (view->rootdelonly);
|
|
|
|
}
|
2005-01-14 03:28:09 +00:00
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_freezezones(dns_view_t *view, bool value) {
|
2005-01-14 03:28:09 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
2013-04-10 13:49:57 -07:00
|
|
|
REQUIRE(view->zonetable != NULL);
|
|
|
|
|
2021-08-03 15:40:47 +10:00
|
|
|
return (dns_zt_freezezones(view->zonetable, view, value));
|
2005-01-14 03:28:09 +00:00
|
|
|
}
|
2006-12-21 06:03:37 +00:00
|
|
|
|
2012-05-14 10:06:05 -07:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setadbstats(dns_view_t *view, isc_stats_t *stats) {
|
2012-05-14 10:06:05 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(!view->frozen);
|
|
|
|
REQUIRE(view->adbstats == NULL);
|
|
|
|
|
|
|
|
isc_stats_attach(stats, &view->adbstats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_getadbstats(dns_view_t *view, isc_stats_t **statsp) {
|
2012-05-14 10:06:05 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->adbstats != NULL) {
|
2012-05-14 10:06:05 -07:00
|
|
|
isc_stats_attach(view->adbstats, statsp);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-05-14 10:06:05 -07:00
|
|
|
}
|
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setresstats(dns_view_t *view, isc_stats_t *stats) {
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(!view->frozen);
|
|
|
|
REQUIRE(view->resstats == NULL);
|
2006-12-21 06:03:37 +00:00
|
|
|
|
2009-01-27 22:30:00 +00:00
|
|
|
isc_stats_attach(stats, &view->resstats);
|
2006-12-21 06:03:37 +00:00
|
|
|
}
|
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_getresstats(dns_view_t *view, isc_stats_t **statsp) {
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
2006-12-21 06:03:37 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->resstats != NULL) {
|
2009-01-27 22:30:00 +00:00
|
|
|
isc_stats_attach(view->resstats, statsp);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2008-04-03 05:55:52 +00:00
|
|
|
}
|
2006-12-21 06:03:37 +00:00
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setresquerystats(dns_view_t *view, dns_stats_t *stats) {
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(!view->frozen);
|
|
|
|
REQUIRE(view->resquerystats == NULL);
|
2006-12-21 06:03:37 +00:00
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
dns_stats_attach(stats, &view->resquerystats);
|
|
|
|
}
|
2006-12-21 06:03:37 +00:00
|
|
|
|
2008-04-03 05:55:52 +00:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_getresquerystats(dns_view_t *view, dns_stats_t **statsp) {
|
2008-04-03 05:55:52 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(statsp != NULL && *statsp == NULL);
|
2006-12-21 06:03:37 +00:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->resquerystats != NULL) {
|
2008-04-03 05:55:52 +00:00
|
|
|
dns_stats_attach(view->resquerystats, statsp);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2006-12-21 06:03:37 +00:00
|
|
|
}
|
2009-10-27 22:46:13 +00:00
|
|
|
|
2014-05-29 22:22:53 -07:00
|
|
|
isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_view_initntatable(dns_view_t *view, isc_taskmgr_t *taskmgr,
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_timermgr_t *timermgr) {
|
2014-05-29 22:22:53 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->ntatable_priv != NULL) {
|
2014-05-29 22:22:53 -07:00
|
|
|
dns_ntatable_detach(&view->ntatable_priv);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-06-18 16:47:22 -07:00
|
|
|
return (dns_ntatable_create(view, taskmgr, timermgr,
|
|
|
|
&view->ntatable_priv));
|
2014-05-29 22:22:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_getntatable(dns_view_t *view, dns_ntatable_t **ntp) {
|
2014-05-29 22:22:53 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(ntp != NULL && *ntp == NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->ntatable_priv == NULL) {
|
2014-05-29 22:22:53 -07:00
|
|
|
return (ISC_R_NOTFOUND);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-05-29 22:22:53 -07:00
|
|
|
dns_ntatable_attach(view->ntatable_priv, ntp);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2009-10-27 22:46:13 +00:00
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_initsecroots(dns_view_t *view, isc_mem_t *mctx) {
|
2009-10-27 22:46:13 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->secroots_priv != NULL) {
|
2009-10-27 22:46:13 +00:00
|
|
|
dns_keytable_detach(&view->secroots_priv);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-10-27 22:46:13 +00:00
|
|
|
return (dns_keytable_create(mctx, &view->secroots_priv));
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_getsecroots(dns_view_t *view, dns_keytable_t **ktp) {
|
2009-10-27 22:46:13 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(ktp != NULL && *ktp == NULL);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->secroots_priv == NULL) {
|
2009-10-27 22:46:13 +00:00
|
|
|
return (ISC_R_NOTFOUND);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2009-10-27 22:46:13 +00:00
|
|
|
dns_keytable_attach(view->secroots_priv, ktp);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
bool
|
2020-02-12 13:59:18 +01:00
|
|
|
dns_view_ntacovers(dns_view_t *view, isc_stdtime_t now, const dns_name_t *name,
|
2020-02-13 14:44:37 -08:00
|
|
|
const dns_name_t *anchor) {
|
2014-05-29 22:22:53 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->ntatable_priv == NULL) {
|
2018-04-17 08:29:14 -07:00
|
|
|
return (false);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2014-05-29 22:22:53 -07:00
|
|
|
|
|
|
|
return (dns_ntatable_covered(view->ntatable_priv, now, name, anchor));
|
|
|
|
}
|
|
|
|
|
2009-10-27 22:46:13 +00:00
|
|
|
isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_view_issecuredomain(dns_view_t *view, const dns_name_t *name,
|
2019-04-24 11:17:15 +02:00
|
|
|
isc_stdtime_t now, bool checknta, bool *ntap,
|
2020-02-13 14:44:37 -08:00
|
|
|
bool *secure_domain) {
|
|
|
|
isc_result_t result;
|
|
|
|
bool secure = false;
|
2014-05-29 22:22:53 -07:00
|
|
|
dns_fixedname_t fn;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_name_t *anchor;
|
2014-05-29 22:22:53 -07:00
|
|
|
|
2009-10-27 22:46:13 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
2011-08-30 21:14:50 +00:00
|
|
|
|
2019-04-24 11:17:15 +02:00
|
|
|
if (view->secroots_priv == NULL) {
|
2011-08-30 21:14:50 +00:00
|
|
|
return (ISC_R_NOTFOUND);
|
2019-04-24 11:17:15 +02:00
|
|
|
}
|
2014-05-29 22:22:53 -07:00
|
|
|
|
2018-03-28 14:38:09 +02:00
|
|
|
anchor = dns_fixedname_initname(&fn);
|
2014-05-29 22:22:53 -07:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = dns_keytable_issecuredomain(view->secroots_priv, name, anchor,
|
|
|
|
&secure);
|
2019-04-24 11:17:15 +02:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2014-05-29 22:22:53 -07:00
|
|
|
return (result);
|
2019-04-24 11:17:15 +02:00
|
|
|
}
|
2014-05-29 22:22:53 -07:00
|
|
|
|
2019-04-24 11:17:15 +02:00
|
|
|
if (ntap != NULL) {
|
|
|
|
*ntap = false;
|
|
|
|
}
|
2014-06-18 16:47:22 -07:00
|
|
|
if (checknta && secure && view->ntatable_priv != NULL &&
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_ntatable_covered(view->ntatable_priv, now, name, anchor))
|
|
|
|
{
|
2019-04-24 11:17:15 +02:00
|
|
|
if (ntap != NULL) {
|
|
|
|
*ntap = true;
|
|
|
|
}
|
2018-04-17 08:29:14 -07:00
|
|
|
secure = false;
|
2019-04-24 11:17:15 +02:00
|
|
|
}
|
2014-05-29 22:22:53 -07:00
|
|
|
|
|
|
|
*secure_domain = secure;
|
|
|
|
return (ISC_R_SUCCESS);
|
2009-10-27 22:46:13 +00:00
|
|
|
}
|
2010-05-14 04:38:52 +00:00
|
|
|
|
|
|
|
void
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_view_untrust(dns_view_t *view, const dns_name_t *keyname,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_rdata_dnskey_t *dnskey) {
|
|
|
|
isc_result_t result;
|
2010-05-14 04:38:52 +00:00
|
|
|
dns_keytable_t *sr = NULL;
|
|
|
|
|
2019-12-11 00:09:15 -08:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(keyname != NULL);
|
|
|
|
REQUIRE(dnskey != NULL);
|
|
|
|
|
2010-05-14 04:38:52 +00:00
|
|
|
/*
|
|
|
|
* Clear the revoke bit, if set, so that the key will match what's
|
|
|
|
* in secroots now.
|
|
|
|
*/
|
|
|
|
dnskey->flags &= ~DNS_KEYFLAG_REVOKE;
|
|
|
|
|
2019-12-11 00:09:15 -08:00
|
|
|
result = dns_view_getsecroots(view, &sr);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2010-05-14 04:38:52 +00:00
|
|
|
return;
|
2019-12-11 00:09:15 -08:00
|
|
|
}
|
2016-04-14 18:52:52 -07:00
|
|
|
|
2019-12-11 00:09:15 -08:00
|
|
|
result = dns_keytable_deletekey(sr, keyname, dnskey);
|
2010-05-14 04:38:52 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
2016-04-14 18:52:52 -07:00
|
|
|
/*
|
|
|
|
* If key was found in secroots, then it was a
|
|
|
|
* configured trust anchor, and we want to fail
|
|
|
|
* secure. If there are no other configured keys,
|
|
|
|
* then leave a null key so that we can't validate
|
|
|
|
* anymore.
|
|
|
|
*/
|
2019-12-11 00:09:15 -08:00
|
|
|
dns_keytable_marksecure(sr, keyname);
|
2010-05-14 04:38:52 +00:00
|
|
|
}
|
2016-04-14 18:52:52 -07:00
|
|
|
|
2019-12-11 00:09:15 -08:00
|
|
|
dns_keytable_detach(&sr);
|
2010-05-14 04:38:52 +00:00
|
|
|
}
|
|
|
|
|
2017-04-23 23:16:53 -07:00
|
|
|
/*
|
2020-02-20 14:49:36 -08:00
|
|
|
* Create path to a directory and a filename constructed from viewname.
|
2017-04-23 23:16:53 -07:00
|
|
|
* This is a front-end to isc_file_sanitize(), allowing backward
|
|
|
|
* compatibility to older versions when a file couldn't be expected
|
|
|
|
* to be in the specified directory but might be in the current working
|
|
|
|
* directory instead.
|
|
|
|
*
|
|
|
|
* It first tests for the existence of a file <viewname>.<suffix> in
|
|
|
|
* 'directory'. If the file does not exist, it checks again in the
|
|
|
|
* current working directory. If it does not exist there either,
|
|
|
|
* return the path inside the directory.
|
|
|
|
*
|
|
|
|
* Returns ISC_R_SUCCESS if a path to an existing file is found or
|
|
|
|
* a new path is created; returns ISC_R_NOSPACE if the path won't
|
|
|
|
* fit in 'buflen'.
|
|
|
|
*/
|
2017-05-02 10:58:41 -07:00
|
|
|
|
2017-04-23 23:16:53 -07:00
|
|
|
static isc_result_t
|
2020-02-12 13:59:18 +01:00
|
|
|
nz_legacy(const char *directory, const char *viewname, const char *suffix,
|
2020-02-13 14:44:37 -08:00
|
|
|
char *buffer, size_t buflen) {
|
2017-04-23 23:16:53 -07:00
|
|
|
isc_result_t result;
|
2020-02-13 14:44:37 -08:00
|
|
|
char newbuf[PATH_MAX];
|
2017-04-23 23:16:53 -07:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
result = isc_file_sanitize(directory, viewname, suffix, buffer, buflen);
|
2017-04-23 23:16:53 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
return (result);
|
|
|
|
} else if (directory == NULL || isc_file_exists(buffer)) {
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
} else {
|
|
|
|
/* Save buffer */
|
|
|
|
strlcpy(newbuf, buffer, sizeof(newbuf));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It isn't in the specified directory; check CWD.
|
|
|
|
*/
|
|
|
|
result = isc_file_sanitize(NULL, viewname, suffix, buffer, buflen);
|
|
|
|
if (result != ISC_R_SUCCESS || isc_file_exists(buffer)) {
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File does not exist in either 'directory' or CWD,
|
|
|
|
* so use the path in 'directory'.
|
|
|
|
*/
|
|
|
|
strlcpy(buffer, newbuf, buflen);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2016-07-21 11:13:03 -07:00
|
|
|
isc_result_t
|
2018-04-17 08:29:14 -07:00
|
|
|
dns_view_setnewzones(dns_view_t *view, bool allow, void *cfgctx,
|
2020-02-13 14:44:37 -08:00
|
|
|
void (*cfg_destroy)(void **), uint64_t mapsize) {
|
2017-06-13 10:15:34 -07:00
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
2020-02-13 14:44:37 -08:00
|
|
|
char buffer[1024];
|
2016-07-21 11:13:03 -07:00
|
|
|
#ifdef HAVE_LMDB
|
|
|
|
MDB_env *env = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
int status;
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifdef HAVE_LMDB */
|
2016-07-21 11:13:03 -07:00
|
|
|
|
2017-04-27 09:48:29 +10:00
|
|
|
#ifndef HAVE_LMDB
|
|
|
|
UNUSED(mapsize);
|
2020-02-13 21:48:23 +01:00
|
|
|
#endif /* ifndef HAVE_LMDB */
|
2017-04-27 09:48:29 +10:00
|
|
|
|
2010-08-11 18:14:20 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE((cfgctx != NULL && cfg_destroy != NULL) || !allow);
|
|
|
|
|
2010-09-06 04:31:11 +00:00
|
|
|
if (view->new_zone_file != NULL) {
|
|
|
|
isc_mem_free(view->mctx, view->new_zone_file);
|
|
|
|
view->new_zone_file = NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-21 11:13:03 -07:00
|
|
|
#ifdef HAVE_LMDB
|
|
|
|
if (view->new_zone_dbenv != NULL) {
|
2020-02-12 13:59:18 +01:00
|
|
|
mdb_env_close((MDB_env *)view->new_zone_dbenv);
|
2016-07-21 11:13:03 -07:00
|
|
|
view->new_zone_dbenv = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (view->new_zone_db != NULL) {
|
|
|
|
isc_mem_free(view->mctx, view->new_zone_db);
|
|
|
|
view->new_zone_db = NULL;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_LMDB */
|
|
|
|
|
2010-09-06 04:31:11 +00:00
|
|
|
if (view->new_zone_config != NULL) {
|
|
|
|
view->cfg_destroy(&view->new_zone_config);
|
|
|
|
view->cfg_destroy = NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-23 23:16:53 -07:00
|
|
|
if (!allow) {
|
2016-07-21 11:13:03 -07:00
|
|
|
return (ISC_R_SUCCESS);
|
2017-04-23 23:16:53 -07:00
|
|
|
}
|
2014-11-04 19:43:27 -08:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
CHECK(nz_legacy(view->new_zone_dir, view->name, "nzf", buffer,
|
|
|
|
sizeof(buffer)));
|
2017-05-10 10:50:42 +10:00
|
|
|
|
2016-07-21 11:13:03 -07:00
|
|
|
view->new_zone_file = isc_mem_strdup(view->mctx, buffer);
|
|
|
|
|
|
|
|
#ifdef HAVE_LMDB
|
2020-02-12 13:59:18 +01:00
|
|
|
CHECK(nz_legacy(view->new_zone_dir, view->name, "nzd", buffer,
|
|
|
|
sizeof(buffer)));
|
2017-05-10 10:50:42 +10:00
|
|
|
|
2016-07-21 11:13:03 -07:00
|
|
|
view->new_zone_db = isc_mem_strdup(view->mctx, buffer);
|
|
|
|
|
|
|
|
status = mdb_env_create(&env);
|
2017-11-30 13:43:46 +01:00
|
|
|
if (status != MDB_SUCCESS) {
|
2017-05-10 10:50:42 +10:00
|
|
|
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
|
|
|
|
ISC_LOGMODULE_OTHER, ISC_LOG_ERROR,
|
|
|
|
"mdb_env_create failed: %s",
|
|
|
|
mdb_strerror(status));
|
2017-06-13 10:15:34 -07:00
|
|
|
CHECK(ISC_R_FAILURE);
|
2016-07-21 11:13:03 -07:00
|
|
|
}
|
|
|
|
|
2017-04-26 23:43:35 +05:30
|
|
|
if (mapsize != 0ULL) {
|
|
|
|
status = mdb_env_set_mapsize(env, mapsize);
|
2017-11-30 13:43:46 +01:00
|
|
|
if (status != MDB_SUCCESS) {
|
2017-05-10 10:50:42 +10:00
|
|
|
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
|
|
|
|
ISC_LOGMODULE_OTHER, ISC_LOG_ERROR,
|
|
|
|
"mdb_env_set_mapsize failed: %s",
|
|
|
|
mdb_strerror(status));
|
2017-06-13 10:15:34 -07:00
|
|
|
CHECK(ISC_R_FAILURE);
|
2017-04-26 23:43:35 +05:30
|
|
|
}
|
2017-11-30 13:43:46 +01:00
|
|
|
view->new_zone_mapsize = mapsize;
|
2017-04-26 23:43:35 +05:30
|
|
|
}
|
|
|
|
|
2017-11-30 13:43:46 +01:00
|
|
|
status = mdb_env_open(env, view->new_zone_db, DNS_LMDB_FLAGS, 0600);
|
|
|
|
if (status != MDB_SUCCESS) {
|
2017-05-10 10:50:42 +10:00
|
|
|
isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL,
|
|
|
|
ISC_LOGMODULE_OTHER, ISC_LOG_ERROR,
|
|
|
|
"mdb_env_open of '%s' failed: %s",
|
|
|
|
view->new_zone_db, mdb_strerror(status));
|
2017-06-13 10:15:34 -07:00
|
|
|
CHECK(ISC_R_FAILURE);
|
2016-07-21 11:13:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
view->new_zone_dbenv = env;
|
|
|
|
env = NULL;
|
|
|
|
#endif /* HAVE_LMDB */
|
|
|
|
|
|
|
|
view->new_zone_config = cfgctx;
|
|
|
|
view->cfg_destroy = cfg_destroy;
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2016-07-21 11:13:03 -07:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
if (view->new_zone_file != NULL) {
|
|
|
|
isc_mem_free(view->mctx, view->new_zone_file);
|
|
|
|
view->new_zone_file = NULL;
|
2014-11-04 19:43:27 -08:00
|
|
|
}
|
2016-07-21 11:13:03 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_LMDB
|
|
|
|
if (view->new_zone_db != NULL) {
|
|
|
|
isc_mem_free(view->mctx, view->new_zone_db);
|
|
|
|
view->new_zone_db = NULL;
|
|
|
|
}
|
2017-11-30 13:43:46 +01:00
|
|
|
if (env != NULL) {
|
2016-07-21 11:13:03 -07:00
|
|
|
mdb_env_close(env);
|
2017-11-30 13:43:46 +01:00
|
|
|
}
|
2016-07-21 11:13:03 -07:00
|
|
|
#endif /* HAVE_LMDB */
|
|
|
|
view->new_zone_config = NULL;
|
|
|
|
view->cfg_destroy = NULL;
|
2010-08-11 18:14:20 +00:00
|
|
|
}
|
2016-07-21 11:13:03 -07:00
|
|
|
|
|
|
|
return (result);
|
2010-08-11 18:14:20 +00:00
|
|
|
}
|
2012-12-06 12:59:36 -08:00
|
|
|
|
2017-04-23 23:16:53 -07:00
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setnewzonedir(dns_view_t *view, const char *dir) {
|
2017-04-23 23:16:53 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
|
|
|
if (view->new_zone_dir != NULL) {
|
|
|
|
isc_mem_free(view->mctx, view->new_zone_dir);
|
|
|
|
view->new_zone_dir = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dir == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
view->new_zone_dir = isc_mem_strdup(view->mctx, dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_getnewzonedir(dns_view_t *view) {
|
2017-04-23 23:16:53 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
|
|
|
return (view->new_zone_dir);
|
|
|
|
}
|
|
|
|
|
2012-12-06 12:59:36 -08:00
|
|
|
isc_result_t
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_view_searchdlz(dns_view_t *view, const dns_name_t *name,
|
|
|
|
unsigned int minlabels, dns_clientinfomethods_t *methods,
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_clientinfo_t *clientinfo, dns_db_t **dbp) {
|
|
|
|
dns_fixedname_t fname;
|
|
|
|
dns_name_t *zonename;
|
|
|
|
unsigned int namelabels;
|
|
|
|
unsigned int i;
|
|
|
|
isc_result_t result;
|
2012-12-06 12:59:36 -08:00
|
|
|
dns_dlzfindzone_t findzone;
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_dlzdb_t *dlzdb;
|
|
|
|
dns_db_t *db, *best = NULL;
|
2012-12-06 12:59:36 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Performs checks to make sure data is as we expect it to be.
|
|
|
|
*/
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
REQUIRE(name != NULL);
|
|
|
|
REQUIRE(dbp != NULL && *dbp == NULL);
|
|
|
|
|
|
|
|
/* setup a "fixed" dns name */
|
2018-03-28 14:38:09 +02:00
|
|
|
zonename = dns_fixedname_initname(&fname);
|
2012-12-06 12:59:36 -08:00
|
|
|
|
|
|
|
/* count the number of labels in the name */
|
|
|
|
namelabels = dns_name_countlabels(name);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
for (dlzdb = ISC_LIST_HEAD(view->dlz_searched); dlzdb != NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
dlzdb = ISC_LIST_NEXT(dlzdb, link))
|
|
|
|
{
|
2012-12-06 12:59:36 -08:00
|
|
|
REQUIRE(DNS_DLZ_VALID(dlzdb));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* loop through starting with the longest domain name and
|
|
|
|
* trying shorter names portions of the name until we find a
|
|
|
|
* match, have an error, or are below the 'minlabels'
|
|
|
|
* threshold. minlabels is 0, if neither the standard
|
|
|
|
* database nor any previous DLZ database had a zone name
|
|
|
|
* match. Otherwise minlabels is the number of labels
|
|
|
|
* in that name. We need to beat that for a "better"
|
|
|
|
* match for this DLZ database to be authoritative.
|
|
|
|
*/
|
|
|
|
for (i = namelabels; i > minlabels && i > 1; i--) {
|
|
|
|
if (i == namelabels) {
|
2021-05-21 17:20:44 -07:00
|
|
|
dns_name_copy(name, zonename);
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2012-12-06 12:59:36 -08:00
|
|
|
dns_name_split(name, i, NULL, zonename);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-12-06 12:59:36 -08:00
|
|
|
|
|
|
|
/* ask SDLZ driver if the zone is supported */
|
|
|
|
db = NULL;
|
|
|
|
findzone = dlzdb->implementation->methods->findzone;
|
|
|
|
result = (*findzone)(dlzdb->implementation->driverarg,
|
|
|
|
dlzdb->dbdata, dlzdb->mctx,
|
2020-02-12 13:59:18 +01:00
|
|
|
view->rdclass, zonename, methods,
|
|
|
|
clientinfo, &db);
|
2012-12-06 12:59:36 -08:00
|
|
|
|
|
|
|
if (result != ISC_R_NOTFOUND) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (best != NULL) {
|
2012-12-06 12:59:36 -08:00
|
|
|
dns_db_detach(&best);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-12-06 12:59:36 -08:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
INSIST(db != NULL);
|
|
|
|
dns_db_attach(db, &best);
|
|
|
|
dns_db_detach(&db);
|
|
|
|
minlabels = i;
|
|
|
|
} else {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (db != NULL) {
|
2012-12-06 12:59:36 -08:00
|
|
|
dns_db_detach(&db);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-12-06 12:59:36 -08:00
|
|
|
break;
|
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (db != NULL) {
|
2012-12-06 12:59:36 -08:00
|
|
|
dns_db_detach(&db);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2012-12-06 12:59:36 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (best != NULL) {
|
|
|
|
dns_db_attach(best, dbp);
|
|
|
|
dns_db_detach(&best);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
2014-09-03 23:28:14 -07:00
|
|
|
|
2018-03-28 14:19:37 +02:00
|
|
|
uint32_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_getfailttl(dns_view_t *view) {
|
2014-09-03 23:28:14 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
return (view->fail_ttl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setfailttl(dns_view_t *view, uint32_t fail_ttl) {
|
2014-09-03 23:28:14 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
view->fail_ttl = fail_ttl;
|
|
|
|
}
|
|
|
|
|
2015-01-12 09:04:16 +05:30
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_saventa(dns_view_t *view) {
|
|
|
|
isc_result_t result;
|
|
|
|
bool removefile = false;
|
2015-01-12 09:04:16 +05:30
|
|
|
dns_ntatable_t *ntatable = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
FILE *fp = NULL;
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->nta_lifetime == 0) {
|
2015-01-12 09:04:16 +05:30
|
|
|
return (ISC_R_SUCCESS);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
/* Open NTA save file for overwrite. */
|
|
|
|
CHECK(isc_stdio_open(view->nta_file, "w", &fp));
|
|
|
|
|
|
|
|
result = dns_view_getntatable(view, &ntatable);
|
|
|
|
if (result == ISC_R_NOTFOUND) {
|
2018-04-17 08:29:14 -07:00
|
|
|
removefile = true;
|
2015-01-12 09:04:16 +05:30
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2015-01-12 23:45:21 +00:00
|
|
|
CHECK(result);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
result = dns_ntatable_save(ntatable, fp);
|
|
|
|
if (result == ISC_R_NOTFOUND) {
|
2018-04-17 08:29:14 -07:00
|
|
|
removefile = true;
|
2015-01-12 09:04:16 +05:30
|
|
|
result = ISC_R_SUCCESS;
|
2016-08-08 09:50:34 +10:00
|
|
|
} else if (result == ISC_R_SUCCESS) {
|
|
|
|
result = isc_stdio_close(fp);
|
|
|
|
fp = NULL;
|
2015-01-12 09:04:16 +05:30
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (ntatable != NULL) {
|
2015-01-12 09:04:16 +05:30
|
|
|
dns_ntatable_detach(&ntatable);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (fp != NULL) {
|
2016-08-08 09:50:34 +10:00
|
|
|
(void)isc_stdio_close(fp);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
/* Don't leave half-baked NTA save files lying around. */
|
2020-02-13 21:48:23 +01:00
|
|
|
if (result != ISC_R_SUCCESS || removefile) {
|
2020-02-12 13:59:18 +01:00
|
|
|
(void)isc_file_remove(view->nta_file);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TSTR(t) ((t).value.as_textregion.base)
|
|
|
|
#define TLEN(t) ((t).value.as_textregion.length)
|
|
|
|
|
|
|
|
isc_result_t
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_loadnta(dns_view_t *view) {
|
|
|
|
isc_result_t result;
|
2015-01-12 09:04:16 +05:30
|
|
|
dns_ntatable_t *ntatable = NULL;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_token_t token;
|
|
|
|
isc_stdtime_t now;
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (view->nta_lifetime == 0) {
|
2015-01-12 09:04:16 +05:30
|
|
|
return (ISC_R_SUCCESS);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
CHECK(isc_lex_create(view->mctx, 1025, &lex));
|
|
|
|
CHECK(isc_lex_openfile(lex, view->nta_file));
|
|
|
|
CHECK(dns_view_getntatable(view, &ntatable));
|
|
|
|
isc_stdtime_get(&now);
|
|
|
|
|
|
|
|
for (;;) {
|
2020-02-13 14:44:37 -08:00
|
|
|
int options = (ISC_LEXOPT_EOL | ISC_LEXOPT_EOF);
|
|
|
|
char *name, *type, *timestamp;
|
|
|
|
size_t len;
|
|
|
|
dns_fixedname_t fn;
|
2016-12-30 15:45:08 +11:00
|
|
|
const dns_name_t *ntaname;
|
2020-02-13 14:44:37 -08:00
|
|
|
isc_buffer_t b;
|
|
|
|
isc_stdtime_t t;
|
|
|
|
bool forced;
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
CHECK(isc_lex_gettoken(lex, options, &token));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (token.type == isc_tokentype_eof) {
|
2015-01-12 09:04:16 +05:30
|
|
|
break;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (token.type != isc_tokentype_string) {
|
2015-01-12 09:04:16 +05:30
|
|
|
CHECK(ISC_R_UNEXPECTEDTOKEN);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
name = TSTR(token);
|
|
|
|
len = TLEN(token);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strcmp(name, ".") == 0) {
|
2015-01-12 09:04:16 +05:30
|
|
|
ntaname = dns_rootname;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2016-12-30 15:45:08 +11:00
|
|
|
dns_name_t *fname;
|
2018-03-28 14:38:09 +02:00
|
|
|
fname = dns_fixedname_initname(&fn);
|
2015-01-12 09:04:16 +05:30
|
|
|
|
2015-04-17 11:39:26 +02:00
|
|
|
isc_buffer_init(&b, name, (unsigned int)len);
|
|
|
|
isc_buffer_add(&b, (unsigned int)len);
|
2020-02-12 13:59:18 +01:00
|
|
|
CHECK(dns_name_fromtext(fname, &b, dns_rootname, 0,
|
|
|
|
NULL));
|
2016-12-30 15:45:08 +11:00
|
|
|
ntaname = fname;
|
2015-01-12 09:04:16 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(isc_lex_gettoken(lex, options, &token));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (token.type != isc_tokentype_string) {
|
2015-01-12 09:04:16 +05:30
|
|
|
CHECK(ISC_R_UNEXPECTEDTOKEN);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
type = TSTR(token);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (strcmp(type, "regular") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
forced = false;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else if (strcmp(type, "forced") == 0) {
|
2018-04-17 08:29:14 -07:00
|
|
|
forced = true;
|
2020-02-13 21:48:23 +01:00
|
|
|
} else {
|
2015-01-12 09:04:16 +05:30
|
|
|
CHECK(ISC_R_UNEXPECTEDTOKEN);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
CHECK(isc_lex_gettoken(lex, options, &token));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (token.type != isc_tokentype_string) {
|
2015-01-12 09:04:16 +05:30
|
|
|
CHECK(ISC_R_UNEXPECTEDTOKEN);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
timestamp = TSTR(token);
|
|
|
|
CHECK(dns_time32_fromtext(timestamp, &t));
|
|
|
|
|
|
|
|
CHECK(isc_lex_gettoken(lex, options, &token));
|
|
|
|
if (token.type != isc_tokentype_eol &&
|
2020-02-13 21:48:23 +01:00
|
|
|
token.type != isc_tokentype_eof) {
|
2015-01-12 09:04:16 +05:30
|
|
|
CHECK(ISC_R_UNEXPECTEDTOKEN);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
if (now <= t) {
|
2020-02-13 21:48:23 +01:00
|
|
|
if (t > (now + 604800)) {
|
2015-01-12 09:04:16 +05:30
|
|
|
t = now + 604800;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
(void)dns_ntatable_add(ntatable, ntaname, forced, 0, t);
|
2015-06-08 13:57:24 +02:00
|
|
|
} else {
|
|
|
|
char nb[DNS_NAME_FORMATSIZE];
|
|
|
|
dns_name_format(ntaname, nb, sizeof(nb));
|
|
|
|
isc_log_write(dns_lctx, DNS_LOGCATEGORY_DNSSEC,
|
|
|
|
DNS_LOGMODULE_NTA, ISC_LOG_INFO,
|
|
|
|
"ignoring expired NTA at %s", nb);
|
2015-01-12 09:04:16 +05:30
|
|
|
}
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2020-02-13 21:48:23 +01:00
|
|
|
if (ntatable != NULL) {
|
2015-01-12 09:04:16 +05:30
|
|
|
dns_ntatable_detach(&ntatable);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-01-12 09:04:16 +05:30
|
|
|
|
|
|
|
if (lex != NULL) {
|
|
|
|
isc_lex_close(lex);
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
2017-10-04 23:44:08 -07:00
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setviewcommit(dns_view_t *view) {
|
2020-08-24 11:44:09 +10:00
|
|
|
dns_zone_t *redirect = NULL, *managed_keys = NULL;
|
|
|
|
|
2017-10-04 23:44:08 -07:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
|
|
|
LOCK(&view->lock);
|
|
|
|
|
|
|
|
if (view->redirect != NULL) {
|
2020-08-24 11:44:09 +10:00
|
|
|
dns_zone_attach(view->redirect, &redirect);
|
2017-10-04 23:44:08 -07:00
|
|
|
}
|
|
|
|
if (view->managed_keys != NULL) {
|
2020-08-24 11:44:09 +10:00
|
|
|
dns_zone_attach(view->managed_keys, &managed_keys);
|
2017-10-04 23:44:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
UNLOCK(&view->lock);
|
2020-08-24 11:44:09 +10:00
|
|
|
|
2021-01-14 13:02:57 -08:00
|
|
|
if (view->zonetable != NULL) {
|
|
|
|
dns_zt_setviewcommit(view->zonetable);
|
|
|
|
}
|
2020-08-24 11:44:09 +10:00
|
|
|
if (redirect != NULL) {
|
|
|
|
dns_zone_setviewcommit(redirect);
|
|
|
|
dns_zone_detach(&redirect);
|
|
|
|
}
|
|
|
|
if (managed_keys != NULL) {
|
|
|
|
dns_zone_setviewcommit(managed_keys);
|
|
|
|
dns_zone_detach(&managed_keys);
|
|
|
|
}
|
2017-10-04 23:44:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-02-13 14:44:37 -08:00
|
|
|
dns_view_setviewrevert(dns_view_t *view) {
|
2020-08-24 11:44:09 +10:00
|
|
|
dns_zone_t *redirect = NULL, *managed_keys = NULL;
|
2017-10-04 23:44:08 -07:00
|
|
|
dns_zt_t *zonetable;
|
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dns_zt_setviewrevert() attempts to lock this view, so we must
|
|
|
|
* release the lock.
|
|
|
|
*/
|
|
|
|
LOCK(&view->lock);
|
|
|
|
if (view->redirect != NULL) {
|
2020-08-24 11:44:09 +10:00
|
|
|
dns_zone_attach(view->redirect, &redirect);
|
2017-10-04 23:44:08 -07:00
|
|
|
}
|
|
|
|
if (view->managed_keys != NULL) {
|
2020-08-24 11:44:09 +10:00
|
|
|
dns_zone_attach(view->managed_keys, &managed_keys);
|
2017-10-04 23:44:08 -07:00
|
|
|
}
|
|
|
|
zonetable = view->zonetable;
|
|
|
|
UNLOCK(&view->lock);
|
|
|
|
|
2020-08-24 11:44:09 +10:00
|
|
|
if (redirect != NULL) {
|
|
|
|
dns_zone_setviewrevert(redirect);
|
|
|
|
dns_zone_detach(&redirect);
|
|
|
|
}
|
|
|
|
if (managed_keys != NULL) {
|
|
|
|
dns_zone_setviewrevert(managed_keys);
|
|
|
|
dns_zone_detach(&managed_keys);
|
|
|
|
}
|
2017-10-04 23:44:08 -07:00
|
|
|
if (zonetable != NULL) {
|
|
|
|
dns_zt_setviewrevert(zonetable);
|
|
|
|
}
|
|
|
|
}
|
2020-11-28 18:10:35 -03:00
|
|
|
|
|
|
|
bool
|
|
|
|
dns_view_staleanswerenabled(dns_view_t *view) {
|
|
|
|
uint32_t stale_ttl = 0;
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
|
|
|
|
|
|
|
if (dns_db_getservestalettl(view->cachedb, &stale_ttl) != ISC_R_SUCCESS)
|
|
|
|
{
|
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
if (stale_ttl > 0) {
|
|
|
|
if (view->staleanswersok == dns_stale_answer_yes) {
|
|
|
|
result = true;
|
|
|
|
} else if (view->staleanswersok == dns_stale_answer_conf) {
|
|
|
|
result = view->staleanswersenable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|