1999-01-19 06:32:53 +00:00
|
|
|
/*
|
2000-02-03 22:29:57 +00:00
|
|
|
* Copyright (C) 1999, 2000 Internet Software Consortium.
|
1999-01-19 06:32:53 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <isc/app.h>
|
2000-04-10 21:31:41 +00:00
|
|
|
#include <isc/base64.h>
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <isc/dir.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/lex.h>
|
2000-05-09 15:02:20 +00:00
|
|
|
#include <isc/string.h>
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <isc/task.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
#include <isc/timer.h>
|
1999-12-16 22:24:22 +00:00
|
|
|
#include <isc/util.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
1999-12-02 22:38:34 +00:00
|
|
|
#include <dns/cache.h>
|
1999-10-13 17:50:21 +00:00
|
|
|
#include <dns/confparser.h>
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <dns/db.h>
|
2000-01-26 19:25:22 +00:00
|
|
|
#include <dns/dispatch.h>
|
2000-01-21 23:55:12 +00:00
|
|
|
#include <dns/journal.h>
|
2000-04-10 21:31:41 +00:00
|
|
|
#include <dns/keytable.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/peer.h>
|
2000-04-10 21:31:41 +00:00
|
|
|
#include <dns/rdatastruct.h>
|
2000-01-31 19:59:11 +00:00
|
|
|
#include <dns/resolver.h>
|
2000-01-22 01:59:02 +00:00
|
|
|
#include <dns/rootns.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/tkey.h>
|
2000-01-24 19:14:26 +00:00
|
|
|
#include <dns/tkeyconf.h>
|
|
|
|
#include <dns/tsigconf.h>
|
1999-08-05 22:14:43 +00:00
|
|
|
#include <dns/view.h>
|
1999-10-13 17:50:21 +00:00
|
|
|
#include <dns/zone.h>
|
1999-12-16 23:11:07 +00:00
|
|
|
#include <dns/zoneconf.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-18 18:09:47 +00:00
|
|
|
#include <named/client.h>
|
2000-01-13 23:32:41 +00:00
|
|
|
#include <named/interfacemgr.h>
|
1999-10-22 19:35:19 +00:00
|
|
|
#include <named/log.h>
|
2000-02-28 18:38:44 +00:00
|
|
|
#include <named/logconf.h>
|
2000-01-28 20:09:49 +00:00
|
|
|
#include <named/os.h>
|
1999-07-24 01:16:38 +00:00
|
|
|
#include <named/server.h>
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
/*
|
|
|
|
* Check an operation for failure. Assumes that the function
|
|
|
|
* using it has a 'result' variable and a 'cleanup' label.
|
|
|
|
*/
|
|
|
|
#define CHECK(op) \
|
|
|
|
do { result = (op); \
|
|
|
|
if (result != ISC_R_SUCCESS) goto cleanup; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define CHECKM(op, msg) \
|
|
|
|
do { result = (op); \
|
|
|
|
if (result != ISC_R_SUCCESS) { \
|
|
|
|
isc_log_write(ns_g_lctx, \
|
|
|
|
NS_LOGCATEGORY_GENERAL, \
|
|
|
|
NS_LOGMODULE_SERVER, \
|
|
|
|
ISC_LOG_ERROR, \
|
|
|
|
"%s: %s", msg, \
|
|
|
|
isc_result_totext(result)); \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
} while (0) \
|
|
|
|
|
|
|
|
#define CHECKFATAL(op, msg) \
|
|
|
|
do { result = (op); \
|
|
|
|
if (result != ISC_R_SUCCESS) \
|
|
|
|
fatal(msg, result); \
|
|
|
|
} while (0) \
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
typedef struct {
|
|
|
|
isc_mem_t * mctx;
|
|
|
|
dns_viewlist_t viewlist;
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_aclconfctx_t *aclconf;
|
1999-10-15 01:51:48 +00:00
|
|
|
} ns_load_t;
|
1999-10-13 17:50:21 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
static void fatal(char *msg, isc_result_t result);
|
2000-01-24 22:21:47 +00:00
|
|
|
static void ns_server_reload(isc_task_t *task, isc_event_t *event);
|
2000-01-26 17:35:16 +00:00
|
|
|
|
2000-01-25 21:21:05 +00:00
|
|
|
static isc_result_t
|
|
|
|
ns_listenelt_fromconfig(dns_c_lstnon_t *celt, dns_c_ctx_t *cctx,
|
|
|
|
dns_aclconfctx_t *actx,
|
|
|
|
isc_mem_t *mctx, ns_listenelt_t **target);
|
|
|
|
static isc_result_t
|
|
|
|
ns_listenlist_fromconfig(dns_c_lstnlist_t *clist, dns_c_ctx_t *cctx,
|
|
|
|
dns_aclconfctx_t *actx,
|
|
|
|
isc_mem_t *mctx, ns_listenlist_t **target);
|
2000-01-21 23:55:12 +00:00
|
|
|
|
2000-04-06 17:31:33 +00:00
|
|
|
/*
|
|
|
|
* Configure a single view ACL at '*aclp'. Get its configuration by
|
|
|
|
* calling 'getvcacl' (for per-view configuration) and maybe 'getscacl'
|
|
|
|
* (for a global default).
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
configure_view_acl(dns_c_view_t *cview,
|
|
|
|
dns_c_ctx_t *cctx,
|
|
|
|
dns_aclconfctx_t *actx, isc_mem_t *mctx,
|
|
|
|
isc_result_t (*getvcacl)
|
|
|
|
(dns_c_view_t *, dns_c_ipmatchlist_t **),
|
|
|
|
isc_result_t (*getscacl)
|
|
|
|
(dns_c_ctx_t *, dns_c_ipmatchlist_t **),
|
|
|
|
dns_acl_t **aclp)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
dns_c_ipmatchlist_t *cacl = NULL;
|
|
|
|
if (*aclp != NULL)
|
|
|
|
dns_acl_detach(aclp);
|
|
|
|
if (getvcacl != NULL && cview != NULL)
|
|
|
|
(void) (*getvcacl)(cview, &cacl);
|
|
|
|
if (cacl == NULL && getscacl != NULL)
|
|
|
|
(void) (*getscacl)(cctx, &cacl);
|
|
|
|
if (cacl == NULL) {
|
|
|
|
/* No value available. *aclp == NULL. */
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = dns_acl_fromconfig(cacl, cctx, actx, mctx, aclp);
|
|
|
|
|
|
|
|
dns_c_ipmatchlist_detach(&cacl);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-04-10 21:31:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a null-terminated string of base64 text into
|
|
|
|
* binary, storing it in a buffer.
|
|
|
|
* 'mctx' is only used internally.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
base64_cstring_tobuffer(isc_mem_t *mctx, char *cstr, isc_buffer_t *target)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
isc_buffer_t source;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_boolean_t isopen = ISC_FALSE;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&source, cstr, strlen(cstr));
|
2000-04-11 20:47:00 +00:00
|
|
|
isc_buffer_add(&source, strlen(cstr));
|
2000-04-10 21:31:41 +00:00
|
|
|
CHECK(isc_lex_create(mctx, 256, &lex));
|
|
|
|
CHECK(isc_lex_openbuffer(lex, &source));
|
|
|
|
isopen = ISC_TRUE;
|
|
|
|
CHECK(isc_base64_tobuffer(lex, target, -1));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (isopen)
|
|
|
|
(void) isc_lex_close(lex);
|
|
|
|
if (lex != NULL)
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure the trusted keys or security roots of a view.
|
|
|
|
* The configuration values are read from 'cctx' and 'cview' using
|
|
|
|
* the function 'cget'. The variable to be configured is '*target'.
|
|
|
|
* XXX not really view specific yet
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
configure_view_dnsseckeys(dns_c_ctx_t *cctx,
|
|
|
|
dns_c_view_t *cview,
|
|
|
|
isc_mem_t *mctx,
|
|
|
|
isc_result_t (*cget)
|
|
|
|
(dns_c_ctx_t *, dns_c_tkeylist_t **),
|
|
|
|
dns_keytable_t **target)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
dns_c_tkeylist_t *ckeys = NULL;
|
|
|
|
dns_c_tkey_t *ckey;
|
|
|
|
dns_keytable_t *keytable = NULL;
|
|
|
|
dst_key_t *dstkey = NULL;
|
|
|
|
|
|
|
|
CHECK(dns_keytable_create(mctx, &keytable));
|
|
|
|
|
2000-04-11 17:52:57 +00:00
|
|
|
result = (*cget)(cctx, &ckeys);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
for (ckey = ISC_LIST_HEAD(ckeys->tkeylist);
|
|
|
|
ckey != NULL;
|
|
|
|
ckey = ISC_LIST_NEXT(ckey, next))
|
|
|
|
{
|
|
|
|
dns_rdataclass_t viewclass;
|
2000-04-28 02:08:37 +00:00
|
|
|
dns_rdata_key_t keystruct;
|
2000-04-11 17:52:57 +00:00
|
|
|
isc_int32_t flags, proto, alg;
|
|
|
|
unsigned char keydata[4096];
|
|
|
|
isc_buffer_t keydatabuf;
|
|
|
|
unsigned char rrdata[4096];
|
|
|
|
isc_buffer_t rrdatabuf;
|
|
|
|
isc_region_t r;
|
2000-05-24 23:13:32 +00:00
|
|
|
dns_fixedname_t fkeyname;
|
|
|
|
dns_name_t *keyname;
|
|
|
|
isc_buffer_t namebuf;
|
2000-04-11 17:52:57 +00:00
|
|
|
|
|
|
|
if (cview == NULL)
|
|
|
|
viewclass = dns_rdataclass_in;
|
|
|
|
else
|
|
|
|
CHECK(dns_c_view_getviewclass(cview,
|
|
|
|
&viewclass));
|
|
|
|
keystruct.common.rdclass = viewclass;
|
|
|
|
keystruct.common.rdtype = dns_rdatatype_key;
|
|
|
|
/*
|
2000-04-26 01:44:07 +00:00
|
|
|
* The key data in keystruct is not
|
|
|
|
* dynamically allocated.
|
2000-04-11 17:52:57 +00:00
|
|
|
*/
|
2000-04-26 01:44:07 +00:00
|
|
|
keystruct.mctx = NULL;
|
2000-04-11 17:52:57 +00:00
|
|
|
|
|
|
|
ISC_LINK_INIT(&keystruct.common, link);
|
|
|
|
|
|
|
|
flags = ckey->pubkey->flags;
|
|
|
|
proto = ckey->pubkey->protocol;
|
|
|
|
alg = ckey->pubkey->algorithm;
|
|
|
|
if (flags < 0 || flags > 0xffff)
|
2000-05-15 21:14:38 +00:00
|
|
|
CHECKM(ISC_R_RANGE, "key flags");
|
2000-04-11 17:52:57 +00:00
|
|
|
if (proto < 0 || proto > 0xff)
|
2000-05-15 21:14:38 +00:00
|
|
|
CHECKM(ISC_R_RANGE, "key protocol");
|
2000-04-11 17:52:57 +00:00
|
|
|
if (alg < 0 || alg > 0xff)
|
2000-05-15 21:14:38 +00:00
|
|
|
CHECKM(ISC_R_RANGE, "key algorithm");
|
2000-04-11 17:52:57 +00:00
|
|
|
keystruct.flags = flags;
|
|
|
|
keystruct.protocol = proto;
|
|
|
|
keystruct.algorithm = alg;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&keydatabuf, keydata, sizeof(keydata));
|
|
|
|
isc_buffer_init(&rrdatabuf, rrdata, sizeof(rrdata));
|
2000-04-11 17:52:57 +00:00
|
|
|
|
|
|
|
CHECK(base64_cstring_tobuffer(mctx, ckey->pubkey->key,
|
|
|
|
&keydatabuf));
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&keydatabuf, &r);
|
2000-04-11 17:52:57 +00:00
|
|
|
keystruct.datalen = r.length;
|
|
|
|
keystruct.data = r.base;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
CHECK(dns_rdata_fromstruct(NULL,
|
|
|
|
keystruct.common.rdclass,
|
2000-04-11 17:52:57 +00:00
|
|
|
keystruct.common.rdtype,
|
|
|
|
&keystruct, &rrdatabuf));
|
2000-05-24 23:13:32 +00:00
|
|
|
dns_fixedname_init(&fkeyname);
|
|
|
|
keyname = dns_fixedname_name(&fkeyname);
|
|
|
|
isc_buffer_init(&namebuf, ckey->domain,
|
|
|
|
strlen(ckey->domain));
|
|
|
|
isc_buffer_add(&namebuf, strlen(ckey->domain));
|
|
|
|
CHECK(dns_name_fromtext(keyname, &namebuf,
|
|
|
|
dns_rootname, ISC_FALSE, NULL));
|
|
|
|
CHECK(dst_key_fromdns(keyname, &rrdatabuf, mctx,
|
2000-04-11 17:52:57 +00:00
|
|
|
&dstkey));
|
|
|
|
|
|
|
|
CHECK(dns_keytable_add(keytable, &dstkey));
|
|
|
|
INSIST(dstkey == NULL);
|
|
|
|
}
|
|
|
|
} else if (result != ISC_R_NOTFOUND)
|
|
|
|
goto cleanup;
|
|
|
|
|
2000-04-10 21:31:41 +00:00
|
|
|
dns_keytable_detach(target);
|
|
|
|
*target = keytable; /* Transfer ownership. */
|
|
|
|
keytable = NULL;
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (dstkey != NULL)
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_free(&dstkey);
|
2000-04-10 21:31:41 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
/*
|
|
|
|
* Get a dispatch appropriate for the resolver of a given view.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
get_view_querysource_dispatch(dns_c_ctx_t *cctx, dns_c_view_t *cview,
|
|
|
|
int af, dns_dispatch_t **dispatchp)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
dns_dispatch_t *disp;
|
|
|
|
isc_sockaddr_t sa;
|
|
|
|
unsigned int attrs, attrmask;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make compiler happy.
|
|
|
|
*/
|
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
|
|
|
|
switch (af) {
|
|
|
|
case AF_INET:
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
if (cview != NULL)
|
|
|
|
result = dns_c_view_getquerysource(cview, &sa);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-05-24 05:10:00 +00:00
|
|
|
result = dns_c_ctx_getquerysource(cctx, &sa);
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
isc_sockaddr_any(&sa);
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
if (cview != NULL)
|
|
|
|
result = dns_c_view_getquerysourcev6(cview, &sa);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
result = dns_c_ctx_getquerysourcev6(cctx, &sa);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
isc_sockaddr_any6(&sa);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
INSIST(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
INSIST(isc_sockaddr_pf(&sa) == af);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we don't support this address family, we're done!
|
|
|
|
*/
|
|
|
|
switch (af) {
|
|
|
|
case AF_INET:
|
|
|
|
result = isc_net_probeipv4();
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
result = isc_net_probeipv6();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
INSIST(0);
|
|
|
|
}
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find a dispatcher that we can share.
|
|
|
|
*/
|
|
|
|
attrs = 0;
|
|
|
|
attrs |= DNS_DISPATCHATTR_UDP;
|
|
|
|
switch (af) {
|
|
|
|
case AF_INET:
|
|
|
|
attrs |= DNS_DISPATCHATTR_IPV4;
|
|
|
|
break;
|
|
|
|
case AF_INET6:
|
|
|
|
attrs |= DNS_DISPATCHATTR_IPV6;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
attrmask = 0;
|
|
|
|
attrmask |= DNS_DISPATCHATTR_UDP;
|
|
|
|
attrmask |= DNS_DISPATCHATTR_TCP;
|
|
|
|
attrmask |= DNS_DISPATCHATTR_IPV4;
|
|
|
|
attrmask |= DNS_DISPATCHATTR_IPV6;
|
|
|
|
|
|
|
|
disp = NULL;
|
|
|
|
result = dns_dispatch_getudp(ns_g_dispatchmgr, ns_g_socketmgr,
|
|
|
|
ns_g_taskmgr, &sa, 4096,
|
|
|
|
1000, 32768, 16411, 16433,
|
|
|
|
attrs, attrmask, &disp);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
*dispatchp = disp;
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
2000-04-07 17:08:12 +00:00
|
|
|
* Configure 'view' according to 'cview', taking defaults from 'cctx'
|
|
|
|
* where values are missing in cctx.
|
|
|
|
*
|
|
|
|
* When configuring the default view, cctx will be NULL and the
|
|
|
|
* glboal defaults in cview used exclusively.
|
2000-01-21 19:24:01 +00:00
|
|
|
*/
|
1999-10-15 01:51:48 +00:00
|
|
|
static isc_result_t
|
2000-04-06 17:31:33 +00:00
|
|
|
configure_view(dns_view_t *view, dns_c_ctx_t *cctx, dns_c_view_t *cview,
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
isc_mem_t *mctx, dns_aclconfctx_t *actx)
|
1999-10-15 01:51:48 +00:00
|
|
|
{
|
2000-03-02 23:47:39 +00:00
|
|
|
dns_cache_t *cache = NULL;
|
1999-10-15 01:51:48 +00:00
|
|
|
isc_result_t result;
|
1999-12-17 01:02:49 +00:00
|
|
|
isc_int32_t cleaning_interval;
|
2000-01-21 20:24:49 +00:00
|
|
|
dns_tsig_keyring_t *ring;
|
2000-01-31 19:59:11 +00:00
|
|
|
dns_c_forw_t forward;
|
|
|
|
dns_c_iplist_t *forwarders;
|
|
|
|
dns_fwdpolicy_t fwdpolicy;
|
|
|
|
isc_sockaddrlist_t addresses;
|
|
|
|
isc_sockaddr_t *sa, *next_sa;
|
2000-03-02 23:47:39 +00:00
|
|
|
dns_view_t *pview = NULL; /* Production view */
|
2000-01-31 19:59:11 +00:00
|
|
|
unsigned int i;
|
2000-04-12 01:38:26 +00:00
|
|
|
isc_mem_t *cmctx;
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
dns_dispatch_t *dispatch4 = NULL;
|
|
|
|
dns_dispatch_t *dispatch6 = NULL;
|
2000-03-02 23:47:39 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
REQUIRE(DNS_VIEW_VALID(view));
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-01-31 19:59:11 +00:00
|
|
|
ISC_LIST_INIT(addresses);
|
2000-04-12 01:38:26 +00:00
|
|
|
cmctx = NULL;
|
2000-01-31 19:59:11 +00:00
|
|
|
|
2000-01-27 01:00:16 +00:00
|
|
|
RWLOCK(&view->conflock, isc_rwlocktype_write);
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-03-02 23:47:39 +00:00
|
|
|
* Configure the view's cache. Try to reuse an existing
|
|
|
|
* cache if possible, otherwise create a new cache.
|
|
|
|
* Note that the ADB is not preserved in either case.
|
|
|
|
*
|
|
|
|
* XXX Determining when it is safe to reuse a cache is
|
|
|
|
* tricky. When the view's configuration changes, the cached
|
|
|
|
* data may become invalid because it reflects our old
|
|
|
|
* view of the world. As more view attributes become
|
|
|
|
* configurable, we will have to add code here to check
|
|
|
|
* whether they have changed in ways that could
|
|
|
|
* invalidate the cache.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
2000-03-02 23:47:39 +00:00
|
|
|
result = dns_viewlist_find(&ns_g_server->viewlist,
|
|
|
|
view->name, view->rdclass,
|
|
|
|
&pview);
|
|
|
|
if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
if (pview != NULL) {
|
|
|
|
INSIST(pview->cache != NULL);
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_DEBUG(3), "reusing existing cache");
|
|
|
|
dns_cache_attach(pview->cache, &cache);
|
|
|
|
dns_view_detach(&pview);
|
|
|
|
} else {
|
2000-04-12 01:38:26 +00:00
|
|
|
CHECK(isc_mem_create(0, 0, &cmctx));
|
|
|
|
CHECK(dns_cache_create(cmctx, ns_g_taskmgr, ns_g_timermgr,
|
2000-03-02 23:47:39 +00:00
|
|
|
view->rdclass, "rbt", 0, NULL, &cache));
|
|
|
|
}
|
1999-12-02 22:38:34 +00:00
|
|
|
dns_view_setcache(view, cache);
|
2000-04-07 18:04:24 +00:00
|
|
|
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
if (cview != NULL)
|
2000-05-08 14:38:29 +00:00
|
|
|
result = dns_c_view_getcleaninterval(cview,
|
|
|
|
&cleaning_interval);
|
2000-04-07 18:04:24 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-04-10 22:00:13 +00:00
|
|
|
result = dns_c_ctx_getcleaninterval(cctx, &cleaning_interval);
|
2000-04-07 18:04:24 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
cleaning_interval = 3600; /* Default is 1 hour. */
|
1999-12-17 01:02:49 +00:00
|
|
|
dns_cache_setcleaninginterval(cache, cleaning_interval);
|
2000-04-07 18:04:24 +00:00
|
|
|
|
1999-12-02 22:38:34 +00:00
|
|
|
dns_cache_detach(&cache);
|
1999-05-03 19:56:23 +00:00
|
|
|
|
1999-10-25 18:59:20 +00:00
|
|
|
/*
|
|
|
|
* XXXRTH Temporary support for loading cache contents.
|
|
|
|
*/
|
|
|
|
if (ns_g_cachefile != NULL) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_DEBUG(1), "loading cache '%s'",
|
|
|
|
ns_g_cachefile);
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_db_load(view->cachedb, ns_g_cachefile));
|
1999-10-25 18:59:20 +00:00
|
|
|
}
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
|
|
|
* Resolver.
|
|
|
|
*
|
2000-01-26 19:25:22 +00:00
|
|
|
* XXXRTH Hardwired number of tasks.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
CHECK(get_view_querysource_dispatch(cctx, cview, AF_INET,
|
|
|
|
&dispatch4));
|
|
|
|
CHECK(get_view_querysource_dispatch(cctx, cview, AF_INET6,
|
|
|
|
&dispatch6));
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_view_createresolver(view, ns_g_taskmgr, 31,
|
|
|
|
ns_g_socketmgr, ns_g_timermgr,
|
2000-05-10 21:34:50 +00:00
|
|
|
0, ns_g_dispatchmgr,
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
dispatch4, dispatch6));
|
|
|
|
if (dispatch4 != NULL)
|
|
|
|
dns_dispatch_detach(&dispatch4);
|
|
|
|
if (dispatch6 != NULL)
|
|
|
|
dns_dispatch_detach(&dispatch6);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-01-31 19:59:11 +00:00
|
|
|
/*
|
|
|
|
* Set resolver forwarding policy.
|
|
|
|
*/
|
2000-04-07 16:23:54 +00:00
|
|
|
if ((cview != NULL &&
|
|
|
|
dns_c_view_getforwarders(cview, &forwarders) == ISC_R_SUCCESS) ||
|
2000-04-07 01:07:07 +00:00
|
|
|
(dns_c_ctx_getforwarders(cctx, &forwarders) == ISC_R_SUCCESS))
|
|
|
|
{
|
2000-01-31 19:59:11 +00:00
|
|
|
fwdpolicy = dns_fwdpolicy_first;
|
|
|
|
/*
|
|
|
|
* Ugh. Convert between list formats.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < forwarders->nextidx; i++) {
|
|
|
|
sa = isc_mem_get(view->mctx, sizeof *sa);
|
|
|
|
if (sa == NULL) {
|
|
|
|
result = ISC_R_NOMEMORY;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
*sa = forwarders->ips[i];
|
|
|
|
isc_sockaddr_setport(sa, 53);
|
|
|
|
ISC_LINK_INIT(sa, link);
|
|
|
|
ISC_LIST_APPEND(addresses, sa, link);
|
|
|
|
}
|
|
|
|
INSIST(!ISC_LIST_EMPTY(addresses));
|
2000-02-11 15:29:37 +00:00
|
|
|
dns_c_iplist_detach(&forwarders);
|
2000-01-31 19:59:11 +00:00
|
|
|
CHECK(dns_resolver_setforwarders(view->resolver, &addresses));
|
|
|
|
/*
|
|
|
|
* XXXRTH The configuration type 'dns_c_forw_t' should be
|
|
|
|
* elminated.
|
|
|
|
*/
|
2000-04-07 16:23:54 +00:00
|
|
|
if ((cview != NULL &&
|
2000-05-08 14:38:29 +00:00
|
|
|
dns_c_view_getforward(cview, &forward) == ISC_R_SUCCESS) ||
|
2000-04-07 01:07:07 +00:00
|
|
|
(dns_c_ctx_getforward(cctx, &forward) == ISC_R_SUCCESS)) {
|
2000-01-31 19:59:11 +00:00
|
|
|
INSIST(forward == dns_c_forw_first ||
|
|
|
|
forward == dns_c_forw_only);
|
|
|
|
if (forward == dns_c_forw_only)
|
|
|
|
fwdpolicy = dns_fwdpolicy_only;
|
|
|
|
}
|
|
|
|
CHECK(dns_resolver_setfwdpolicy(view->resolver, fwdpolicy));
|
|
|
|
}
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-27 01:57:08 +00:00
|
|
|
* We have default hints for class IN if we need them.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
2000-01-27 01:57:08 +00:00
|
|
|
if (view->rdclass == dns_rdataclass_in && view->hints == NULL)
|
2000-04-06 17:31:33 +00:00
|
|
|
dns_view_sethints(view, ns_g_server->in_roothints);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-04-06 17:31:33 +00:00
|
|
|
/*
|
|
|
|
* If we still have no hints, this is a non-IN view with no
|
|
|
|
* "hints zone" configured. That's an error.
|
|
|
|
*/
|
|
|
|
if (view->hints == NULL) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
2000-04-07 17:08:12 +00:00
|
|
|
"no root hints for view '%s'",
|
|
|
|
cview == NULL ? "<default>" : cview->name);
|
2000-04-06 17:31:33 +00:00
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2000-01-21 20:24:49 +00:00
|
|
|
/*
|
2000-01-21 23:55:12 +00:00
|
|
|
* Configure the view's TSIG keys.
|
2000-01-21 20:24:49 +00:00
|
|
|
*/
|
|
|
|
ring = NULL;
|
2000-01-24 19:14:26 +00:00
|
|
|
CHECK(dns_tsigkeyring_fromconfig(cctx, view->mctx, &ring));
|
2000-01-21 20:24:49 +00:00
|
|
|
dns_view_setkeyring(view, ring);
|
|
|
|
|
2000-02-24 21:12:16 +00:00
|
|
|
/*
|
|
|
|
* Configure the view's peer list.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
dns_peerlist_t *newpeers = NULL;
|
|
|
|
if (cctx->peers != NULL) {
|
|
|
|
dns_peerlist_attach(cctx->peers, &newpeers);
|
|
|
|
} else {
|
|
|
|
CHECK(dns_peerlist_new(mctx, &newpeers));
|
|
|
|
}
|
|
|
|
dns_peerlist_detach(&view->peers);
|
|
|
|
view->peers = newpeers; /* Transfer ownership. */
|
|
|
|
}
|
2000-04-06 17:31:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure the "match-clients" ACL.
|
|
|
|
*/
|
|
|
|
CHECK(configure_view_acl(cview, cctx, actx, ns_g_mctx,
|
|
|
|
dns_c_view_getmatchclients, NULL,
|
|
|
|
&view->matchclients));
|
|
|
|
|
2000-04-06 20:25:48 +00:00
|
|
|
/*
|
|
|
|
* Configure other configurable data.
|
|
|
|
*/
|
2000-04-06 23:58:01 +00:00
|
|
|
view->recursion = ISC_TRUE;
|
2000-04-06 20:25:48 +00:00
|
|
|
(void) dns_c_ctx_getrecursion(cctx, &view->recursion);
|
2000-04-06 23:58:01 +00:00
|
|
|
if (cview != NULL)
|
|
|
|
(void) dns_c_view_getrecursion(cview, &view->recursion);
|
2000-04-06 20:25:48 +00:00
|
|
|
|
|
|
|
view->auth_nxdomain = ISC_FALSE; /* Was true in BIND 8 */
|
|
|
|
(void) dns_c_ctx_getauthnxdomain(cctx, &view->auth_nxdomain);
|
2000-04-06 23:58:01 +00:00
|
|
|
if (cview != NULL)
|
|
|
|
(void) dns_c_view_getauthnxdomain(cview, &view->auth_nxdomain);
|
2000-04-06 20:25:48 +00:00
|
|
|
|
|
|
|
view->transfer_format = dns_one_answer;
|
|
|
|
(void) dns_c_ctx_gettransferformat(cctx, &view->transfer_format);
|
2000-04-06 23:58:01 +00:00
|
|
|
if (cview != NULL)
|
2000-04-10 22:00:13 +00:00
|
|
|
(void) dns_c_view_gettransferformat(cview,
|
|
|
|
&view->transfer_format);
|
2000-04-06 23:58:01 +00:00
|
|
|
|
|
|
|
CHECK(configure_view_acl(cview, cctx, actx, ns_g_mctx,
|
|
|
|
dns_c_view_getallowquery,
|
|
|
|
dns_c_ctx_getallowquery,
|
|
|
|
&view->queryacl));
|
|
|
|
|
|
|
|
CHECK(configure_view_acl(cview, cctx, actx, ns_g_mctx,
|
|
|
|
dns_c_view_getrecursionacl,
|
|
|
|
dns_c_ctx_getallowrecursion,
|
|
|
|
&view->recursionacl));
|
2000-04-07 22:30:43 +00:00
|
|
|
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
if (cview != NULL)
|
|
|
|
result = dns_c_view_getrequestixfr(cview, &view->requestixfr);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
result = dns_c_ctx_getrequestixfr(cctx, &view->requestixfr);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
view->requestixfr = ISC_TRUE;
|
|
|
|
|
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
if (cview != NULL)
|
|
|
|
result = dns_c_view_getprovideixfr(cview, &view->provideixfr);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
result = dns_c_ctx_getprovideixfr(cctx, &view->provideixfr);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
view->provideixfr = ISC_TRUE;
|
|
|
|
|
2000-04-11 00:37:59 +00:00
|
|
|
/*
|
|
|
|
* For now, there is only one kind of trusted keys, the
|
|
|
|
* "security roots".
|
|
|
|
*/
|
|
|
|
CHECK(configure_view_dnsseckeys(cctx, cview, mctx,
|
2000-04-10 21:31:41 +00:00
|
|
|
dns_c_ctx_gettrustedkeys,
|
2000-04-11 00:37:59 +00:00
|
|
|
&view->secroots));
|
|
|
|
|
2000-04-07 22:37:42 +00:00
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
cleanup:
|
2000-01-27 01:00:16 +00:00
|
|
|
RWUNLOCK(&view->conflock, isc_rwlocktype_write);
|
2000-01-31 19:59:11 +00:00
|
|
|
|
|
|
|
for (sa = ISC_LIST_HEAD(addresses);
|
|
|
|
sa != NULL;
|
|
|
|
sa = next_sa) {
|
|
|
|
next_sa = ISC_LIST_NEXT(sa, link);
|
|
|
|
isc_mem_put(view->mctx, sa, sizeof *sa);
|
|
|
|
}
|
|
|
|
|
2000-04-12 01:38:26 +00:00
|
|
|
if (cmctx != NULL)
|
|
|
|
isc_mem_detach(&cmctx);
|
|
|
|
|
1999-08-05 22:14:43 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-12-08 21:27:08 +00:00
|
|
|
/*
|
|
|
|
* Create the special view that handles queries for
|
|
|
|
* "version.bind. CH". The version string returned is that
|
2000-04-07 22:36:15 +00:00
|
|
|
* configured in 'cctx', or a compiled-in default if
|
1999-12-08 21:27:08 +00:00
|
|
|
* there is no "version" configuration option.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
2000-05-17 19:45:36 +00:00
|
|
|
create_version_view(dns_c_ctx_t *cctx, dns_zonemgr_t *zmgr, dns_view_t **viewp)
|
|
|
|
{
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t result;
|
1999-12-08 21:27:08 +00:00
|
|
|
dns_db_t *db = NULL;
|
|
|
|
dns_zone_t *zone = NULL;
|
|
|
|
dns_dbversion_t *dbver = NULL;
|
|
|
|
dns_difftuple_t *tuple = NULL;
|
|
|
|
dns_diff_t diff;
|
|
|
|
dns_view_t *view = NULL;
|
|
|
|
char *versiontext;
|
2000-01-19 21:25:24 +00:00
|
|
|
unsigned char buf[256];
|
1999-12-08 21:27:08 +00:00
|
|
|
isc_region_t r;
|
|
|
|
size_t len;
|
|
|
|
dns_rdata_t rdata;
|
2000-01-21 19:24:01 +00:00
|
|
|
static unsigned char origindata[] = "\007version\004bind";
|
|
|
|
dns_name_t origin;
|
1999-12-08 21:27:08 +00:00
|
|
|
|
|
|
|
REQUIRE(viewp != NULL && *viewp == NULL);
|
|
|
|
|
2000-05-19 02:34:23 +00:00
|
|
|
CHECK(dns_view_create(ns_g_mctx, dns_rdataclass_ch, "_version",
|
|
|
|
&view));
|
|
|
|
|
1999-12-08 21:27:08 +00:00
|
|
|
dns_diff_init(ns_g_mctx, &diff);
|
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
dns_name_init(&origin, NULL);
|
|
|
|
r.base = origindata;
|
|
|
|
r.length = sizeof(origindata);
|
|
|
|
dns_name_fromregion(&origin, &r);
|
|
|
|
|
2000-05-23 00:40:59 +00:00
|
|
|
result = dns_c_ctx_getversion(cctx, &versiontext);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
1999-12-08 21:27:08 +00:00
|
|
|
versiontext = ns_g_version;
|
|
|
|
len = strlen(versiontext);
|
|
|
|
if (len > 255)
|
|
|
|
len = 255; /* Silently truncate. */
|
|
|
|
buf[0] = len;
|
|
|
|
memcpy(buf + 1, versiontext, len);
|
|
|
|
|
|
|
|
r.base = buf;
|
|
|
|
r.length = 1 + len;
|
|
|
|
dns_rdata_fromregion(&rdata, dns_rdataclass_ch, dns_rdatatype_txt, &r);
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_zone_create(&zone, ns_g_mctx));
|
|
|
|
CHECK(dns_zone_setorigin(zone, &origin));
|
2000-05-23 01:21:32 +00:00
|
|
|
dns_zone_setclass(zone, dns_rdataclass_ch);
|
2000-05-19 02:34:23 +00:00
|
|
|
dns_zone_setview(zone, view);
|
|
|
|
|
2000-05-17 19:45:36 +00:00
|
|
|
CHECK(dns_zonemgr_managezone(zmgr, zone));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_db_create(ns_g_mctx, "rbt", &origin, ISC_FALSE,
|
|
|
|
dns_rdataclass_ch, 0, NULL, &db));
|
|
|
|
|
|
|
|
CHECK(dns_db_newversion(db, &dbver));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_difftuple_create(ns_g_mctx, DNS_DIFFOP_ADD, &origin,
|
|
|
|
0, &rdata, &tuple));
|
1999-12-08 21:27:08 +00:00
|
|
|
dns_diff_append(&diff, &tuple);
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_diff_apply(&diff, db, dbver));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
|
|
|
dns_db_closeversion(db, &dbver, ISC_TRUE);
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_zone_replacedb(zone, db, ISC_FALSE));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_view_addzone(view, zone));
|
1999-12-08 21:27:08 +00:00
|
|
|
|
|
|
|
dns_view_freeze(view);
|
|
|
|
|
|
|
|
/* Transfer ownership. */
|
|
|
|
*viewp = view;
|
|
|
|
view = NULL;
|
|
|
|
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (view != NULL)
|
|
|
|
dns_view_detach(&view);
|
|
|
|
if (zone != NULL)
|
|
|
|
dns_zone_detach(&zone);
|
|
|
|
if (dbver != NULL)
|
|
|
|
dns_db_closeversion(db, &dbver, ISC_FALSE);
|
|
|
|
if (db != NULL)
|
|
|
|
dns_db_detach(&db);
|
|
|
|
dns_diff_clear(&diff);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-01-27 01:57:08 +00:00
|
|
|
static isc_result_t
|
|
|
|
configure_hints(dns_view_t *view, const char *filename) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_db_t *db;
|
|
|
|
|
|
|
|
db = NULL;
|
|
|
|
result = dns_rootns_create(view->mctx, view->rdclass, filename, &db);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
dns_view_sethints(view, db);
|
|
|
|
dns_db_detach(&db);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
2000-04-06 17:31:33 +00:00
|
|
|
/*
|
|
|
|
* Find an existing view matching the name and class of 'cview'
|
|
|
|
* in 'viewlist', or create a new one and add it to the list.
|
|
|
|
*
|
|
|
|
* If 'cview' is NULL, find or create the default view.
|
|
|
|
*
|
|
|
|
* The view found or created is attached to '*viewp'.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
find_or_create_view(dns_c_view_t *cview, dns_viewlist_t *viewlist,
|
|
|
|
dns_view_t **viewp)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
char *viewname;
|
|
|
|
dns_rdataclass_t viewclass;
|
|
|
|
dns_view_t *view = NULL;
|
|
|
|
|
|
|
|
if (cview != NULL) {
|
|
|
|
viewname = cview->name;
|
|
|
|
result = dns_c_view_getviewclass(cview, &viewclass);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
} else {
|
|
|
|
viewname = "_default";
|
|
|
|
viewclass = dns_rdataclass_in;
|
|
|
|
}
|
|
|
|
result = dns_viewlist_find(viewlist, viewname,
|
|
|
|
viewclass, &view);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
*viewp = view;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
if (result != ISC_R_NOTFOUND)
|
|
|
|
return (result);
|
|
|
|
INSIST(view == NULL);
|
|
|
|
|
|
|
|
result = dns_view_create(ns_g_mctx, viewclass, viewname, &view);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
ISC_LIST_APPEND(*viewlist, view, link);
|
|
|
|
dns_view_attach(view, viewp);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
|
|
|
* Configure or reconfigure a zone. This callback function
|
|
|
|
* is called after parsing each "zone" statement in named.conf.
|
|
|
|
*/
|
1999-08-05 22:14:43 +00:00
|
|
|
static isc_result_t
|
2000-01-27 01:00:16 +00:00
|
|
|
configure_zone(dns_c_ctx_t *cctx, dns_c_zone_t *czone, dns_c_view_t *cview,
|
1999-10-15 01:51:48 +00:00
|
|
|
void *uap)
|
|
|
|
{
|
2000-01-21 19:24:01 +00:00
|
|
|
ns_load_t *lctx = (ns_load_t *) uap;
|
|
|
|
dns_view_t *view = NULL; /* New view */
|
|
|
|
dns_view_t *pview = NULL; /* Production view */
|
|
|
|
dns_zone_t *zone = NULL; /* New or reused zone */
|
2000-05-22 17:07:43 +00:00
|
|
|
dns_zone_t *dupzone = NULL;
|
2000-01-21 19:24:01 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
isc_result_t result;
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
char *corigin;
|
|
|
|
isc_buffer_t buffer;
|
|
|
|
dns_fixedname_t fixorigin;
|
|
|
|
dns_name_t *origin;
|
2000-01-27 01:00:16 +00:00
|
|
|
|
1999-08-05 22:14:43 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* Get the zone origin as a dns_name_t.
|
1999-08-05 22:14:43 +00:00
|
|
|
*/
|
2000-01-21 19:24:01 +00:00
|
|
|
corigin = NULL;
|
|
|
|
/* XXX casting away const */
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_c_zone_getname(czone, (const char **) &corigin));
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&buffer, corigin, strlen(corigin));
|
2000-01-21 19:24:01 +00:00
|
|
|
isc_buffer_add(&buffer, strlen(corigin));
|
|
|
|
dns_fixedname_init(&fixorigin);
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_name_fromtext(dns_fixedname_name(&fixorigin),
|
|
|
|
&buffer, dns_rootname, ISC_FALSE, NULL));
|
2000-01-21 19:24:01 +00:00
|
|
|
origin = dns_fixedname_name(&fixorigin);
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* Find or create the view in the new view list.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
|
|
|
view = NULL;
|
2000-04-06 17:31:33 +00:00
|
|
|
CHECK(find_or_create_view(cview, &lctx->viewlist, &view));
|
|
|
|
|
|
|
|
if (czone->zclass != view->rdclass) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
|
|
|
"zone '%s': wrong class for view '%s'",
|
|
|
|
corigin, cview ? cview->name : "<default view>");
|
|
|
|
result = ISC_R_FAILURE;
|
2000-01-21 19:24:01 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2000-04-06 17:31:33 +00:00
|
|
|
|
2000-01-27 01:57:08 +00:00
|
|
|
/*
|
|
|
|
* Master zones must have 'file' set.
|
|
|
|
*/
|
|
|
|
if (czone->ztype == dns_c_zone_master &&
|
|
|
|
czone->u.mzone.file == NULL) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
|
|
|
"zone '%s': 'file' not specified",
|
|
|
|
corigin);
|
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "hints zones" aren't zones. If we've got one,
|
|
|
|
* configure it and return.
|
|
|
|
*/
|
|
|
|
if (czone->ztype == dns_c_zone_hint) {
|
|
|
|
if (czone->u.hzone.file == NULL) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
|
|
|
"zone '%s': 'file' not specified",
|
|
|
|
corigin);
|
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (dns_name_equal(origin, dns_rootname)) {
|
|
|
|
result = configure_hints(view, czone->u.hzone.file);
|
|
|
|
} else {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
|
|
|
|
"ignoring non-root hint zone '%s'",
|
|
|
|
corigin);
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "stub zones" aren't zones either. Eventually we'll
|
|
|
|
* create a "cache freshener" to keep the stub data in the
|
|
|
|
* cache.
|
|
|
|
*/
|
|
|
|
if (czone->ztype == dns_c_zone_stub) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
|
|
|
|
"stub zone '%s': stub zones are not supported in this release",
|
|
|
|
corigin);
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "forward zones" aren't zones either. Eventually we'll
|
|
|
|
* translate this syntax into the appropriate selective forwarding
|
|
|
|
* configuration.
|
|
|
|
*/
|
|
|
|
if (czone->ztype == dns_c_zone_forward) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_WARNING,
|
|
|
|
"forward zone '%s': forward zones are not supported in this release",
|
|
|
|
corigin);
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
|
|
|
* Check for duplicates in the new zone table.
|
|
|
|
*/
|
2000-05-22 17:07:43 +00:00
|
|
|
result = dns_view_findzone(view, origin, &dupzone);
|
2000-01-21 19:24:01 +00:00
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
/*
|
|
|
|
* We already have this zone!
|
|
|
|
*/
|
2000-05-22 17:07:43 +00:00
|
|
|
dns_zone_detach(&dupzone);
|
2000-01-21 19:24:01 +00:00
|
|
|
result = ISC_R_EXISTS;
|
|
|
|
goto cleanup;
|
1999-10-15 01:51:48 +00:00
|
|
|
}
|
2000-05-22 17:07:43 +00:00
|
|
|
INSIST(dupzone == NULL);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* See if we can reuse an existing zone. This is
|
|
|
|
* only possible if all of these are true:
|
|
|
|
* - The zone's view exists
|
|
|
|
* - A zone with the right name exists in the view
|
|
|
|
* - The zone is compatible with the config
|
|
|
|
* options (e.g., an existing master zone cannot
|
|
|
|
* be reused if the options specify a slave zone)
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
2000-01-12 01:19:47 +00:00
|
|
|
result = dns_viewlist_find(&ns_g_server->viewlist,
|
|
|
|
view->name, view->rdclass,
|
1999-10-15 01:51:48 +00:00
|
|
|
&pview);
|
|
|
|
if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
2000-01-21 19:24:01 +00:00
|
|
|
if (pview != NULL)
|
|
|
|
result = dns_view_findzone(pview, origin, &zone);
|
|
|
|
if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
|
|
|
if (zone != NULL) {
|
|
|
|
if (! dns_zone_reusable(zone, czone))
|
|
|
|
dns_zone_detach(&zone);
|
|
|
|
}
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-05-23 04:38:22 +00:00
|
|
|
if (zone != NULL) {
|
|
|
|
/*
|
|
|
|
* We found a reusable zone. Make it use the
|
|
|
|
* new view.
|
|
|
|
*/
|
|
|
|
dns_zone_setview(zone, view);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We cannot reuse an existing zone, we have
|
|
|
|
* to create a new one.
|
|
|
|
*/
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_zone_create(&zone, lctx->mctx));
|
|
|
|
CHECK(dns_zone_setorigin(zone, origin));
|
2000-05-19 02:34:23 +00:00
|
|
|
dns_zone_setview(zone, view);
|
2000-05-23 04:38:22 +00:00
|
|
|
CHECK(dns_zonemgr_managezone(ns_g_server->zonemgr, zone));
|
2000-01-21 19:24:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure the zone.
|
|
|
|
*/
|
2000-04-06 23:58:01 +00:00
|
|
|
CHECK(dns_zone_configure(cctx, cview, czone, lctx->aclconf, zone));
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
|
|
|
* Add the zone to its view in the new view list.
|
|
|
|
*/
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(dns_view_addzone(view, zone));
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-14 01:37:00 +00:00
|
|
|
cleanup:
|
1999-10-15 01:51:48 +00:00
|
|
|
if (zone != NULL)
|
|
|
|
dns_zone_detach(&zone);
|
|
|
|
if (pview != NULL)
|
|
|
|
dns_view_detach(&pview);
|
|
|
|
if (view != NULL)
|
|
|
|
dns_view_detach(&view);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
|
|
|
return (result);
|
1999-05-03 19:56:23 +00:00
|
|
|
}
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
/*
|
|
|
|
* Configure a single server quota.
|
|
|
|
*/
|
2000-01-15 00:37:31 +00:00
|
|
|
static void
|
|
|
|
configure_server_quota(dns_c_ctx_t *cctx,
|
|
|
|
isc_result_t (*getquota)(dns_c_ctx_t *, isc_int32_t *),
|
|
|
|
isc_quota_t *quota, int defaultvalue)
|
|
|
|
{
|
|
|
|
isc_int32_t val = defaultvalue;
|
|
|
|
(void)(*getquota)(cctx, &val);
|
|
|
|
quota->max = val;
|
|
|
|
}
|
|
|
|
|
2000-02-08 01:30:16 +00:00
|
|
|
/*
|
|
|
|
* This function is called as soon as the 'options' statement has been
|
|
|
|
* parsed.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
options_callback(dns_c_ctx_t *cctx, void *uap) {
|
|
|
|
isc_result_t result;
|
|
|
|
|
2000-02-16 18:21:17 +00:00
|
|
|
UNUSED(uap);
|
2000-02-08 01:30:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Change directory.
|
|
|
|
*/
|
|
|
|
if (cctx->options != NULL &&
|
|
|
|
cctx->options->directory != NULL) {
|
|
|
|
result = isc_dir_chdir(cctx->options->directory);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_ERROR, "change directory "
|
|
|
|
"to '%s' failed: %s",
|
|
|
|
cctx->options->directory,
|
|
|
|
isc_result_totext(result));
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2000-02-16 19:58:39 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
scan_interfaces(ns_server_t *server) {
|
|
|
|
ns_interfacemgr_scan(server->interfacemgr);
|
|
|
|
dns_aclenv_copy(&server->aclenv,
|
|
|
|
ns_interfacemgr_getaclenv(server->interfacemgr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This event callback is invoked to do periodic network
|
|
|
|
* interface scanning.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
interface_timer_tick(isc_task_t *task, isc_event_t *event) {
|
2000-04-17 19:22:44 +00:00
|
|
|
ns_server_t *server = (ns_server_t *) event->ev_arg;
|
2000-02-16 19:58:39 +00:00
|
|
|
UNUSED(task);
|
|
|
|
isc_event_free(&event);
|
|
|
|
RWLOCK(&server->conflock, isc_rwlocktype_write);
|
|
|
|
scan_interfaces(server);
|
|
|
|
RWUNLOCK(&server->conflock, isc_rwlocktype_write);
|
|
|
|
}
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
static isc_result_t
|
2000-01-29 01:38:09 +00:00
|
|
|
load_configuration(const char *filename, ns_server_t *server,
|
|
|
|
isc_boolean_t first_time)
|
|
|
|
{
|
1999-10-15 01:51:48 +00:00
|
|
|
isc_result_t result;
|
|
|
|
ns_load_t lctx;
|
|
|
|
dns_c_cbks_t callbacks;
|
2000-04-07 22:36:15 +00:00
|
|
|
dns_c_ctx_t *cctx;
|
2000-04-06 23:58:01 +00:00
|
|
|
dns_view_t *view = NULL;
|
2000-04-06 17:31:33 +00:00
|
|
|
dns_view_t *view_next;
|
2000-01-21 23:55:12 +00:00
|
|
|
dns_viewlist_t tmpviewlist;
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_aclconfctx_t aclconfctx;
|
2000-03-08 22:31:52 +00:00
|
|
|
dns_dispatch_t *dispatchv4 = NULL;
|
|
|
|
dns_dispatch_t *dispatchv6 = NULL;
|
2000-01-29 01:38:09 +00:00
|
|
|
char *pidfilename;
|
2000-02-16 19:58:39 +00:00
|
|
|
isc_int32_t interface_interval;
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_aclconfctx_init(&aclconfctx);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
2000-01-27 01:00:16 +00:00
|
|
|
RWLOCK(&server->conflock, isc_rwlocktype_write);
|
|
|
|
dns_zonemgr_lockconf(server->zonemgr, isc_rwlocktype_write);
|
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
lctx.mctx = ns_g_mctx;
|
1999-12-16 23:11:07 +00:00
|
|
|
lctx.aclconf = &aclconfctx;
|
1999-10-15 01:51:48 +00:00
|
|
|
ISC_LIST_INIT(lctx.viewlist);
|
1999-07-24 01:16:38 +00:00
|
|
|
|
2000-01-27 01:00:16 +00:00
|
|
|
callbacks.zonecbk = configure_zone;
|
1999-10-15 01:51:48 +00:00
|
|
|
callbacks.zonecbkuap = &lctx;
|
2000-02-08 01:30:16 +00:00
|
|
|
callbacks.optscbk = options_callback;
|
1999-10-15 01:51:48 +00:00
|
|
|
callbacks.optscbkuap = NULL;
|
1999-09-24 01:42:22 +00:00
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
2000-01-12 01:19:47 +00:00
|
|
|
ISC_LOG_INFO, "loading configuration from '%s'",
|
|
|
|
filename);
|
1999-07-24 01:16:38 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
/*
|
|
|
|
* Parse the configuration file creating a parse tree. Any
|
|
|
|
* 'zone' statements are handled immediately by calling
|
2000-01-27 01:00:16 +00:00
|
|
|
* configure_zone() through 'callbacks'.
|
2000-01-21 19:24:01 +00:00
|
|
|
*/
|
2000-04-07 22:36:15 +00:00
|
|
|
cctx = NULL;
|
|
|
|
CHECK(dns_c_parse_namedconf(filename, ns_g_mctx, &cctx,
|
2000-01-21 23:55:12 +00:00
|
|
|
&callbacks));
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
/*
|
|
|
|
* Configure various server options.
|
|
|
|
*/
|
2000-04-07 22:36:15 +00:00
|
|
|
configure_server_quota(cctx, dns_c_ctx_gettransfersout,
|
2000-01-21 23:55:12 +00:00
|
|
|
&server->xfroutquota, 10);
|
2000-04-07 22:36:15 +00:00
|
|
|
configure_server_quota(cctx, dns_c_ctx_gettcpclients,
|
2000-01-21 23:55:12 +00:00
|
|
|
&server->tcpquota, 100);
|
2000-04-07 22:36:15 +00:00
|
|
|
configure_server_quota(cctx, dns_c_ctx_getrecursiveclients,
|
2000-01-21 23:55:12 +00:00
|
|
|
&server->recursionquota, 100);
|
2000-01-13 23:32:41 +00:00
|
|
|
|
2000-02-25 00:52:11 +00:00
|
|
|
/*
|
|
|
|
* Configure the zone manager.
|
|
|
|
*/
|
2000-02-25 17:34:05 +00:00
|
|
|
{
|
|
|
|
isc_int32_t transfersin = 10;
|
2000-04-07 22:36:15 +00:00
|
|
|
(void) dns_c_ctx_gettransfersin(cctx, &transfersin);
|
2000-02-25 17:34:05 +00:00
|
|
|
dns_zonemgr_settransfersin(server->zonemgr, transfersin);
|
|
|
|
}
|
2000-02-25 00:52:11 +00:00
|
|
|
{
|
|
|
|
isc_int32_t transfersperns = 2;
|
2000-04-07 22:36:15 +00:00
|
|
|
(void) dns_c_ctx_gettransfersperns(cctx, &transfersperns);
|
2000-02-25 00:52:11 +00:00
|
|
|
dns_zonemgr_settransfersperns(server->zonemgr, transfersperns);
|
|
|
|
}
|
|
|
|
|
2000-01-13 23:32:41 +00:00
|
|
|
/*
|
|
|
|
* Configure the interface manager according to the "listen-on"
|
|
|
|
* statement.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
dns_c_lstnlist_t *clistenon = NULL;
|
|
|
|
ns_listenlist_t *listenon = NULL;
|
|
|
|
|
2000-04-07 22:36:15 +00:00
|
|
|
(void) dns_c_ctx_getlistenlist(cctx, &clistenon);
|
2000-01-13 23:32:41 +00:00
|
|
|
if (clistenon != NULL) {
|
|
|
|
result = ns_listenlist_fromconfig(clistenon,
|
2000-04-07 22:36:15 +00:00
|
|
|
cctx,
|
2000-01-13 23:32:41 +00:00
|
|
|
&aclconfctx,
|
2000-01-26 19:25:22 +00:00
|
|
|
ns_g_mctx,
|
|
|
|
&listenon);
|
2000-01-13 23:32:41 +00:00
|
|
|
} else {
|
|
|
|
/* Not specified, use default. */
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECK(ns_listenlist_default(ns_g_mctx, ns_g_port,
|
|
|
|
&listenon));
|
2000-01-13 23:32:41 +00:00
|
|
|
}
|
|
|
|
ns_interfacemgr_setlistenon(server->interfacemgr, listenon);
|
|
|
|
ns_listenlist_detach(&listenon);
|
|
|
|
}
|
|
|
|
|
2000-01-26 19:25:22 +00:00
|
|
|
/*
|
|
|
|
* Rescan the interface list to pick up changes in the
|
|
|
|
* listen-on option. It's important that we do this before we try
|
|
|
|
* to configure the query source, since the dispatcher we use might
|
|
|
|
* be shared with an interface.
|
|
|
|
*/
|
2000-02-16 19:58:39 +00:00
|
|
|
scan_interfaces(server);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Arrange for further interface scanning to occur periodically
|
|
|
|
* as specified by the "interface-interval" option.
|
|
|
|
*/
|
|
|
|
interface_interval = 3600; /* Default is 1 hour. */
|
2000-04-07 22:36:15 +00:00
|
|
|
(void) dns_c_ctx_getinterfaceinterval(cctx, &interface_interval);
|
2000-02-16 19:58:39 +00:00
|
|
|
if (interface_interval == 0) {
|
2000-04-06 17:31:33 +00:00
|
|
|
isc_timer_reset(server->interface_timer,
|
|
|
|
isc_timertype_inactive,
|
2000-02-16 19:58:39 +00:00
|
|
|
NULL, NULL, ISC_TRUE);
|
|
|
|
} else {
|
|
|
|
isc_interval_t interval;
|
|
|
|
isc_interval_set(&interval, interface_interval, 0);
|
|
|
|
isc_timer_reset(server->interface_timer, isc_timertype_ticker,
|
|
|
|
NULL, &interval, ISC_FALSE);
|
|
|
|
}
|
2000-01-26 19:25:22 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-04-08 00:49:19 +00:00
|
|
|
* Configure and freeze all explicit views. Explicit
|
|
|
|
* views that have zones were already created at parsing
|
2000-04-06 17:31:33 +00:00
|
|
|
* time, but views with no zones must be created here.
|
|
|
|
*/
|
2000-04-07 22:36:15 +00:00
|
|
|
if (cctx->views != NULL) {
|
2000-04-06 17:31:33 +00:00
|
|
|
dns_c_view_t *cview;
|
2000-04-07 22:36:15 +00:00
|
|
|
for (cview = ISC_LIST_HEAD(cctx->views->views);
|
2000-04-06 17:31:33 +00:00
|
|
|
cview != NULL;
|
|
|
|
cview = ISC_LIST_NEXT(cview, next))
|
|
|
|
{
|
|
|
|
view = NULL;
|
|
|
|
CHECK(find_or_create_view(cview,
|
|
|
|
&lctx.viewlist, &view));
|
|
|
|
INSIST(view != NULL);
|
2000-04-07 22:36:15 +00:00
|
|
|
CHECK(configure_view(view, cctx, cview, ns_g_mctx,
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
&aclconfctx));
|
2000-04-06 17:31:33 +00:00
|
|
|
dns_view_freeze(view);
|
|
|
|
dns_view_detach(&view);
|
|
|
|
}
|
|
|
|
}
|
2000-04-08 00:49:19 +00:00
|
|
|
INSIST(view == NULL);
|
2000-04-06 17:31:33 +00:00
|
|
|
|
|
|
|
/*
|
2000-04-08 00:49:19 +00:00
|
|
|
* Make sure we have a default view if and only if there
|
|
|
|
* were no explicit views.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
2000-04-08 00:49:19 +00:00
|
|
|
if (cctx->views == NULL || ISC_LIST_EMPTY(cctx->views->views)) {
|
|
|
|
/*
|
|
|
|
* No explicit views; there ought to be a default view.
|
|
|
|
* There may already be one created as a size effect
|
|
|
|
* of zone statements, or we may have to create one.
|
|
|
|
* In either case, we need to configure and freeze it.
|
|
|
|
*/
|
|
|
|
CHECK(find_or_create_view(NULL, &lctx.viewlist, &view));
|
2000-04-07 22:36:15 +00:00
|
|
|
CHECK(configure_view(view, cctx, NULL,
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
ns_g_mctx, &aclconfctx));
|
2000-04-08 00:49:19 +00:00
|
|
|
dns_view_freeze(view);
|
|
|
|
dns_view_detach(&view);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* There are explicit views. There should not be
|
|
|
|
* a default view. If there is one, complain.
|
|
|
|
*/
|
|
|
|
result = dns_viewlist_find(&lctx.viewlist, "_default",
|
|
|
|
dns_rdataclass_in, &view);
|
|
|
|
if (result == ISC_R_SUCCESS) {
|
|
|
|
dns_view_detach(&view);
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
|
|
|
"when using 'view' statements, "
|
|
|
|
"all zones must be in views");
|
|
|
|
result = ISC_R_FAILURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2000-01-21 19:24:01 +00:00
|
|
|
}
|
2000-04-08 00:49:19 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 19:24:01 +00:00
|
|
|
* Create (or recreate) the version view.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
|
|
|
view = NULL;
|
2000-05-17 19:45:36 +00:00
|
|
|
CHECK(create_version_view(cctx, server->zonemgr, &view));
|
1999-10-15 01:51:48 +00:00
|
|
|
ISC_LIST_APPEND(lctx.viewlist, view, link);
|
1999-12-08 21:27:08 +00:00
|
|
|
view = NULL;
|
1999-01-31 12:31:31 +00:00
|
|
|
|
1999-10-15 01:51:48 +00:00
|
|
|
/*
|
2000-01-21 23:55:12 +00:00
|
|
|
* Swap our new view list with the production one.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
2000-01-21 23:55:12 +00:00
|
|
|
tmpviewlist = server->viewlist;
|
1999-12-22 18:45:56 +00:00
|
|
|
server->viewlist = lctx.viewlist;
|
2000-01-21 23:55:12 +00:00
|
|
|
lctx.viewlist = tmpviewlist;
|
1999-10-15 01:51:48 +00:00
|
|
|
|
|
|
|
/*
|
2000-01-25 19:05:46 +00:00
|
|
|
* Load the TKEY information from the configuration.
|
1999-10-15 01:51:48 +00:00
|
|
|
*/
|
2000-01-25 19:05:46 +00:00
|
|
|
{
|
|
|
|
dns_tkey_ctx_t *t = NULL;
|
2000-04-07 22:36:15 +00:00
|
|
|
CHECKM(dns_tkeyctx_fromconfig(cctx, ns_g_mctx, &t),
|
2000-01-25 19:05:46 +00:00
|
|
|
"configuring TKEY");
|
|
|
|
if (server->tkeyctx != NULL)
|
|
|
|
dns_tkeyctx_destroy(&server->tkeyctx);
|
|
|
|
server->tkeyctx = t;
|
|
|
|
}
|
2000-01-29 01:38:09 +00:00
|
|
|
|
2000-04-18 22:17:27 +00:00
|
|
|
/*
|
|
|
|
* Relinquish root privileges.
|
|
|
|
*/
|
|
|
|
if (first_time)
|
|
|
|
ns_os_changeuser(ns_g_username);
|
|
|
|
|
2000-02-28 18:38:44 +00:00
|
|
|
/*
|
|
|
|
* Configure the logging system.
|
2000-04-18 22:17:27 +00:00
|
|
|
*
|
|
|
|
* Do this after changing UID to make sure that any log
|
|
|
|
* files specified in named.conf get created by the
|
|
|
|
* unprivileged user, not root.
|
2000-02-28 18:38:44 +00:00
|
|
|
*/
|
2000-02-28 22:17:59 +00:00
|
|
|
if (ns_g_logstderr) {
|
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
|
2000-05-02 18:45:08 +00:00
|
|
|
"ignoring config file logging "
|
|
|
|
"statement due to -g option");
|
2000-02-28 22:17:59 +00:00
|
|
|
} else {
|
2000-02-28 18:38:44 +00:00
|
|
|
dns_c_logginglist_t *clog = NULL;
|
|
|
|
isc_logconfig_t *logc = NULL;
|
|
|
|
|
2000-03-01 00:40:54 +00:00
|
|
|
CHECKM(isc_logconfig_create(ns_g_lctx, &logc),
|
|
|
|
"creating new logging configuration");
|
|
|
|
|
2000-04-07 22:36:15 +00:00
|
|
|
(void) dns_c_ctx_getlogging(cctx, &clog);
|
2000-04-28 18:53:45 +00:00
|
|
|
if (clog != NULL) {
|
2000-03-01 00:40:54 +00:00
|
|
|
CHECKM(ns_log_configure(logc, clog),
|
|
|
|
"configuring logging");
|
2000-04-28 18:53:45 +00:00
|
|
|
} else {
|
|
|
|
CHECKM(ns_log_setdefaultchannels(logc),
|
|
|
|
"setting up default logging channels");
|
|
|
|
CHECKM(ns_log_setdefaultcategory(logc),
|
|
|
|
"setting up default 'category default'");
|
|
|
|
}
|
2000-02-28 18:38:44 +00:00
|
|
|
|
|
|
|
result = isc_logconfig_use(ns_g_lctx, logc);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
isc_logconfig_destroy(&logc);
|
2000-04-13 22:41:23 +00:00
|
|
|
CHECKM(result, "installing logging configuration");
|
2000-02-28 18:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-02 18:45:08 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_DEBUG(1),
|
|
|
|
"now using logging configuration from "
|
|
|
|
"config file");
|
|
|
|
|
2000-04-07 22:36:15 +00:00
|
|
|
if (dns_c_ctx_getpidfilename(cctx, &pidfilename) ==
|
2000-01-29 01:38:09 +00:00
|
|
|
ISC_R_NOTFOUND)
|
2000-02-08 21:15:41 +00:00
|
|
|
pidfilename = ns_g_defaultpidfile;
|
2000-01-29 01:38:09 +00:00
|
|
|
ns_os_writepidfile(pidfilename);
|
2000-01-04 22:02:26 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
dns_aclconfctx_destroy(&aclconfctx);
|
1999-12-17 00:19:29 +00:00
|
|
|
|
2000-04-07 22:36:15 +00:00
|
|
|
dns_c_ctx_delete(&cctx);
|
2000-01-21 23:55:12 +00:00
|
|
|
|
2000-01-21 19:24:01 +00:00
|
|
|
cleanup:
|
2000-01-21 23:55:12 +00:00
|
|
|
/*
|
|
|
|
* This cleans up either the old production view list
|
|
|
|
* or our temporary list depending on whether they
|
|
|
|
* were swapped above or not.
|
|
|
|
*/
|
|
|
|
for (view = ISC_LIST_HEAD(lctx.viewlist);
|
|
|
|
view != NULL;
|
|
|
|
view = view_next) {
|
|
|
|
view_next = ISC_LIST_NEXT(view, link);
|
|
|
|
ISC_LIST_UNLINK(lctx.viewlist, view, link);
|
|
|
|
dns_view_detach(&view);
|
2000-01-27 01:00:16 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
}
|
2000-01-27 01:00:16 +00:00
|
|
|
|
2000-03-08 22:31:52 +00:00
|
|
|
if (dispatchv4 != NULL)
|
|
|
|
dns_dispatch_detach(&dispatchv4);
|
|
|
|
if (dispatchv6 != NULL)
|
|
|
|
dns_dispatch_detach(&dispatchv6);
|
|
|
|
|
2000-01-27 01:00:16 +00:00
|
|
|
dns_zonemgr_unlockconf(server->zonemgr, isc_rwlocktype_write);
|
2000-02-16 19:58:39 +00:00
|
|
|
RWUNLOCK(&server->conflock, isc_rwlocktype_write);
|
2000-01-21 23:55:12 +00:00
|
|
|
return (result);
|
1999-07-24 01:16:38 +00:00
|
|
|
}
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-22 01:36:34 +00:00
|
|
|
static isc_result_t
|
|
|
|
load_zones(ns_server_t *server, isc_boolean_t stop) {
|
|
|
|
isc_result_t result;
|
|
|
|
dns_view_t *view;
|
2000-01-27 01:00:16 +00:00
|
|
|
|
|
|
|
dns_zonemgr_lockconf(server->zonemgr, isc_rwlocktype_read);
|
2000-01-22 01:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Load zone data from disk.
|
|
|
|
*/
|
|
|
|
for (view = ISC_LIST_HEAD(server->viewlist);
|
|
|
|
view != NULL;
|
|
|
|
view = ISC_LIST_NEXT(view, link))
|
|
|
|
{
|
|
|
|
CHECK(dns_view_load(view, stop));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Force zone maintenance. Do this after loading
|
|
|
|
* so that we know when we need to force AXFR of
|
|
|
|
* slave zones whose master files are missing.
|
|
|
|
*/
|
|
|
|
CHECK(dns_zonemgr_forcemaint(server->zonemgr));
|
|
|
|
cleanup:
|
2000-01-27 01:00:16 +00:00
|
|
|
dns_zonemgr_unlockconf(server->zonemgr, isc_rwlocktype_read);
|
2000-01-22 01:36:34 +00:00
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
static void
|
|
|
|
run_server(isc_task_t *task, isc_event_t *event) {
|
2000-01-18 18:09:47 +00:00
|
|
|
isc_result_t result;
|
2000-04-17 19:22:44 +00:00
|
|
|
ns_server_t *server = (ns_server_t *)event->ev_arg;
|
2000-01-29 01:38:09 +00:00
|
|
|
|
2000-02-16 18:21:17 +00:00
|
|
|
UNUSED(task);
|
1999-10-15 01:51:48 +00:00
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_event_free(&event);
|
1999-01-19 06:32:53 +00:00
|
|
|
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
CHECKFATAL(dns_dispatchmgr_create(ns_g_mctx, &ns_g_dispatchmgr),
|
|
|
|
"creating dispatch manager");
|
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKFATAL(ns_clientmgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
|
|
|
|
&server->clientmgr),
|
|
|
|
"creating client manager");
|
2000-01-18 18:09:47 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKFATAL(ns_interfacemgr_create(ns_g_mctx, ns_g_taskmgr,
|
2000-05-10 21:34:50 +00:00
|
|
|
ns_g_socketmgr, ns_g_dispatchmgr,
|
|
|
|
server->clientmgr,
|
2000-01-21 23:55:12 +00:00
|
|
|
&server->interfacemgr),
|
|
|
|
"creating interface manager");
|
2000-01-18 18:09:47 +00:00
|
|
|
|
2000-02-16 19:58:39 +00:00
|
|
|
CHECKFATAL(isc_timer_create(ns_g_timermgr, isc_timertype_inactive,
|
|
|
|
NULL, NULL, server->task,
|
|
|
|
interface_timer_tick,
|
|
|
|
server, &server->interface_timer),
|
|
|
|
"creating interface timer");
|
|
|
|
|
2000-01-29 01:38:09 +00:00
|
|
|
CHECKFATAL(load_configuration(ns_g_conffile, server, ISC_TRUE),
|
2000-01-21 23:55:12 +00:00
|
|
|
"loading configuration");
|
1999-10-15 01:51:48 +00:00
|
|
|
|
2000-01-22 01:36:34 +00:00
|
|
|
CHECKFATAL(load_zones(server, ISC_TRUE),
|
|
|
|
"loading zones");
|
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
1999-10-23 00:02:23 +00:00
|
|
|
ISC_LOG_INFO, "running");
|
1999-07-24 01:16:38 +00:00
|
|
|
}
|
1999-01-28 05:52:20 +00:00
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
static void
|
|
|
|
shutdown_server(isc_task_t *task, isc_event_t *event) {
|
1999-08-05 22:14:43 +00:00
|
|
|
dns_view_t *view, *view_next;
|
2000-04-17 19:22:44 +00:00
|
|
|
ns_server_t *server = (ns_server_t *)event->ev_arg;
|
1999-12-16 23:11:07 +00:00
|
|
|
|
2000-01-27 01:00:16 +00:00
|
|
|
UNUSED(task);
|
|
|
|
|
|
|
|
RWLOCK(&server->conflock, isc_rwlocktype_write);
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-10-22 19:35:19 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
1999-10-23 00:02:23 +00:00
|
|
|
ISC_LOG_INFO, "shutting down");
|
1999-08-05 22:14:43 +00:00
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
for (view = ISC_LIST_HEAD(server->viewlist);
|
1999-08-05 22:14:43 +00:00
|
|
|
view != NULL;
|
|
|
|
view = view_next) {
|
|
|
|
view_next = ISC_LIST_NEXT(view, link);
|
1999-12-22 18:45:56 +00:00
|
|
|
ISC_LIST_UNLINK(server->viewlist, view, link);
|
1999-08-05 22:14:43 +00:00
|
|
|
dns_view_detach(&view);
|
|
|
|
}
|
1999-10-15 01:51:48 +00:00
|
|
|
|
2000-01-18 18:09:47 +00:00
|
|
|
ns_clientmgr_destroy(&server->clientmgr);
|
2000-02-16 19:58:39 +00:00
|
|
|
isc_timer_detach(&server->interface_timer);
|
2000-05-17 19:45:36 +00:00
|
|
|
|
2000-01-12 01:17:34 +00:00
|
|
|
ns_interfacemgr_shutdown(server->interfacemgr);
|
|
|
|
ns_interfacemgr_detach(&server->interfacemgr);
|
2000-05-17 19:45:36 +00:00
|
|
|
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
dns_dispatchmgr_destroy(&ns_g_dispatchmgr);
|
|
|
|
|
2000-01-19 22:02:18 +00:00
|
|
|
dns_zonemgr_shutdown(server->zonemgr);
|
2000-05-17 19:45:36 +00:00
|
|
|
dns_zonemgr_detach(&server->zonemgr);
|
Merge the mlg-20000518 branch onto the mainline. Change summary:
dns_dispatch_create() no longer exists. dns_dispatch_createtcp()
and dns_dispatch_getudp() are the replacements. _createtcp() takes
a bound, connected TCP socket, while _getudp() will search for
a sharable UDP socket, and if found, attach to it and return a
pointer to it. If one is not found, it will create a udp socket,
bind it to a supplied local address, and create a new dispatcher
around it.
dns_dispatch_remove{request,response}() no longer take the dispatch
as an argument.
query-source can now be set per view.
The dispatch manager holds onto three memory pools, one for
allocating dispatchers from, one for events, and one for
requests/replies. The free list on these pools is hard-coded,
but set to 1024. This keeps us from having to dig into the
isc_mem_t the pools draw from as often.
dns_resolver_create() and dns_view_createresolver() require that
valid dispatchers be passed in; dispatchers are no longer created
for the caller.
2000-05-19 21:46:46 +00:00
|
|
|
|
2000-01-13 22:07:24 +00:00
|
|
|
isc_task_detach(&server->task);
|
2000-01-27 01:00:16 +00:00
|
|
|
|
1999-07-24 01:16:38 +00:00
|
|
|
isc_event_free(&event);
|
2000-01-27 01:00:16 +00:00
|
|
|
|
|
|
|
RWUNLOCK(&server->conflock, isc_rwlocktype_write);
|
1999-07-24 01:16:38 +00:00
|
|
|
}
|
1999-01-19 06:32:53 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
void
|
1999-12-16 23:11:07 +00:00
|
|
|
ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
|
1999-12-22 18:45:56 +00:00
|
|
|
isc_result_t result;
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
ns_server_t *server = isc_mem_get(mctx, sizeof(*server));
|
|
|
|
if (server == NULL)
|
2000-01-21 23:55:12 +00:00
|
|
|
fatal("allocating server object", ISC_R_NOMEMORY);
|
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
server->mctx = mctx;
|
2000-01-13 22:07:24 +00:00
|
|
|
server->task = NULL;
|
|
|
|
|
2000-01-27 21:20:32 +00:00
|
|
|
CHECKFATAL(isc_rwlock_init(&server->conflock, 1, 1),
|
2000-01-27 01:00:16 +00:00
|
|
|
"initializing server configuration lock");
|
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
/* Initialize configuration data with default values. */
|
2000-01-27 01:00:16 +00:00
|
|
|
|
2000-01-13 21:17:08 +00:00
|
|
|
result = isc_quota_init(&server->xfroutquota, 10);
|
2000-01-12 01:19:47 +00:00
|
|
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
2000-01-13 21:17:08 +00:00
|
|
|
result = isc_quota_init(&server->tcpquota, 10);
|
2000-01-12 01:19:47 +00:00
|
|
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
2000-01-13 21:17:08 +00:00
|
|
|
result = isc_quota_init(&server->recursionquota, 100);
|
2000-01-12 01:19:47 +00:00
|
|
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
2000-02-09 22:59:40 +00:00
|
|
|
|
|
|
|
result = dns_aclenv_init(mctx, &server->aclenv);
|
2000-03-20 21:06:27 +00:00
|
|
|
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
2000-02-09 22:59:40 +00:00
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
/* Initialize server data structures. */
|
2000-01-18 18:09:47 +00:00
|
|
|
server->zonemgr = NULL;
|
|
|
|
server->clientmgr = NULL;
|
|
|
|
server->interfacemgr = NULL;
|
1999-12-22 18:45:56 +00:00
|
|
|
ISC_LIST_INIT(server->viewlist);
|
2000-04-06 17:31:33 +00:00
|
|
|
server->in_roothints = NULL;
|
2000-01-18 23:38:42 +00:00
|
|
|
|
2000-01-27 01:57:08 +00:00
|
|
|
CHECKFATAL(dns_rootns_create(mctx, dns_rdataclass_in, NULL,
|
2000-04-06 17:31:33 +00:00
|
|
|
&server->in_roothints),
|
2000-01-21 23:55:12 +00:00
|
|
|
"setting up root hints");
|
2000-01-24 22:21:47 +00:00
|
|
|
|
|
|
|
CHECKFATAL(isc_mutex_init(&server->reload_event_lock),
|
|
|
|
"initializing reload event lock");
|
|
|
|
server->reload_event =
|
|
|
|
isc_event_allocate(ns_g_mctx, server,
|
|
|
|
NS_EVENT_RELOAD,
|
|
|
|
ns_server_reload,
|
|
|
|
server,
|
|
|
|
sizeof(isc_event_t));
|
|
|
|
CHECKFATAL(server->reload_event == NULL ?
|
|
|
|
ISC_R_NOMEMORY : ISC_R_SUCCESS,
|
|
|
|
"allocating reload event");
|
2000-01-25 19:05:46 +00:00
|
|
|
|
|
|
|
server->tkeyctx = NULL;
|
|
|
|
CHECKFATAL(dns_tkeyctx_create(ns_g_mctx, &server->tkeyctx),
|
|
|
|
"creating TKEY context");
|
|
|
|
|
2000-01-13 22:07:24 +00:00
|
|
|
/*
|
|
|
|
* Setup the server task, which is responsible for coordinating
|
|
|
|
* startup and shutdown of the server.
|
|
|
|
*/
|
2000-04-12 01:38:26 +00:00
|
|
|
CHECKFATAL(isc_task_create(ns_g_taskmgr, 0, &server->task),
|
2000-01-21 23:55:12 +00:00
|
|
|
"creating server task");
|
2000-01-25 19:31:23 +00:00
|
|
|
isc_task_setname(server->task, "server", server);
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKFATAL(isc_task_onshutdown(server->task, shutdown_server, server),
|
|
|
|
"isc_task_onshutdown");
|
|
|
|
CHECKFATAL(isc_app_onrun(ns_g_mctx, server->task, run_server, server),
|
|
|
|
"isc_app_onrun");
|
|
|
|
|
2000-02-16 19:58:39 +00:00
|
|
|
server->interface_timer = NULL;
|
|
|
|
/*
|
|
|
|
* Create a timer for periodic interface scanning.
|
|
|
|
*/
|
2000-01-21 23:55:12 +00:00
|
|
|
CHECKFATAL(dns_zonemgr_create(ns_g_mctx, ns_g_taskmgr, ns_g_timermgr,
|
|
|
|
ns_g_socketmgr, &server->zonemgr),
|
|
|
|
"dns_zonemgr_create");
|
2000-01-19 22:02:18 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
server->magic = NS_SERVER_MAGIC;
|
|
|
|
*serverp = server;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ns_server_destroy(ns_server_t **serverp) {
|
|
|
|
ns_server_t *server = *serverp;
|
|
|
|
REQUIRE(NS_SERVER_VALID(server));
|
|
|
|
|
2000-01-25 19:05:46 +00:00
|
|
|
if (server->tkeyctx != NULL)
|
|
|
|
dns_tkeyctx_destroy(&server->tkeyctx);
|
|
|
|
|
2000-01-24 22:21:47 +00:00
|
|
|
isc_event_free(&server->reload_event);
|
|
|
|
|
1999-12-22 18:45:56 +00:00
|
|
|
INSIST(ISC_LIST_EMPTY(server->viewlist));
|
2000-01-18 23:38:42 +00:00
|
|
|
|
2000-04-06 17:31:33 +00:00
|
|
|
dns_db_detach(&server->in_roothints);
|
2000-01-18 23:38:42 +00:00
|
|
|
|
2000-02-09 22:59:40 +00:00
|
|
|
dns_aclenv_destroy(&server->aclenv);
|
|
|
|
|
2000-01-11 21:18:22 +00:00
|
|
|
isc_quota_destroy(&server->recursionquota);
|
|
|
|
isc_quota_destroy(&server->tcpquota);
|
|
|
|
isc_quota_destroy(&server->xfroutquota);
|
2000-01-27 01:00:16 +00:00
|
|
|
isc_rwlock_destroy(&server->conflock);
|
2000-01-26 19:25:22 +00:00
|
|
|
|
1999-12-16 23:11:07 +00:00
|
|
|
server->magic = 0;
|
|
|
|
isc_mem_put(server->mctx, server, sizeof(*server));
|
|
|
|
}
|
2000-01-18 22:49:55 +00:00
|
|
|
|
2000-01-21 23:55:12 +00:00
|
|
|
static void
|
2000-03-14 21:19:31 +00:00
|
|
|
fatal(char *msg, isc_result_t result) {
|
2000-01-21 23:55:12 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
2000-03-14 21:19:31 +00:00
|
|
|
ISC_LOG_CRITICAL, "%s: %s", msg,
|
|
|
|
isc_result_totext(result));
|
1999-10-23 00:02:23 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_SERVER,
|
|
|
|
ISC_LOG_CRITICAL, "exiting (due to fatal error)");
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-01-24 22:21:47 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
ns_server_reload(isc_task_t *task, isc_event_t *event) {
|
|
|
|
isc_result_t result;
|
2000-04-17 19:22:44 +00:00
|
|
|
ns_server_t *server = (ns_server_t *)event->ev_arg;
|
2000-01-24 22:21:47 +00:00
|
|
|
UNUSED(task);
|
|
|
|
|
2000-01-29 01:38:09 +00:00
|
|
|
result = load_configuration(ns_g_conffile, server, ISC_FALSE);
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-24 22:21:47 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
|
|
|
"reloading configuration failed: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
|
|
|
result = load_zones(server, ISC_FALSE);
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-24 22:21:47 +00:00
|
|
|
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
|
|
|
|
NS_LOGMODULE_SERVER, ISC_LOG_ERROR,
|
|
|
|
"reloading zones failed: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
|
|
|
LOCK(&server->reload_event_lock);
|
|
|
|
INSIST(server->reload_event == NULL);
|
|
|
|
server->reload_event = event;
|
|
|
|
UNLOCK(&server->reload_event_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ns_server_reloadwanted(ns_server_t *server) {
|
|
|
|
LOCK(&server->reload_event_lock);
|
|
|
|
if (server->reload_event != NULL)
|
|
|
|
isc_task_send(server->task, &server->reload_event);
|
|
|
|
UNLOCK(&server->reload_event_lock);
|
|
|
|
}
|
2000-01-25 21:21:05 +00:00
|
|
|
|
2000-01-31 22:06:09 +00:00
|
|
|
static isc_result_t
|
2000-01-25 21:21:05 +00:00
|
|
|
ns_listenlist_fromconfig(dns_c_lstnlist_t *clist, dns_c_ctx_t *cctx,
|
|
|
|
dns_aclconfctx_t *actx,
|
|
|
|
isc_mem_t *mctx, ns_listenlist_t **target)
|
|
|
|
{
|
|
|
|
dns_c_lstnon_t *ce;
|
|
|
|
isc_result_t result;
|
|
|
|
ns_listenlist_t *dlist = NULL;
|
|
|
|
|
|
|
|
REQUIRE(target != NULL && *target == NULL);
|
|
|
|
|
|
|
|
result = ns_listenlist_create(mctx, &dlist);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
for (ce = ISC_LIST_HEAD(clist->elements);
|
|
|
|
ce != NULL;
|
|
|
|
ce = ISC_LIST_NEXT(ce, next))
|
|
|
|
{
|
|
|
|
ns_listenelt_t *delt = NULL;
|
|
|
|
result = ns_listenelt_fromconfig(ce, cctx, actx, mctx, &delt);
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2000-01-25 21:21:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
ISC_LIST_APPEND(dlist->elts, delt, link);
|
|
|
|
}
|
|
|
|
*target = dlist;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
ns_listenlist_detach(&dlist);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a listen list from the corresponding configuration
|
|
|
|
* data structure.
|
|
|
|
*/
|
|
|
|
static isc_result_t
|
|
|
|
ns_listenelt_fromconfig(dns_c_lstnon_t *celt, dns_c_ctx_t *cctx,
|
|
|
|
dns_aclconfctx_t *actx,
|
|
|
|
isc_mem_t *mctx, ns_listenelt_t **target)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
ns_listenelt_t *delt = NULL;
|
|
|
|
REQUIRE(target != NULL && *target == NULL);
|
|
|
|
result = ns_listenelt_create(mctx, celt->port, NULL, &delt);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
result = dns_acl_fromconfig(celt->iml, cctx, actx, mctx, &delt->acl);
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-01-25 21:21:05 +00:00
|
|
|
ns_listenelt_destroy(delt);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
*target = delt;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|