lwresd.c File Reference

Main program for the Lightweight Resolver Daemon. More...

#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <isc/list.h>
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/once.h>
#include <isc/print.h>
#include <isc/socket.h>
#include <isc/task.h>
#include <isc/util.h>
#include <isccfg/namedconf.h>
#include <dns/log.h>
#include <dns/result.h>
#include <dns/view.h>
#include <named/globals.h>
#include <named/log.h>
#include <named/lwaddr.h>
#include <named/lwresd.h>
#include <named/lwdclient.h>
#include <named/lwsearch.h>
#include <named/server.h>

Go to the source code of this file.

Defines

#define LWRESD_MAGIC   ISC_MAGIC('L', 'W', 'R', 'D')
#define VALID_LWRESD(l)   ISC_MAGIC_VALID(l, LWRESD_MAGIC)
#define LWRESLISTENER_MAGIC   ISC_MAGIC('L', 'W', 'R', 'L')
#define VALID_LWRESLISTENER(l)   ISC_MAGIC_VALID(l, LWRESLISTENER_MAGIC)
#define LWRESD_NCLIENTS_MAX   32768
 max clients per task
#define CHECK(op)

Functions

typedef ISC_LIST (ns_lwreslistener_t)
void * ns__lwresd_memalloc (void *arg, size_t size)
 Wrappers around our memory management stuff, for the lwres functions.
void ns__lwresd_memfree (void *arg, void *mem, size_t size)
static isc_result_t buffer_putstr (isc_buffer_t *b, const char *s)
isc_result_t ns_lwresd_parseeresolvconf (isc_mem_t *mctx, cfg_parser_t *pctx, cfg_obj_t **configp)
isc_result_t ns_lwdmanager_create (isc_mem_t *mctx, const cfg_obj_t *lwres, ns_lwresd_t **lwresdp)
 create manager
void ns_lwdmanager_attach (ns_lwresd_t *source, ns_lwresd_t **targetp)
 attach to manager
void ns_lwdmanager_detach (ns_lwresd_t **lwresdp)
 detach from manager
void ns_lwreslistener_attach (ns_lwreslistener_t *source, ns_lwreslistener_t **targetp)
 attach to listener
void ns_lwreslistener_detach (ns_lwreslistener_t **listenerp)
 detach from lister
static isc_result_t listener_create (isc_mem_t *mctx, ns_lwresd_t *lwresd, ns_lwreslistener_t **listenerp)
static isc_result_t listener_bind (ns_lwreslistener_t *listener, isc_sockaddr_t *address)
static void listener_copysock (ns_lwreslistener_t *oldlistener, ns_lwreslistener_t *newlistener)
static isc_result_t listener_startclients (ns_lwreslistener_t *listener)
static void listener_shutdown (ns_lwreslistener_t *listener)
static isc_result_t find_listener (isc_sockaddr_t *address, ns_lwreslistener_t **listenerp)
void ns_lwreslistener_unlinkcm (ns_lwreslistener_t *listener, ns_lwdclientmgr_t *cm)
 link client manager
void ns_lwreslistener_linkcm (ns_lwreslistener_t *listener, ns_lwdclientmgr_t *cm)
 unlink client manager
static isc_result_t configure_listener (isc_sockaddr_t *address, ns_lwresd_t *lwresd, isc_mem_t *mctx, ns_lwreslistenerlist_t *newlisteners)
isc_result_t ns_lwresd_configure (isc_mem_t *mctx, const cfg_obj_t *config)
 Configure lwresd.
void ns_lwresd_shutdown (void)
 Trigger shutdown.


Detailed Description

Main program for the Lightweight Resolver Daemon.

To paraphrase the old saying about X11, "It's not a lightweight deamon for resolvers, it's a deamon for lightweight resolvers".

Definition in file lwresd.c.


Define Documentation

#define LWRESD_MAGIC   ISC_MAGIC('L', 'W', 'R', 'D')

Definition at line 57 of file lwresd.c.

Referenced by ns_lwdmanager_create().

#define VALID_LWRESD (  )     ISC_MAGIC_VALID(l, LWRESD_MAGIC)

Definition at line 58 of file lwresd.c.

Referenced by ns_lwdmanager_attach(), and ns_lwdmanager_detach().

#define LWRESLISTENER_MAGIC   ISC_MAGIC('L', 'W', 'R', 'L')

