Commit 208e3e41 authored by Brian Wellington's avatar Brian Wellington
Browse files

lwresd bug fixes, command line updates, configurability stuff

parent e7ddc97b
......@@ -50,6 +50,7 @@ EXTERN isc_socketmgr_t * ns_g_socketmgr INIT(NULL);
EXTERN omapi_object_t * ns_g_omapimgr INIT(NULL);
EXTERN const char * ns_g_version INIT(VERSION);
EXTERN in_port_t ns_g_port INIT(0);
EXTERN in_port_t lwresd_g_queryport INIT(0);
EXTERN ns_server_t * ns_g_server INIT(NULL);
EXTERN ns_lwresd_t * ns_g_lwresd INIT(NULL);
......@@ -67,6 +68,7 @@ EXTERN unsigned int ns_g_debuglevel INIT(0);
*/
EXTERN const char * ns_g_conffile INIT(NS_SYSCONFDIR
"/named.conf");
EXTERN const char * lwresd_g_conffile INIT("/etc/resolv.conf");
/*
* Misc.
......@@ -78,6 +80,8 @@ EXTERN isc_boolean_t ns_g_logstderr INIT(ISC_FALSE);
EXTERN const char * ns_g_defaultpidfile INIT(NS_LOCALSTATEDIR
"/run/named.pid");
EXTERN const char * lwresd_g_defaultpidfile INIT(NS_LOCALSTATEDIR
"/run/lwresd.pid");
EXTERN const char * ns_g_username INIT(NULL);
/*
......
......@@ -49,6 +49,7 @@
#include <named/lwresd.h>
#include <named/lwdclient.h>
#include <named/server.h>
#include <named/os.h>
#define LWRESD_MAGIC ISC_MAGIC('L', 'W', 'R', 'D')
#define VALID_LWRESD(l) ISC_MAGIC_VALID(l, LWRESD_MAGIC)
......@@ -111,7 +112,7 @@ shutdown_lwresd(isc_task_t *task, isc_event_t *event) {
static void
parse_resolv_conf(isc_mem_t *mctx, isc_sockaddrlist_t forwarders) {
parse_resolv_conf(isc_mem_t *mctx, isc_sockaddrlist_t *forwarders) {
lwres_context_t *lwctx;
lwres_conf_t *lwc;
int lwresult;
......@@ -119,6 +120,7 @@ parse_resolv_conf(isc_mem_t *mctx, isc_sockaddrlist_t forwarders) {
struct in6_addr ina6;
isc_sockaddr_t *sa;
int i;
in_port_t port;
lwctx = NULL;
lwresult = lwres_context_create(&lwctx, mctx, mem_alloc, mem_free,
......@@ -126,7 +128,7 @@ parse_resolv_conf(isc_mem_t *mctx, isc_sockaddrlist_t forwarders) {
if (lwresult != LWRES_R_SUCCESS)
return;
lwresult = lwres_conf_parse(lwctx, "/etc/resolv.conf");
lwresult = lwres_conf_parse(lwctx, lwresd_g_conffile);
if (lwresult != LWRES_R_SUCCESS)
goto out;
......@@ -137,26 +139,31 @@ parse_resolv_conf(isc_mem_t *mctx, isc_sockaddrlist_t forwarders) {
lwc = lwres_conf_get(lwctx);
INSIST(lwc != NULL);
if (lwresd_g_queryport == 0)
port = 53;
else
port = lwresd_g_queryport;
/*
* Run through the list of nameservers, and set them to be our
* forwarders.
*/
for (i = 0 ; i < lwc->nsnext ; i++) {
switch (lwc->nameservers[i].family) {
case AF_INET:
case LWRES_ADDRTYPE_V4:
sa = isc_mem_get(mctx, sizeof *sa);
INSIST(sa != NULL);
memcpy(&ina.s_addr, lwc->nameservers[i].address, 4);
isc_sockaddr_fromin(sa, &ina, 53);
ISC_LIST_APPEND(forwarders, sa, link);
isc_sockaddr_fromin(sa, &ina, port);
ISC_LIST_APPEND(*forwarders, sa, link);
sa = NULL;
break;
case AF_INET6:
case LWRES_ADDRTYPE_V6:
sa = isc_mem_get(mctx, sizeof *sa);
INSIST(sa != NULL);
memcpy(&ina6.s6_addr, lwc->nameservers[i].address, 16);
isc_sockaddr_fromin6(sa, &ina6, 53);
ISC_LIST_APPEND(forwarders, sa, link);
isc_sockaddr_fromin6(sa, &ina6, port);
ISC_LIST_APPEND(*forwarders, sa, link);
sa = NULL;
break;
default:
......@@ -253,7 +260,7 @@ ns_lwresd_createview(isc_mem_t *mctx, dns_view_t **viewp) {
* If we have forwarders, set them here.
*/
ISC_LIST_INIT(forwarders);
parse_resolv_conf(mctx, forwarders);
parse_resolv_conf(mctx, &forwarders);
if (ISC_LIST_HEAD(forwarders) != NULL) {
isc_sockaddr_t *sa;
......@@ -304,6 +311,8 @@ ns_lwresd_create(isc_mem_t *mctx, dns_view_t *view, ns_lwresd_t **lwresdp) {
fatal("failed to bind lwresd protocol socket", result);
}
ns_os_writepidfile(lwresd_g_defaultpidfile);
lwresd = isc_mem_get(mctx, sizeof(*lwresd));
if (lwresd == NULL)
fatal("allocating lightweight resolver object", ISC_R_NOMEMORY);
......
......@@ -164,6 +164,15 @@ library_unexpected_error(const char *file, int line, const char *format,
}
}
static void
lwresd_usage(void) {
fprintf(stderr,
"usage: lwresd [-C conffile] [-d debuglevel] "
"[-f|-g] [-n number_of_cpus]\n"
" [-p listen-port] [-P query-port] [-s] "
"[-t chrootdir] [-u username] [-i pidfile]\n");
}
static void
usage(void) {
fprintf(stderr,
......@@ -172,6 +181,80 @@ usage(void) {
" [-p port] [-s] [-t chrootdir] [-u username]\n");
}
static void
parse_lwresd_command_line(int argc, char *argv[]) {
int ch;
unsigned int port;
isc_commandline_errprint = ISC_FALSE;
while ((ch = isc_commandline_parse(argc, argv,
"C:d:fgi:n:p:P:st:u:")) !=
-1) {
switch (ch) {
case 'C':
lwresd_g_conffile = isc_commandline_argument;
break;
case 'd':
ns_g_debuglevel = atoi(isc_commandline_argument);
break;
case 'f':
ns_g_foreground = ISC_TRUE;
break;
case 'g':
ns_g_foreground = ISC_TRUE;
ns_g_logstderr = ISC_TRUE;
break;
case 'i':
lwresd_g_defaultpidfile = isc_commandline_argument;
break;
case 'n':
ns_g_cpus = atoi(isc_commandline_argument);
if (ns_g_cpus == 0)
ns_g_cpus = 1;
break;
case 'p':
port = atoi(isc_commandline_argument);
if (port < 1 || port > 65535)
ns_main_earlyfatal("port '%s' out of range",
isc_commandline_argument);
ns_g_port = port;
break;
case 'P':
port = atoi(isc_commandline_argument);
if (port < 1 || port > 65535)
ns_main_earlyfatal("port '%s' out of range",
isc_commandline_argument);
lwresd_g_queryport = port;
break;
case 's':
/* XXXRTH temporary syntax */
want_stats = ISC_TRUE;
break;
case 't':
/* XXXJAB should we make a copy? */
ns_g_chrootdir = isc_commandline_argument;
break;
case 'u':
ns_g_username = isc_commandline_argument;
break;
case '?':
lwresd_usage();
ns_main_earlyfatal("unknown option '-%c'",
isc_commandline_option);
default:
ns_main_earlyfatal("parsing options returned %d", ch);
}
}
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc > 0) {
lwresd_usage();
ns_main_earlyfatal("extra command line arguments");
}
}
static void
parse_command_line(int argc, char *argv[]) {
int ch;
......@@ -183,8 +266,11 @@ parse_command_line(int argc, char *argv[]) {
s = argv[0];
else
s++;
if (strcmp(s, "lwresd") == 0)
if (strcmp(s, "lwresd") == 0) {
lwresd_only = ISC_TRUE;
parse_lwresd_command_line(argc, argv);
return;
}
isc_commandline_errprint = ISC_FALSE;
while ((ch = isc_commandline_parse(argc, argv,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment