server.c revision 2e097e67d87630bbefb5c1b0bea6f1bc8b2ec86d
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff/*
ee980d3fc4c23b7f87fed96d3ba5e928937c9ed4Tinderbox User * Copyright (C) 1999, 2000 Internet Software Consortium.
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * copyright notice and this permission notice appear in all copies.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * SOFTWARE.
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff */
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
23daf8948b2e5462ccea082a441e9759dffa50cdMark Andrews#include <config.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <sys/stat.h>
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence#include <fcntl.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <errno.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <stdio.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <stdlib.h>
07072c9456f1112705db701bb35f12dbdcb217b0Mark Andrews#include <unistd.h>
07072c9456f1112705db701bb35f12dbdcb217b0Mark Andrews#include <string.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <stdarg.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
80617c8faa03b2c425e320597eb768073fd0b987Michael Graff#include <isc/app.h>
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff#include <isc/assertions.h>
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#include <isc/dir.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <isc/error.h>
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#include <isc/mem.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <isc/result.h>
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt#include <isc/rwlock.h>
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉#include <isc/socket.h>
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence#include <isc/task.h>
32eddfc189108fa93e31761e13150594c7a79d2bDavid Lawrence#include <isc/thread.h>
a095cd0ef599eb04d74fb9f9bc46ae13081c5bcbMark Andrews#include <isc/timer.h>
440be4c866f6935ac069db79a414304507a664c2Michael Graff#include <isc/util.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington#include <dns/acl.h>
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff#include <dns/aclconf.h>
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff#include <dns/cache.h>
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff#include <dns/confacl.h>
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff#include <dns/confctx.h>
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews#include <dns/confip.h>
8907d8fa04fdaa65baf0bc6b01230b2ebde93106Mark Andrews#include <dns/confparser.h>
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff#include <dns/db.h>
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#include <dns/dispatch.h>
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#include <dns/fixedname.h>
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews#include <dns/journal.h>
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews#include <dns/master.h>
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews#include <dns/name.h>
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉#include <dns/rdata.h>
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉#include <dns/resolver.h>
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews#include <dns/result.h>
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews#include <dns/rootns.h>
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews#include <dns/tkeyconf.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <dns/tsigconf.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <dns/types.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <dns/view.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <dns/zone.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <dns/zoneconf.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <named/client.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <named/globals.h>
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <named/interfacemgr.h>
07072c9456f1112705db701bb35f12dbdcb217b0Mark Andrews#include <named/listenlist.h>
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews#include <named/log.h>
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews#include <named/logconf.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <named/os.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein#include <named/server.h>
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews#include <named/types.h>
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉/*
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews * Check an operation for failure. Assumes that the function
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews * using it has a 'result' variable and a 'cleanup' label.
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff#define CHECK(op) \
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff do { result = (op); \
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (result != ISC_R_SUCCESS) goto cleanup; \
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington } while (0)
b312748a11d27fe387984973ba79975a9d6863c4Mark Andrews
d9059b0c38bd630c367d81424d72b1308cd74b04Tatuya JINMEI 神明達哉#define CHECKM(op, msg) \
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 do { result = (op); \
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (result != ISC_R_SUCCESS) { \
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_log_write(ns_g_lctx, \
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff NS_LOGCATEGORY_GENERAL, \
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff NS_LOGMODULE_SERVER, \
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff ISC_LOG_ERROR, \
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews "%s: %s", msg, \
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_totext(result)); \
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 goto cleanup; \
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } \
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } while (0) \
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews#define CHECKFATAL(op, msg) \
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews do { result = (op); \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein if (result != ISC_R_SUCCESS) \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein fatal(msg, result); \
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein } while (0) \
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Grafftypedef struct {
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt isc_mem_t * mctx;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_viewlist_t viewlist;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_aclconfctx_t *aclconf;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt} ns_load_t;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austeinstatic void fatal(char *msg, isc_result_t result);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Huntstatic void ns_server_reload(isc_task_t *task, isc_event_t *event);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Huntstatic isc_result_t
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Huntns_listenelt_fromconfig(dns_c_lstnon_t *celt, dns_c_ctx_t *cctx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_aclconfctx_t *actx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mem_t *mctx, ns_listenelt_t **target);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉ns_listenlist_fromconfig(dns_c_lstnlist_t *clist, dns_c_ctx_t *cctx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_aclconfctx_t *actx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mem_t *mctx, ns_listenlist_t **target);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Configure a single view ACL at '*aclp'. Get its configuration by
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * calling 'getvcacl' (for per-view configuration) and maybe 'getscacl'
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * (for a global default).
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉configure_view_acl(dns_c_view_t *cview,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_c_ctx_t *cctx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_aclconfctx_t *actx, isc_mem_t *mctx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_t (*getvcacl)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (dns_c_view_t *, dns_c_ipmatchlist_t **),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_t (*getscacl)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (dns_c_ctx_t *, dns_c_ipmatchlist_t **),
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff dns_acl_t **aclp)
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff{
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_result_t result;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff dns_c_ipmatchlist_t *cacl = NULL;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (*aclp != NULL)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_acl_detach(aclp);
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff if (getvcacl != NULL && cview != NULL)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff (void) (*getvcacl)(cview, &cacl);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (cacl == NULL && getscacl != NULL)
038a3e6bfe6e15479b0469bd87de3a7139ad1109Brian Wellington (void) (*getscacl)(cctx, &cacl);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (cacl == NULL) {
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff /* No value available. *aclp == NULL. */
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff return (ISC_R_SUCCESS);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff }
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff result = dns_acl_fromconfig(cacl, cctx, actx, mctx, aclp);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_c_ipmatchlist_detach(&cacl);
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Configure 'view' according to 'cctx'.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉configure_view(dns_view_t *view, dns_c_ctx_t *cctx, dns_c_view_t *cview,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_mem_t *mctx, dns_aclconfctx_t *actx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉{
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_cache_t *cache = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_t result;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_int32_t cleaning_interval;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_tsig_keyring_t *ring;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_c_forw_t forward;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_c_iplist_t *forwarders;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_fwdpolicy_t fwdpolicy;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_sockaddrlist_t addresses;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_sockaddr_t *sa, *next_sa;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_t *pview = NULL; /* Production view */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 unsigned int i;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 REQUIRE(DNS_VIEW_VALID(view));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LIST_INIT(addresses);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 RWLOCK(&view->conflock, isc_rwlocktype_write);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews /*
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * Configure the view's cache. Try to reuse an existing
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * cache if possible, otherwise create a new cache.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Note that the ADB is not preserved in either case.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 * XXX Determining when it is safe to reuse a cache is
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 * tricky. When the view's configuration changes, the cached
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * data may become invalid because it reflects our old
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff * view of the world. As more view attributes become
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * configurable, we will have to add code here to check
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * whether they have changed in ways that could
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * invalidate the cache.
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews */
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews result = dns_viewlist_find(&ns_g_server->viewlist,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews view->name, view->rdclass,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews &pview);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews goto cleanup;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews if (pview != NULL) {
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews INSIST(pview->cache != NULL);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews NS_LOGMODULE_SERVER,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews ISC_LOG_DEBUG(3), "reusing existing cache");
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews dns_cache_attach(pview->cache, &cache);
607dc8013a8cb34cd03b59292aa1ac01e008c9c1Michael Graff dns_view_detach(&pview);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(dns_cache_create(mctx, ns_g_taskmgr, ns_g_timermgr,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 view->rdclass, "rbt", 0, NULL, &cache));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_setcache(view, cache);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 cleaning_interval = 3600; /* Default is 1 hour. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (void) dns_c_ctx_getcleaninterval(cctx, &cleaning_interval);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_cache_setcleaninginterval(cache, cleaning_interval);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff dns_cache_detach(&cache);
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein /*
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * XXXRTH Temporary support for loading cache contents.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (ns_g_cachefile != NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NS_LOGMODULE_SERVER,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LOG_DEBUG(1), "loading cache '%s'",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_g_cachefile);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(dns_db_load(view->cachedb, ns_g_cachefile));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein }
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Resolver.
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington *
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * XXXRTH Hardwired number of tasks.
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt */
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt CHECK(dns_view_createresolver(view, ns_g_taskmgr, 31,
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt ns_g_socketmgr, ns_g_timermgr,
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein 0, dispatchv4, dispatchv6));
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff /*
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff * Set resolver forwarding policy.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein */
ce5bd92088923d1c76e26d313d1d8c0b8bbe38feMichael Graff if (dns_c_ctx_getforwarders(cctx, &forwarders) == ISC_R_SUCCESS) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff fwdpolicy = dns_fwdpolicy_first;
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein /*
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * Ugh. Convert between list formats.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff for (i = 0; i < forwarders->nextidx; i++) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff sa = isc_mem_get(view->mctx, sizeof *sa);
f98d6edb191348477c9c5a156003df627d9bc42cBrian Wellington if (sa == NULL) {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein result = ISC_R_NOMEMORY;
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff goto cleanup;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *sa = forwarders->ips[i];
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_sockaddr_setport(sa, 53);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ISC_LINK_INIT(sa, link);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein ISC_LIST_APPEND(addresses, sa, link);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein }
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews INSIST(!ISC_LIST_EMPTY(addresses));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_c_iplist_detach(&forwarders);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews CHECK(dns_resolver_setforwarders(view->resolver, &addresses));
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews /*
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * XXXRTH The configuration type 'dns_c_forw_t' should be
83f8c56f43852bf9a9c6964eae285284b23f9d8dMichael Graff * elminated.
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews */
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews if (dns_c_ctx_getforward(cctx, &forward) == ISC_R_SUCCESS) {
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews INSIST(forward == dns_c_forw_first ||
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff forward == dns_c_forw_only);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (forward == dns_c_forw_only)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff fwdpolicy = dns_fwdpolicy_only;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(dns_resolver_setfwdpolicy(view->resolver, fwdpolicy));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff /*
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff * We have default hints for class IN if we need them.
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff if (view->rdclass == dns_rdataclass_in && view->hints == NULL)
a8dcebd0419f27234664e89b9cd48bc54cad08a7Michael Graff dns_view_sethints(view, ns_g_server->in_roothints);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * If we still have no hints, this is a non-IN view with no
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * "hints zone" configured. That's an error.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (view->hints == NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "no root hints for view '%s'", cview->name);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = ISC_R_FAILURE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 goto cleanup;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Configure the view's TSIG keys.
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff */
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence ring = NULL;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff CHECK(dns_tsigkeyring_fromconfig(cctx, view->mctx, &ring));
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 dns_view_setkeyring(view, ring);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff /*
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington * Configure the view's peer list.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_peerlist_t *newpeers = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (cctx->peers != NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_peerlist_attach(cctx->peers, &newpeers);
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(dns_peerlist_new(mctx, &newpeers));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_peerlist_detach(&view->peers);
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff view->peers = newpeers; /* Transfer ownership. */
8470db5b12c18cfb32a757e265ce4e7789052c92Michael Graff }
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt /*
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews * Configure the "match-clients" ACL.
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews */
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews CHECK(configure_view_acl(cview, cctx, actx, ns_g_mctx,
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff dns_c_view_getmatchclients, NULL,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff &view->matchclients));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Configure other configurable data.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt view->recursion = ISC_TRUE;
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt (void) dns_c_ctx_getrecursion(cctx, &view->recursion);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (cview != NULL)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff (void) dns_c_view_getrecursion(cview, &view->recursion);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff view->auth_nxdomain = ISC_FALSE; /* Was true in BIND 8 */
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff (void) dns_c_ctx_getauthnxdomain(cctx, &view->auth_nxdomain);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (cview != NULL)
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt (void) dns_c_view_getauthnxdomain(cview, &view->auth_nxdomain);
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff view->transfer_format = dns_one_answer;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff (void) dns_c_ctx_gettransferformat(cctx, &view->transfer_format);
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews if (cview != NULL)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (void) dns_c_view_gettransferformat(cview, &view->transfer_format);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews CHECK(configure_view_acl(cview, cctx, actx, ns_g_mctx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_c_view_getallowquery,
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt dns_c_ctx_getallowquery,
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt &view->queryacl));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(configure_view_acl(cview, cctx, actx, ns_g_mctx,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_c_view_getrecursionacl,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_c_ctx_getallowrecursion,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff &view->recursionacl));
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson cleanup:
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson RWUNLOCK(&view->conflock, isc_rwlocktype_write);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff for (sa = ISC_LIST_HEAD(addresses);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff sa != NULL;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff sa = next_sa) {
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff next_sa = ISC_LIST_NEXT(sa, link);
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington isc_mem_put(view->mctx, sa, sizeof *sa);
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington }
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff return (result);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff}
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff/*
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * Create the special view that handles queries for
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * "version.bind. CH". The version string returned is that
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * configured in 'configctx', or a compiled-in default if
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff * there is no "version" configuration option.
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff */
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrewsstatic isc_result_t
870a748bae74b9c4b264da96cfbcb4e90d7a2c1dMark Andrewscreate_version_view(dns_c_ctx_t *configctx, dns_view_t **viewp) {
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews isc_result_t result;
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews dns_db_t *db = NULL;
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews dns_zone_t *zone = NULL;
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews dns_dbversion_t *dbver = NULL;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson dns_difftuple_t *tuple = NULL;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson dns_diff_t diff;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson dns_view_t *view = NULL;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson char *versiontext;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff unsigned char buf[256];
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff isc_region_t r;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff size_t len;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_rdata_t rdata;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff static unsigned char origindata[] = "\007version\004bind";
9317787889b6d2437b2f8e77583b49246f7511feAndreas Gustafsson dns_name_t origin;
9317787889b6d2437b2f8e77583b49246f7511feAndreas Gustafsson
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence REQUIRE(viewp != NULL && *viewp == NULL);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_diff_init(ns_g_mctx, &diff);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_name_init(&origin, NULL);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff r.base = origindata;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff r.length = sizeof(origindata);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_name_fromregion(&origin, &r);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff (void) dns_c_ctx_getversion(configctx, &versiontext);
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson if (versiontext == NULL)
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson versiontext = ns_g_version;
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson len = strlen(versiontext);
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson if (len > 255)
76c8294c81fb48b1da6e1fc5b83322a4cedb8e58Andreas Gustafsson len = 255; /* Silently truncate. */
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff buf[0] = len;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff memcpy(buf + 1, versiontext, len);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff r.base = buf;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff r.length = 1 + len;
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff dns_rdata_fromregion(&rdata, dns_rdataclass_ch, dns_rdatatype_txt, &r);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff CHECK(dns_zone_create(&zone, ns_g_mctx));
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington CHECK(dns_zone_setorigin(zone, &origin));
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington
f6579931b38b357013736ce3efc79a34480af5ceBrian Wellington CHECK(dns_db_create(ns_g_mctx, "rbt", &origin, ISC_FALSE,
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff dns_rdataclass_ch, 0, NULL, &db));
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff CHECK(dns_db_newversion(db, &dbver));
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff CHECK(dns_difftuple_create(ns_g_mctx, DNS_DIFFOP_ADD, &origin,
f3ca27e9fe307b55e35ea8d7b37351650630e5a3Andreas Gustafsson 0, &rdata, &tuple));
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_diff_append(&diff, &tuple);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff CHECK(dns_diff_apply(&diff, db, dbver));
ec46482ef3c0c3e9747f0074cb9263adb8aef961Andreas Gustafsson
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff dns_db_closeversion(db, &dbver, ISC_TRUE);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff CHECK(dns_view_create(ns_g_mctx, dns_rdataclass_ch, "_version",
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff &view));
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff CHECK(dns_zone_replacedb(zone, db, ISC_FALSE));
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff CHECK(dns_view_addzone(view, zone));
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_freeze(view);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 /* Transfer ownership. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *viewp = view;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 view = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = ISC_R_SUCCESS;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 cleanup:
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (view != NULL)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_detach(&view);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (zone != NULL)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_zone_detach(&zone);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (dbver != NULL)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_db_closeversion(db, &dbver, ISC_FALSE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (db != NULL)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_db_detach(&db);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_diff_clear(&diff);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉static isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉configure_hints(dns_view_t *view, const char *filename) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_result_t result;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 dns_db_t *db;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 db = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_rootns_create(view->mctx, view->rdclass, filename, &db);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result == ISC_R_SUCCESS) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_sethints(view, db);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_db_detach(&db);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Find an existing view matching the name and class of 'cview'
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * in 'viewlist', or create a new one and add it to the list.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * If 'cview' is NULL, find or create the default view.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 *
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * The view found or created is attached to '*viewp'.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉find_or_create_view(dns_c_view_t *cview, dns_viewlist_t *viewlist,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_t **viewp)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉{
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_t result;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char *viewname;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_rdataclass_t viewclass;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_t *view = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (cview != NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 viewname = cview->name;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_c_view_getviewclass(cview, &viewclass);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 viewname = "_default";
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 viewclass = dns_rdataclass_in;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews result = dns_viewlist_find(viewlist, viewname,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 viewclass, &view);
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews if (result == ISC_R_SUCCESS) {
281bab0f36eaedc56f859721fbdf45568b71cd60Mark Andrews *viewp = view;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_NOTFOUND)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 INSIST(view == NULL);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_view_create(ns_g_mctx, viewclass, viewname, &view);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LIST_APPEND(*viewlist, view, link);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_attach(view, viewp);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Configure or reconfigure a zone. This callback function
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * is called after parsing each "zone" statement in named.conf.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉configure_zone(dns_c_ctx_t *cctx, dns_c_zone_t *czone, dns_c_view_t *cview,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 void *uap)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉{
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_load_t *lctx = (ns_load_t *) uap;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_t *view = NULL; /* New view */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_view_t *pview = NULL; /* Production view */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_zone_t *zone = NULL; /* New or reused zone */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_zone_t *tzone = NULL; /* Temporary zone */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_t result;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char *corigin;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_buffer_t buffer;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_fixedname_t fixorigin;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_name_t *origin;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Get the zone origin as a dns_name_t.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 corigin = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /* XXX casting away const */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(dns_c_zone_getname(czone, (const char **) &corigin));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_buffer_init(&buffer, corigin, strlen(corigin),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_BUFFERTYPE_TEXT);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_buffer_add(&buffer, strlen(corigin));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_fixedname_init(&fixorigin);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(dns_name_fromtext(dns_fixedname_name(&fixorigin),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 &buffer, dns_rootname, ISC_FALSE, NULL));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 origin = dns_fixedname_name(&fixorigin);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Find or create the view in the new view list.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 view = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(find_or_create_view(cview, &lctx->viewlist, &view));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (czone->zclass != view->rdclass) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "zone '%s': wrong class for view '%s'",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 corigin, cview ? cview->name : "<default view>");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = ISC_R_FAILURE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 goto cleanup;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 /*
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Master zones must have 'file' set.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (czone->ztype == dns_c_zone_master &&
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 czone->u.mzone.file == NULL) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 "zone '%s': 'file' not specified",
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 corigin);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = ISC_R_FAILURE;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 goto cleanup;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 /*
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * "hints zones" aren't zones. If we've got one,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * configure it and return.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (czone->ztype == dns_c_zone_hint) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (czone->u.hzone.file == NULL) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 "zone '%s': 'file' not specified",
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 corigin);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = ISC_R_FAILURE;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 goto cleanup;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (dns_name_equal(origin, dns_rootname)) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = configure_hints(view, czone->u.hzone.file);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "ignoring non-root hint zone '%s'",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 corigin);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = ISC_R_SUCCESS;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 goto cleanup;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * "stub zones" aren't zones either. Eventually we'll
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * create a "cache freshener" to keep the stub data in the
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * cache.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (czone->ztype == dns_c_zone_stub) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "stub zone '%s': stub zones are not supported in this release",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 corigin);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = ISC_R_SUCCESS;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 goto cleanup;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * "forward zones" aren't zones either. Eventually we'll
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * translate this syntax into the appropriate selective forwarding
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * configuration.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (czone->ztype == dns_c_zone_forward) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
0a9fedafec59fd3ec2eeadc3f123db163e71c0fbMichael Graff NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "forward zone '%s': forward zones are not supported in this release",
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff corigin);
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff result = ISC_R_SUCCESS;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff goto cleanup;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Check for duplicates in the new zone table.
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff */
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff result = dns_view_findzone(view, origin, &tzone);
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff if (result == ISC_R_SUCCESS) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews * We already have this zone!
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff */
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews result = ISC_R_EXISTS;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff goto cleanup;
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff }
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff
0941f35ad9b4f48a5324af405a730c3cb3e0aad8Michael Graff /*
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson * See if we can reuse an existing zone. This is
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson * only possible if all of these are true:
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson * - The zone's view exists
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * - A zone with the right name exists in the view
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews * - The zone is compatible with the config
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * options (e.g., an existing master zone cannot
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * be reused if the options specify a slave zone)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = dns_viewlist_find(&ns_g_server->viewlist,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff view->name, view->rdclass,
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews &pview);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (pview != NULL)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = dns_view_findzone(pview, origin, &zone);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff goto cleanup;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (zone != NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (! dns_zone_reusable(zone, czone))
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_zone_detach(&zone);
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson }
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson /*
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson * If we cannot reuse an existing zone, we will have to
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * create a new one.
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff if (zone == NULL) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff CHECK(dns_zone_create(&zone, lctx->mctx));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff CHECK(dns_zone_setorigin(zone, origin));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff CHECK(dns_zonemgr_managezone(ns_g_server->zonemgr,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff zone));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /*
c17c59662f0969a5e52e8b7529cbde1a7c746095Andreas Gustafsson * Configure the zone.
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews */
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews CHECK(dns_zone_configure(cctx, cview, czone, lctx->aclconf, zone));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * Add the zone to its view in the new view list.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff CHECK(dns_view_addzone(view, zone));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff cleanup:
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (tzone != NULL)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_zone_detach(&tzone);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (zone != NULL)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_zone_detach(&zone);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (pview != NULL)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_view_detach(&pview);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff if (view != NULL)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff dns_view_detach(&view);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff return (result);
f98d6edb191348477c9c5a156003df627d9bc42cBrian Wellington}
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Configure a single server quota.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static void
46993e1d9d18410a5852b7d990338b70b158855cMichael Graffconfigure_server_quota(dns_c_ctx_t *cctx,
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff isc_result_t (*getquota)(dns_c_ctx_t *, isc_int32_t *),
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff isc_quota_t *quota, int defaultvalue)
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff{
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff isc_int32_t val = defaultvalue;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff (void)(*getquota)(cctx, &val);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff quota->max = val;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff}
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
46993e1d9d18410a5852b7d990338b70b158855cMichael Graffstatic isc_result_t
46993e1d9d18410a5852b7d990338b70b158855cMichael Graffconfigure_server_querysource(dns_c_ctx_t *cctx, ns_server_t *server, int af,
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff dns_dispatch_t **dispatchp) {
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_result_t result;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington struct in_addr ina;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff isc_sockaddr_t sa, any4, any6, *any;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington isc_socket_t *socket;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington dns_dispatch_t **server_dispatchp;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_sockaddr_t *server_dispatchaddr;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff /*
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington * Make compiler happy.
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington */
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington result = ISC_R_FAILURE;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington any = NULL;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington server_dispatchp = NULL;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff server_dispatchaddr = NULL;
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington ina.s_addr = htonl(INADDR_ANY);
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff isc_sockaddr_fromin(&any4, &ina, 0);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_sockaddr_fromin6(&any6, &in6addr_any, 0);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff *dispatchp = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff switch (af) {
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt case AF_INET:
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt any = &any4;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt result = dns_c_ctx_getquerysource(cctx, &sa);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt break;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt case AF_INET6:
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 any = &any6;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = dns_c_ctx_getquerysourcev6(cctx, &sa);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 break;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 default:
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 INSIST(0);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 sa = *any;
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington
04458c8b5da001294e820289b34bf3aee6258f27Michael Graff INSIST(isc_sockaddr_pf(&sa) == af);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington /*
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington * If we don't support this address family, we're done!
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington */
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington switch (af) {
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington case AF_INET:
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff result = isc_net_probeipv4();
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff break;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews case AF_INET6:
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews result = isc_net_probeipv6();
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews break;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews default:
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews INSIST(0);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews }
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews if (result != ISC_R_SUCCESS)
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews return (ISC_R_SUCCESS);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews if (isc_sockaddr_equal(&sa, any)) {
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews /*
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * The query source is fully wild. No special dispatcher
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * work needs to be done.
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews */
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews return (ISC_R_SUCCESS);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews }
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews /*
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * If the interface manager has a dispatcher for this address,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * use it.
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews */
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews switch (af) {
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews case AF_INET:
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews server_dispatchp = &server->querysrc_dispatchv4;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews server_dispatchaddr = &server->querysrc_addressv4;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews break;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews case AF_INET6:
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews server_dispatchp = &server->querysrc_dispatchv6;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews server_dispatchaddr = &server->querysrc_addressv6;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews break;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews default:
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews INSIST(0);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews }
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews if (ns_interfacemgr_findudpdispatcher(server->interfacemgr, &sa,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews dispatchp) !=
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews ISC_R_SUCCESS) {
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews /*
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * The interface manager doesn't have a matching dispatcher.
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews */
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews if (*server_dispatchp != NULL) {
cfc22e53a89ccac4eb04b4f41a93f73e629e80edEvan Hunt /*
cfc22e53a89ccac4eb04b4f41a93f73e629e80edEvan Hunt * We've already got a custom dispatcher. If it is
cfc22e53a89ccac4eb04b4f41a93f73e629e80edEvan Hunt * compatible with the new configuration, use it.
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews */
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews if (isc_sockaddr_equal(server_dispatchaddr,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews &sa)) {
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_dispatch_attach(*server_dispatchp,
536e36ac8d3c31cd9d61cfa12496177ce263145aMark Andrews dispatchp);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews return (ISC_R_SUCCESS);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews }
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews /*
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * The existing custom dispatcher is not compatible.
cfc22e53a89ccac4eb04b4f41a93f73e629e80edEvan Hunt * We don't need it anymore.
cfc22e53a89ccac4eb04b4f41a93f73e629e80edEvan Hunt */
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews dns_dispatch_detach(server_dispatchp);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt }
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt /*
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt * Create a custom dispatcher.
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt */
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews INSIST(*server_dispatchp == NULL);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews *server_dispatchaddr = sa;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews socket = NULL;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews result = isc_socket_create(ns_g_socketmgr, af,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews isc_sockettype_udp,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews &socket);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews if (result != ISC_R_SUCCESS)
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews return (result);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews result = isc_socket_bind(socket, &sa);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS) {
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 isc_socket_detach(&socket);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 return (result);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 }
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 result = dns_dispatch_create(ns_g_mctx, socket,
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 server->task, 4096,
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 1000, 32768, 16411, 16433, NULL,
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 server_dispatchp);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 /*
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 * Regardless of whether dns_dispatch_create() succeeded or
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 * failed, we don't need to keep the reference to the socket.
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 */
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 isc_socket_detach(&socket);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 return (result);
2b2fc9b4df2db5686126c9eb56973b0af0c109e5Automatic Updater dns_dispatch_attach(*server_dispatchp, dispatchp);
cfc22e53a89ccac4eb04b4f41a93f73e629e80edEvan Hunt } else {
cfc22e53a89ccac4eb04b4f41a93f73e629e80edEvan Hunt /*
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 * We're sharing a UDP dispatcher with the interface manager
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 * now. Any prior custom dispatcher can be discarded.
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 */
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 if (*server_dispatchp != NULL)
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 dns_dispatch_detach(server_dispatchp);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 }
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * This function is called as soon as the 'options' statement has been
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * parsed.
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt */
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Huntstatic isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉options_callback(dns_c_ctx_t *cctx, void *uap) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_t result;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 UNUSED(uap);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Change directory.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 if (cctx->options != NULL &&
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 cctx->options->directory != NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_dir_chdir(cctx->options->directory);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS) {
089f456eb39d614cb6904107d4a9580ed4f3f296Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews NS_LOGMODULE_SERVER,
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt ISC_LOG_ERROR, "change directory "
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "to '%s' failed: %s",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 cctx->options->directory,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_totext(result));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static void
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉scan_interfaces(ns_server_t *server) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_interfacemgr_scan(server->interfacemgr);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_aclenv_copy(&server->aclenv,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_interfacemgr_getaclenv(server->interfacemgr));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉/*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * This event callback is invoked to do periodic network
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * interface scanning.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static void
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉interface_timer_tick(isc_task_t *task, isc_event_t *event) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_server_t *server = (ns_server_t *) event->arg;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews UNUSED(task);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_event_free(&event);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 RWLOCK(&server->conflock, isc_rwlocktype_write);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 scan_interfaces(server);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 RWUNLOCK(&server->conflock, isc_rwlocktype_write);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static isc_result_t
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉load_configuration(const char *filename, ns_server_t *server,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_boolean_t first_time)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉{
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_t result;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_load_t lctx;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_c_cbks_t callbacks;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_c_ctx_t *configctx;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_view_t *view = NULL;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_view_t *view_next;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_viewlist_t tmpviewlist;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 dns_aclconfctx_t aclconfctx;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_dispatch_t *dispatchv4 = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_dispatch_t *dispatchv6 = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 char *pidfilename;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt isc_int32_t interface_interval;
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_aclconfctx_init(&aclconfctx);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 RWLOCK(&server->conflock, isc_rwlocktype_write);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_zonemgr_lockconf(server->zonemgr, isc_rwlocktype_write);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
089f456eb39d614cb6904107d4a9580ed4f3f296Tatuya JINMEI 神明達哉 lctx.mctx = ns_g_mctx;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews lctx.aclconf = &aclconfctx;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt ISC_LIST_INIT(lctx.viewlist);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews callbacks.zonecbk = configure_zone;
f07b2fccaf6be13d9440d323e9e79ee84fe345e2Evan Hunt callbacks.zonecbkuap = &lctx;
2f17ad4545ca552c92c88f7cb1e2525050c10c67Automatic Updater callbacks.optscbk = options_callback;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews callbacks.optscbkuap = NULL;
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews ISC_LOG_INFO, "loading configuration from '%s'",
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews filename);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews /*
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * Parse the configuration file creating a parse tree. Any
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * 'zone' statements are handled immediately by calling
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * configure_zone() through 'callbacks'.
9cf04a12ec5ea0ee64338feef76e885980a524dfMark Andrews */
9cf04a12ec5ea0ee64338feef76e885980a524dfMark Andrews configctx = NULL;
9cf04a12ec5ea0ee64338feef76e885980a524dfMark Andrews CHECK(dns_c_parse_namedconf(filename, ns_g_mctx, &configctx,
9cf04a12ec5ea0ee64338feef76e885980a524dfMark Andrews &callbacks));
9cf04a12ec5ea0ee64338feef76e885980a524dfMark Andrews
9cf04a12ec5ea0ee64338feef76e885980a524dfMark Andrews /*
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews * Configure various server options.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 configure_server_quota(configctx, dns_c_ctx_gettransfersout,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 &server->xfroutquota, 10);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 configure_server_quota(configctx, dns_c_ctx_gettcpclients,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 &server->tcpquota, 100);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 configure_server_quota(configctx, dns_c_ctx_getrecursiveclients,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews &server->recursionquota, 100);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt (void) dns_c_ctx_getprovideixfr(configctx, &server->provide_ixfr);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Configure the zone manager.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_int32_t transfersin = 10;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (void) dns_c_ctx_gettransfersin(configctx, &transfersin);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_zonemgr_settransfersin(server->zonemgr, transfersin);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_int32_t transfersperns = 2;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (void) dns_c_ctx_gettransfersperns(configctx, &transfersperns);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_zonemgr_settransfersperns(server->zonemgr, transfersperns);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_boolean_t requestixfr = ISC_TRUE;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (void) dns_c_ctx_getrequestixfr(configctx, &requestixfr);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_zonemgr_setrequestixfr(server->zonemgr, requestixfr);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Configure the interface manager according to the "listen-on"
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 * statement.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dns_c_lstnlist_t *clistenon = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_listenlist_t *listenon = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (void) dns_c_ctx_getlistenlist(configctx, &clistenon);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (clistenon != NULL) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = ns_listenlist_fromconfig(clistenon,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 configctx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 &aclconfctx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_g_mctx,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews &listenon);
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /* Not specified, use default. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(ns_listenlist_default(ns_g_mctx, ns_g_port,
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 &listenon));
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 }
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 ns_interfacemgr_setlistenon(server->interfacemgr, listenon);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 ns_listenlist_detach(&listenon);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 }
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Rescan the interface list to pick up changes in the
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * listen-on option. It's important that we do this before we try
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * to configure the query source, since the dispatcher we use might
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * be shared with an interface.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 scan_interfaces(server);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Arrange for further interface scanning to occur periodically
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * as specified by the "interface-interval" option.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 interface_interval = 3600; /* Default is 1 hour. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 (void) dns_c_ctx_getinterfaceinterval(configctx, &interface_interval);
34350037a886e7a16728335821da2bbff95683a9Evan Hunt if (interface_interval == 0) {
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 isc_timer_reset(server->interface_timer,
34350037a886e7a16728335821da2bbff95683a9Evan Hunt isc_timertype_inactive,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NULL, NULL, ISC_TRUE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 } else {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_interval_t interval;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_interval_set(&interval, interface_interval, 0);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_timer_reset(server->interface_timer, isc_timertype_ticker,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NULL, &interval, ISC_FALSE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECK(configure_server_querysource(configctx, server,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews AF_INET, &dispatchv4));
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews CHECK(configure_server_querysource(configctx, server,
96b3cb85d3b06d99323a6ea7ae04f4eb3d74e8bcMark Andrews AF_INET6, &dispatchv6));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /*
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Configure and freeze the views.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 * Views that have zones were already created at parsing
34350037a886e7a16728335821da2bbff95683a9Evan Hunt * time, but views with no zones must be created here.
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 */
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 if (configctx->views != NULL) {
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 dns_c_view_t *cview;
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 for (cview = ISC_LIST_HEAD(configctx->views->views);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 cview != NULL;
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 cview = ISC_LIST_NEXT(cview, next))
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 {
34350037a886e7a16728335821da2bbff95683a9Evan Hunt view = NULL;
34350037a886e7a16728335821da2bbff95683a9Evan Hunt CHECK(find_or_create_view(cview,
34350037a886e7a16728335821da2bbff95683a9Evan Hunt &lctx.viewlist, &view));
34350037a886e7a16728335821da2bbff95683a9Evan Hunt INSIST(view != NULL);
34350037a886e7a16728335821da2bbff95683a9Evan Hunt CHECK(configure_view(view, configctx, cview, ns_g_mctx,
34350037a886e7a16728335821da2bbff95683a9Evan Hunt &aclconfctx,
34350037a886e7a16728335821da2bbff95683a9Evan Hunt dispatchv4, dispatchv6));
34350037a886e7a16728335821da2bbff95683a9Evan Hunt dns_view_freeze(view);
34350037a886e7a16728335821da2bbff95683a9Evan Hunt dns_view_detach(&view);
34350037a886e7a16728335821da2bbff95683a9Evan Hunt }
34350037a886e7a16728335821da2bbff95683a9Evan Hunt }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 /*
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * If we haven't created any views, create and configure
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * a default view for class IN. (We're a caching-only server.)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (ISC_LIST_EMPTY(lctx.viewlist)) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 CHECKM(dns_view_create(ns_g_mctx, dns_rdataclass_in,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 "_default", &view),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "creating default view");
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff CHECK(configure_view(view, configctx, NULL,
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson ns_g_mctx, &aclconfctx,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 dispatchv4, dispatchv6));
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 ISC_LIST_APPEND(lctx.viewlist, view, link);
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson dns_view_freeze(view);
3530e10080e5a7d95c7d13abdc02c1d8bd12ec18Andreas Gustafsson view = NULL; /* Ownership transferred to list. */
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff }
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 /*
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * Create (or recreate) the version view.
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff view = NULL;
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews CHECK(create_version_view(configctx, &view));
bd7237e653e15bfb7f202a1c0914271912597ef4Michael Graff ISC_LIST_APPEND(lctx.viewlist, view, link);
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 view = NULL;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /*
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 * Swap our new view list with the production one.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff tmpviewlist = server->viewlist;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 server->viewlist = lctx.viewlist;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff lctx.viewlist = tmpviewlist;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff /*
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff * Load the TKEY information from the configuration.
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_tkey_ctx_t *t = NULL;
3d181bc9f12154a56bfbb536198a6c481cbcd525David Lawrence CHECKM(dns_tkeyctx_fromconfig(configctx, ns_g_mctx, &t),
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt "configuring TKEY");
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff if (server->tkeyctx != NULL)
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews dns_tkeyctx_destroy(&server->tkeyctx);
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff server->tkeyctx = t;
ce5bd92088923d1c76e26d313d1d8c0b8bbe38feMichael Graff }
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews /*
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews * Configure the logging system.
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff */
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (ns_g_logstderr) {
ef4b66d3557505af25fec8ce461f07ddd671ea1eBob Halley isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews NS_LOGMODULE_SERVER, ISC_LOG_INFO,
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews "ignoring named.conf logging statement "
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews "due to -g option");
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews } else {
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_c_logginglist_t *clog = NULL;
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews isc_logconfig_t *logc = NULL;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff CHECKM(isc_logconfig_create(ns_g_lctx, &logc),
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff "creating new logging configuration");
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff (void) dns_c_ctx_getlogging(configctx, &clog);
c6066a8e67f40c7c12925c5634485f55713c06d6Michael Graff if (clog != NULL)
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff CHECKM(ns_log_configure(logc, clog),
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "configuring logging");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff else
8470db5b12c18cfb32a757e265ce4e7789052c92Michael Graff CHECKM(ns_log_setdefaults(logc),
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt "setting up default logging defaults");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff result = isc_logconfig_use(ns_g_lctx, logc);
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews if (result != ISC_R_SUCCESS) {
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt isc_logconfig_destroy(&logc);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt CHECKM(result, "intalling logging configuration");
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews }
6fe411037dafd168a9f65e6b254c50f3db616688Michael Graff }
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt if (first_time)
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt ns_os_changeuser(ns_g_username);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt if (dns_c_ctx_getpidfilename(configctx, &pidfilename) ==
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt ISC_R_NOTFOUND)
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt pidfilename = ns_g_defaultpidfile;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt ns_os_writepidfile(pidfilename);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_aclconfctx_destroy(&aclconfctx);
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_c_ctx_delete(&configctx);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt cleanup:
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt /*
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt * This cleans up either the old production view list
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt * or our temporary list depending on whether they
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt * were swapped above or not.
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt */
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt for (view = ISC_LIST_HEAD(lctx.viewlist);
ee980d3fc4c23b7f87fed96d3ba5e928937c9ed4Tinderbox User view != NULL;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt view = view_next) {
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt view_next = ISC_LIST_NEXT(view, link);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt ISC_LIST_UNLINK(lctx.viewlist, view, link);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_view_detach(&view);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt }
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt if (dispatchv4 != NULL)
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_dispatch_detach(&dispatchv4);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt if (dispatchv6 != NULL)
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_dispatch_detach(&dispatchv6);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_zonemgr_unlockconf(server->zonemgr, isc_rwlocktype_write);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt RWUNLOCK(&server->conflock, isc_rwlocktype_write);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt return (result);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt}
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Huntstatic isc_result_t
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Huntload_zones(ns_server_t *server, isc_boolean_t stop) {
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt isc_result_t result;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_view_t *view;
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt dns_zonemgr_lockconf(server->zonemgr, isc_rwlocktype_read);
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt /*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * Load zone data from disk.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff for (view = ISC_LIST_HEAD(server->viewlist);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff view != NULL;
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff view = ISC_LIST_NEXT(view, link))
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff CHECK(dns_view_load(view, stop));
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt }
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff /*
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * Force zone maintenance. Do this after loading
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt * so that we know when we need to force AXFR of
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff * slave zones whose master files are missing.
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff */
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt CHECK(dns_zonemgr_forcemaint(server->zonemgr));
ce10da99834b806d5a92a6e5b4c8ff3990a4ae0fBrian Wellington cleanup:
ce10da99834b806d5a92a6e5b4c8ff3990a4ae0fBrian Wellington dns_zonemgr_unlockconf(server->zonemgr, isc_rwlocktype_read);
5e589b5356a4125b5af32605dead82ab8b467c88Mark Andrews return (result);
5e589b5356a4125b5af32605dead82ab8b467c88Mark Andrews}
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffstatic void
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffrun_server(isc_task_t *task, isc_event_t *event) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_result_t result;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_server_t *server = (ns_server_t *) event->arg;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 UNUSED(task);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_event_free(&event);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECKFATAL(ns_clientmgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 &server->clientmgr),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "creating client manager");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECKFATAL(ns_interfacemgr_create(ns_g_mctx, ns_g_taskmgr,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_g_socketmgr, server->clientmgr,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 &server->interfacemgr),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "creating interface manager");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECKFATAL(isc_timer_create(ns_g_timermgr, isc_timertype_inactive,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NULL, NULL, server->task,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 interface_timer_tick,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 server, &server->interface_timer),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "creating interface timer");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff CHECKFATAL(load_configuration(ns_g_conffile, server, ISC_TRUE),
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff "loading configuration");
135b1206c96d03353ac59fde7be0053dacc6568eAndreas Gustafsson
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff CHECKFATAL(load_zones(server, ISC_TRUE),
e992af4209b737f511b6f2fad3ddb7bdfc17b9aeTatuya JINMEI 神明達哉 "loading zones");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff ISC_LOG_INFO, "running");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffstatic void
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graffshutdown_server(isc_task_t *task, isc_event_t *event) {
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_view_t *view, *view_next;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff ns_server_t *server = (ns_server_t *) event->arg;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff UNUSED(task);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff RWLOCK(&server->conflock, isc_rwlocktype_write);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LOG_INFO, "shutting down");
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff for (view = ISC_LIST_HEAD(server->viewlist);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff view != NULL;
58efc48a9623797187726360efb57cbabd916f0dMichael Graff view = view_next) {
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff view_next = ISC_LIST_NEXT(view, link);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews ISC_LIST_UNLINK(server->viewlist, view, link);
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington dns_view_detach(&view);
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (server->querysrc_dispatchv4 != NULL)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff dns_dispatch_detach(&server->querysrc_dispatchv4);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (server->querysrc_dispatchv6 != NULL)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff dns_dispatch_detach(&server->querysrc_dispatchv6);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff ns_clientmgr_destroy(&server->clientmgr);
a7c76f1924d5fc914c579fd3b0276ffbddd2f65aMark Andrews isc_timer_detach(&server->interface_timer);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff ns_interfacemgr_shutdown(server->interfacemgr);
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff ns_interfacemgr_detach(&server->interfacemgr);
8ed2c82a73a6c0a9c04ad26a4ef39b5a738099f6Andreas Gustafsson dns_zonemgr_shutdown(server->zonemgr);
f98d6edb191348477c9c5a156003df627d9bc42cBrian Wellington
6f1422b81ed2c5142092e2ced8e3faf0e61f3ba0Michael Graff isc_task_detach(&server->task);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
e992af4209b737f511b6f2fad3ddb7bdfc17b9aeTatuya JINMEI 神明達哉 isc_event_free(&event);
e992af4209b737f511b6f2fad3ddb7bdfc17b9aeTatuya JINMEI 神明達哉
e992af4209b737f511b6f2fad3ddb7bdfc17b9aeTatuya JINMEI 神明達哉 RWUNLOCK(&server->conflock, isc_rwlocktype_write);
e992af4209b737f511b6f2fad3ddb7bdfc17b9aeTatuya JINMEI 神明達哉}
e992af4209b737f511b6f2fad3ddb7bdfc17b9aeTatuya JINMEI 神明達哉
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellingtonvoid
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellingtonns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington isc_result_t result;
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ns_server_t *server = isc_mem_get(mctx, sizeof(*server));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (server == NULL)
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 fatal("allocating server object", ISC_R_NOMEMORY);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 server->mctx = mctx;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 server->task = NULL;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 CHECKFATAL(isc_rwlock_init(&server->conflock, 1, 1),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "initializing server configuration lock");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 /* Initialize configuration data with default values. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = isc_quota_init(&server->xfroutquota, 10);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff RUNTIME_CHECK(result == ISC_R_SUCCESS);
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley result = isc_quota_init(&server->tcpquota, 10);
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley RUNTIME_CHECK(result == ISC_R_SUCCESS);
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley result = isc_quota_init(&server->recursionquota, 100);
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley RUNTIME_CHECK(result == ISC_R_SUCCESS);
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff server->provide_ixfr = ISC_TRUE;
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley result = dns_aclenv_init(mctx, &server->aclenv);
46993e1d9d18410a5852b7d990338b70b158855cMichael Graff RUNTIME_CHECK(result == ISC_R_SUCCESS);
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley
35f06ab0e6d5ad26176b7584de7b4d405272ba68Brian Wellington /* Initialize server data structures. */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 server->zonemgr = NULL;
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley server->clientmgr = NULL;
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley server->interfacemgr = NULL;
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley ISC_LIST_INIT(server->viewlist);
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley server->in_roothints = NULL;
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 CHECKFATAL(dns_rootns_create(mctx, dns_rdataclass_in, NULL,
321b1c0501d6d97c852ae02e13bdfef6f0bbe776Automatic Updater &server->in_roothints),
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 "setting up root hints");
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 CHECKFATAL(isc_mutex_init(&server->reload_event_lock),
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 "initializing reload event lock");
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 server->reload_event =
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 isc_event_allocate(ns_g_mctx, server,
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 NS_EVENT_RELOAD,
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 ns_server_reload,
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 server,
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 sizeof(isc_event_t));
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 CHECKFATAL(server->reload_event == NULL ?
61facaae4eb15535e1b0cebf007500551874f133Mark Andrews ISC_R_NOMEMORY : ISC_R_SUCCESS,
61facaae4eb15535e1b0cebf007500551874f133Mark Andrews "allocating reload event");
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 server->tkeyctx = NULL;
2f76108082f11d4979048f1c22602391c5733c88Tatuya JINMEI 神明達哉 CHECKFATAL(dns_tkeyctx_create(ns_g_mctx, &server->tkeyctx),
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "creating TKEY context");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 server->querysrc_dispatchv4 = NULL;
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley server->querysrc_dispatchv6 = NULL;
6da50be4364a17cdcd14095c0110aaa6a0566178Bob Halley
135b1206c96d03353ac59fde7be0053dacc6568eAndreas Gustafsson /*
135b1206c96d03353ac59fde7be0053dacc6568eAndreas Gustafsson * Setup the server task, which is responsible for coordinating
135b1206c96d03353ac59fde7be0053dacc6568eAndreas Gustafsson * startup and shutdown of the server.
135b1206c96d03353ac59fde7be0053dacc6568eAndreas Gustafsson */
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff CHECKFATAL(isc_task_create(ns_g_taskmgr, ns_g_mctx, 0, &server->task),
135b1206c96d03353ac59fde7be0053dacc6568eAndreas Gustafsson "creating server task");
135b1206c96d03353ac59fde7be0053dacc6568eAndreas Gustafsson isc_task_setname(server->task, "server", server);
135b1206c96d03353ac59fde7be0053dacc6568eAndreas Gustafsson CHECKFATAL(isc_task_onshutdown(server->task, shutdown_server, server),
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff "isc_task_onshutdown");
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff CHECKFATAL(isc_app_onrun(ns_g_mctx, server->task, run_server, server),
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington "isc_app_onrun");
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington server->interface_timer = NULL;
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington /*
8ed67113ec802546179294a682581faa75e890c9Andreas Gustafsson * Create a timer for periodic interface scanning.
8ed67113ec802546179294a682581faa75e890c9Andreas Gustafsson */
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews CHECKFATAL(dns_zonemgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington ns_g_socketmgr, &server->zonemgr),
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington "dns_zonemgr_create");
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington server->magic = NS_SERVER_MAGIC;
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington *serverp = server;
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington}
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellingtonvoid
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellingtonns_server_destroy(ns_server_t **serverp) {
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington ns_server_t *server = *serverp;
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington REQUIRE(NS_SERVER_VALID(server));
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington REQUIRE(server->querysrc_dispatchv4 == NULL);
e21d199dca95aff5d50f133d6b064309e209af00Brian Wellington REQUIRE(server->querysrc_dispatchv6 == NULL);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff if (server->tkeyctx != NULL)
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff dns_tkeyctx_destroy(&server->tkeyctx);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_event_free(&server->reload_event);
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff INSIST(ISC_LIST_EMPTY(server->viewlist));
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff dns_zonemgr_destroy(&server->zonemgr);
8ed2c82a73a6c0a9c04ad26a4ef39b5a738099f6Andreas Gustafsson server->zonemgr = NULL;
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff dns_db_detach(&server->in_roothints);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff dns_aclenv_destroy(&server->aclenv);
8ed2c82a73a6c0a9c04ad26a4ef39b5a738099f6Andreas Gustafsson
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff isc_quota_destroy(&server->recursionquota);
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff isc_quota_destroy(&server->tcpquota);
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff isc_quota_destroy(&server->xfroutquota);
e618d503ba1a38fc407b071c43ded97ac59f0106Brian Wellington isc_rwlock_destroy(&server->conflock);
e618d503ba1a38fc407b071c43ded97ac59f0106Brian Wellington
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graff server->magic = 0;
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graff isc_mem_put(server->mctx, server, sizeof(*server));
1ec39fc7a8b6ad92de3363d4c50b75e24fcd6accMichael Graff}
e618d503ba1a38fc407b071c43ded97ac59f0106Brian Wellington
e618d503ba1a38fc407b071c43ded97ac59f0106Brian Wellingtonstatic void
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrewsfatal(char *msg, isc_result_t result) {
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LOG_CRITICAL, "%s: %s", msg,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_totext(result));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 ISC_LOG_CRITICAL, "exiting (due to fatal error)");
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 exit(1);
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews}
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉static void
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉ns_server_reload(isc_task_t *task, isc_event_t *event) {
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 isc_result_t result;
e2fe1fda755f24f593406dc26fed87e8ea1bb502Tatuya JINMEI 神明達哉 ns_server_t *server = (ns_server_t *)event->arg;
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 UNUSED(task);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = load_configuration(ns_g_conffile, server, ISC_FALSE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 "reloading configuration failed: %s",
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_result_totext(result));
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 }
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 result = load_zones(server, ISC_FALSE);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS) {
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
f19e6ef1eb7d5abf547fc1af24e561bdc5d75b22Mark Andrews "reloading zones failed: %s",
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews isc_result_totext(result));
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews }
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews LOCK(&server->reload_event_lock);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews INSIST(server->reload_event == NULL);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews server->reload_event = event;
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews UNLOCK(&server->reload_event_lock);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews}
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrewsvoid
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrewsns_server_reloadwanted(ns_server_t *server) {
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews LOCK(&server->reload_event_lock);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews if (server->reload_event != NULL)
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews isc_task_send(server->task, &server->reload_event);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews UNLOCK(&server->reload_event_lock);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews}
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrewsstatic isc_result_t
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrewsns_listenlist_fromconfig(dns_c_lstnlist_t *clist, dns_c_ctx_t *cctx,
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews dns_aclconfctx_t *actx,
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews isc_mem_t *mctx, ns_listenlist_t **target)
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews{
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews dns_c_lstnon_t *ce;
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews isc_result_t result;
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews ns_listenlist_t *dlist = NULL;
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews REQUIRE(target != NULL && *target == NULL);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews result = ns_listenlist_create(mctx, &dlist);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews if (result != ISC_R_SUCCESS)
db30f4bdcb66afb7eb1ab0c6882cc70be9a53d79Mark Andrews return (result);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews for (ce = ISC_LIST_HEAD(clist->elements);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews ce != NULL;
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews ce = ISC_LIST_NEXT(ce, next))
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews {
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews ns_listenelt_t *delt = NULL;
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews result = ns_listenelt_fromconfig(ce, cctx, actx, mctx, &delt);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews if (result != ISC_R_SUCCESS)
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews goto cleanup;
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews ISC_LIST_APPEND(dlist->elts, delt, link);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews }
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews *target = dlist;
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews return (ISC_R_SUCCESS);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews cleanup:
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews ns_listenlist_detach(&dlist);
a295fbb55cfed38bcf2853c60410cce52ab6cebbMark Andrews return (result);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉}
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews
54489ba1672458382e8dfb5490fcfc7230f8ea85Evan Hunt/*
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews * Create a listen list from the corresponding configuration
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews * data structure.
d8c2b1787119de43dd6b7e3927ff193ed5df682fMark Andrews */
ab0e5066083abcbec62513a3cc041d1f1eb9098aMichael Graffstatic isc_result_t
8d1943e8ffa991d54c5406342e44d7134762e7eaMichael Graffns_listenelt_fromconfig(dns_c_lstnon_t *celt, dns_c_ctx_t *cctx,
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff dns_aclconfctx_t *actx,
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff isc_mem_t *mctx, ns_listenelt_t **target)
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff{
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff isc_result_t result;
0b14ebe3132846e91bea02992493e3d506233e76Michael Graff ns_listenelt_t *delt = NULL;
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews REQUIRE(target != NULL && *target == NULL);
8affb49a70de247206cb04aae87730f2b4c90dd0Mark Andrews result = ns_listenelt_create(mctx, celt->port, NULL, &delt);
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 if (result != ISC_R_SUCCESS)
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff return (result);
d1ba6e9180c7d7458656a6e53e52fde056fd244cMichael Graff
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff result = dns_acl_fromconfig(celt->iml, cctx, actx, mctx, &delt->acl);
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff if (result != ISC_R_SUCCESS) {
e618d503ba1a38fc407b071c43ded97ac59f0106Brian Wellington ns_listenelt_destroy(delt);
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff return (result);
58efc48a9623797187726360efb57cbabd916f0dMichael Graff }
e44487bfc23599b6b240e09d83d1c862fecfcc82Michael Graff *target = delt;
ae8d0aedd64a7580dc2fc4a9cd61934527552f3bMichael Graff return (ISC_R_SUCCESS);
58efc48a9623797187726360efb57cbabd916f0dMichael Graff}
20c266cbc999c724e03e6edd437fb4181b92f095Michael Graff