Commandline options to set forwarder, udp timeout.

git-svn-id: file:///svn/unbound/trunk@58 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2007-02-02 12:52:40 +00:00
parent bfe5459835
commit b968590e00
7 changed files with 58 additions and 29 deletions

View file

@ -55,6 +55,8 @@ static void usage()
printf("-h this help\n"); printf("-h this help\n");
printf("-p port the port to listen on\n"); printf("-p port the port to listen on\n");
printf("-v verbose (multiple times increase verbosity)\n"); printf("-v verbose (multiple times increase verbosity)\n");
printf("-f ip set forwarder address\n");
printf("-z port set forwarder port\n");
printf("Version %s\n", PACKAGE_VERSION); printf("Version %s\n", PACKAGE_VERSION);
printf("BSD licensed, see LICENSE file in source package.\n"); printf("BSD licensed, see LICENSE file in source package.\n");
printf("Report bugs to %s.\n", PACKAGE_BUGREPORT); printf("Report bugs to %s.\n", PACKAGE_BUGREPORT);
@ -84,8 +86,14 @@ main(int argc, char* argv[])
log_init(); log_init();
/* parse the options */ /* parse the options */
while( (c=getopt(argc, argv, "hvp:")) != -1) { while( (c=getopt(argc, argv, "f:hvp:z:")) != -1) {
switch(c) { switch(c) {
case 'f':
fwd = optarg;
break;
case 'z':
fwdport = optarg;
break;
case 'p': case 'p':
if(!atoi(optarg)) if(!atoi(optarg))
fatal_exit("invalid port '%s'", optarg); fatal_exit("invalid port '%s'", optarg);
@ -119,7 +127,7 @@ main(int argc, char* argv[])
} }
if(!worker_set_fwd(worker, fwd, fwdport)) { if(!worker_set_fwd(worker, fwd, fwdport)) {
worker_delete(worker); worker_delete(worker);
fatal_exit("could set forwarder address"); fatal_exit("could not set forwarder address");
} }
/* drop user priviliges and chroot if needed */ /* drop user priviliges and chroot if needed */

View file

@ -188,23 +188,38 @@ void worker_delete(struct worker* worker)
int worker_set_fwd(struct worker* worker, const char* ip, const char* port) int worker_set_fwd(struct worker* worker, const char* ip, const char* port)
{ {
struct addrinfo *res = NULL; uint16_t p;
struct addrinfo hints;
int r;
log_assert(worker && ip); log_assert(worker && ip);
memset(&hints, 0, sizeof(hints)); if(port)
hints.ai_family = AF_UNSPEC; p = (uint16_t)atoi(port);
hints.ai_socktype = SOCK_DGRAM; else p = (uint16_t)atoi(UNBOUND_DNS_PORT);
if(!port) if(!p) {
port = UNBOUND_DNS_PORT; log_err("Bad port number %s", port?port:"default_port");
if((r=getaddrinfo(ip, port, &hints, &res)) != 0 || !res) {
log_err("failed %s:%s getaddrinfo: %s %s",
ip, port,
gai_strerror(r), r==EAI_SYSTEM?strerror(errno):"");
return 0; return 0;
} }
worker->fwd_addrlen = res->ai_addrlen; if(str_is_ip6(ip)) {
memcpy(&worker->fwd_addr, &res->ai_addr, res->ai_addrlen); struct sockaddr_in6* sa =
freeaddrinfo(res); (struct sockaddr_in6*)&worker->fwd_addr;
worker->fwd_addrlen = (socklen_t)sizeof(struct sockaddr_in6);
memset(sa, 0, worker->fwd_addrlen);
sa->sin6_family = AF_INET6;
sa->sin6_port = htons(p);
if(inet_pton((int)sa->sin6_family, ip, &sa->sin6_addr) <= 0) {
log_err("Bad ip6 address %s", ip);
return 0;
}
} else { /* ip4 */
struct sockaddr_in* sa =
(struct sockaddr_in*)&worker->fwd_addr;
worker->fwd_addrlen = (socklen_t)sizeof(struct sockaddr_in);
memset(sa, 0, worker->fwd_addrlen);
sa->sin_family = AF_INET;
sa->sin_port = htons(p);
if(inet_pton((int)sa->sin_family, ip, &sa->sin_addr) <= 0) {
log_err("Bad ip4 address %s", ip);
return 0;
}
}
verbose(VERB_ALGO, "fwd queries to: %s %d", ip, p);
return 1; return 1;
} }

View file

@ -3,6 +3,8 @@
address families. address families.
- uses IPV6_USE_MIN_MTU for udp6 ,IPV6_V6ONLY to make ip6 sockets. - uses IPV6_USE_MIN_MTU for udp6 ,IPV6_V6ONLY to make ip6 sockets.
- listens on both ip4 and ip6 ports to provide correct return address. - listens on both ip4 and ip6 ports to provide correct return address.
- worker fwder address filled correctly.
- fixup timer code.
1 February 2007: Wouter 1 February 2007: Wouter
- outside network more UDP work. - outside network more UDP work.

View file

@ -42,6 +42,8 @@ unbound
.Nm unbound .Nm unbound
.Op Fl h .Op Fl h
.Op Fl p Ar port .Op Fl p Ar port
.Op Fl f Ar ip
.Op Fl z Ar port
.Op Fl v .Op Fl v
.Sh DESCRIPTION .Sh DESCRIPTION
@ -58,6 +60,12 @@ Show the version and commandline option help.
.It Fl p Ar port .It Fl p Ar port
Start listening on the given port. Default is port 53(DNS). Start listening on the given port. Default is port 53(DNS).
.It Fl f Ar ip
Set forwarder address. DNS queries will be forwarded to this server.
.It Fl z Ar ip
Set forwarder port. DNS queries will be forwarded to this port.
.It Fl v .It Fl v
Increase verbosity. If given multiple times, more information is logged. Increase verbosity. If given multiple times, more information is logged.

View file

@ -107,6 +107,7 @@ static int outnet_udp_cb(struct comm_point* c, void* arg, int error,
} }
comm_timer_disable(p->timer); comm_timer_disable(p->timer);
/* TODO handle it */ /* TODO handle it */
log_info("outnet handle udp reply");
return 0; return 0;
} }
@ -226,6 +227,7 @@ static void pending_udp_timer_cb(void *arg)
{ {
/* struct pending* p = (struct pending*)arg; */ /* struct pending* p = (struct pending*)arg; */
/* it timed out . TODO handle it. */ /* it timed out . TODO handle it. */
log_info("timeout udp");
} }
struct outside_network* struct outside_network*
@ -429,8 +431,7 @@ static void select_port(struct outside_network* outnet, struct pending* pend)
else pend->c = outnet->udp4_ports[chosen]; else pend->c = outnet->udp4_ports[chosen];
log_assert(pend->c); log_assert(pend->c);
log_info("chose query %x outbound %d of %d", log_info("query %x outbound %d of %d", pend->id, chosen, nummax);
pend->id, chosen, nummax);
} }
@ -458,7 +459,7 @@ void pending_udp_query(struct outside_network* outnet, ldns_buffer* packet,
/* system calls to set timeout after sending UDP to make roundtrip /* system calls to set timeout after sending UDP to make roundtrip
smaller. */ smaller. */
tv.tv_sec = (int)time(NULL) + timeout; tv.tv_sec = timeout;
tv.tv_usec = 0; tv.tv_usec = 0;
comm_timer_set(pend->timer, &tv); comm_timer_set(pend->timer, &tv);
} }

