]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Commandline options to set forwarder, udp timeout.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 2 Feb 2007 12:52:40 +0000 (12:52 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 2 Feb 2007 12:52:40 +0000 (12:52 +0000)
git-svn-id: file:///svn/unbound/trunk@58 be551aaa-1e26-0410-a405-d3ace91eadb9

daemon/unbound.c
daemon/worker.c
doc/Changelog
doc/unbound.8
services/outside_network.c
util/netevent.c
util/netevent.h

index f1c90d4564c7bb4bdfa8b540ca209763b7730575..476dc4278b84022c7d2f44e0038a2d27472510e1 100644 (file)
@@ -55,6 +55,8 @@ static void usage()
        printf("-h      this help\n");
        printf("-p port the port to listen on\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("BSD licensed, see LICENSE file in source package.\n");
        printf("Report bugs to %s.\n", PACKAGE_BUGREPORT);
@@ -84,8 +86,14 @@ main(int argc, char* argv[])
 
        log_init();
        /* parse the options */
-       while( (c=getopt(argc, argv, "hvp:")) != -1) {
+       while( (c=getopt(argc, argv, "f:hvp:z:")) != -1) {
                switch(c) {
+               case 'f':
+                       fwd = optarg;
+                       break;
+               case 'z':
+                       fwdport = optarg;
+                       break;
                case 'p':
                        if(!atoi(optarg))
                                fatal_exit("invalid port '%s'", optarg);
@@ -119,7 +127,7 @@ main(int argc, char* argv[])
        }
        if(!worker_set_fwd(worker, fwd, fwdport)) {
                worker_delete(worker);
-               fatal_exit("could set forwarder address");
+               fatal_exit("could not set forwarder address");
        }
        
        /* drop user priviliges and chroot if needed */
index 9051101b11bd168271807b4b094a57c4e10aaaac..f676e497a52f79203ec9ce6e85e4ea6029337ea4 100644 (file)
@@ -188,23 +188,38 @@ void worker_delete(struct worker* worker)
 
 int worker_set_fwd(struct worker* worker, const char* ip, const char* port)
 {
-       struct addrinfo *res = NULL;
-       struct addrinfo hints;
-       int r;
+       uint16_t p;
        log_assert(worker && ip);
-       memset(&hints, 0, sizeof(hints));
-       hints.ai_family = AF_UNSPEC;
-       hints.ai_socktype = SOCK_DGRAM;
-       if(!port) 
-               port = UNBOUND_DNS_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):"");
+       if(port)
+               p = (uint16_t)atoi(port);
+       else    p = (uint16_t)atoi(UNBOUND_DNS_PORT);
+       if(!p) {
+               log_err("Bad port number %s", port?port:"default_port");
                return 0;
        }
-       worker->fwd_addrlen = res->ai_addrlen;
-       memcpy(&worker->fwd_addr, &res->ai_addr, res->ai_addrlen);
-       freeaddrinfo(res);
+       if(str_is_ip6(ip)) {
+               struct sockaddr_in6* sa = 
+                       (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;
 }
index b3aa8349b3a46fa0415d30696cad81c9e42a90ff..2cf55294a0aac17f186fc7b2bae1814eaa957129 100644 (file)
@@ -3,6 +3,8 @@
          address families.
        - 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.
+       - worker fwder address filled correctly.
+       - fixup timer code.
 
 1 February 2007: Wouter
        - outside network more UDP work.
index afd8db47a196e2b026ef88766e353b7fbf0e1acf..d347f429dfee2b69c06644972ea2ce53dc4b11e8 100644 (file)
@@ -42,6 +42,8 @@ unbound
 .Nm unbound
 .Op Fl h
 .Op Fl p Ar port
+.Op Fl f Ar ip
+.Op Fl z Ar port
 .Op Fl v
 
 .Sh DESCRIPTION
@@ -58,6 +60,12 @@ Show the version and commandline option help.
 .It Fl p Ar port
 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
 Increase verbosity. If given multiple times, more information is logged.
 
index fd761dde23b3b2356ea981e2e84ffac2ef8f602b..41f98d77a908ab503f56a4cfd329b58353374803 100644 (file)
@@ -107,6 +107,7 @@ static int outnet_udp_cb(struct comm_point* c, void* arg, int error,
        }
        comm_timer_disable(p->timer);
        /* TODO handle it */
+       log_info("outnet handle udp reply");
 
        return 0;
 }
@@ -226,6 +227,7 @@ static void pending_udp_timer_cb(void *arg)
 {
        /* struct pending* p = (struct pending*)arg; */
        /* it timed out . TODO handle it. */
+       log_info("timeout udp");
 }
 
 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];
        log_assert(pend->c);
 
-       log_info("chose query %x outbound %d of %d", 
-               pend->id, chosen, nummax);
+       log_info("query %x outbound %d of %d", 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
           smaller. */
-       tv.tv_sec = (int)time(NULL) + timeout;
+       tv.tv_sec = timeout;
        tv.tv_usec = 0;
        comm_timer_set(pend->timer, &tv);
 }
index 64151c1349e380d87cb8283706a8f5336bbc0e2d..17db720b6e2fe5b1fada40553e3ca8631b38d64e 100644 (file)
@@ -448,7 +448,9 @@ struct comm_timer* comm_timer_create(struct comm_base* base,
        }
        tm->callback = cb;
        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) {
                log_err("timer_create: event_base_set failed.");
                free(tm->ev_timer);
@@ -470,8 +472,7 @@ void comm_timer_set(struct comm_timer* timer, struct timeval* tv)
 {
        if(timer->ev_timer->enabled)
                comm_timer_disable(timer);
-       memcpy((struct timeval*)&timer->timeout, tv, sizeof(struct timeval));
-       evtimer_add(&timer->ev_timer->ev, (struct timeval*)&timer->timeout);
+       evtimer_add(&timer->ev_timer->ev, tv);
        timer->ev_timer->enabled = 1;
 }
 
index 1ae890863b7a194e1677c338b3708b93b520e413..a47a9dd7cbdb2f04414684e1ee264b3d9e609ba3 100644 (file)
@@ -184,12 +184,6 @@ struct comm_timer {
        /** the internal event stuff */
        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 */
        void (*callback)(void*);