Definition at line 60 of file lwresd.c.

Referenced by listener_create().

#define VALID_LWRESLISTENER (  )     ISC_MAGIC_VALID(l, LWRESLISTENER_MAGIC)

Definition at line 61 of file lwresd.c.

Referenced by ns_lwreslistener_attach(), ns_lwreslistener_detach(), ns_lwreslistener_linkcm(), and ns_lwreslistener_unlinkcm().

#define LWRESD_NCLIENTS_MAX   32768

max clients per task

Definition at line 63 of file lwresd.c.

Referenced by ns_lwdmanager_create().

#define CHECK ( op   ) 

Value:

do { result = (op);                                     \
                if (result != ISC_R_SUCCESS) goto cleanup;      \
        } while (0)

Definition at line 92 of file lwresd.c.


Function Documentation

typedef ISC_LIST ( ns_lwreslistener_t   ) 

Definition at line 65 of file lwresd.c.

References isc_mutex_init, ISC_R_SUCCESS, and RUNTIME_CHECK.

void* ns__lwresd_memalloc ( void *  arg,
size_t  size 
)

Wrappers around our memory management stuff, for the lwres functions.

Definition at line 82 of file lwresd.c.

References isc_mem_get.

Referenced by ns_lwdclientmgr_create(), and ns_lwresd_parseeresolvconf().

void ns__lwresd_memfree ( void *  arg,
void *  mem,
size_t  size 
)

Definition at line 87 of file lwresd.c.

References isc_mem_put.

Referenced by ns_lwdclientmgr_create(), and ns_lwresd_parseeresolvconf().

static isc_result_t buffer_putstr ( isc_buffer_t b,
const char *  s 
) [static]

Definition at line 98 of file lwresd.c.

References isc_buffer_availablelength, isc_buffer_putmem, ISC_R_NOSPACE, and ISC_R_SUCCESS.

Referenced by ns_lwresd_parseeresolvconf().

isc_result_t ns_lwresd_parseeresolvconf ( isc_mem_t mctx,
cfg_parser_t pctx,
cfg_obj_t **  configp 
)

Definition at line 110 of file lwresd.c.

References buffer_putstr(), cfg_parse_buffer(), cfg_type_namedconf, CHECK, cleanup(), DNS_R_SYNTAX, INSIST, isc_buffer_base, isc_buffer_init, isc_buffer_usedlength, ISC_LOG_ERROR, isc_log_write(), isc_netaddr_format(), ISC_NETADDR_FORMATSIZE, isc_netaddr_fromsockaddr(), isc_netaddr_masktoprefixlen(), isc_netaddr_totext(), ISC_R_NOMEMORY, ISC_R_SUCCESS, lwaddr_sockaddr_fromlwresaddr(), lwctx, ns__lwresd_memalloc(), ns__lwresd_memfree(), NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, str, and text.

Referenced by load_configuration().

isc_result_t ns_lwdmanager_create ( isc_mem_t mctx,
const cfg_obj_t lwres,
ns_lwresd_t **  lwresdp 
)

create manager

Definition at line 285 of file lwresd.c.

References cfg_list_first(), cfg_list_next(), cfg_listelt_value(), cfg_map_get(), cfg_obj_asstring(), cfg_obj_asuint32(), cfg_tuple_get(), dns_fixedname_init, dns_fixedname_name, dns_name_fromtext(), dns_rootname, dns_view_detach(), dns_viewlist_find(), INSIST, isc_buffer_add, isc_buffer_constinit, ISC_FALSE, ISC_LOG_WARNING, isc_log_write(), isc_mem_attach(), isc_mem_detach(), isc_mem_get, isc_mem_put, isc_mutex_init, ISC_R_NOMEMORY, ISC_R_SUCCESS, ns_lwresd::lock, LWRESD_MAGIC, LWRESD_NCLIENTS_MAX, ns_lwresd::magic, ns_lwresd::mctx, name, namebuf, ns_lwresd::nclients, ns_lwresd::ndots, ns_config_getclass(), NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, ns_lwsearchlist_append(), ns_lwsearchlist_create(), ns_lwsearchlist_detach(), ns_lwresd::ntasks, ns_lwresd::refs, RUNTIME_CHECK, search(), ns_lwresd::search, ns_lwresd::shutting_down, and ns_lwresd::view.