View file

@ -448,7 +448,9 @@ struct comm_timer* comm_timer_create(struct comm_base* base,
} }
tm->callback = cb; tm->callback = cb;
tm->cb_arg = cb_arg; tm->cb_arg = cb_arg;
evtimer_set(&tm->ev_timer->ev, comm_timer_callback, tm); /*evtimer_set(&tm->ev_timer->ev, comm_timer_callback, tm);*/
event_set(&tm->ev_timer->ev, -1, EV_PERSIST|EV_TIMEOUT,
comm_timer_callback, tm);
if(event_base_set(base->eb->base, &tm->ev_timer->ev) != 0) { if(event_base_set(base->eb->base, &tm->ev_timer->ev) != 0) {
log_err("timer_create: event_base_set failed."); log_err("timer_create: event_base_set failed.");
free(tm->ev_timer); free(tm->ev_timer);
@ -470,8 +472,7 @@ void comm_timer_set(struct comm_timer* timer, struct timeval* tv)
{ {
if(timer->ev_timer->enabled) if(timer->ev_timer->enabled)
comm_timer_disable(timer); comm_timer_disable(timer);
memcpy((struct timeval*)&timer->timeout, tv, sizeof(struct timeval)); evtimer_add(&timer->ev_timer->ev, tv);
evtimer_add(&timer->ev_timer->ev, (struct timeval*)&timer->timeout);
timer->ev_timer->enabled = 1; timer->ev_timer->enabled = 1;
} }

View file

@ -184,12 +184,6 @@ struct comm_timer {
/** the internal event stuff */ /** the internal event stuff */
struct internal_timer* ev_timer; struct internal_timer* ev_timer;
/**
* the timeout, absolute value seconds.
* Do not write to this, call comm_timer_set instead.
*/
const struct timeval timeout;
/** callback function, takes user arg only */ /** callback function, takes user arg only */
void (*callback)(void*); void (*callback)(void*);