lwresd.c revision c7c5645e062287294326fdb92e7e9b831950c4f3
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * Copyright (C) 2000-2002 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * Permission to use, copy, modify, and distribute this software for any
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/* $Id: lwresd.c,v 1.44 2003/04/17 06:39:33 marka Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * Main program for the Lightweight Resolver Daemon.
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * To paraphrase the old saying about X11, "It's not a lightweight deamon
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * for resolvers, it's a deamon for lightweight resolvers".
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson#define LWRESD_MAGIC ISC_MAGIC('L', 'W', 'R', 'D')
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson#define VALID_LWRESD(l) ISC_MAGIC_VALID(l, LWRESD_MAGIC)
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson#define LWRESLISTENER_MAGIC ISC_MAGIC('L', 'W', 'R', 'L')
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson#define VALID_LWRESLISTENER(l) ISC_MAGIC_VALID(l, LWRESLISTENER_MAGIC)
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson * The total number of clients we can handle will be NTASKS * NRECVS.
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson#define NTASKS 2 /* tasks to create to handle lwres queries */
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson#define NRECVS 2 /* max clients per task */
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafssontypedef ISC_LIST(ns_lwreslistener_t) ns_lwreslistenerlist_t;
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson RUNTIME_CHECK(isc_mutex_init(&listeners_lock) == ISC_R_SUCCESS);
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson * Wrappers around our memory management stuff, for the lwres functions.
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafssonns__lwresd_memalloc(void *arg, size_t size) {
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafssonns__lwresd_memfree(void *arg, void *mem, size_t size) {
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson if (result != ISC_R_SUCCESS) goto cleanup; \
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafssonbuffer_putstr(isc_buffer_t *b, const char *s) {
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson if (isc_buffer_availablelength(b) <= len)
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson isc_buffer_putmem(b, (const unsigned char *)s, len);
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson * Convert a resolv.conf file into a config structure.
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafssonns_lwresd_parseeresolvconf(isc_mem_t *mctx, cfg_parser_t *pctx,
fd0bc40a2580299d20ae212d89bda13862d78b3aAndreas Gustafsson lwresult = lwres_context_create(&lwctx, mctx, ns__lwresd_memalloc,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson lwresult = lwres_conf_parse(lwctx, lwresd_g_resolvconffile);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * Build the list of forwarders.
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson CHECK(buffer_putstr(&b, "\tforwarders {\n"));
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews * Build the sortlist
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson lwres_addr_t *lwaddr = &lwc->sortlist[i].addr;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson lwres_addr_t *lwmask = &lwc->sortlist[i].mask;
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson CHECK(lwaddr_sockaddr_fromlwresaddr(&sa, lwmask, 0));
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson result = isc_netaddr_masktoprefixlen(&na, &mask);
6eccf5bd07eb9abf65cc08fec4a8fc97b62c0e1bBrian Wellington "processing sortlist: '%s' is "
6eccf5bd07eb9abf65cc08fec4a8fc97b62c0e1bBrian Wellington "not a valid netmask",
6eccf5bd07eb9abf65cc08fec4a8fc97b62c0e1bBrian Wellington CHECK(lwaddr_sockaddr_fromlwresaddr(&sa, lwaddr, 0));
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson * Build the search path
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson CHECK(buffer_putstr(&b, lwc->search[i]));
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson * Build the ndots line
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson snprintf(str, sizeof(str), "%u", lwc->ndots);
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson * Build the listen-on line
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson CHECK(buffer_putstr(&b, "\tlisten-on {\n"));
febaa091847ab004f40500cc475a819f2c73fcddAndreas Gustafsson return (cfg_parse_buffer(pctx, &b, &cfg_type_namedconf, configp));
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson * Handle lwresd manager objects
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafssonns_lwdmanager_create(isc_mem_t *mctx, cfg_obj_t *lwres,
ea419adc4eca4c3e44f2c282035b5dce6b795fe2Andreas Gustafsson INSIST(lwresdp != NULL && *lwresdp == NULL);
aa23a35d81a9618a40c4a9b44be48009553e4777Andreas Gustafsson lwresd = isc_mem_get(mctx, sizeof(ns_lwresd_t));
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence RUNTIME_CHECK(isc_mutex_init(&lwresd->lock) == ISC_R_SUCCESS);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson (void)cfg_map_get(lwres, "view", &viewobj);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson vname = cfg_obj_asstring(cfg_tuple_get(viewobj, "name"));
aa39170da817cae7b4c6c735cc832e05ec3d2351Mark Andrews result = ns_config_getclass(obj, dns_rdataclass_in, &vclass);
7693d4de8fca501dfe6989a7f30d8d3c86fe096aAndreas Gustafsson result = dns_viewlist_find(&ns_g_server->viewlist, vname, vclass,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson (void)cfg_map_get(lwres, "search", &searchobj);
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson result = ns_lwsearchlist_create(lwresd->mctx,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson "couldn't create searchlist");
6017f424ee3c02d7f22132c77576ea38542fa949Andreas Gustafsson for (element = cfg_list_first(searchobj);
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson isc_buffer_add(&namebuf, strlen(searchstr));
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson result = dns_name_fromtext(name, &namebuf,
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson "invalid name %s in searchlist",
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson result = ns_lwsearchlist_append(lwresd->search, name);
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafsson "couldn't update searchlist");
9c566a852f31c3a5d0b9d6eaf11463114339c01dAndreas Gustafssonns_lwdmanager_attach(ns_lwresd_t *source, ns_lwresd_t **targetp) {
6eccf5bd07eb9abf65cc08fec4a8fc97b62c0e1bBrian Wellingtonns_lwdmanager_detach(ns_lwresd_t **lwresdp) {
a1747570262ed336c213aaf6bd31bc91993a46deAndreas Gustafsson INSIST(lwresdp != NULL && *lwresdp != NULL);
if (!done)
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
static isc_result_t
int pf;
return (ISC_R_FAMILYNOSUPPORT);
if (port == 0)
return (result);
sizeof(socktext));
return (result);
return (ISC_R_SUCCESS);
static isc_result_t
return (result);
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
static isc_result_t
return (result);
return (ISC_R_SUCCESS);
return (ISC_R_SUCCESS);
return (result);
return (ISC_R_SUCCESS);
if (port == 0)
&newlisteners));
isc_uint32_t i;
for (i = 0; i < count; i++)
return (result);
ns_lwresd_shutdown(void) {