Referenced by ns_lwresd_configure().

void ns_lwdmanager_attach ( ns_lwresd_t source,
ns_lwresd_t **  targetp 
)

attach to manager

Definition at line 429 of file lwresd.c.

References INSIST, ns_lwresd::lock, LOCK, ns_lwresd::refs, UNLOCK, and VALID_LWRESD.

Referenced by listener_create().

void ns_lwdmanager_detach ( ns_lwresd_t **  lwresdp  ) 

detach from manager

Definition at line 441 of file lwresd.c.

References dns_view_detach(), INSIST, ISC_FALSE, isc_mem_detach(), isc_mem_put, ISC_TRUE, ns_lwresd::lock, LOCK, ns_lwresd::magic, ns_lwresd::mctx, mctx, ns_lwsearchlist_detach(), ns_lwresd::refs, ns_lwresd::search, UNLOCK, VALID_LWRESD, and ns_lwresd::view.

Referenced by ns_lwresd_configure(), and ns_lwreslistener_detach().

void ns_lwreslistener_attach ( ns_lwreslistener_t source,
ns_lwreslistener_t **  targetp 
)

attach to listener

Definition at line 476 of file lwresd.c.

References INSIST, ns_lwreslistener::lock, LOCK, ns_lwreslistener::refs, UNLOCK, and VALID_LWRESLISTENER.

Referenced by ns_lwdclientmgr_create().

void ns_lwreslistener_detach ( ns_lwreslistener_t **  listenerp  ) 

detach from lister

Definition at line 490 of file lwresd.c.

References INSIST, ISC_FALSE, isc_mem_detach(), isc_mem_put, isc_socket_detach(), ISC_TRUE, ns_lwreslistener::lock, LOCK, ns_lwreslistener::magic, ns_lwreslistener::manager, ns_lwreslistener::mctx, mctx, ns_lwdmanager_detach(), ns_lwreslistener::refs, ns_lwreslistener::sock, UNLOCK, and VALID_LWRESLISTENER.

Referenced by configure_listener(), lwdclientmgr_destroy(), ns_lwresd_configure(), and ns_lwresd_shutdown().

static isc_result_t listener_create ( isc_mem_t mctx,
ns_lwresd_t lwresd,
ns_lwreslistener_t **  listenerp 
) [static]

Definition at line 524 of file lwresd.c.

References ISC_LINK_INIT, ISC_LIST_INIT, isc_mem_attach(), isc_mem_get, isc_mem_put, isc_mutex_init, ISC_R_NOMEMORY, ISC_R_SUCCESS, ns_lwreslistener::lock, LWRESLISTENER_MAGIC, ns_lwreslistener::magic, ns_lwreslistener::manager, ns_lwreslistener::mctx, ns_lwdmanager_attach(), ns_lwreslistener::refs, REQUIRE, and ns_lwreslistener::sock.

Referenced by configure_listener().

static isc_result_t listener_bind ( ns_lwreslistener_t listener,
isc_sockaddr_t address 
) [static]

Definition at line 561 of file lwresd.c.

References ns_lwreslistener::address, AF_INET6, ISC_LOG_WARNING, isc_log_write(), isc_net_probeipv4(), isc_net_probeipv6(), ISC_R_FAMILYNOSUPPORT, ISC_R_SUCCESS, isc_result_totext(), isc_sockaddr_format(), ISC_SOCKADDR_FORMATSIZE, isc_sockaddr_getport(), isc_sockaddr_pf(), isc_sockaddr_setport(), isc_socket_bind(), isc_socket_create(), isc_socket_detach(), ISC_SOCKET_REUSEADDRESS, isc_sockettype_udp, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, port, ns_lwreslistener::sock, and sock.

Referenced by configure_listener().

static void listener_copysock ( ns_lwreslistener_t oldlistener,
ns_lwreslistener_t newlistener 
) [static]

Definition at line 610 of file lwresd.c.

References ns_lwreslistener::address, isc_socket_attach(), and ns_lwreslistener::sock.

Referenced by configure_listener().

static isc_result_t listener_startclients ( ns_lwreslistener_t listener  )  [static]

Definition at line 618 of file lwresd.c.

