server.c revision 349f684cf175422918d10e91e7bee747c18ae840
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
28d9fd53819cc163629c867466b20d8ebcae8842David Lawrence * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Copyright (C) 1999-2003 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
15a44745412679c30a6d022733925af70a38b715David Lawrence * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15a44745412679c30a6d022733925af70a38b715David Lawrence * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15a44745412679c30a6d022733925af70a38b715David Lawrence * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15a44745412679c30a6d022733925af70a38b715David Lawrence * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15a44745412679c30a6d022733925af70a38b715David Lawrence * PERFORMANCE OF THIS SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews/* $Id: server.c,v 1.424 2004/04/20 07:16:23 marka Exp $ */
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <config.h>
de153390f5a1f6d4fa86af91d4cae772d9846ca0Mark Andrews
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <stdlib.h>
822f6cdabb1edd44472c7a758b5cae71376fa9beBrian Wellington
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <isc/app.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/base64.h>
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence#include <isc/dir.h>
973a19342597823f111fce6a8cd5adfd0e2e7c0dMark Andrews#include <isc/entropy.h>
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff#include <isc/file.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/hash.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/lex.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/parseint.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/print.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/resource.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#include <isc/stdio.h>
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews#include <isc/string.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/task.h>
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews#include <isc/timer.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/util.h>
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson#include <isccfg/namedconf.h>
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson#include <bind9/check.h>
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrews#include <dns/adb.h>
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence#include <dns/cache.h>
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence#include <dns/db.h>
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence#include <dns/dispatch.h>
eb6bd543c7d072efdca509eb17f8f301c1467b53Mark Andrews#include <dns/forward.h>
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews#include <dns/journal.h>
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence#include <dns/keytable.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/master.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/masterdump.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/order.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/peer.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/portlist.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/rdataclass.h>
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence#include <dns/rdataset.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/rdatastruct.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/resolver.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/rootns.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/secalg.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/stats.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/tkey.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/view.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dns/zone.h>
0b056755b2f423ba5f6adac8f7851d78f7d11437David Lawrence#include <dns/zt.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dst/dst.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <dst/result.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <named/client.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <named/config.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <named/control.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <named/interfacemgr.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <named/log.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <named/logconf.h>
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence#include <named/lwresd.h>
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson#include <named/main.h>
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence#include <named/os.h>
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson#include <named/server.h>
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson#include <named/tkeyconf.h>
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson#include <named/tsigconf.h>
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson#include <named/zoneconf.h>
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson/*
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * Check an operation for failure. Assumes that the function
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence * using it has a 'result' variable and a 'cleanup' label.
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson#define CHECK(op) \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence do { result = (op); \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (result != ISC_R_SUCCESS) goto cleanup; \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence } while (0)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence#define CHECKM(op, msg) \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence do { result = (op); \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (result != ISC_R_SUCCESS) { \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_log_write(ns_g_lctx, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence NS_LOGCATEGORY_GENERAL, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence NS_LOGMODULE_SERVER, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ISC_LOG_ERROR, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "%s: %s", msg, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_result_totext(result)); \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence goto cleanup; \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence } \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence } while (0) \
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence#define CHECKMF(op, msg, file) \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence do { result = (op); \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (result != ISC_R_SUCCESS) { \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_log_write(ns_g_lctx, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence NS_LOGCATEGORY_GENERAL, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence NS_LOGMODULE_SERVER, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ISC_LOG_ERROR, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "%s '%s': %s", msg, file, \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_result_totext(result)); \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence goto cleanup; \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence } \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence } while (0) \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence#define CHECKFATAL(op, msg) \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence do { result = (op); \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (result != ISC_R_SUCCESS) \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence fatal(msg, result); \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence } while (0) \
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestruct ns_dispatch {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_sockaddr_t addr;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence unsigned int dispatchgen;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_dispatch_t *dispatch;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ISC_LINK(struct ns_dispatch) link;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence};
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestruct dumpcontext {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_mem_t *mctx;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_boolean_t dumpcache;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_boolean_t dumpzones;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence FILE *fp;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ISC_LIST(struct viewlistentry) viewlist;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence struct viewlistentry *view;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence struct zonelistentry *zone;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_dumpctx_t *mdctx;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_db_t *db;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_db_t *cache;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_task_t *task;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_dbversion_t *version;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence};
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestruct viewlistentry {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_view_t *view;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ISC_LINK(struct viewlistentry) link;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ISC_LIST(struct zonelistentry) zonelist;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence};
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestruct zonelistentry {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_zone_t *zone;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence ISC_LINK(struct zonelistentry) link;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence};
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic void
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencefatal(const char *msg, isc_result_t result);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencestatic void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencens_server_reload(isc_task_t *task, isc_event_t *event);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrewsstatic isc_result_t
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrewsns_listenelt_fromconfig(cfg_obj_t *listener, cfg_obj_t *config,
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews ns_aclconfctx_t *actx,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_mem_t *mctx, ns_listenelt_t **target);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencestatic isc_result_t
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrencens_listenlist_fromconfig(cfg_obj_t *listenlist, cfg_obj_t *config,
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson ns_aclconfctx_t *actx,
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews isc_mem_t *mctx, ns_listenlist_t **target);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsstatic isc_result_t
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsconfigure_forward(cfg_obj_t *config, dns_view_t *view, dns_name_t *origin,
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews cfg_obj_t *forwarders, cfg_obj_t *forwardtype);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsstatic isc_result_t
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsconfigure_alternates(cfg_obj_t *config, dns_view_t *view,
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews cfg_obj_t *alternates);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsstatic isc_result_t
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsconfigure_zone(cfg_obj_t *config, cfg_obj_t *zconfig, cfg_obj_t *vconfig,
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews isc_mem_t *mctx, dns_view_t *view,
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews ns_aclconfctx_t *aclconf);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsstatic void
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrewsend_reserved_dispatches(ns_server_t *server, isc_boolean_t all);
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews
f6407f9a0b890bebbfd5f738d9c4aef3d3315fe9Michael Graff/*
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews * Configure a single view ACL at '*aclp'. Get its configuration by
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews * calling 'getvcacl' (for per-view configuration) and maybe 'getscacl'
2002be4f65776451676df6ee21a2e28f52bcad6dMark Andrews * (for a global default).
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews */
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsstatic isc_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsconfigure_view_acl(cfg_obj_t *vconfig, cfg_obj_t *config,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews const char *aclname, ns_aclconfctx_t *actx,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_mem_t *mctx, dns_acl_t **aclp)
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews{
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews isc_result_t result;
bed8e84810a80dad3d37870be927d1dfd015f480Mark Andrews cfg_obj_t *maps[3];
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews cfg_obj_t *aclobj = NULL;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews int i = 0;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews if (*aclp != NULL)
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews dns_acl_detach(aclp);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews if (vconfig != NULL)
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews maps[i++] = cfg_tuple_get(vconfig, "options");
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews if (config != NULL) {
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews cfg_obj_t *options = NULL;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews (void)cfg_map_get(config, "options", &options);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews if (options != NULL)
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews maps[i++] = options;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington }
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington maps[i] = NULL;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews result = ns_config_get(maps, aclname, &aclobj);
613991eef6bb79b9703382aff26cddd0281da915Bob Halley if (aclobj == NULL)
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews /*
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews * No value available. *aclp == NULL.
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington */
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington return (ISC_R_SUCCESS);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington result = ns_acl_fromconfig(aclobj, config, actx, mctx, aclp);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington return (result);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington}
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellingtonstatic isc_result_t
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellingtonconfigure_view_dnsseckey(cfg_obj_t *vconfig, cfg_obj_t *key,
87ecd67dae468cf5c9bae213c6fa321449b2ebc2Andreas Gustafsson dns_keytable_t *keytable, isc_mem_t *mctx)
87ecd67dae468cf5c9bae213c6fa321449b2ebc2Andreas Gustafsson{
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews dns_rdataclass_t viewclass;
87ecd67dae468cf5c9bae213c6fa321449b2ebc2Andreas Gustafsson dns_rdata_dnskey_t keystruct;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews isc_uint32_t flags, proto, alg;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews char *keystr, *keynamestr;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews unsigned char keydata[4096];
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews isc_buffer_t keydatabuf;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews unsigned char rrdata[4096];
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews isc_buffer_t rrdatabuf;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson isc_region_t r;
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews dns_fixedname_t fkeyname;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews dns_name_t *keyname;
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews isc_buffer_t namebuf;
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews isc_result_t result;
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews dst_key_t *dstkey = NULL;
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews flags = cfg_obj_asuint32(cfg_tuple_get(key, "flags"));
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews proto = cfg_obj_asuint32(cfg_tuple_get(key, "protocol"));
bcd7fdf06ca76eb2f6eb157f56b612c503e062a7Mark Andrews alg = cfg_obj_asuint32(cfg_tuple_get(key, "algorithm"));
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews keyname = dns_fixedname_name(&fkeyname);
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews keynamestr = cfg_obj_asstring(cfg_tuple_get(key, "name"));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (vconfig == NULL)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson viewclass = dns_rdataclass_in;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson else {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson cfg_obj_t *classobj = cfg_tuple_get(vconfig, "class");
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(ns_config_getclass(classobj, dns_rdataclass_in,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson &viewclass));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keystruct.common.rdclass = viewclass;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keystruct.common.rdtype = dns_rdatatype_dnskey;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews /*
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff * The key data in keystruct is not dynamically allocated.
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews */
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence keystruct.mctx = NULL;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff ISC_LINK_INIT(&keystruct.common, link);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington if (flags > 0xffff)
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington CHECKM(ISC_R_RANGE, "key flags");
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff if (proto > 0xff)
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff CHECKM(ISC_R_RANGE, "key protocol");
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff if (alg > 0xff)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECKM(ISC_R_RANGE, "key algorithm");
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keystruct.flags = (isc_uint16_t)flags;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence keystruct.protocol = (isc_uint8_t)proto;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keystruct.algorithm = (isc_uint8_t)alg;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson isc_buffer_init(&keydatabuf, keydata, sizeof(keydata));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson isc_buffer_init(&rrdatabuf, rrdata, sizeof(rrdata));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keystr = cfg_obj_asstring(cfg_tuple_get(key, "key"));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(isc_base64_decodestring(keystr, &keydatabuf));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson isc_buffer_usedregion(&keydatabuf, &r);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keystruct.datalen = r.length;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keystruct.data = r.base;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(dns_rdata_fromstruct(NULL,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keystruct.common.rdclass,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keystruct.common.rdtype,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson &keystruct, &rrdatabuf));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson dns_fixedname_init(&fkeyname);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson isc_buffer_init(&namebuf, keynamestr, strlen(keynamestr));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson isc_buffer_add(&namebuf, strlen(keynamestr));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(dns_name_fromtext(keyname, &namebuf,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson dns_rootname, ISC_FALSE,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson NULL));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(dst_key_fromdns(keyname, viewclass, &rrdatabuf,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson mctx, &dstkey));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(dns_keytable_add(keytable, &dstkey));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(dstkey == NULL);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson return (ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson cleanup:
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (result == DST_R_NOCRYPTO) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson cfg_obj_log(key, ns_g_lctx, ISC_LOG_ERROR,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson "ignoring trusted key for '%s': no crypto support",
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson keynamestr);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = ISC_R_SUCCESS;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence } else {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson cfg_obj_log(key, ns_g_lctx, ISC_LOG_ERROR,
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews "configuring trusted key for '%s': %s",
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews keynamestr, isc_result_totext(result));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = ISC_R_FAILURE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (dstkey != NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dst_key_free(&dstkey);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * Configure DNSSEC keys for a view. Currently used only for
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * the security roots.
e6bd97dded968f82e26b270842b789bff7bca422Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * The per-view configuration values and the server-global defaults are read
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * from 'vconfig' and 'config'. The variable to be configured is '*target'.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t
29c818c7d40fc8898b062903ec703851328a4deaMark Andrewsconfigure_view_dnsseckeys(cfg_obj_t *vconfig, cfg_obj_t *config,
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews isc_mem_t *mctx, dns_keytable_t **target)
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews{
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews isc_result_t result;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews cfg_obj_t *keys = NULL;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews cfg_obj_t *voptions = NULL;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews cfg_listelt_t *element, *element2;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews cfg_obj_t *keylist;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews cfg_obj_t *key;
29c818c7d40fc8898b062903ec703851328a4deaMark Andrews dns_keytable_t *keytable = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CHECK(dns_keytable_create(mctx, &keytable));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (vconfig != NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews voptions = cfg_tuple_get(vconfig, "options");
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews keys = NULL;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (voptions != NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews (void)cfg_map_get(voptions, "trusted-keys", &keys);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (keys == NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews (void)cfg_map_get(config, "trusted-keys", &keys);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews for (element = cfg_list_first(keys);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews element != NULL;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley element = cfg_list_next(element))
d981ca645597116d227a48bf37cc5edc061c854dBob Halley {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews keylist = cfg_listelt_value(element);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews for (element2 = cfg_list_first(keylist);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews element2 != NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews element2 = cfg_list_next(element2))
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews key = cfg_listelt_value(element2);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews CHECK(configure_view_dnsseckey(vconfig, key,
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews keytable, mctx));
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews }
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews }
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews dns_keytable_detach(target);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews *target = keytable; /* Transfer ownership. */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews keytable = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = ISC_R_SUCCESS;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cleanup:
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsmustbesecure(cfg_obj_t *mbs, dns_resolver_t *resolver)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley{
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews cfg_listelt_t *element;
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews cfg_obj_t *obj;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence const char *str;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews dns_fixedname_t fixed;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews dns_name_t *name;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews isc_boolean_t value;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_result_t result;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t b;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_fixedname_init(&fixed);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews name = dns_fixedname_name(&fixed);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews for (element = cfg_list_first(mbs);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews element != NULL;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence element = cfg_list_next(element))
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews {
19d365e4448f1782611280b020987988b7ac3210Mark Andrews obj = cfg_listelt_value(element);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews str = cfg_obj_asstring(cfg_tuple_get(obj, "name"));
19d365e4448f1782611280b020987988b7ac3210Mark Andrews isc_buffer_init(&b, str, strlen(str));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(&b, strlen(str));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CHECK(dns_name_fromtext(name, &b, dns_rootname,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_FALSE, NULL));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews value = cfg_obj_asboolean(cfg_tuple_get(obj, "value"));
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff CHECK(dns_resolver_setmustbesecure(resolver, name, value));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley }
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews result = ISC_R_SUCCESS;
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews cleanup:
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews * Get a dispatch appropriate for the resolver of a given view.
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t
19d365e4448f1782611280b020987988b7ac3210Mark Andrewsget_view_querysource_dispatch(cfg_obj_t **maps,
19d365e4448f1782611280b020987988b7ac3210Mark Andrews int af, dns_dispatch_t **dispatchp)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews{
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_result_t result;
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews dns_dispatch_t *disp;
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff isc_sockaddr_t sa;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int attrs, attrmask;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews cfg_obj_t *obj = NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews /*
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Make compiler happy.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = ISC_R_FAILURE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews switch (af) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews case AF_INET:
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = ns_config_get(maps, "query-source", &obj);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews INSIST(result == ISC_R_SUCCESS);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews break;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews case AF_INET6:
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = ns_config_get(maps, "query-source-v6", &obj);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(result == ISC_R_SUCCESS);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence break;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence default:
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence INSIST(0);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff }
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews sa = *(cfg_obj_assockaddr(obj));
ad7209ea70d346527ffdcda335153831341d9dcfAndreas Gustafsson INSIST(isc_sockaddr_pf(&sa) == af);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
d981ca645597116d227a48bf37cc5edc061c854dBob Halley /*
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * If we don't support this address family, we're done!
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff switch (af) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews case AF_INET:
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = isc_net_probeipv4();
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews break;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews case AF_INET6:
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = isc_net_probeipv6();
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews break;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff default:
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(0);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews }
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews if (result != ISC_R_SUCCESS)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley /*
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews * Try to find a dispatcher that we can share.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
19d365e4448f1782611280b020987988b7ac3210Mark Andrews attrs = 0;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence attrs |= DNS_DISPATCHATTR_UDP;
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson switch (af) {
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson case AF_INET:
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson attrs |= DNS_DISPATCHATTR_IPV4;
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson break;
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson case AF_INET6:
693ddf84daa745a0ea8ca311a8154dfa03eabc43Andreas Gustafsson attrs |= DNS_DISPATCHATTR_IPV6;
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews break;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews attrmask = 0;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence attrmask |= DNS_DISPATCHATTR_UDP;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews attrmask |= DNS_DISPATCHATTR_TCP;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence attrmask |= DNS_DISPATCHATTR_IPV4;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence attrmask |= DNS_DISPATCHATTR_IPV6;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley disp = NULL;
f0a5bb8f86631ce638cb2b6c65bbb9bcf9b0cdc0Bob Halley result = dns_dispatch_getudp(ns_g_dispatchmgr, ns_g_socketmgr,
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff ns_g_taskmgr, &sa, 4096,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews 1000, 32768, 16411, 16433,
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff attrs, attrmask, &disp);
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews if (result != ISC_R_SUCCESS) {
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence isc_sockaddr_t any;
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence char buf[ISC_SOCKADDR_FORMATSIZE];
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews switch (af) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews case AF_INET:
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_sockaddr_any(&any);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews break;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews case AF_INET6:
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_sockaddr_any6(&any);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews break;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews }
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (isc_sockaddr_equal(&sa, &any))
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews return (ISC_R_SUCCESS);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_sockaddr_format(&sa, buf, sizeof(buf));
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews "could not get query source dispatcher (%s)",
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews buf);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews return (result);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews }
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews *dispatchp = disp;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews return (ISC_R_SUCCESS);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews}
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrewsstatic isc_result_t
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrewsconfigure_order(dns_order_t *order, cfg_obj_t *ent) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_rdataclass_t rdclass;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_rdatatype_t rdtype;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews cfg_obj_t *obj;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_fixedname_t fixed;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews unsigned int mode = 0;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews const char *str;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_buffer_t b;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_result_t result;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = ns_config_getclass(cfg_tuple_get(ent, "class"),
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_rdataclass_any, &rdclass);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (result != ISC_R_SUCCESS)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews return (result);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = ns_config_gettype(cfg_tuple_get(ent, "type"),
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_rdatatype_any, &rdtype);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (result != ISC_R_SUCCESS)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews return (result);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews obj = cfg_tuple_get(ent, "name");
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (cfg_obj_isstring(obj))
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews str = cfg_obj_asstring(obj);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews else
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews str = "*";
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_buffer_init(&b, str, strlen(str));
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_buffer_add(&b, strlen(str));
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_fixedname_init(&fixed);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = dns_name_fromtext(dns_fixedname_name(&fixed), &b,
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_rootname, ISC_FALSE, NULL);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (result != ISC_R_SUCCESS)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews return (result);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews obj = cfg_tuple_get(ent, "ordering");
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews INSIST(cfg_obj_isstring(obj));
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews str = cfg_obj_asstring(obj);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (!strcasecmp(str, "fixed"))
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews mode = DNS_RDATASETATTR_FIXEDORDER;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews else if (!strcasecmp(str, "random"))
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews mode = DNS_RDATASETATTR_RANDOMIZE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews else if (!strcasecmp(str, "cyclic"))
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews mode = 0;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews else
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews INSIST(0);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews return (dns_order_add(order, dns_fixedname_name(&fixed),
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews rdtype, rdclass, mode));
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews}
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrewsstatic isc_result_t
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrewsconfigure_peer(cfg_obj_t *cpeer, isc_mem_t *mctx, dns_peer_t **peerp) {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_sockaddr_t *sa;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_netaddr_t na;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_peer_t *peer;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews cfg_obj_t *obj;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews char *str;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_result_t result;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews sa = cfg_obj_assockaddr(cfg_map_getname(cpeer));
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_netaddr_fromsockaddr(&na, sa);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews peer = NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews result = dns_peer_new(mctx, &na, &peer);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (result != ISC_R_SUCCESS)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews return (result);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews obj = NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews (void)cfg_map_get(cpeer, "bogus", &obj);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (obj != NULL)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews CHECK(dns_peer_setbogus(peer, cfg_obj_asboolean(obj)));
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews obj = NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews (void)cfg_map_get(cpeer, "provide-ixfr", &obj);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (obj != NULL)
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff CHECK(dns_peer_setprovideixfr(peer, cfg_obj_asboolean(obj)));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews obj = NULL;
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews (void)cfg_map_get(cpeer, "request-ixfr", &obj);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews if (obj != NULL)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews CHECK(dns_peer_setrequestixfr(peer, cfg_obj_asboolean(obj)));
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews obj = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews (void)cfg_map_get(cpeer, "edns", &obj);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (obj != NULL)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews CHECK(dns_peer_setsupportedns(peer, cfg_obj_asboolean(obj)));
f305d86668bfd4d4727c3e0f70e7e97a2fa1b772Bob Halley
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson obj = NULL;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews (void)cfg_map_get(cpeer, "transfers", &obj);
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence if (obj != NULL)
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence CHECK(dns_peer_settransfers(peer, cfg_obj_asuint32(obj)));
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews obj = NULL;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence (void)cfg_map_get(cpeer, "transfer-format", &obj);
19d365e4448f1782611280b020987988b7ac3210Mark Andrews if (obj != NULL) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews str = cfg_obj_asstring(obj);
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff if (strcasecmp(str, "many-answers") == 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CHECK(dns_peer_settransferformat(peer,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_many_answers));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews else if (strcasecmp(str, "one-answer") == 0)
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews CHECK(dns_peer_settransferformat(peer,
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_one_answer));
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews else
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews INSIST(0);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews }
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews obj = NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews (void)cfg_map_get(cpeer, "keys", &obj);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (obj != NULL) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews result = dns_peer_setkeybycharp(peer, cfg_obj_asstring(obj));
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (result != ISC_R_SUCCESS)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews goto cleanup;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews }
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews obj = NULL;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (isc_sockaddr_pf(sa) == AF_INET)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews (void)cfg_map_get(cpeer, "transfer-source", &obj);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews else
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews (void)cfg_map_get(cpeer, "transfer-source-v6", &obj);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (obj != NULL) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews result = dns_peer_settransfersource(peer,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews cfg_obj_assockaddr(obj));
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (result != ISC_R_SUCCESS)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews goto cleanup;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews }
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews *peerp = peer;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews return (ISC_R_SUCCESS);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews cleanup:
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews dns_peer_detach(&peer);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (result);
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews}
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graffstatic isc_result_t
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrewsdisable_algorithms(cfg_obj_t *disabled, dns_resolver_t *resolver) {
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews isc_result_t result;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews cfg_obj_t *algorithms;
c0d0a59d1b665423b8a0d1829d0f0da121cb3473Andreas Gustafsson cfg_listelt_t *element;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews const char *str;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff dns_fixedname_t fixed;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews dns_name_t *name;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews isc_buffer_t b;
fdd04623a6a36aad8449ef0877d8801a558873b8Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_fixedname_init(&fixed);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews name = dns_fixedname_name(&fixed);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews str = cfg_obj_asstring(cfg_tuple_get(disabled, "name"));
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_buffer_init(&b, str, strlen(str));
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_buffer_add(&b, strlen(str));
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews CHECK(dns_name_fromtext(name, &b, dns_rootname, ISC_FALSE, NULL));
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews algorithms = cfg_tuple_get(disabled, "algorithms");
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews for (element = cfg_list_first(algorithms);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews element != NULL;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews element = cfg_list_next(element))
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews isc_textregion_t r;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff dns_secalg_t alg;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews r.base = cfg_obj_asstring(cfg_listelt_value(element));
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews r.length = strlen(r.base);
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews result = dns_secalg_fromtext(&alg, &r);
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews if (result != ISC_R_SUCCESS) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_uint8_t ui;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews result = isc_parse_uint8(&ui, r.base, 10);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews alg = ui;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_log(cfg_listelt_value(element),
d981ca645597116d227a48bf37cc5edc061c854dBob Halley ns_g_lctx, ISC_LOG_ERROR,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "invalid algorithm");
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff CHECK(result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CHECK(dns_resolver_disable_algorithm(resolver, name, alg));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cleanup:
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (result);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff}
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley/*
19d365e4448f1782611280b020987988b7ac3210Mark Andrews * Configure 'view' according to 'vconfig', taking defaults from 'config'
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * where values are missing in 'vconfig'.
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews *
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews * When configuring the default view, 'vconfig' will be NULL and the
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews * global defaults in 'config' used exclusively.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence */
19d365e4448f1782611280b020987988b7ac3210Mark Andrewsstatic isc_result_t
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrenceconfigure_view(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig,
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_mem_t *mctx, ns_aclconfctx_t *actx,
19d365e4448f1782611280b020987988b7ac3210Mark Andrews isc_boolean_t need_hints)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence{
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence cfg_obj_t *maps[4];
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence cfg_obj_t *cfgmaps[3];
f8aae502686e2448c48f56697c212a50e2a1cbaeAndreas Gustafsson cfg_obj_t *options = NULL;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff cfg_obj_t *voptions = NULL;
f8aae502686e2448c48f56697c212a50e2a1cbaeAndreas Gustafsson cfg_obj_t *forwardtype;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_t *forwarders;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_t *alternates;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews cfg_obj_t *zonelist;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews cfg_obj_t *disabled;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews cfg_obj_t *obj;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews cfg_listelt_t *element;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews in_port_t port;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_cache_t *cache = NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_result_t result;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_uint32_t max_adb_size;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_uint32_t max_cache_size;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_uint32_t lame_ttl;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_tsig_keyring_t *ring;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_view_t *pview = NULL; /* Production view */
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_mem_t *cmctx;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_dispatch_t *dispatch4 = NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_dispatch_t *dispatch6 = NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_boolean_t reused_cache = ISC_FALSE;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews int i;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews const char *str;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews dns_order_t *order = NULL;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_uint32_t udpsize;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned int check = 0;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(DNS_VIEW_VALID(view));
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence cmctx = NULL;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (config != NULL)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence (void)cfg_map_get(config, "options", &options);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson i = 0;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson if (vconfig != NULL) {
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson voptions = cfg_tuple_get(vconfig, "options");
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson maps[i++] = voptions;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson }
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley if (options != NULL)
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson maps[i++] = options;
7ab0e69f61e61e81d489c95c7ebd981e74e7ef16Andreas Gustafsson maps[i++] = ns_g_defaults;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff maps[i] = NULL;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson i = 0;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson if (voptions != NULL)
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson cfgmaps[i++] = voptions;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (config != NULL)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence cfgmaps[i++] = config;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence cfgmaps[i] = NULL;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson /*
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * Set the view's port number for outgoing queries.
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson */
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson CHECKM(ns_config_getport(config, &port), "port");
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson dns_view_setdstport(view, port);
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson /*
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson * Configure the zones.
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson */
ae70d32b67cf30e06553c01479e71c87b21d984cBob Halley zonelist = NULL;
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson if (voptions != NULL)
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson (void)cfg_map_get(voptions, "zone", &zonelist);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff else
d981ca645597116d227a48bf37cc5edc061c854dBob Halley (void)cfg_map_get(config, "zone", &zonelist);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews for (element = cfg_list_first(zonelist);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews element != NULL;
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews element = cfg_list_next(element))
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_t *zconfig = cfg_listelt_value(element);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CHECK(configure_zone(config, zconfig, vconfig, mctx, view,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews actx));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
19d365e4448f1782611280b020987988b7ac3210Mark Andrews
19d365e4448f1782611280b020987988b7ac3210Mark Andrews /*
0c310d16b05ee94743d33f6920907edee6084fc8Michael Graff * Configure the view's cache. Try to reuse an existing
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * cache if possible, otherwise create a new cache.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Note that the ADB is not preserved in either case.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * XXX Determining when it is safe to reuse a cache is
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews * tricky. When the view's configuration changes, the cached
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews * data may become invalid because it reflects our old
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * view of the world. As more view attributes become
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * configurable, we will have to add code here to check
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * whether they have changed in ways that could
d981ca645597116d227a48bf37cc5edc061c854dBob Halley * invalidate the cache.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = dns_viewlist_find(&ns_g_server->viewlist,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews view->name, view->rdclass,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews &pview);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews goto cleanup;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff if (pview != NULL) {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews INSIST(pview->cache != NULL);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews NS_LOGMODULE_SERVER, ISC_LOG_DEBUG(3),
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "reusing existing cache");
19d365e4448f1782611280b020987988b7ac3210Mark Andrews reused_cache = ISC_TRUE;
19d365e4448f1782611280b020987988b7ac3210Mark Andrews dns_cache_attach(pview->cache, &cache);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_view_detach(&pview);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews CHECK(isc_mem_create(0, 0, &cmctx));
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews CHECK(dns_cache_create(cmctx, ns_g_taskmgr, ns_g_timermgr,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews view->rdclass, "rbt", 0, NULL, &cache));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_view_setcache(view, cache);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews /*
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews * cache-file cannot be inherited if views are present, but this
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews * should be caught by the configuration checking stage.
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews */
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews obj = NULL;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews result = ns_config_get(maps, "cache-file", &obj);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews if (result == ISC_R_SUCCESS && strcmp(view->name, "_bind") != 0) {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews CHECK(dns_cache_setfilename(cache, cfg_obj_asstring(obj)));
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff if (!reused_cache)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley CHECK(dns_cache_load(cache));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley }
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff obj = NULL;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = ns_config_get(maps, "cleaning-interval", &obj);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley INSIST(result == ISC_R_SUCCESS);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_cache_setcleaninginterval(cache, cfg_obj_asuint32(obj) * 60);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley obj = NULL;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = ns_config_get(maps, "max-cache-size", &obj);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley INSIST(result == ISC_R_SUCCESS);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (cfg_obj_isstring(obj)) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley str = cfg_obj_asstring(obj);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley INSIST(strcasecmp(str, "unlimited") == 0);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley max_cache_size = ISC_UINT32_MAX;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley } else {
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews isc_resourcevalue_t value;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley value = cfg_obj_asuint64(obj);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews if (value > ISC_UINT32_MAX) {
d981ca645597116d227a48bf37cc5edc061c854dBob Halley cfg_obj_log(obj, ns_g_lctx, ISC_LOG_ERROR,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley "'max-cache-size "
d981ca645597116d227a48bf37cc5edc061c854dBob Halley "%" ISC_PRINT_QUADFORMAT "d' is too large",
d981ca645597116d227a48bf37cc5edc061c854dBob Halley value);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff result = ISC_R_RANGE;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley goto cleanup;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff }
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley max_cache_size = (isc_uint32_t)value;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews }
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley dns_cache_setcachesize(cache, max_cache_size);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley dns_cache_detach(&cache);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley /*
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley * Check-names.
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley */
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley obj = NULL;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley str = "";
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley result = ns_config_get(maps, "check-names", &obj);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews INSIST(result == ISC_R_SUCCESS);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews for (element = cfg_list_first(obj);
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews element != NULL;
9916239908343b3eb17f0578de4c3cd6a313d85fMark Andrews element = cfg_list_next(element)) {
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley cfg_obj_t *value, *type;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley value = cfg_listelt_value(element);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley type = cfg_tuple_get(value, "type");
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley if (strcasecmp(cfg_obj_asstring(type), "response") == 0) {
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff str = cfg_obj_asstring(cfg_tuple_get(value, "mode"));
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff break;
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff }
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff }
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff if (strcasecmp(str, "fail") == 0) {
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff check = DNS_RESOLVER_CHECKNAMES |
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff DNS_RESOLVER_CHECKNAMESFAIL;
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff view->checknames = ISC_TRUE;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence } else if (strcasecmp(str, "warn") == 0) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson check = DNS_RESOLVER_CHECKNAMES;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff view->checknames = ISC_FALSE;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson } else if (strcasecmp(str, "ignore") == 0) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson check = 0;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson view->checknames = ISC_FALSE;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson } else
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(0);
88ba491496daf4463a2c898be8a6c47775a6d048Mark Andrews
88ba491496daf4463a2c898be8a6c47775a6d048Mark Andrews /*
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * Resolver.
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson *
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * XXXRTH Hardwired number of tasks.
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(get_view_querysource_dispatch(maps, AF_INET, &dispatch4));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(get_view_querysource_dispatch(maps, AF_INET6, &dispatch6));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (dispatch4 == NULL && dispatch6 == NULL) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson UNEXPECTED_ERROR(__FILE__, __LINE__,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson "unable to obtain neither an IPv4 nor"
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson " an IPv6 dispatch");
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence result = ISC_R_UNEXPECTED;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson goto cleanup;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(dns_view_createresolver(view, ns_g_taskmgr, 31,
34b394b43e2207e8f8f3703f0402422121455638David Lawrence ns_g_socketmgr, ns_g_timermgr,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson check, ns_g_dispatchmgr,
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff dispatch4, dispatch6));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Set the ADB cache size to 1/8th of the max-cache-size.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson max_adb_size = 0;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (max_cache_size != 0) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson max_adb_size = max_cache_size / 8;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (max_adb_size == 0)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson max_adb_size = 1; /* Force minimum. */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson dns_adb_setadbsize(view->adb, max_adb_size);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff /*
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * Set resolver's lame-ttl.
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson obj = NULL;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = ns_config_get(maps, "lame-ttl", &obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(result == ISC_R_SUCCESS);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff lame_ttl = cfg_obj_asuint32(obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (lame_ttl > 1800)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson lame_ttl = 1800;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson dns_resolver_setlamettl(view->resolver, lame_ttl);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson /*
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * Set the resolver's EDNS UDP size.
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson obj = NULL;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = ns_config_get(maps, "edns-udp-size", &obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(result == ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson udpsize = cfg_obj_asuint32(obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (udpsize < 512)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson udpsize = 512;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (udpsize > 4096)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson udpsize = 4096;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff dns_resolver_setudpsize(view->resolver, (isc_uint16_t)udpsize);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff /*
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * Set supported DNSSEC algorithms.
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff dns_resolver_reset_algorithms(view->resolver);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence disabled = NULL;
16996a04884731d647f43a5eb54f678581f09f68David Lawrence (void)ns_config_get(maps, "disable-algorithms", &disabled);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews if (disabled != NULL) {
16996a04884731d647f43a5eb54f678581f09f68David Lawrence for (element = cfg_list_first(disabled);
16996a04884731d647f43a5eb54f678581f09f68David Lawrence element != NULL;
16996a04884731d647f43a5eb54f678581f09f68David Lawrence element = cfg_list_next(element))
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence CHECK(disable_algorithms(cfg_listelt_value(element),
ed019cabc1cc75d4412010c331876e4ae5080a4dDavid Lawrence view->resolver));
16996a04884731d647f43a5eb54f678581f09f68David Lawrence }
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence /*
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence * A global or view "forwarders" option, if present,
600cfa2ba4c50017581b6c14e3a688a82ecebbe0David Lawrence * creates an entry for "." in the forwarding table.
16996a04884731d647f43a5eb54f678581f09f68David Lawrence */
16996a04884731d647f43a5eb54f678581f09f68David Lawrence forwardtype = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff forwarders = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff (void)ns_config_get(maps, "forward", &forwardtype);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff (void)ns_config_get(maps, "forwarders", &forwarders);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff if (forwarders != NULL)
fc024be774c7cdee938da018aa3994be746e36deDavid Lawrence CHECK(configure_forward(config, view, dns_rootname,
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff forwarders, forwardtype));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff /*
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * Dual Stack Servers.
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson */
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson alternates = NULL;
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson (void)ns_config_get(maps, "dual-stack-servers", &alternates);
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson if (alternates != NULL)
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson CHECK(configure_alternates(config, view, alternates));
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff /*
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * We have default hints for class IN if we need them.
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff */
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff if (view->rdclass == dns_rdataclass_in && view->hints == NULL)
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff dns_view_sethints(view, ns_g_server->in_roothints);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff /*
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * If we still have no hints, this is a non-IN view with no
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * "hints zone" configured. Issue a warning, except if this
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * is a root server. Root servers never need to consult
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * their hints, so it's no point requiring users to configure
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * them.
16996a04884731d647f43a5eb54f678581f09f68David Lawrence */
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff if (view->hints == NULL) {
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews dns_zone_t *rootzone = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff (void)dns_view_findzone(view, dns_rootname, &rootzone);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff if (rootzone != NULL) {
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff dns_zone_detach(&rootzone);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews need_hints = ISC_FALSE;
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews }
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews if (need_hints)
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
16996a04884731d647f43a5eb54f678581f09f68David Lawrence "no root hints for view '%s'",
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff view->name);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff }
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff /*
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * Configure the view's TSIG keys.
6b0ce7d29fac9df84ed34aa2d4634e754aec750dAndreas Gustafsson */
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff ring = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff CHECK(ns_tsigkeyring_fromconfig(config, vconfig, view->mctx, &ring));
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff dns_view_setkeyring(view, ring);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff /*
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff * Configure the view's peer list.
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff */
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff {
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff cfg_obj_t *peers = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff cfg_listelt_t *element;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff dns_peerlist_t *newpeers = NULL;
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews (void)ns_config_get(cfgmaps, "server", &peers);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff CHECK(dns_peerlist_new(mctx, &newpeers));
79eec6934923f97a61edb8dbe2641ce56dc30085Bob Halley for (element = cfg_list_first(peers);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff element != NULL;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence element = cfg_list_next(element))
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff {
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews cfg_obj_t *cpeer = cfg_listelt_value(element);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff dns_peer_t *peer;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff CHECK(configure_peer(cpeer, mctx, &peer));
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff dns_peerlist_addpeer(newpeers, peer);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff dns_peer_detach(&peer);
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff }
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff dns_peerlist_detach(&view->peers);
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence view->peers = newpeers; /* Transfer ownership. */
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence }
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff /*
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff * Configure the views rrset-order.
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff */
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff {
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff cfg_obj_t *rrsetorder = NULL;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff cfg_listelt_t *element;
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff
94a537e6ab3069f8d34e12e5ea722250be2b89c8Michael Graff (void)ns_config_get(maps, "rrset-order", &rrsetorder);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews CHECK(dns_order_create(mctx, &order));
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews for (element = cfg_list_first(rrsetorder);
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews element != NULL;
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews element = cfg_list_next(element))
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence cfg_obj_t *ent = cfg_listelt_value(element);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff CHECK(configure_order(order, ent));
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff }
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff if (view->order != NULL)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff dns_order_detach(&view->order);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff dns_order_attach(order, &view->order);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff dns_order_detach(&order);
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff }
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews /*
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews * Copy the aclenv object.
79eec6934923f97a61edb8dbe2641ce56dc30085Bob Halley */
79eec6934923f97a61edb8dbe2641ce56dc30085Bob Halley dns_aclenv_copy(&view->aclenv, &ns_g_server->aclenv);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews /*
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington * Configure the "match-clients" and "match-destinations" ACL.
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington */
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington CHECK(configure_view_acl(vconfig, config, "match-clients", actx,
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington ns_g_mctx, &view->matchclients));
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews CHECK(configure_view_acl(vconfig, config, "match-destinations", actx,
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews ns_g_mctx, &view->matchdestinations));
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews /*
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Configure the "match-recursive-only" option.
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews */
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews obj = NULL;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington (void) ns_config_get(maps, "match-recursive-only", &obj);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington if (obj != NULL && cfg_obj_asboolean(obj))
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington view->matchrecursiveonly = ISC_TRUE;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington else
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington view->matchrecursiveonly = ISC_FALSE;
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington /*
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington * Configure other configurable data.
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington */
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington obj = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence result = ns_config_get(maps, "recursion", &obj);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington INSIST(result == ISC_R_SUCCESS);
5d83b561ad7eb84885a8ec63dee4c51b335f067aBrian Wellington view->recursion = cfg_obj_asboolean(obj);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews obj = NULL;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = ns_config_get(maps, "auth-nxdomain", &obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(result == ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson view->auth_nxdomain = cfg_obj_asboolean(obj);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence obj = NULL;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews result = ns_config_get(maps, "minimal-responses", &obj);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff INSIST(result == ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson view->minimalresponses = cfg_obj_asboolean(obj);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews obj = NULL;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews result = ns_config_get(maps, "transfer-format", &obj);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff INSIST(result == ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson str = cfg_obj_asstring(obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (strcasecmp(str, "many-answers") == 0)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson view->transfer_format = dns_many_answers;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson else if (strcasecmp(str, "one-answer") == 0)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff view->transfer_format = dns_one_answer;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson else
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews INSIST(0);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson /*
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * Set sources where additional data and CNAME/DNAME
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews * targets for authoritative answers may be found.
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff obj = NULL;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = ns_config_get(maps, "additional-from-auth", &obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(result == ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson view->additionalfromauth = cfg_obj_asboolean(obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (view->recursion && ! view->additionalfromauth) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff cfg_obj_log(obj, ns_g_lctx, ISC_LOG_WARNING,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson "'additional-from-auth no' is only supported "
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews "with 'recursion no'");
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff view->additionalfromauth = ISC_TRUE;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews obj = NULL;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews result = ns_config_get(maps, "additional-from-cache", &obj);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff INSIST(result == ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson view->additionalfromcache = cfg_obj_asboolean(obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (view->recursion && ! view->additionalfromcache) {
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson cfg_obj_log(obj, ns_g_lctx, ISC_LOG_WARNING,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson "'additional-from-cache no' is only supported "
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson "with 'recursion no'");
88ba491496daf4463a2c898be8a6c47775a6d048Mark Andrews view->additionalfromcache = ISC_TRUE;
88ba491496daf4463a2c898be8a6c47775a6d048Mark Andrews }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(configure_view_acl(vconfig, config, "allow-query",
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson actx, ns_g_mctx, &view->queryacl));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (strcmp(view->name, "_bind") != 0)
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(configure_view_acl(vconfig, config, "allow-recursion",
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson actx, ns_g_mctx, &view->recursionacl));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson /*
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson * Warning if both "recursion no;" and allow-recursion are active
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * except for "allow-recursion { none; };".
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson */
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (!view->recursion && view->recursionacl != NULL &&
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson (view->recursionacl->length != 1 ||
34b394b43e2207e8f8f3703f0402422121455638David Lawrence view->recursionacl->elements[0].type != dns_aclelementtype_any ||
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson view->recursionacl->elements[0].negative != ISC_TRUE)) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff const char *forview = " for view ";
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson const char *viewname = view->name;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson if (!strcmp(view->name, "_bind") ||
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews !strcmp(view->name, "_default")) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence forview = "";
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson viewname = "";
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson "both \"recursion no;\" and \"allow-recursion\" "
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson "active%s%s", forview, viewname);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson }
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson CHECK(configure_view_acl(vconfig, config, "sortlist",
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson actx, ns_g_mctx, &view->sortlist));
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson obj = NULL;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = ns_config_get(maps, "request-ixfr", &obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(result == ISC_R_SUCCESS);
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews view->requestixfr = cfg_obj_asboolean(obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson obj = NULL;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = ns_config_get(maps, "provide-ixfr", &obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(result == ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson view->provideixfr = cfg_obj_asboolean(obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson obj = NULL;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence result = ns_config_get(maps, "dnssec-enable", &obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson INSIST(result == ISC_R_SUCCESS);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson view->enablednssec = cfg_obj_asboolean(obj);
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews obj = NULL;
3ddd92da6651bc72aa79a04195ad389d86fd1a66Andreas Gustafsson result = ns_config_get(maps, "dnssec-lookaside", &obj);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_SUCCESS) {
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews const char *dlv;
54c26ab21c61c6d6b1e484bb88dc3ac263845d17Mark Andrews isc_buffer_t b;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dlv = cfg_obj_asstring(obj);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_buffer_init(&b, dlv, strlen(dlv));
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_buffer_add(&b, strlen(dlv));
a98551ef592e9be6008e0141ceeb32efd586c5efMark Andrews CHECK(dns_name_fromtext(dns_fixedname_name(&view->dlv_fixed),
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews &b, dns_rootname, ISC_TRUE, NULL));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews view->dlv = dns_fixedname_name(&view->dlv_fixed);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews view->dlv = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff /*
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * For now, there is only one kind of trusted keys, the
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * "security roots".
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (view->enablednssec) {
fe47f41b13620bfafc4f8cf65d5df24f1e568764Bob Halley CHECK(configure_view_dnsseckeys(vconfig, config, mctx,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews &view->secroots));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_resolver_resetmustbesecure(view->resolver);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence obj = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = ns_config_get(maps, "dnssec-must-be-secure", &obj);
fe47f41b13620bfafc4f8cf65d5df24f1e568764Bob Halley if (result == ISC_R_SUCCESS)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CHECK(mustbesecure(obj, view->resolver));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews obj = NULL;
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews result = ns_config_get(maps, "max-cache-ttl", &obj);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(result == ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews view->maxcachettl = cfg_obj_asuint32(obj);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews obj = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = ns_config_get(maps, "max-ncache-ttl", &obj);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews INSIST(result == ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews view->maxncachettl = cfg_obj_asuint32(obj);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (view->maxncachettl > 7 * 24 * 3600)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff view->maxncachettl = 7 * 24 * 3600;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews obj = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = ns_config_get(maps, "preferred-glue", &obj);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result == ISC_R_SUCCESS) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews str = cfg_obj_asstring(obj);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (strcasecmp(str, "a") == 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews view->preferred_glue = dns_rdatatype_a;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff else if (strcasecmp(str, "aaaa") == 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews view->preferred_glue = dns_rdatatype_aaaa;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews else
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews view->preferred_glue = 0;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff view->preferred_glue = 0;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews obj = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = ns_config_get(maps, "root-delegation-only", &obj);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (result == ISC_R_SUCCESS) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff dns_view_setrootdelonly(view, ISC_TRUE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (!cfg_obj_isvoid(obj)) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_fixedname_t fixed;
fe47f41b13620bfafc4f8cf65d5df24f1e568764Bob Halley dns_name_t *name;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t b;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff char *str;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_t *exclude;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff dns_fixedname_init(&fixed);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews name = dns_fixedname_name(&fixed);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews for (element = cfg_list_first(obj);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews element != NULL;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews element = cfg_list_next(element)) {
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews exclude = cfg_listelt_value(element);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews str = cfg_obj_asstring(exclude);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews isc_buffer_init(&b, str, strlen(str));
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews isc_buffer_add(&b, strlen(str));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CHECK(dns_name_fromtext(name, &b, dns_rootname,
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence ISC_FALSE, NULL));
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews CHECK(dns_view_excludedelegationonly(view,
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews name));
f0ff273b530afa730025e1c5ad311950f7ff4328Mark Andrews }
f0ff273b530afa730025e1c5ad311950f7ff4328Mark Andrews }
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews } else
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews dns_view_setrootdelonly(view, ISC_FALSE);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence result = ISC_R_SUCCESS;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence cleanup:
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (dispatch4 != NULL)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews dns_dispatch_detach(&dispatch4);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (dispatch6 != NULL)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_dispatch_detach(&dispatch6);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (order != NULL)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews dns_order_detach(&order);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (cmctx != NULL)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews isc_mem_detach(&cmctx);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence if (cache != NULL)
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews dns_cache_detach(&cache);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews return (result);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews}
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrewsstatic isc_result_t
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrewsconfigure_hints(dns_view_t *view, const char *filename) {
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews isc_result_t result;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews dns_db_t *db;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews db = NULL;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews result = dns_rootns_create(view->mctx, view->rdclass, filename, &db);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews if (result == ISC_R_SUCCESS) {
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews dns_view_sethints(view, db);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews dns_db_detach(&db);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews }
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews return (result);
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews}
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrewsstatic isc_result_t
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrewsconfigure_alternates(cfg_obj_t *config, dns_view_t *view,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence cfg_obj_t *alternates)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff{
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews cfg_obj_t *portobj;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews cfg_obj_t *addresses;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews cfg_listelt_t *element;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews isc_result_t result = ISC_R_SUCCESS;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews in_port_t port;
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews
7d62ddffbb4d1cc97b8d80b7ee4944554a57523eMark Andrews /*
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * Determine which port to send requests to.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (ns_g_lwresdonly && ns_g_port != 0)
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff port = ns_g_port;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews else
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CHECKM(ns_config_getport(config, &port), "port");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (alternates != NULL) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews portobj = cfg_tuple_get(alternates, "port");
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence if (cfg_obj_isuint32(portobj)) {
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_uint32_t val = cfg_obj_asuint32(portobj);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (val > ISC_UINT16_MAX) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "port '%u' out of range", val);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_RANGE);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence port = (in_port_t) val;
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews addresses = NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (alternates != NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews addresses = cfg_tuple_get(alternates, "addresses");
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews for (element = cfg_list_first(addresses);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews element != NULL;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews element = cfg_list_next(element))
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_t *alternate = cfg_listelt_value(element);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_sockaddr_t sa;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (!cfg_obj_issockaddr(alternate)) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_fixedname_t fixed;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t *name;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews char *str = cfg_obj_asstring(cfg_tuple_get(alternate,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "name"));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t buffer;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews in_port_t myport = port;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_init(&buffer, str, strlen(str));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(&buffer, strlen(str));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dns_fixedname_init(&fixed);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews name = dns_fixedname_name(&fixed);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews CHECK(dns_name_fromtext(name, &buffer, dns_rootname,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_FALSE, NULL));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews portobj = cfg_tuple_get(alternates, "port");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (cfg_obj_isuint32(portobj)) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_uint32_t val = cfg_obj_asuint32(portobj);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (val > ISC_UINT16_MAX) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_log(portobj, ns_g_lctx,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_LOG_ERROR,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "port '%u' out of range",
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff val);
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence return (ISC_R_RANGE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews myport = (in_port_t) val;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence CHECK(dns_resolver_addalternate(view->resolver, NULL,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews name, myport));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews continue;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews sa = *cfg_obj_assockaddr(alternate);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (isc_sockaddr_getport(&sa) == 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_sockaddr_setport(&sa, port);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff CHECK(dns_resolver_addalternate(view->resolver, &sa,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews NULL, 0));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cleanup:
26b0f58b6c4d65bc8b131debf40b8c376c2978bfBob Halley return (result);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_result_t
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrenceconfigure_forward(cfg_obj_t *config, dns_view_t *view, dns_name_t *origin,
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence cfg_obj_t *forwarders, cfg_obj_t *forwardtype)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews{
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews cfg_obj_t *portobj;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_t *faddresses;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_listelt_t *element;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff dns_fwdpolicy_t fwdpolicy = dns_fwdpolicy_none;
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews isc_sockaddrlist_t addresses;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_sockaddr_t *sa;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_result_t result;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence in_port_t port;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff /*
e4653123ecc6cdbfc0b9eda6e98e44af3b1f9a08Mark Andrews * Determine which port to send forwarded requests to.
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (ns_g_lwresdonly && ns_g_port != 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews port = ns_g_port;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff else
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews CHECKM(ns_config_getport(config, &port), "port");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (forwarders != NULL) {
1c3191528684f3dd93ebb122298c2f8ebfc6d397Mark Andrews portobj = cfg_tuple_get(forwarders, "port");
34b394b43e2207e8f8f3703f0402422121455638David Lawrence if (cfg_obj_isuint32(portobj)) {
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_uint32_t val = cfg_obj_asuint32(portobj);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (val > ISC_UINT16_MAX) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence "port '%u' out of range", val);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_RANGE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews port = (in_port_t) val;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff }
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson }
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson faddresses = NULL;
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson if (forwarders != NULL)
34b394b43e2207e8f8f3703f0402422121455638David Lawrence faddresses = cfg_tuple_get(forwarders, "addresses");
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson ISC_LIST_INIT(addresses);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
7c0378745269fe49a05904935afc42b85528f53aDavid Lawrence for (element = cfg_list_first(faddresses);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff element != NULL;
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson element = cfg_list_next(element))
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson {
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson cfg_obj_t *forwarder = cfg_listelt_value(element);
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson sa = isc_mem_get(view->mctx, sizeof(isc_sockaddr_t));
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson if (sa == NULL) {
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson result = ISC_R_NOMEMORY;
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson goto cleanup;
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson }
5466ce3f279d9fa83ce826bcdc9482bc591152aeAndreas Gustafsson *sa = *cfg_obj_assockaddr(forwarder);
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews if (isc_sockaddr_getport(sa) == 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_sockaddr_setport(sa, port);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_LINK_INIT(sa, link);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence ISC_LIST_APPEND(addresses, sa, link);
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (ISC_LIST_EMPTY(addresses)) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (forwardtype != NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews cfg_obj_log(forwarders, ns_g_lctx, ISC_LOG_WARNING,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "no forwarders seen; disabling "
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "forwarding");
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews fwdpolicy = dns_fwdpolicy_none;
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews } else {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (forwardtype == NULL)
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence fwdpolicy = dns_fwdpolicy_first;
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews else {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews char *forwardstr = cfg_obj_asstring(forwardtype);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (strcasecmp(forwardstr, "first") == 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews fwdpolicy = dns_fwdpolicy_first;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews else if (strcasecmp(forwardstr, "only") == 0)
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson fwdpolicy = dns_fwdpolicy_only;
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson else
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence INSIST(0);
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson }
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson }
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson result = dns_fwdtable_add(view->fwdtable, origin, &addresses,
5a219d878f0bd786e86da2c9b92999260dda3f8dAndreas Gustafsson fwdpolicy);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff if (result != ISC_R_SUCCESS) {
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews char namebuf[DNS_NAME_FORMATSIZE];
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews dns_name_format(origin, namebuf, sizeof(namebuf));
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews cfg_obj_log(forwarders, ns_g_lctx, ISC_LOG_WARNING,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews "could not set up forwarding for domain '%s': %s",
0c8649cea98afc061dd2938fd315df53b8fc35caAndreas Gustafsson namebuf, isc_result_totext(result));
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews goto cleanup;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence }
2192b4497348ccab94ca6f3f779cec399c72a8efMark Andrews
2192b4497348ccab94ca6f3f779cec399c72a8efMark Andrews result = ISC_R_SUCCESS;
25870d4a37ab4bc8e675502b08335200167cc044Bob Halley
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews cleanup:
25870d4a37ab4bc8e675502b08335200167cc044Bob Halley
25870d4a37ab4bc8e675502b08335200167cc044Bob Halley while (!ISC_LIST_EMPTY(addresses)) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews sa = ISC_LIST_HEAD(addresses);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews ISC_LIST_UNLINK(addresses, sa, link);
035504dbd8ca5949e8380b860873b3385a4e61e5Mark Andrews isc_mem_put(view->mctx, sa, sizeof(isc_sockaddr_t));
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff }
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (result);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews}
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
c0d0a59d1b665423b8a0d1829d0f0da121cb3473Andreas Gustafsson/*
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews * Create a new view and add it to the list.
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff *
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews * If 'vconfig' is NULL, create the default view.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * The view created is attached to '*viewp'.
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff */
2192b4497348ccab94ca6f3f779cec399c72a8efMark Andrewsstatic isc_result_t
2192b4497348ccab94ca6f3f779cec399c72a8efMark Andrewscreate_view(cfg_obj_t *vconfig, dns_viewlist_t *viewlist, dns_view_t **viewp) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_result_t result;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews const char *viewname;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews dns_rdataclass_t viewclass;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews dns_view_t *view = NULL;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (vconfig != NULL) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff cfg_obj_t *classobj = NULL;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff viewname = cfg_obj_asstring(cfg_tuple_get(vconfig, "name"));
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews classobj = cfg_tuple_get(vconfig, "class");
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews result = ns_config_getclass(classobj, dns_rdataclass_in,
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff &viewclass);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews } else {
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews viewname = "_default";
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews viewclass = dns_rdataclass_in;
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence }
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews result = dns_viewlist_find(viewlist, viewname, viewclass, &view);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result == ISC_R_SUCCESS)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (ISC_R_EXISTS);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (result != ISC_R_NOTFOUND)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (result);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews INSIST(view == NULL);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews result = dns_view_create(ns_g_mctx, viewclass, viewname, &view);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (result != ISC_R_SUCCESS)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (result);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews ISC_LIST_APPEND(*viewlist, view, link);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews dns_view_attach(view, viewp);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (ISC_R_SUCCESS);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews}
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews/*
904294c0c952227f7778fd0ba2ccea08c097b872Mark Andrews * Configure or reconfigure a zone.
904294c0c952227f7778fd0ba2ccea08c097b872Mark Andrews */
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsstatic isc_result_t
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrewsconfigure_zone(cfg_obj_t *config, cfg_obj_t *zconfig, cfg_obj_t *vconfig,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_mem_t *mctx, dns_view_t *view,
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews ns_aclconfctx_t *aclconf)
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews{
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence dns_view_t *pview = NULL; /* Production view */
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence dns_zone_t *zone = NULL; /* New or reused zone */
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence dns_zone_t *dupzone = NULL;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence cfg_obj_t *options = NULL;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence cfg_obj_t *zoptions = NULL;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews cfg_obj_t *typeobj = NULL;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence cfg_obj_t *forwarders = NULL;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence cfg_obj_t *forwardtype = NULL;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews cfg_obj_t *only = NULL;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_result_t result;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_result_t tresult;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews isc_buffer_t buffer;
ffe74cc719aa0f10c38fbc1f2f3ea7db0960cb8fMark Andrews dns_fixedname_t fixorigin;
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews dns_name_t *origin;
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews const char *zname;
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews dns_rdataclass_t zclass;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence const char *ztypestr;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence options = NULL;
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence (void)cfg_map_get(config, "options", &options);
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence zoptions = cfg_tuple_get(zconfig, "options");
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews /*
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews * Get the zone origin as a dns_name_t.
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews */
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews zname = cfg_obj_asstring(cfg_tuple_get(zconfig, "name"));
8a17d1e7cdba9fdcf71fb2f821a954a251204105Mark Andrews isc_buffer_init(&buffer, zname, strlen(zname));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_buffer_add(&buffer, strlen(zname));
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence dns_fixedname_init(&fixorigin);
47b26abe77184f9bedc68e36bdad03332cf67570David Lawrence CHECK(dns_name_fromtext(dns_fixedname_name(&fixorigin),
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews &buffer, dns_rootname, ISC_FALSE, NULL));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews origin = dns_fixedname_name(&fixorigin);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews CHECK(ns_config_getclass(cfg_tuple_get(zconfig, "class"),
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews view->rdclass, &zclass));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (zclass != view->rdclass) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews const char *vname = NULL;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (vconfig != NULL)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews vname = cfg_obj_asstring(cfg_tuple_get(vconfig,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews "name"));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews else
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews vname = "<default view>";
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews "zone '%s': wrong class for view '%s'",
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews zname, vname);
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews result = ISC_R_FAILURE;
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews goto cleanup;
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews }
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews (void)cfg_map_get(zoptions, "type", &typeobj);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (typeobj == NULL) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews cfg_obj_log(zconfig, ns_g_lctx, ISC_LOG_ERROR,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews "zone '%s' 'type' not specified", zname);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return (ISC_R_FAILURE);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews ztypestr = cfg_obj_asstring(typeobj);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * "hints zones" aren't zones. If we've got one,
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff * configure it and return.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff if (strcasecmp(ztypestr, "hint") == 0) {
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff cfg_obj_t *fileobj = NULL;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (cfg_map_get(zoptions, "file", &fileobj) != ISC_R_SUCCESS) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "zone '%s': 'file' not specified",
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews zname);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff result = ISC_R_FAILURE;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews goto cleanup;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (dns_name_equal(origin, dns_rootname)) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews char *hintsfile = cfg_obj_asstring(fileobj);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews result = configure_hints(view, hintsfile);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (result != ISC_R_SUCCESS) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews NS_LOGMODULE_SERVER,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews ISC_LOG_ERROR,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews "could not configure root hints "
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews "from '%s': %s", hintsfile,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_result_totext(result));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews goto cleanup;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Hint zones may also refer to delegation only points.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews only = NULL;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews tresult = cfg_map_get(zoptions, "delegation-only",
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews &only);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (tresult == ISC_R_SUCCESS && cfg_obj_asboolean(only))
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews CHECK(dns_view_adddelegationonly(view, origin));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews } else {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews "ignoring non-root hint zone '%s'",
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews zname);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews result = ISC_R_SUCCESS;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /* Skip ordinary zone processing. */
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff goto cleanup;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * "forward zones" aren't zones either. Translate this syntax into
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * the appropriate selective forwarding configuration and return.
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (strcasecmp(ztypestr, "forward") == 0) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews forwardtype = NULL;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews forwarders = NULL;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews (void)cfg_map_get(zoptions, "forward", &forwardtype);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews (void)cfg_map_get(zoptions, "forwarders", &forwarders);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews result = configure_forward(config, view, origin, forwarders,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews forwardtype);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews goto cleanup;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * "delegation-only zones" aren't zones either.
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (strcasecmp(ztypestr, "delegation-only") == 0) {
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff result = dns_view_adddelegationonly(view, origin);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews goto cleanup;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Check for duplicates in the new zone table.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence result = dns_view_findzone(view, origin, &dupzone);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (result == ISC_R_SUCCESS) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * We already have this zone!
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence cfg_obj_log(zconfig, ns_g_lctx, ISC_LOG_ERROR,
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence "zone '%s' already exists", zname);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_zone_detach(&dupzone);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence result = ISC_R_EXISTS;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence goto cleanup;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews INSIST(dupzone == NULL);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
df8c9ee4819c97089664ccc035eb2aa7569034fdDavid Lawrence * See if we can reuse an existing zone. This is
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * only possible if all of these are true:
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * - The zone's view exists
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * - A zone with the right name exists in the view
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * - The zone is compatible with the config
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * options (e.g., an existing master zone cannot
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * be reused if the options specify a slave zone)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews result = dns_viewlist_find(&ns_g_server->viewlist,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews view->name, view->rdclass,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews &pview);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews goto cleanup;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (pview != NULL)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews result = dns_view_findzone(pview, origin, &zone);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews goto cleanup;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (zone != NULL) {
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (! ns_zone_reusable(zone, zconfig))
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence dns_zone_detach(&zone);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (zone != NULL) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * We found a reusable zone. Make it use the
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * new view.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews dns_zone_setview(zone, view);
df8c9ee4819c97089664ccc035eb2aa7569034fdDavid Lawrence } else {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * We cannot reuse an existing zone, we have
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * to create a new one.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence CHECK(dns_zone_create(&zone, mctx));
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence CHECK(dns_zone_setorigin(zone, origin));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews dns_zone_setview(zone, view);
df8c9ee4819c97089664ccc035eb2aa7569034fdDavid Lawrence CHECK(dns_zonemgr_managezone(ns_g_server->zonemgr, zone));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * If the zone contains a 'forwarders' statement, configure
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * selective forwarding.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews forwarders = NULL;
df8c9ee4819c97089664ccc035eb2aa7569034fdDavid Lawrence if (cfg_map_get(zoptions, "forwarders", &forwarders) == ISC_R_SUCCESS)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews forwardtype = NULL;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews (void)cfg_map_get(zoptions, "forward", &forwardtype);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews CHECK(configure_forward(config, view, origin, forwarders,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews forwardtype));
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence * Stub and forward zones may also refer to delegation only points.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence only = NULL;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (cfg_map_get(zoptions, "delegation-only", &only) == ISC_R_SUCCESS)
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (cfg_obj_asboolean(only))
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews CHECK(dns_view_adddelegationonly(view, origin));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Configure the zone.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews CHECK(ns_zone_configure(config, vconfig, zconfig, aclconf, zone));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Add the zone to its view in the new view list.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews CHECK(dns_view_addzone(view, zone));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews cleanup:
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (zone != NULL)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews dns_zone_detach(&zone);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (pview != NULL)
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews dns_view_detach(&pview);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (result);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews}
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews/*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Configure a single server quota.
15330e4fa27c82ac04cc2ce234ec930e4b6b42d3Mark Andrews */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrencestatic void
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrenceconfigure_server_quota(cfg_obj_t **maps, const char *name, isc_quota_t *quota)
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence{
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence cfg_obj_t *obj = NULL;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_result_t result;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
83ac7ce833930a5c6cb92ad9c04a58e775579e73Bob Halley result = ns_config_get(maps, name, &obj);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews INSIST(result == ISC_R_SUCCESS);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews quota->max = cfg_obj_asuint32(obj);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews}
83ac7ce833930a5c6cb92ad9c04a58e775579e73Bob Halley
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews/*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * This function is called as soon as the 'directory' statement has been
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff * parsed. This can be extended to support other options if necessary.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
83ac7ce833930a5c6cb92ad9c04a58e775579e73Bob Halleystatic isc_result_t
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsdirectory_callback(const char *clausename, cfg_obj_t *obj, void *arg) {
83ac7ce833930a5c6cb92ad9c04a58e775579e73Bob Halley isc_result_t result;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews char *directory;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews REQUIRE(strcasecmp("directory", clausename) == 0);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews UNUSED(arg);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews UNUSED(clausename);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Change directory.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews directory = cfg_obj_asstring(obj);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (! isc_file_ischdiridempotent(directory))
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff cfg_obj_log(obj, ns_g_lctx, ISC_LOG_WARNING,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews "option 'directory' contains relative path '%s'",
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews directory);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews result = isc_dir_chdir(directory);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews if (result != ISC_R_SUCCESS) {
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews cfg_obj_log(obj, ns_g_lctx, ISC_LOG_ERROR,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews "change directory to '%s' failed: %s",
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff directory, isc_result_totext(result));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return (result);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews }
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews return (ISC_R_SUCCESS);
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews}
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsstatic void
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrewsscan_interfaces(ns_server_t *server, isc_boolean_t verbose) {
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence isc_boolean_t match_mapped = server->aclenv.match_mapped;
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews ns_interfacemgr_scan(server->interfacemgr, verbose);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence /*
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * Update the "localhost" and "localnets" ACLs to match the
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews * current set of network interfaces.
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews */
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews dns_aclenv_copy(&server->aclenv,
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews ns_interfacemgr_getaclenv(server->interfacemgr));
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews
3a4ec3da9fa14511cbc3660f75817cfacb3f4d1eMark Andrews server->aclenv.match_mapped = match_mapped;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews}
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrewsstatic isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceadd_listenelt(isc_mem_t *mctx, ns_listenlist_t *list, isc_sockaddr_t *addr) {
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence ns_listenelt_t *lelt = NULL;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence dns_acl_t *src_acl = NULL;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_aclelement_t aelt;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews isc_result_t result;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence isc_sockaddr_t any_sa6;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews REQUIRE(isc_sockaddr_pf(addr) == AF_INET6);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews isc_sockaddr_any6(&any_sa6);
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews if (!isc_sockaddr_equal(&any_sa6, addr)) {
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews aelt.type = dns_aclelementtype_ipprefix;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews aelt.negative = ISC_FALSE;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews aelt.u.ip_prefix.prefixlen = 128;
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews isc_netaddr_fromin6(&aelt.u.ip_prefix.address,
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews &addr->type.sin6.sin6_addr);
28059de4efa18062184a3fdbb0f607809fa55edaAndreas Gustafsson
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews result = dns_acl_create(mctx, 1, &src_acl);
fd4810861c0c0ccb9aebde94e9d289442b2630dbMark Andrews if (result != ISC_R_SUCCESS)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews return (result);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews result = dns_acl_appendelement(src_acl, &aelt);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (result != ISC_R_SUCCESS)
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence goto clean;
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrence result = ns_listenelt_create(mctx, isc_sockaddr_getport(addr),
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews src_acl, &lelt);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (result != ISC_R_SUCCESS)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews goto clean;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews ISC_LIST_APPEND(list->elts, lelt, link);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews }
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews return (ISC_R_SUCCESS);
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews clean:
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews INSIST(lelt == NULL);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (src_acl != NULL)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_acl_detach(&src_acl);
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews return (result);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews}
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews/*
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence * Make a list of xxx-source addresses and call ns_interfacemgr_adjust()
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews * to update the listening interfaces accordingly.
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews * We currently only consider IPv6, because this only affects IPv6 wildcard
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews * sockets.
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews */
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrewsstatic void
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrewsadjust_interfaces(ns_server_t *server, isc_mem_t *mctx) {
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence isc_result_t result;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews ns_listenlist_t *list = NULL;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_view_t *view;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_zone_t *zone, *next;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews isc_sockaddr_t addr, *addrp;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence result = ns_listenlist_create(mctx, &list);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews if (result != ISC_R_SUCCESS)
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews return;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews for (view = ISC_LIST_HEAD(server->viewlist);
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews view != NULL;
20b20b23948b90cb2f7d7f402da99d09f837efd0David Lawrence view = ISC_LIST_NEXT(view, link)) {
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dns_dispatch_t *dispatch6;
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews
82d05588933a3c765aa8518fe455d6477d640b99Mark Andrews dispatch6 = dns_resolver_dispatchv6(view->resolver);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson INSIST(dispatch6 != NULL);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley result = dns_dispatch_getlocaladdress(dispatch6, &addr);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence if (result != ISC_R_SUCCESS)
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley goto fail;
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley result = add_listenelt(mctx, list, &addr);
0513f89e68f82f9ec54e7af9c979a7c43babbe31Bob Halley if (result != ISC_R_SUCCESS)
ebd68da027cfa8da0fb536c3db11bb88292f41c7Andreas Gustafsson goto fail;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence }
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff zone = NULL;
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff for (result = dns_zone_first(server->zonemgr, &zone);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff result == ISC_R_SUCCESS;
ebd68da027cfa8da0fb536c3db11bb88292f41c7Andreas Gustafsson next = NULL, result = dns_zone_next(zone, &next), zone = next) {
ebd68da027cfa8da0fb536c3db11bb88292f41c7Andreas Gustafsson dns_view_t *zoneview;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff /*
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff * At this point the zone list may contain a stale zone
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff * just removed from the configuration. To see the validity,
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff * check if the corresponding view is in our current view list.
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff */
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff zoneview = dns_zone_getview(zone);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff INSIST(zoneview != NULL);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence for (view = ISC_LIST_HEAD(server->viewlist);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff view != NULL && view != zoneview;
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff view = ISC_LIST_NEXT(view, link))
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff ;
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff if (view == NULL)
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff continue;
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff addrp = dns_zone_getnotifysrc6(zone);
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence result = add_listenelt(mctx, list, addrp);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff if (result != ISC_R_SUCCESS)
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff goto fail;
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff addrp = dns_zone_getxfrsource6(zone);
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff result = add_listenelt(mctx, list, addrp);
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff if (result != ISC_R_SUCCESS)
3bb3b7ac462a90c2b8b1fb783324d800e2ba748cMichael Graff goto fail;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence }
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff ns_interfacemgr_adjust(server->interfacemgr, list, ISC_TRUE);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff clean:
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff ns_listenlist_detach(&list);
fa460c223a69449eaac67ddb6abafe74f5e1ff02Michael Graff return;
7ec579cd5d07228c0d6cece58b80694ad8d59de9Michael Graff
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence fail:
f8aae502686e2448c48f56697c212a50e2a1cbaeAndreas Gustafsson /*
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson * Even when we failed the procedure, most of other interfaces
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson * should work correctly. We therefore just warn it.
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence */
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff "could not adjust the listen-on list; "
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson "some interfaces may not work");
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson goto clean;
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafsson}
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff/*
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff * This event callback is invoked to do periodic network
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff * interface scanning.
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff */
6324997211a5e2d82528dcde98e8981190a35faeMichael Graffstatic void
b469f0321d2bcea3914c57d26fd43319e506c313Andreas Gustafssoninterface_timer_tick(isc_task_t *task, isc_event_t *event) {
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson isc_result_t result;
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson ns_server_t *server = (ns_server_t *) event->ev_arg;
8abddcd3f24476b945419659e7cb73bcb970886bDavid Lawrence INSIST(task == server->task);
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson UNUSED(task);
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson isc_event_free(&event);
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson /*
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson * XXX should scan interfaces unlocked and get exclusive access
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson * only to replace ACLs.
014892d86d30b7eceb0003d51788f9b5cadfc1bfAndreas Gustafsson */
result = isc_task_beginexclusive(server->task);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
scan_interfaces(server, ISC_FALSE);
isc_task_endexclusive(server->task);
}
static void
heartbeat_timer_tick(isc_task_t *task, isc_event_t *event) {
ns_server_t *server = (ns_server_t *) event->ev_arg;
dns_view_t *view;
UNUSED(task);
isc_event_free(&event);
view = ISC_LIST_HEAD(server->viewlist);
while (view != NULL) {
dns_view_dialup(view);
view = ISC_LIST_NEXT(view, link);
}
}
/*
* Replace the current value of '*field', a dynamically allocated
* string or NULL, with a dynamically allocated copy of the
* null-terminated string pointed to by 'value', or NULL.
*/
static isc_result_t
setstring(ns_server_t *server, char **field, const char *value) {
char *copy;
if (value != NULL) {
copy = isc_mem_strdup(server->mctx, value);
if (copy == NULL)
return (ISC_R_NOMEMORY);
} else {
copy = NULL;
}
if (*field != NULL)
isc_mem_free(server->mctx, *field);
*field = copy;
return (ISC_R_SUCCESS);
}
/*
* Replace the current value of '*field', a dynamically allocated
* string or NULL, with another dynamically allocated string
* or NULL if whether 'obj' is a string or void value, respectively.
*/
static isc_result_t
setoptstring(ns_server_t *server, char **field, cfg_obj_t *obj) {
if (cfg_obj_isvoid(obj))
return (setstring(server, field, NULL));
else
return (setstring(server, field, cfg_obj_asstring(obj)));
}
static void
set_limit(cfg_obj_t **maps, const char *configname, const char *description,
isc_resource_t resourceid, isc_resourcevalue_t defaultvalue)
{
cfg_obj_t *obj = NULL;
char *resource;
isc_resourcevalue_t value;
isc_result_t result;
if (ns_config_get(maps, configname, &obj) != ISC_R_SUCCESS)
return;
if (cfg_obj_isstring(obj)) {
resource = cfg_obj_asstring(obj);
if (strcasecmp(resource, "unlimited") == 0)
value = ISC_RESOURCE_UNLIMITED;
else {
INSIST(strcasecmp(resource, "default") == 0);
value = defaultvalue;
}
} else
value = cfg_obj_asuint64(obj);
result = isc_resource_setlimit(resourceid, value);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
result == ISC_R_SUCCESS ?
ISC_LOG_DEBUG(3) : ISC_LOG_WARNING,
"set maximum %s to %" ISC_PRINT_QUADFORMAT "d: %s",
description, value, isc_result_totext(result));
}
#define SETLIMIT(cfgvar, resource, description) \
set_limit(maps, cfgvar, description, isc_resource_ ## resource, \
ns_g_init ## resource)
static void
set_limits(cfg_obj_t **maps) {
SETLIMIT("stacksize", stacksize, "stack size");
SETLIMIT("datasize", datasize, "data size");
SETLIMIT("coresize", coresize, "core size");
SETLIMIT("files", openfiles, "open files");
}
static isc_result_t
portlist_fromconf(dns_portlist_t *portlist, unsigned int family,
cfg_obj_t *ports)
{
cfg_listelt_t *element;
isc_result_t result = ISC_R_SUCCESS;
for (element = cfg_list_first(ports);
element != NULL;
element = cfg_list_next(element)) {
cfg_obj_t *obj = cfg_listelt_value(element);
in_port_t port = (in_port_t)cfg_obj_asuint32(obj);
result = dns_portlist_add(portlist, family, port);
if (result != ISC_R_SUCCESS)
break;
}
return (result);
}
static isc_result_t
load_configuration(const char *filename, ns_server_t *server,
isc_boolean_t first_time)
{
isc_result_t result;
cfg_parser_t *parser = NULL;
cfg_obj_t *config;
cfg_obj_t *options;
cfg_obj_t *views;
cfg_obj_t *obj;
cfg_obj_t *v4ports, *v6ports;
cfg_obj_t *maps[3];
cfg_obj_t *builtin_views;
cfg_listelt_t *element;
dns_view_t *view = NULL;
dns_view_t *view_next;
dns_viewlist_t viewlist;
dns_viewlist_t tmpviewlist;
ns_aclconfctx_t aclconfctx;
isc_uint32_t interface_interval;
isc_uint32_t heartbeat_interval;
isc_uint32_t udpsize;
in_port_t listen_port;
int i;
ns_aclconfctx_init(&aclconfctx);
ISC_LIST_INIT(viewlist);
/* Ensure exclusive access to configuration data. */
result = isc_task_beginexclusive(server->task);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
/*
* Parse the global default pseudo-config file.
*/
if (first_time) {
CHECK(ns_config_parsedefaults(ns_g_parser, &ns_g_config));
RUNTIME_CHECK(cfg_map_get(ns_g_config, "options",
&ns_g_defaults) ==
ISC_R_SUCCESS);
}
/*
* Parse the configuration file using the new config code.
*/
result = ISC_R_FAILURE;
config = NULL;
/*
* Unless this is lwresd with the -C option, parse the config file.
*/
if (!(ns_g_lwresdonly && lwresd_g_useresolvconf)) {
isc_log_write(ns_g_lctx,
NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "loading configuration from '%s'",
filename);
CHECK(cfg_parser_create(ns_g_mctx, ns_g_lctx, &parser));
cfg_parser_setcallback(parser, directory_callback, NULL);
result = cfg_parse_file(parser, filename, &cfg_type_namedconf,
&config);
}
/*
* If this is lwresd with the -C option, or lwresd with no -C or -c
* option where the above parsing failed, parse resolv.conf.
*/
if (ns_g_lwresdonly &&
(lwresd_g_useresolvconf ||
(!ns_g_conffileset && result == ISC_R_FILENOTFOUND)))
{
isc_log_write(ns_g_lctx,
NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "loading configuration from '%s'",
lwresd_g_resolvconffile);
if (parser != NULL)
cfg_parser_destroy(&parser);
CHECK(cfg_parser_create(ns_g_mctx, ns_g_lctx, &parser));
result = ns_lwresd_parseeresolvconf(ns_g_mctx, parser,
&config);
}
CHECK(result);
/*
* Check the validity of the configuration.
*/
CHECK(bind9_check_namedconf(config, ns_g_lctx, ns_g_mctx));
/*
* Fill in the maps array, used for resolving defaults.
*/
i = 0;
options = NULL;
result = cfg_map_get(config, "options", &options);
if (result == ISC_R_SUCCESS)
maps[i++] = options;
maps[i++] = ns_g_defaults;
maps[i++] = NULL;
/*
* Set process limits, which (usually) needs to be done as root.
*/
set_limits(maps);
/*
* Configure various server options.
*/
configure_server_quota(maps, "transfers-out", &server->xfroutquota);
configure_server_quota(maps, "tcp-clients", &server->tcpquota);
configure_server_quota(maps, "recursive-clients",
&server->recursionquota);
CHECK(configure_view_acl(NULL, config, "blackhole", &aclconfctx,
ns_g_mctx, &server->blackholeacl));
if (server->blackholeacl != NULL)
dns_dispatchmgr_setblackhole(ns_g_dispatchmgr,
server->blackholeacl);
obj = NULL;
result = ns_config_get(maps, "match-mapped-addresses", &obj);
INSIST(result == ISC_R_SUCCESS);
server->aclenv.match_mapped = cfg_obj_asboolean(obj);
v4ports = NULL;
v6ports = NULL;
(void)ns_config_get(maps, "avoid-v4-udp-ports", &v4ports);
(void)ns_config_get(maps, "avoid-v6-udp-ports", &v6ports);
if (v4ports != NULL || v6ports != NULL) {
dns_portlist_t *portlist = NULL;
result = dns_portlist_create(ns_g_mctx, &portlist);
if (result == ISC_R_SUCCESS && v4ports != NULL)
result = portlist_fromconf(portlist, AF_INET, v4ports);
if (result == ISC_R_SUCCESS && v6ports != NULL)
portlist_fromconf(portlist, AF_INET6, v6ports);
if (result == ISC_R_SUCCESS)
dns_dispatchmgr_setblackportlist(ns_g_dispatchmgr, portlist);
if (portlist != NULL)
dns_portlist_detach(&portlist);
CHECK(result);
} else
dns_dispatchmgr_setblackportlist(ns_g_dispatchmgr, NULL);
/*
* Set the EDNS UDP size when we don't match a view.
*/
obj = NULL;
result = ns_config_get(maps, "edns-udp-size", &obj);
INSIST(result == ISC_R_SUCCESS);
udpsize = cfg_obj_asuint32(obj);
if (udpsize < 512)
udpsize = 512;
if (udpsize > 4096)
udpsize = 4096;
ns_g_udpsize = (isc_uint16_t)udpsize;
/*
* Configure the zone manager.
*/
obj = NULL;
result = ns_config_get(maps, "transfers-in", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zonemgr_settransfersin(server->zonemgr, cfg_obj_asuint32(obj));
obj = NULL;
result = ns_config_get(maps, "transfers-per-ns", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zonemgr_settransfersperns(server->zonemgr, cfg_obj_asuint32(obj));
obj = NULL;
result = ns_config_get(maps, "serial-query-rate", &obj);
INSIST(result == ISC_R_SUCCESS);
dns_zonemgr_setserialqueryrate(server->zonemgr, cfg_obj_asuint32(obj));
/*
* Determine which port to use for listening for incoming connections.
*/
if (ns_g_port != 0)
listen_port = ns_g_port;
else
CHECKM(ns_config_getport(config, &listen_port), "port");
/*
* Find the listen queue depth.
*/
obj = NULL;
result = ns_config_get(maps, "tcp-listen-queue", &obj);
INSIST(result == ISC_R_SUCCESS);
ns_g_listen = cfg_obj_asuint32(obj);
if (ns_g_listen < 3)
ns_g_listen = 3;
/*
* Configure the interface manager according to the "listen-on"
* statement.
*/
{
cfg_obj_t *clistenon = NULL;
ns_listenlist_t *listenon = NULL;
clistenon = NULL;
/*
* Even though listen-on is present in the default
* configuration, we can't use it here, since it isn't
* used if we're in lwresd mode. This way is easier.
*/
if (options != NULL)
(void)cfg_map_get(options, "listen-on", &clistenon);
if (clistenon != NULL) {
result = ns_listenlist_fromconfig(clistenon,
config,
&aclconfctx,
ns_g_mctx,
&listenon);
} else if (!ns_g_lwresdonly) {
/*
* Not specified, use default.
*/
CHECK(ns_listenlist_default(ns_g_mctx, listen_port,
ISC_TRUE, &listenon));
}
if (listenon != NULL) {
ns_interfacemgr_setlistenon4(server->interfacemgr,
listenon);
ns_listenlist_detach(&listenon);
}
}
/*
* Ditto for IPv6.
*/
{
cfg_obj_t *clistenon = NULL;
ns_listenlist_t *listenon = NULL;
if (options != NULL)
(void)cfg_map_get(options, "listen-on-v6", &clistenon);
if (clistenon != NULL) {
result = ns_listenlist_fromconfig(clistenon,
config,
&aclconfctx,
ns_g_mctx,
&listenon);
} else if (!ns_g_lwresdonly) {
/*
* Not specified, use default.
*/
CHECK(ns_listenlist_default(ns_g_mctx, listen_port,
ISC_FALSE, &listenon));
}
if (listenon != NULL) {
ns_interfacemgr_setlistenon6(server->interfacemgr,
listenon);
ns_listenlist_detach(&listenon);
}
}
/*
* Rescan the interface list to pick up changes in the
* listen-on option. It's important that we do this before we try
* to configure the query source, since the dispatcher we use might
* be shared with an interface.
*/
scan_interfaces(server, ISC_TRUE);
/*
* Arrange for further interface scanning to occur periodically
* as specified by the "interface-interval" option.
*/
obj = NULL;
result = ns_config_get(maps, "interface-interval", &obj);
INSIST(result == ISC_R_SUCCESS);
interface_interval = cfg_obj_asuint32(obj) * 60;
if (interface_interval == 0) {
CHECK(isc_timer_reset(server->interface_timer,
isc_timertype_inactive,
NULL, NULL, ISC_TRUE));
} else if (server->interface_interval != interface_interval) {
isc_interval_t interval;
isc_interval_set(&interval, interface_interval, 0);
CHECK(isc_timer_reset(server->interface_timer,
isc_timertype_ticker,
NULL, &interval, ISC_FALSE));
}
server->interface_interval = interface_interval;
/*
* Configure the dialup heartbeat timer.
*/
obj = NULL;
result = ns_config_get(maps, "heartbeat-interval", &obj);
INSIST(result == ISC_R_SUCCESS);
heartbeat_interval = cfg_obj_asuint32(obj) * 60;
if (heartbeat_interval == 0) {
CHECK(isc_timer_reset(server->heartbeat_timer,
isc_timertype_inactive,
NULL, NULL, ISC_TRUE));
} else if (server->heartbeat_interval != heartbeat_interval) {
isc_interval_t interval;
isc_interval_set(&interval, heartbeat_interval, 0);
CHECK(isc_timer_reset(server->heartbeat_timer,
isc_timertype_ticker,
NULL, &interval, ISC_FALSE));
}
server->heartbeat_interval = heartbeat_interval;
/*
* Configure and freeze all explicit views. Explicit
* views that have zones were already created at parsing
* time, but views with no zones must be created here.
*/
views = NULL;
(void)cfg_map_get(config, "view", &views);
for (element = cfg_list_first(views);
element != NULL;
element = cfg_list_next(element))
{
cfg_obj_t *vconfig = cfg_listelt_value(element);
view = NULL;
CHECK(create_view(vconfig, &viewlist, &view));
INSIST(view != NULL);
CHECK(configure_view(view, config, vconfig,
ns_g_mctx, &aclconfctx, ISC_TRUE));
dns_view_freeze(view);
dns_view_detach(&view);
}
/*
* Make sure we have a default view if and only if there
* were no explicit views.
*/
if (views == NULL) {
/*
* No explicit views; there ought to be a default view.
* There may already be one created as a side effect
* of zone statements, or we may have to create one.
* In either case, we need to configure and freeze it.
*/
CHECK(create_view(NULL, &viewlist, &view));
CHECK(configure_view(view, config, NULL, ns_g_mctx,
&aclconfctx, ISC_TRUE));
dns_view_freeze(view);
dns_view_detach(&view);
}
/*
* Create (or recreate) the built-in views. Currently
* there is only one, the _bind view.
*/
builtin_views = NULL;
RUNTIME_CHECK(cfg_map_get(ns_g_config, "view",
&builtin_views) == ISC_R_SUCCESS);
for (element = cfg_list_first(builtin_views);
element != NULL;
element = cfg_list_next(element))
{
cfg_obj_t *vconfig = cfg_listelt_value(element);
CHECK(create_view(vconfig, &viewlist, &view));
CHECK(configure_view(view, config, vconfig, ns_g_mctx,
&aclconfctx, ISC_FALSE));
dns_view_freeze(view);
dns_view_detach(&view);
view = NULL;
}
/*
* Swap our new view list with the production one.
*/
tmpviewlist = server->viewlist;
server->viewlist = viewlist;
viewlist = tmpviewlist;
/*
* Load the TKEY information from the configuration.
*/
if (options != NULL) {
dns_tkeyctx_t *t = NULL;
CHECKM(ns_tkeyctx_fromconfig(options, ns_g_mctx, ns_g_entropy,
&t),
"configuring TKEY");
if (server->tkeyctx != NULL)
dns_tkeyctx_destroy(&server->tkeyctx);
server->tkeyctx = t;
}
/*
* Bind the control port(s).
*/
CHECKM(ns_controls_configure(ns_g_server->controls, config,
&aclconfctx),
"binding control channel(s)");
/*
* Bind the lwresd port(s).
*/
CHECKM(ns_lwresd_configure(ns_g_mctx, config),
"binding lightweight resolver ports");
/*
* Open the source of entropy.
*/
if (first_time) {
obj = NULL;
result = ns_config_get(maps, "random-device", &obj);
if (result != ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
"no source of entropy found");
} else {
const char *randomdev = cfg_obj_asstring(obj);
result = isc_entropy_createfilesource(ns_g_entropy,
randomdev);
if (result != ISC_R_SUCCESS)
isc_log_write(ns_g_lctx,
NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER,
ISC_LOG_INFO,
"could not open entropy source "
"%s: %s",
randomdev,
isc_result_totext(result));
#ifdef PATH_RANDOMDEV
if (ns_g_fallbackentropy != NULL) {
if (result != ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx,
NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER,
ISC_LOG_INFO,
"using pre-chroot entropy source "
"%s",
PATH_RANDOMDEV);
isc_entropy_detach(&ns_g_entropy);
isc_entropy_attach(ns_g_fallbackentropy,
&ns_g_entropy);
}
isc_entropy_detach(&ns_g_fallbackentropy);
}
#endif
}
}
/*
* Relinquish root privileges.
*/
if (first_time)
ns_os_changeuser();
/*
* Configure the logging system.
*
* Do this after changing UID to make sure that any log
* files specified in named.conf get created by the
* unprivileged user, not root.
*/
if (ns_g_logstderr) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
"ignoring config file logging "
"statement due to -g option");
} else {
cfg_obj_t *logobj = NULL;
isc_logconfig_t *logc = NULL;
CHECKM(isc_logconfig_create(ns_g_lctx, &logc),
"creating new logging configuration");
logobj = NULL;
(void)cfg_map_get(config, "logging", &logobj);
if (logobj != NULL) {
CHECKM(ns_log_configure(logc, logobj),
"configuring logging");
} else {
CHECKM(ns_log_setdefaultchannels(logc),
"setting up default logging channels");
CHECKM(ns_log_setunmatchedcategory(logc),
"setting up default 'category unmatched'");
CHECKM(ns_log_setdefaultcategory(logc),
"setting up default 'category default'");
}
result = isc_logconfig_use(ns_g_lctx, logc);
if (result != ISC_R_SUCCESS) {
isc_logconfig_destroy(&logc);
CHECKM(result, "installing logging configuration");
}
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_DEBUG(1),
"now using logging configuration from "
"config file");
}
/*
* Set the default value of the query logging flag depending
* whether a "queries" category has been defined. This is
* a disgusting hack, but we need to do this for BIND 8
* compatibility.
*/
if (first_time) {
cfg_obj_t *logobj = NULL;
cfg_obj_t *categories = NULL;
obj = NULL;
if (ns_config_get(maps, "querylog", &obj) == ISC_R_SUCCESS) {
server->log_queries = cfg_obj_asboolean(obj);
} else {
(void)cfg_map_get(config, "logging", &logobj);
if (logobj != NULL)
(void)cfg_map_get(logobj, "category",
&categories);
if (categories != NULL) {
cfg_listelt_t *element;
for (element = cfg_list_first(categories);
element != NULL;
element = cfg_list_next(element))
{
cfg_obj_t *catobj;
char *str;
obj = cfg_listelt_value(element);
catobj = cfg_tuple_get(obj, "name");
str = cfg_obj_asstring(catobj);
if (strcasecmp(str, "queries") == 0)
server->log_queries = ISC_TRUE;
}
}
}
}
obj = NULL;
if (ns_config_get(maps, "pid-file", &obj) == ISC_R_SUCCESS)
if (cfg_obj_isvoid(obj))
ns_os_writepidfile(NULL, first_time);
else
ns_os_writepidfile(cfg_obj_asstring(obj), first_time);
else if (ns_g_lwresdonly)
ns_os_writepidfile(lwresd_g_defaultpidfile, first_time);
else
ns_os_writepidfile(ns_g_defaultpidfile, first_time);
obj = NULL;
if (options != NULL &&
cfg_map_get(options, "memstatistics-file", &obj) == ISC_R_SUCCESS)
ns_main_setmemstats(cfg_obj_asstring(obj));
else
ns_main_setmemstats(NULL);
obj = NULL;
result = ns_config_get(maps, "statistics-file", &obj);
INSIST(result == ISC_R_SUCCESS);
CHECKM(setstring(server, &server->statsfile, cfg_obj_asstring(obj)),
"strdup");
obj = NULL;
result = ns_config_get(maps, "dump-file", &obj);
INSIST(result == ISC_R_SUCCESS);
CHECKM(setstring(server, &server->dumpfile, cfg_obj_asstring(obj)),
"strdup");
obj = NULL;
result = ns_config_get(maps, "recursing-file", &obj);
INSIST(result == ISC_R_SUCCESS);
CHECKM(setstring(server, &server->recfile, cfg_obj_asstring(obj)),
"strdup");
obj = NULL;
result = ns_config_get(maps, "version", &obj);
if (result == ISC_R_SUCCESS) {
CHECKM(setoptstring(server, &server->version, obj), "strdup");
server->version_set = ISC_TRUE;
} else {
server->version_set = ISC_FALSE;
}
obj = NULL;
result = ns_config_get(maps, "hostname", &obj);
if (result == ISC_R_SUCCESS) {
CHECKM(setoptstring(server, &server->hostname, obj), "strdup");
server->hostname_set = ISC_TRUE;
} else {
server->hostname_set = ISC_FALSE;
}
obj = NULL;
result = ns_config_get(maps, "server-id", &obj);
server->server_usehostname = ISC_FALSE;
if (result == ISC_R_SUCCESS && cfg_obj_isboolean(obj)) {
server->server_usehostname = ISC_TRUE;
} else if (result == ISC_R_SUCCESS) {
CHECKM(setoptstring(server, &server->server_id, obj), "strdup");
} else {
result = setoptstring(server, &server->server_id, NULL);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
}
obj = NULL;
result = ns_config_get(maps, "flush-zones-on-shutdown", &obj);
if (result == ISC_R_SUCCESS) {
server->flushonshutdown = cfg_obj_asboolean(obj);
} else {
server->flushonshutdown = ISC_FALSE;
}
result = ISC_R_SUCCESS;
cleanup:
ns_aclconfctx_destroy(&aclconfctx);
if (parser != NULL) {
if (config != NULL)
cfg_obj_destroy(parser, &config);
cfg_parser_destroy(&parser);
}
if (view != NULL)
dns_view_detach(&view);
/*
* This cleans up either the old production view list
* or our temporary list depending on whether they
* were swapped above or not.
*/
for (view = ISC_LIST_HEAD(viewlist);
view != NULL;
view = view_next) {
view_next = ISC_LIST_NEXT(view, link);
ISC_LIST_UNLINK(viewlist, view, link);
dns_view_detach(&view);
}
/*
* Adjust the listening interfaces in accordance with the source
* addresses specified in views and zones.
*/
if (isc_net_probeipv6() == ISC_R_SUCCESS)
adjust_interfaces(server, ns_g_mctx);
/* Relinquish exclusive access to configuration data. */
isc_task_endexclusive(server->task);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_DEBUG(1), "load_configuration: %s",
isc_result_totext(result));
return (result);
}
static isc_result_t
load_zones(ns_server_t *server, isc_boolean_t stop) {
isc_result_t result;
dns_view_t *view;
result = isc_task_beginexclusive(server->task);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
/*
* Load zone data from disk.
*/
for (view = ISC_LIST_HEAD(server->viewlist);
view != NULL;
view = ISC_LIST_NEXT(view, link))
{
CHECK(dns_view_load(view, stop));
}
/*
* Force zone maintenance. Do this after loading
* so that we know when we need to force AXFR of
* slave zones whose master files are missing.
*/
CHECK(dns_zonemgr_forcemaint(server->zonemgr));
cleanup:
isc_task_endexclusive(server->task);
return (result);
}
static isc_result_t
load_new_zones(ns_server_t *server, isc_boolean_t stop) {
isc_result_t result;
dns_view_t *view;
result = isc_task_beginexclusive(server->task);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
/*
* Load zone data from disk.
*/
for (view = ISC_LIST_HEAD(server->viewlist);
view != NULL;
view = ISC_LIST_NEXT(view, link))
{
CHECK(dns_view_loadnew(view, stop));
}
/*
* Force zone maintenance. Do this after loading
* so that we know when we need to force AXFR of
* slave zones whose master files are missing.
*/
dns_zonemgr_resumexfrs(server->zonemgr);
cleanup:
isc_task_endexclusive(server->task);
return (result);
}
static void
run_server(isc_task_t *task, isc_event_t *event) {
isc_result_t result;
ns_server_t *server = (ns_server_t *)event->ev_arg;
UNUSED(task);
isc_event_free(&event);
CHECKFATAL(dns_dispatchmgr_create(ns_g_mctx, ns_g_entropy,
&ns_g_dispatchmgr),
"creating dispatch manager");
CHECKFATAL(ns_interfacemgr_create(ns_g_mctx, ns_g_taskmgr,
ns_g_socketmgr, ns_g_dispatchmgr,
&server->interfacemgr),
"creating interface manager");
CHECKFATAL(isc_timer_create(ns_g_timermgr, isc_timertype_inactive,
NULL, NULL, server->task,
interface_timer_tick,
server, &server->interface_timer),
"creating interface timer");
CHECKFATAL(isc_timer_create(ns_g_timermgr, isc_timertype_inactive,
NULL, NULL, server->task,
heartbeat_timer_tick,
server, &server->heartbeat_timer),
"creating heartbeat timer");
CHECKFATAL(cfg_parser_create(ns_g_mctx, NULL, &ns_g_parser),
"creating default configuration parser");
if (ns_g_lwresdonly)
CHECKFATAL(load_configuration(lwresd_g_conffile, server,
ISC_TRUE),
"loading configuration");
else
CHECKFATAL(load_configuration(ns_g_conffile, server, ISC_TRUE),
"loading configuration");
isc_hash_init();
CHECKFATAL(load_zones(server, ISC_FALSE),
"loading zones");
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "running");
}
void
ns_server_flushonshutdown(ns_server_t *server, isc_boolean_t flush) {
REQUIRE(NS_SERVER_VALID(server));
server->flushonshutdown = flush;
}
static void
shutdown_server(isc_task_t *task, isc_event_t *event) {
isc_result_t result;
dns_view_t *view, *view_next;
ns_server_t *server = (ns_server_t *)event->ev_arg;
isc_boolean_t flush = server->flushonshutdown;
UNUSED(task);
INSIST(task == server->task);
result = isc_task_beginexclusive(server->task);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_INFO, "shutting down%s",
flush ? ": flushing changes" : "");
ns_controls_shutdown(server->controls);
end_reserved_dispatches(server, ISC_TRUE);
cfg_obj_destroy(ns_g_parser, &ns_g_config);
cfg_parser_destroy(&ns_g_parser);
for (view = ISC_LIST_HEAD(server->viewlist);
view != NULL;
view = view_next) {
view_next = ISC_LIST_NEXT(view, link);
ISC_LIST_UNLINK(server->viewlist, view, link);
if (flush)
dns_view_flushanddetach(&view);
else
dns_view_detach(&view);
}
isc_timer_detach(&server->interface_timer);
isc_timer_detach(&server->heartbeat_timer);
ns_interfacemgr_shutdown(server->interfacemgr);
ns_interfacemgr_detach(&server->interfacemgr);
dns_dispatchmgr_destroy(&ns_g_dispatchmgr);
dns_zonemgr_shutdown(server->zonemgr);
if (server->blackholeacl != NULL)
dns_acl_detach(&server->blackholeacl);
isc_task_endexclusive(server->task);
isc_task_detach(&server->task);
isc_event_free(&event);
}
void
ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
isc_result_t result;
ns_server_t *server = isc_mem_get(mctx, sizeof(*server));
if (server == NULL)
fatal("allocating server object", ISC_R_NOMEMORY);
server->mctx = mctx;
server->task = NULL;
/* Initialize configuration data with default values. */
result = isc_quota_init(&server->xfroutquota, 10);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
result = isc_quota_init(&server->tcpquota, 10);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
result = isc_quota_init(&server->recursionquota, 100);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
isc_quota_soft(&server->recursionquota, ISC_FALSE);
result = dns_aclenv_init(mctx, &server->aclenv);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
/* Initialize server data structures. */
server->zonemgr = NULL;
server->interfacemgr = NULL;
ISC_LIST_INIT(server->viewlist);
server->in_roothints = NULL;
server->blackholeacl = NULL;
CHECKFATAL(dns_rootns_create(mctx, dns_rdataclass_in, NULL,
&server->in_roothints),
"setting up root hints");
CHECKFATAL(isc_mutex_init(&server->reload_event_lock),
"initializing reload event lock");
server->reload_event =
isc_event_allocate(ns_g_mctx, server,
NS_EVENT_RELOAD,
ns_server_reload,
server,
sizeof(isc_event_t));
CHECKFATAL(server->reload_event == NULL ?
ISC_R_NOMEMORY : ISC_R_SUCCESS,
"allocating reload event");
CHECKFATAL(dst_lib_init(ns_g_mctx, ns_g_entropy, ISC_ENTROPY_GOODONLY),
"initializing DST");
server->tkeyctx = NULL;
CHECKFATAL(dns_tkeyctx_create(ns_g_mctx, ns_g_entropy,
&server->tkeyctx),
"creating TKEY context");
/*
* Setup the server task, which is responsible for coordinating
* startup and shutdown of the server.
*/
CHECKFATAL(isc_task_create(ns_g_taskmgr, 0, &server->task),
"creating server task");
isc_task_setname(server->task, "server", server);
CHECKFATAL(isc_task_onshutdown(server->task, shutdown_server, server),
"isc_task_onshutdown");
CHECKFATAL(isc_app_onrun(ns_g_mctx, server->task, run_server, server),
"isc_app_onrun");
server->interface_timer = NULL;
server->heartbeat_timer = NULL;
server->interface_interval = 0;
server->heartbeat_interval = 0;
CHECKFATAL(dns_zonemgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
ns_g_socketmgr, &server->zonemgr),
"dns_zonemgr_create");
server->statsfile = isc_mem_strdup(server->mctx, "named.stats");
CHECKFATAL(server->statsfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS,
"isc_mem_strdup");
server->querystats = NULL;
server->dumpfile = isc_mem_strdup(server->mctx, "named_dump.db");
CHECKFATAL(server->dumpfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS,
"isc_mem_strdup");
server->recfile = isc_mem_strdup(server->mctx, "named.recursing");
CHECKFATAL(server->recfile == NULL ? ISC_R_NOMEMORY : ISC_R_SUCCESS,
"isc_mem_strdup");
server->hostname_set = ISC_FALSE;
server->hostname = NULL;
server->version_set = ISC_FALSE;
server->version = NULL;
server->server_usehostname = ISC_FALSE;
server->server_id = NULL;
CHECKFATAL(dns_stats_alloccounters(ns_g_mctx, &server->querystats),
"dns_stats_alloccounters");
server->flushonshutdown = ISC_FALSE;
server->log_queries = ISC_FALSE;
server->controls = NULL;
CHECKFATAL(ns_controls_create(server, &server->controls),
"ns_controls_create");
server->dispatchgen = 0;
ISC_LIST_INIT(server->dispatches);
server->magic = NS_SERVER_MAGIC;
*serverp = server;
}
void
ns_server_destroy(ns_server_t **serverp) {
ns_server_t *server = *serverp;
REQUIRE(NS_SERVER_VALID(server));
ns_controls_destroy(&server->controls);
dns_stats_freecounters(server->mctx, &server->querystats);
isc_mem_free(server->mctx, server->statsfile);
isc_mem_free(server->mctx, server->dumpfile);
isc_mem_free(server->mctx, server->recfile);
if (server->version != NULL)
isc_mem_free(server->mctx, server->version);
if (server->hostname != NULL)
isc_mem_free(server->mctx, server->hostname);
if (server->server_id != NULL)
isc_mem_free(server->mctx, server->server_id);
dns_zonemgr_detach(&server->zonemgr);
if (server->tkeyctx != NULL)
dns_tkeyctx_destroy(&server->tkeyctx);
dst_lib_destroy();
isc_event_free(&server->reload_event);
INSIST(ISC_LIST_EMPTY(server->viewlist));
dns_db_detach(&server->in_roothints);
dns_aclenv_destroy(&server->aclenv);
isc_quota_destroy(&server->recursionquota);
isc_quota_destroy(&server->tcpquota);
isc_quota_destroy(&server->xfroutquota);
server->magic = 0;
isc_mem_put(server->mctx, server, sizeof(*server));
*serverp = NULL;
}
static void
fatal(const char *msg, isc_result_t result) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_CRITICAL, "%s: %s", msg,
isc_result_totext(result));
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
ISC_LOG_CRITICAL, "exiting (due to fatal error)");
exit(1);
}
static void
start_reserved_dispatches(ns_server_t *server) {
REQUIRE(NS_SERVER_VALID(server));
server->dispatchgen++;
}
static void
end_reserved_dispatches(ns_server_t *server, isc_boolean_t all) {
ns_dispatch_t *dispatch, *nextdispatch;
REQUIRE(NS_SERVER_VALID(server));
for (dispatch = ISC_LIST_HEAD(server->dispatches);
dispatch != NULL;
dispatch = nextdispatch) {
nextdispatch = ISC_LIST_NEXT(dispatch, link);
if (!all && server->dispatchgen == dispatch-> dispatchgen)
continue;
ISC_LIST_UNLINK(server->dispatches, dispatch, link);
dns_dispatch_detach(&dispatch->dispatch);
isc_mem_put(server->mctx, dispatch, sizeof(*dispatch));
}
}
void
ns_add_reserved_dispatch(ns_server_t *server, isc_sockaddr_t *addr) {
ns_dispatch_t *dispatch;
in_port_t port;
char addrbuf[ISC_SOCKADDR_FORMATSIZE];
isc_result_t result;
unsigned int attrs, attrmask;
REQUIRE(NS_SERVER_VALID(server));
port = isc_sockaddr_getport(addr);
if (port == 0 || port >= 1024)
return;
for (dispatch = ISC_LIST_HEAD(server->dispatches);
dispatch != NULL;
dispatch = ISC_LIST_NEXT(dispatch, link)) {
if (isc_sockaddr_equal(&dispatch->addr, addr))
break;
}
if (dispatch != NULL) {
dispatch->dispatchgen = server->dispatchgen;
return;
}
dispatch = isc_mem_get(server->mctx, sizeof(*dispatch));
if (dispatch == NULL) {
result = ISC_R_NOMEMORY;
goto cleanup;
}
dispatch->addr = *addr;
dispatch->dispatchgen = server->dispatchgen;
dispatch->dispatch = NULL;
attrs = 0;
attrs |= DNS_DISPATCHATTR_UDP;
switch (isc_sockaddr_pf(addr)) {
case AF_INET:
attrs |= DNS_DISPATCHATTR_IPV4;
break;
case AF_INET6:
attrs |= DNS_DISPATCHATTR_IPV6;
break;
default:
result = ISC_R_NOTIMPLEMENTED;
goto cleanup;
}
attrmask = 0;
attrmask |= DNS_DISPATCHATTR_UDP;
attrmask |= DNS_DISPATCHATTR_TCP;
attrmask |= DNS_DISPATCHATTR_IPV4;
attrmask |= DNS_DISPATCHATTR_IPV6;
result = dns_dispatch_getudp(ns_g_dispatchmgr, ns_g_socketmgr,
ns_g_taskmgr, &dispatch->addr, 4096,
1000, 32768, 16411, 16433,
attrs, attrmask, &dispatch->dispatch);
if (result != ISC_R_SUCCESS)
goto cleanup;
ISC_LIST_INITANDPREPEND(server->dispatches, dispatch, link);
return;
cleanup:
if (dispatch != NULL)
isc_mem_put(server->mctx, dispatch, sizeof(*dispatch));
isc_sockaddr_format(addr, addrbuf, sizeof(addrbuf));
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
"unable to create dispatch for reserved port %s: %s",
addrbuf, isc_result_totext(result));
}
static isc_result_t
loadconfig(ns_server_t *server) {
isc_result_t result;
start_reserved_dispatches(server);
result = load_configuration(ns_g_lwresdonly ?
lwresd_g_conffile : ns_g_conffile,
server,
ISC_FALSE);
if (result == ISC_R_SUCCESS)
end_reserved_dispatches(server, ISC_FALSE);
else
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
"reloading configuration failed: %s",
isc_result_totext(result));
return (result);
}
static isc_result_t
reload(ns_server_t *server) {
isc_result_t result;
CHECK(loadconfig(server));
result = load_zones(server, ISC_FALSE);
if (result != ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
"reloading zones failed: %s",
isc_result_totext(result));
}
cleanup:
return (result);
}
static void
reconfig(ns_server_t *server) {
isc_result_t result;
CHECK(loadconfig(server));
result = load_new_zones(server, ISC_FALSE);
if (result != ISC_R_SUCCESS) {
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
"loading new zones failed: %s",
isc_result_totext(result));
}
cleanup: ;
}
/*
* Handle a reload event (from SIGHUP).
*/
static void
ns_server_reload(isc_task_t *task, isc_event_t *event) {
ns_server_t *server = (ns_server_t *)event->ev_arg;
INSIST(task = server->task);
UNUSED(task);
(void)reload(server);
LOCK(&server->reload_event_lock);
INSIST(server->reload_event == NULL);
server->reload_event = event;
UNLOCK(&server->reload_event_lock);
}
void
ns_server_reloadwanted(ns_server_t *server) {
LOCK(&server->reload_event_lock);
if (server->reload_event != NULL)
isc_task_send(server->task, &server->reload_event);
UNLOCK(&server->reload_event_lock);
}
static char *
next_token(char **stringp, const char *delim) {
char *res;
do {
res = strsep(stringp, delim);
if (res == NULL)
break;
} while (*res == '\0');
return (res);
}
/*
* Find the zone specified in the control channel command 'args',
* if any. If a zone is specified, point '*zonep' at it, otherwise
* set '*zonep' to NULL.
*/
static isc_result_t
zone_from_args(ns_server_t *server, char *args, dns_zone_t **zonep) {
char *input, *ptr;
const char *zonetxt;
char *classtxt;
const char *viewtxt = NULL;
dns_fixedname_t name;
isc_result_t result;
isc_buffer_t buf;
dns_view_t *view = NULL;
dns_rdataclass_t rdclass;
REQUIRE(zonep != NULL && *zonep == NULL);
input = args;
/* Skip the command name. */
ptr = next_token(&input, " \t");
if (ptr == NULL)
return (ISC_R_UNEXPECTEDEND);
/* Look for the zone name. */
zonetxt = next_token(&input, " \t");
if (zonetxt == NULL)
return (ISC_R_SUCCESS);
/* Look for the optional class name. */
classtxt = next_token(&input, " \t");
if (classtxt != NULL) {
/* Look for the optional view name. */
viewtxt = next_token(&input, " \t");
}
isc_buffer_init(&buf, zonetxt, strlen(zonetxt));
isc_buffer_add(&buf, strlen(zonetxt));
dns_fixedname_init(&name);
result = dns_name_fromtext(dns_fixedname_name(&name),
&buf, dns_rootname, ISC_FALSE, NULL);
if (result != ISC_R_SUCCESS)
goto fail1;
if (classtxt != NULL) {
isc_textregion_t r;
r.base = classtxt;
r.length = strlen(classtxt);
result = dns_rdataclass_fromtext(&rdclass, &r);
if (result != ISC_R_SUCCESS)
goto fail1;
} else {
rdclass = dns_rdataclass_in;
}
if (viewtxt == NULL)
viewtxt = "_default";
result = dns_viewlist_find(&server->viewlist, viewtxt,
rdclass, &view);
if (result != ISC_R_SUCCESS)
goto fail1;
result = dns_zt_find(view->zonetable, dns_fixedname_name(&name),
0, NULL, zonep);
/* Partial match? */
if (result != ISC_R_SUCCESS && *zonep != NULL)
dns_zone_detach(zonep);
dns_view_detach(&view);
fail1:
return (result);
}
/*
* Act on a "retransfer" command from the command channel.
*/
isc_result_t
ns_server_retransfercommand(ns_server_t *server, char *args) {
isc_result_t result;
dns_zone_t *zone = NULL;
dns_zonetype_t type;
result = zone_from_args(server, args, &zone);
if (result != ISC_R_SUCCESS)
return (result);
if (zone == NULL)
return (ISC_R_UNEXPECTEDEND);
type = dns_zone_gettype(zone);
if (type == dns_zone_slave || type == dns_zone_stub)
dns_zone_forcereload(zone);
else
result = ISC_R_NOTFOUND;
dns_zone_detach(&zone);
return (result);
}
/*
* Act on a "reload" command from the command channel.
*/
isc_result_t
ns_server_reloadcommand(ns_server_t *server, char *args, isc_buffer_t *text) {
isc_result_t result;
dns_zone_t *zone = NULL;
dns_zonetype_t type;
const char *msg = NULL;
result = zone_from_args(server, args, &zone);
if (result != ISC_R_SUCCESS)
return (result);
if (zone == NULL) {
result = reload(server);
if (result == ISC_R_SUCCESS)
msg = "server reload successful";
} else {
type = dns_zone_gettype(zone);
if (type == dns_zone_slave || type == dns_zone_stub) {
dns_zone_refresh(zone);
msg = "zone refresh queued";
} else {
result = dns_zone_load(zone);
dns_zone_detach(&zone);
switch (result) {
case ISC_R_SUCCESS:
msg = "zone reload successful";
break;
case DNS_R_CONTINUE:
msg = "zone reload queued";
result = ISC_R_SUCCESS;
break;
case DNS_R_UPTODATE:
msg = "zone reload up-to-date";
result = ISC_R_SUCCESS;
break;
default:
/* failure message will be generated by rndc */
break;
}
}
}
if (msg != NULL && strlen(msg) < isc_buffer_availablelength(text))
isc_buffer_putmem(text, (const unsigned char *)msg,
strlen(msg) + 1);
return (result);
}
/*
* Act on a "reconfig" command from the command channel.
*/
isc_result_t
ns_server_reconfigcommand(ns_server_t *server, char *args) {
UNUSED(args);
reconfig(server);
return (ISC_R_SUCCESS);
}
/*
* Act on a "refresh" command from the command channel.
*/
isc_result_t
ns_server_refreshcommand(ns_server_t *server, char *args, isc_buffer_t *text) {
isc_result_t result;
dns_zone_t *zone = NULL;
const unsigned char msg[] = "zone refresh queued";
result = zone_from_args(server, args, &zone);
if (result != ISC_R_SUCCESS)
return (result);
if (zone == NULL)
return (ISC_R_UNEXPECTEDEND);
dns_zone_refresh(zone);
dns_zone_detach(&zone);
if (sizeof(msg) <= isc_buffer_availablelength(text))
isc_buffer_putmem(text, msg, sizeof(msg));
return (ISC_R_SUCCESS);
}
isc_result_t
ns_server_togglequerylog(ns_server_t *server) {
server->log_queries = server->log_queries ? ISC_FALSE : ISC_TRUE;
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
"query logging is now %s",
server->log_queries ? "on" : "off");
return (ISC_R_SUCCESS);
}
static isc_result_t
ns_listenlist_fromconfig(cfg_obj_t *listenlist, cfg_obj_t *config,
ns_aclconfctx_t *actx,
isc_mem_t *mctx, ns_listenlist_t **target)
{
isc_result_t result;
cfg_listelt_t *element;
ns_listenlist_t *dlist = NULL;
REQUIRE(target != NULL && *target == NULL);
result = ns_listenlist_create(mctx, &dlist);
if (result != ISC_R_SUCCESS)
return (result);
for (element = cfg_list_first(listenlist);
element != NULL;
element = cfg_list_next(element))
{
ns_listenelt_t *delt = NULL;
cfg_obj_t *listener = cfg_listelt_value(element);
result = ns_listenelt_fromconfig(listener, config, actx,
mctx, &delt);
if (result != ISC_R_SUCCESS)
goto cleanup;
ISC_LIST_APPEND(dlist->elts, delt, link);
}
*target = dlist;
return (ISC_R_SUCCESS);
cleanup:
ns_listenlist_detach(&dlist);
return (result);
}
/*
* Create a listen list from the corresponding configuration
* data structure.
*/
static isc_result_t
ns_listenelt_fromconfig(cfg_obj_t *listener, cfg_obj_t *config,
ns_aclconfctx_t *actx,
isc_mem_t *mctx, ns_listenelt_t **target)
{
isc_result_t result;
cfg_obj_t *portobj;
in_port_t port;
ns_listenelt_t *delt = NULL;
REQUIRE(target != NULL && *target == NULL);
portobj = cfg_tuple_get(listener, "port");
if (!cfg_obj_isuint32(portobj)) {
if (ns_g_port != 0) {
port = ns_g_port;
} else {
result = ns_config_getport(config, &port);
if (result != ISC_R_SUCCESS)
return (result);
}
} else {
if (cfg_obj_asuint32(portobj) >= ISC_UINT16_MAX) {
cfg_obj_log(portobj, ns_g_lctx, ISC_LOG_ERROR,
"port value '%u' is out of range",
cfg_obj_asuint32(portobj));
return (ISC_R_RANGE);
}
port = (in_port_t)cfg_obj_asuint32(portobj);
}
result = ns_listenelt_create(mctx, port, NULL, &delt);
if (result != ISC_R_SUCCESS)
return (result);
result = ns_acl_fromconfig(cfg_tuple_get(listener, "acl"),
config, actx, mctx, &delt->acl);
if (result != ISC_R_SUCCESS) {
ns_listenelt_destroy(delt);
return (result);
}
*target = delt;
return (ISC_R_SUCCESS);
}
isc_result_t
ns_server_dumpstats(ns_server_t *server) {
isc_result_t result;
dns_zone_t *zone, *next;
isc_stdtime_t now;
FILE *fp = NULL;
int i;
int ncounters;
isc_stdtime_get(&now);
CHECKMF(isc_stdio_open(server->statsfile, "a", &fp),
"could not open statistics dump file", server->statsfile);
ncounters = DNS_STATS_NCOUNTERS;
fprintf(fp, "+++ Statistics Dump +++ (%lu)\n", (unsigned long)now);
for (i = 0; i < ncounters; i++)
fprintf(fp, "%s %" ISC_PRINT_QUADFORMAT "u\n",
dns_statscounter_names[i],
server->querystats[i]);
zone = NULL;
for (result = dns_zone_first(server->zonemgr, &zone);
result == ISC_R_SUCCESS;
next = NULL, result = dns_zone_next(zone, &next), zone = next)
{
isc_uint64_t *zonestats = dns_zone_getstatscounters(zone);
if (zonestats != NULL) {
char zonename[DNS_NAME_FORMATSIZE];
dns_view_t *view;
char *viewname;
dns_name_format(dns_zone_getorigin(zone),
zonename, sizeof(zonename));
view = dns_zone_getview(zone);
viewname = view->name;
for (i = 0; i < ncounters; i++) {
fprintf(fp, "%s %" ISC_PRINT_QUADFORMAT
"u %s",
dns_statscounter_names[i],
zonestats[i],
zonename);
if (strcmp(viewname, "_default") != 0)
fprintf(fp, " %s", viewname);
fprintf(fp, "\n");
}
}
}
if (result == ISC_R_NOMORE)
result = ISC_R_SUCCESS;
CHECK(result);
fprintf(fp, "--- Statistics Dump --- (%lu)\n", (unsigned long)now);
cleanup:
if (fp != NULL)
(void)isc_stdio_close(fp);
return (result);
}
static isc_result_t
add_zone_tolist(dns_zone_t *zone, void *uap) {
struct dumpcontext *dctx = uap;
struct zonelistentry *zle;
zle = isc_mem_get(dctx->mctx, sizeof *zle);
if (zle == NULL)
return (ISC_R_NOMEMORY);
zle->zone = NULL;
dns_zone_attach(zone, &zle->zone);
ISC_LINK_INIT(zle, link);
ISC_LIST_APPEND(ISC_LIST_TAIL(dctx->viewlist)->zonelist, zle, link);
return (ISC_R_SUCCESS);
}
static isc_result_t
add_view_tolist(struct dumpcontext *dctx, dns_view_t *view) {
struct viewlistentry *vle;
isc_result_t result = ISC_R_SUCCESS;
vle = isc_mem_get(dctx->mctx, sizeof *vle);
if (vle == NULL)
return (ISC_R_NOMEMORY);
vle->view = NULL;
dns_view_attach(view, &vle->view);
ISC_LINK_INIT(vle, link);
ISC_LIST_INIT(vle->zonelist);
ISC_LIST_APPEND(dctx->viewlist, vle, link);
if (dctx->dumpzones)
result = dns_zt_apply(view->zonetable, ISC_TRUE,
add_zone_tolist, dctx);
return (result);
}
static void
dumpcontext_destroy(struct dumpcontext *dctx) {
struct viewlistentry *vle;
struct zonelistentry *zle;
vle = ISC_LIST_HEAD(dctx->viewlist);
while (vle != NULL) {
ISC_LIST_UNLINK(dctx->viewlist, vle, link);
zle = ISC_LIST_HEAD(vle->zonelist);
while (zle != NULL) {
ISC_LIST_UNLINK(vle->zonelist, zle, link);
dns_zone_detach(&zle->zone);
isc_mem_put(dctx->mctx, zle, sizeof *zle);
zle = ISC_LIST_HEAD(vle->zonelist);
}
dns_view_detach(&vle->view);
isc_mem_put(dctx->mctx, vle, sizeof *vle);
vle = ISC_LIST_HEAD(dctx->viewlist);
}
if (dctx->version != NULL)
dns_db_closeversion(dctx->db, &dctx->version, ISC_FALSE);
if (dctx->db != NULL)
dns_db_detach(&dctx->db);
if (dctx->cache != NULL)
dns_db_detach(&dctx->cache);
if (dctx->task != NULL)
isc_task_detach(&dctx->task);
if (dctx->fp != NULL)
(void)isc_stdio_close(dctx->fp);
if (dctx->mdctx != NULL)
dns_dumpctx_detach(&dctx->mdctx);
isc_mem_put(dctx->mctx, dctx, sizeof *dctx);
}
static void
dumpdone(void *arg, isc_result_t result) {
struct dumpcontext *dctx = arg;
char buf[1024+32];
const dns_master_style_t *style;
if (result != ISC_R_SUCCESS)
goto cleanup;
if (dctx->mdctx != NULL)
dns_dumpctx_detach(&dctx->mdctx);
if (dctx->view == NULL) {
dctx->view = ISC_LIST_HEAD(dctx->viewlist);
if (dctx->view == NULL)
goto done;
INSIST(dctx->zone == NULL);
}
nextview:
fprintf(dctx->fp, ";\n; Start view %s\n;\n", dctx->view->view->name);
if (dctx->zone == NULL && dctx->cache == NULL && dctx->dumpcache) {
style = &dns_master_style_cache;
/* start cache dump */
if (dctx->view->view->cachedb != NULL)
dns_db_attach(dctx->view->view->cachedb, &dctx->cache);
if (dctx->cache != NULL) {
fprintf(dctx->fp, ";\n; Cache dump of view '%s'\n;\n",
dctx->view->view->name);
result = dns_master_dumptostreaminc(dctx->mctx,
dctx->cache, NULL,
style, dctx->fp,
dctx->task,
dumpdone, dctx,
&dctx->mdctx);
if (result == DNS_R_CONTINUE)
return;
if (result == ISC_R_NOTIMPLEMENTED)
fprintf(dctx->fp, "; %s\n",
dns_result_totext(result));
else if (result != ISC_R_SUCCESS)
goto cleanup;
}
}
if (dctx->cache != NULL) {
dns_adb_dump(dctx->view->view->adb, dctx->fp);
dns_db_detach(&dctx->cache);
}
if (dctx->dumpzones) {
style = &dns_master_style_full;
nextzone:
if (dctx->version != NULL)
dns_db_closeversion(dctx->db, &dctx->version,
ISC_FALSE);
if (dctx->db != NULL)
dns_db_detach(&dctx->db);
if (dctx->zone == NULL)
dctx->zone = ISC_LIST_HEAD(dctx->view->zonelist);
else
dctx->zone = ISC_LIST_NEXT(dctx->zone, link);
if (dctx->zone != NULL) {
/* start zone dump */
dns_zone_name(dctx->zone->zone, buf, sizeof(buf));
fprintf(dctx->fp, ";\n; Zone dump of '%s'\n;\n", buf);
result = dns_zone_getdb(dctx->zone->zone, &dctx->db);
if (result != ISC_R_SUCCESS) {
fprintf(dctx->fp, "; %s\n",
dns_result_totext(result));
goto nextzone;
}
dns_db_currentversion(dctx->db, &dctx->version);
result = dns_master_dumptostreaminc(dctx->mctx,
dctx->db,
dctx->version,
style, dctx->fp,
dctx->task,
dumpdone, dctx,
&dctx->mdctx);
if (result == DNS_R_CONTINUE)
return;
if (result == ISC_R_NOTIMPLEMENTED)
fprintf(dctx->fp, "; %s\n",
dns_result_totext(result));
if (result != ISC_R_SUCCESS)
goto cleanup;
}
}
if (dctx->view != NULL)
dctx->view = ISC_LIST_NEXT(dctx->view, link);
if (dctx->view != NULL)
goto nextview;
done:
fprintf(dctx->fp, "; Dump complete\n");
result = isc_stdio_flush(dctx->fp);
if (result == ISC_R_SUCCESS)
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
"dumpdb complete");
cleanup:
if (result != ISC_R_SUCCESS)
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
"dumpdb failed: %s", dns_result_totext(result));
dumpcontext_destroy(dctx);
}
isc_result_t
ns_server_dumpdb(ns_server_t *server, char *args) {
struct dumpcontext *dctx = NULL;
dns_view_t *view;
isc_result_t result;
char *ptr;
const char *sep;
dctx = isc_mem_get(server->mctx, sizeof(*dctx));
if (dctx == NULL)
return (ISC_R_NOMEMORY);
dctx->mctx = server->mctx;
dctx->dumpcache = ISC_TRUE;
dctx->dumpzones = ISC_FALSE;
dctx->fp = NULL;
ISC_LIST_INIT(dctx->viewlist);
dctx->view = NULL;
dctx->zone = NULL;
dctx->cache = NULL;
dctx->mdctx = NULL;
dctx->db = NULL;
dctx->cache = NULL;
dctx->task = NULL;
dctx->version = NULL;
isc_task_attach(server->task, &dctx->task);
CHECKMF(isc_stdio_open(server->dumpfile, "w", &dctx->fp),
"could not open dump file", server->dumpfile);
/* Skip the command name. */
ptr = next_token(&args, " \t");
if (ptr == NULL)
return (ISC_R_UNEXPECTEDEND);
sep = (args == NULL) ? "" : ": ";
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
"dumpdb started%s%s", sep, (args != NULL) ? args : "");
ptr = next_token(&args, " \t");
if (ptr != NULL && strcmp(ptr, "-all") == 0) {
dctx->dumpzones = ISC_TRUE;
dctx->dumpcache = ISC_TRUE;
ptr = next_token(&args, " \t");
} else if (ptr != NULL && strcmp(ptr, "-cache") == 0) {
dctx->dumpzones = ISC_FALSE;
dctx->dumpcache = ISC_TRUE;
ptr = next_token(&args, " \t");
} else if (ptr != NULL && strcmp(ptr, "-zones") == 0) {
dctx->dumpzones = ISC_TRUE;
dctx->dumpcache = ISC_FALSE;
ptr = next_token(&args, " \t");
}
for (view = ISC_LIST_HEAD(server->viewlist);
view != NULL;
view = ISC_LIST_NEXT(view, link))
{
if (ptr != NULL && strcmp(view->name, ptr) != 0)
continue;
CHECK(add_view_tolist(dctx, view));
}
dumpdone(dctx, ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
cleanup:
if (dctx != NULL)
dumpcontext_destroy(dctx);
return (result);
}
isc_result_t
ns_server_dumprecursing(ns_server_t *server) {
FILE *fp = NULL;
isc_result_t result;
CHECKMF(isc_stdio_open(server->recfile, "w", &fp),
"could not open dump file", server->recfile);
fprintf(fp,";\n; Recursing Queries\n;\n");
ns_interfacemgr_dumprecursing(fp, server->interfacemgr);
fprintf(fp, "; Dump complete\n");
cleanup:
if (fp != NULL)
result = isc_stdio_close(fp);
return (result);
}
isc_result_t
ns_server_setdebuglevel(ns_server_t *server, char *args) {
char *ptr;
char *levelstr;
char *endp;
long newlevel;
UNUSED(server);
/* Skip the command name. */
ptr = next_token(&args, " \t");
if (ptr == NULL)
return (ISC_R_UNEXPECTEDEND);
/* Look for the new level name. */
levelstr = next_token(&args, " \t");
if (levelstr == NULL) {
if (ns_g_debuglevel < 99)
ns_g_debuglevel++;
} else {
newlevel = strtol(levelstr, &endp, 10);
if (*endp != '\0' || newlevel < 0 || newlevel > 99)
return (ISC_R_RANGE);
ns_g_debuglevel = (unsigned int)newlevel;
}
isc_log_setdebuglevel(ns_g_lctx, ns_g_debuglevel);
return (ISC_R_SUCCESS);
}
isc_result_t
ns_server_flushcache(ns_server_t *server, char *args) {
char *ptr, *viewname;
dns_view_t *view;
isc_boolean_t flushed = ISC_FALSE;
isc_result_t result;
/* Skip the command name. */
ptr = next_token(&args, " \t");
if (ptr == NULL)
return (ISC_R_UNEXPECTEDEND);
/* Look for the view name. */
viewname = next_token(&args, " \t");
result = isc_task_beginexclusive(server->task);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
for (view = ISC_LIST_HEAD(server->viewlist);
view != NULL;
view = ISC_LIST_NEXT(view, link))
{
if (viewname != NULL && strcasecmp(viewname, view->name) != 0)
continue;
result = dns_view_flushcache(view);
if (result != ISC_R_SUCCESS)
goto out;
flushed = ISC_TRUE;
}
if (flushed)
result = ISC_R_SUCCESS;
else
result = ISC_R_FAILURE;
out:
isc_task_endexclusive(server->task);
return (result);
}
isc_result_t
ns_server_flushname(ns_server_t *server, char *args) {
char *ptr, *target, *viewname;
dns_view_t *view;
isc_boolean_t flushed = ISC_FALSE;
isc_result_t result;
isc_buffer_t b;
dns_fixedname_t fixed;
dns_name_t *name;
/* Skip the command name. */
ptr = next_token(&args, " \t");
if (ptr == NULL)
return (ISC_R_UNEXPECTEDEND);
/* Find the domain name to flush. */
target = next_token(&args, " \t");
if (target == NULL)
return (ISC_R_UNEXPECTEDEND);
isc_buffer_init(&b, target, strlen(target));
isc_buffer_add(&b, strlen(target));
dns_fixedname_init(&fixed);
name = dns_fixedname_name(&fixed);
result = dns_name_fromtext(name, &b, dns_rootname, ISC_FALSE, NULL);
if (result != ISC_R_SUCCESS)
return (result);
/* Look for the view name. */
viewname = next_token(&args, " \t");
result = isc_task_beginexclusive(server->task);
RUNTIME_CHECK(result == ISC_R_SUCCESS);
flushed = ISC_TRUE;
for (view = ISC_LIST_HEAD(server->viewlist);
view != NULL;
view = ISC_LIST_NEXT(view, link))
{
if (viewname != NULL && strcasecmp(viewname, view->name) != 0)
continue;
result = dns_view_flushname(view, name);
if (result != ISC_R_SUCCESS)
flushed = ISC_FALSE;
}
if (flushed)
result = ISC_R_SUCCESS;
else
result = ISC_R_FAILURE;
isc_task_endexclusive(server->task);
return (result);
}
isc_result_t
ns_server_status(ns_server_t *server, isc_buffer_t *text) {
int zonecount, xferrunning, xferdeferred, soaqueries;
unsigned int n;
zonecount = dns_zonemgr_getcount(server->zonemgr, DNS_ZONESTATE_ANY);
xferrunning = dns_zonemgr_getcount(server->zonemgr,
DNS_ZONESTATE_XFERRUNNING);
xferdeferred = dns_zonemgr_getcount(server->zonemgr,
DNS_ZONESTATE_XFERDEFERRED);
soaqueries = dns_zonemgr_getcount(server->zonemgr,
DNS_ZONESTATE_SOAQUERY);
n = snprintf((char *)isc_buffer_used(text),
isc_buffer_availablelength(text),
"number of zones: %u\n"
"debug level: %d\n"
"xfers running: %u\n"
"xfers deferred: %u\n"
"soa queries in progress: %u\n"
"query logging is %s\n"
"recursive clients: %d/%d\n"
"tcp clients: %d/%d\n"
"server is up and running",
zonecount, ns_g_debuglevel, xferrunning, xferdeferred,
soaqueries, server->log_queries ? "ON" : "OFF",
server->recursionquota.used, server->recursionquota.max,
server->tcpquota.used, server->tcpquota.max);
if (n >= isc_buffer_availablelength(text))
return (ISC_R_NOSPACE);
isc_buffer_add(text, n);
return (ISC_R_SUCCESS);
}
/*
* Act on a "freeze" or "unfreeze" command from the command channel.
*/
isc_result_t
ns_server_freeze(ns_server_t *server, isc_boolean_t freeze, char *args) {
isc_result_t result;
dns_zone_t *zone = NULL;
dns_zonetype_t type;
char classstr[DNS_RDATACLASS_FORMATSIZE];
char zonename[DNS_NAME_FORMATSIZE];
dns_view_t *view;
char *journal;
const char *vname, *sep;
isc_boolean_t frozen;
result = zone_from_args(server, args, &zone);
if (result != ISC_R_SUCCESS)
return (result);
if (zone == NULL)
return (ISC_R_UNEXPECTEDEND);
type = dns_zone_gettype(zone);
if (type != dns_zone_master) {
dns_zone_detach(&zone);
return (ISC_R_NOTFOUND);
}
frozen = dns_zone_getupdatedisabled(zone);
if (freeze) {
if (frozen)
result = DNS_R_FROZEN;
if (result == ISC_R_SUCCESS)
result = dns_zone_flush(zone);
if (result == ISC_R_SUCCESS) {
journal = dns_zone_getjournal(zone);
if (journal != NULL)
(void)isc_file_remove(journal);
}
} else {
if (frozen) {
result = dns_zone_load(zone);
if (result == DNS_R_CONTINUE ||
result == DNS_R_UPTODATE)
result = ISC_R_SUCCESS;
}
}
if (result == ISC_R_SUCCESS)
dns_zone_setupdatedisabled(zone, freeze);
view = dns_zone_getview(zone);
if (strcmp(view->name, "_bind") == 0 ||
strcmp(view->name, "_default") == 0)
{
vname = "";
sep = "";
} else {
vname = view->name;
sep = " ";
}
dns_rdataclass_format(dns_zone_getclass(zone), classstr,
sizeof(classstr));
dns_name_format(dns_zone_getorigin(zone),
zonename, sizeof(zonename));
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
"%s zone '%s/%s'%s%s: %s",
freeze ? "freezing" : "unfreezing",
zonename, classstr, sep, vname,
isc_result_totext(result));
dns_zone_detach(&zone);
return (result);
}