References ISC_LIST_EMPTY, ISC_LIST_HEAD, ISC_LIST_NEXT, ISC_LOG_DEBUG, ISC_LOG_ERROR, isc_log_write(), ISC_R_SUCCESS, isc_result_totext(), ns_lwreslistener::lock, LOCK, ns_lwreslistener::manager, ns_lwresd::nclients, NS_LOGCATEGORY_GENERAL, NS_LOGMODULE_LWRESD, ns_lwdclient_startrecv(), ns_lwdclientmgr_create(), ns_lwresd::ntasks, and UNLOCK.

Referenced by configure_listener().

static void listener_shutdown ( ns_lwreslistener_t listener  )  [static]

Definition at line 667 of file lwresd.c.

References ISC_LIST_HEAD, ISC_LIST_NEXT, isc_task_shutdown(), and ns_lwdclientmgr::task.

Referenced by configure_listener(), and ns_lwresd_configure().

static isc_result_t find_listener ( isc_sockaddr_t address,
ns_lwreslistener_t **  listenerp 
) [static]

Definition at line 678 of file lwresd.c.

References ns_lwreslistener::address, INSIST, ISC_LIST_HEAD, ISC_LIST_NEXT, ISC_R_NOTFOUND, ISC_R_SUCCESS, and isc_sockaddr_equal().

Referenced by configure_listener().

void ns_lwreslistener_unlinkcm ( ns_lwreslistener_t listener,
ns_lwdclientmgr_t cm 
)

link client manager

Definition at line 696 of file lwresd.c.

References ISC_LIST_UNLINK, ns_lwreslistener::lock, LOCK, REQUIRE, UNLOCK, and VALID_LWRESLISTENER.

Referenced by lwdclientmgr_destroy().

void ns_lwreslistener_linkcm ( ns_lwreslistener_t listener,
ns_lwdclientmgr_t cm 
)

unlink client manager

Definition at line 706 of file lwresd.c.

References ISC_LIST_APPEND, REQUIRE, and VALID_LWRESLISTENER.

Referenced by ns_lwdclientmgr_create().

static isc_result_t configure_listener ( isc_sockaddr_t address,
ns_lwresd_t lwresd,
isc_mem_t mctx,
ns_lwreslistenerlist_t *  newlisteners 
) [static]

Definition at line 717 of file lwresd.c.

References find_listener(), ISC_LIST_APPEND, ISC_LIST_UNLINK, ISC_LOG_NOTICE, ISC_LOG_WARNING, isc_log_write(), ISC_LOGCATEGORY_GENERAL, ISC_R_SUCCESS, isc_result_totext(), isc_sockaddr_format(), ISC_SOCKADDR_FORMATSIZE, listener_bind(), listener_copysock(), listener_create(), listener_shutdown(), listener_startclients(), NS_LOGMODULE_LWRESD, and ns_lwreslistener_detach().

Referenced by ns_lwresd_configure().

isc_result_t ns_lwresd_configure ( isc_mem_t mctx,
const cfg_obj_t config 
)

Configure lwresd.

Definition at line 778 of file lwresd.c.

References ns_lwreslistener::address, cfg_list_first(), cfg_list_next(), cfg_listelt_value(), cfg_map_get(), CHECK, cleanup(), configure_listener(), INADDR_LOOPBACK, ISC_LIST_APPENDLIST, ISC_LIST_EMPTY, ISC_LIST_HEAD, ISC_LIST_INIT, ISC_LIST_UNLINK, ISC_LOG_NOTICE, isc_log_write(), ISC_LOGCATEGORY_GENERAL, isc_once_do, ISC_R_SUCCESS, isc_sockaddr_format(), ISC_SOCKADDR_FORMATSIZE, isc_sockaddr_fromin(), listener_shutdown(), LOCK, ns_config_getiplist(), ns_config_putiplist(), NS_LOGMODULE_LWRESD, ns_lwdmanager_create(), ns_lwdmanager_detach(), ns_lwreslistener_detach(), once, port, REQUIRE, RUNTIME_CHECK, and UNLOCK.

Referenced by load_configuration().

void ns_lwresd_shutdown ( void   ) 

Trigger shutdown.

Definition at line 883 of file lwresd.c.

References ISC_LIST_EMPTY, ISC_LIST_HEAD, ISC_LIST_UNLINK, isc_once_do, ISC_R_SUCCESS, ns_lwreslistener_detach(), once, and RUNTIME_CHECK.

Referenced by destroy_managers().


Generated on Tue Apr 28 17:41:07 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha