]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Listen to both 4 and 6.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 2 Feb 2007 10:31:25 +0000 (10:31 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Fri, 2 Feb 2007 10:31:25 +0000 (10:31 +0000)
git-svn-id: file:///svn/unbound/trunk@57 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
services/listen_dnsport.c
services/outside_network.c
services/outside_network.h

index fc7f0c319e9da48d33a6223c1a61033720126eff..b3aa8349b3a46fa0415d30696cad81c9e42a90ff 100644 (file)
@@ -2,6 +2,7 @@
        - Created udp4 and udp6 port arrays to provide service for both
          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.
 
 1 February 2007: Wouter
        - outside network more UDP work.
index 31b07ee7b09a885dd717d9d2d0d819fa5c8cb72b..d4966de96bebdcb709b7b15d9d35b15d0ec3ef91 100644 (file)
@@ -40,6 +40,7 @@
  */
 
 #include "services/listen_dnsport.h"
+#include "services/outside_network.h"
 #include "util/netevent.h"
 #include "util/log.h"
 
@@ -69,11 +70,11 @@ verbose_print_addr(struct addrinfo *addr)
                        (socklen_t)sizeof(buf)) == 0) {
                        strncpy(buf, "(null)", sizeof(buf));
                }
-               verbose(VERB_ALGO, "creating %s %s socket %s %d", 
-                       addr->ai_family==AF_INET?"inet":
-                       addr->ai_family==AF_INET6?"inet6":"otherfamily", 
+               verbose(VERB_ALGO, "creating %s%s socket %s %d", 
                        addr->ai_socktype==SOCK_DGRAM?"udp":
-                       addr->ai_socktype==SOCK_STREAM?"tcp":"otherprotocol",
+                       addr->ai_socktype==SOCK_STREAM?"tcp":"otherproto",
+                       addr->ai_family==AF_INET?"4":
+                       addr->ai_family==AF_INET6?"6":"_otherfam", 
                        buf, 
                        ntohs(((struct sockaddr_in*)addr->ai_addr)->sin_port));
        }
@@ -313,27 +314,52 @@ listen_create(struct comm_base* base, int num_ifs, const char* ifs[],
        if(!do_ip4 && !do_ip6) {
                listen_delete(front);
                return NULL;
-       } else if(do_ip4 && do_ip6)
-               hints.ai_family = AF_UNSPEC;
-       else if(do_ip4)
-               hints.ai_family = AF_INET;
-       else if(do_ip6) {
-               hints.ai_family = AF_INET6;
        }
 
+       /* create ip4 and ip6 ports so that return addresses are nice. */
        if(num_ifs == 0) {
-               if(!listen_create_if(NULL, front, base, port, 
-                       do_udp, do_tcp, &hints, bufsize, cb, cb_arg)) {
-                       listen_delete(front);
-                       return NULL;
+               if(do_ip6) {
+                       hints.ai_family = AF_INET6;
+                       if(!listen_create_if(NULL, front, base, port, 
+                               do_udp, do_tcp, &hints, bufsize, cb, cb_arg)) {
+                               listen_delete(front);
+                               return NULL;
+                       }
+               }
+               if(do_ip4) {
+                       hints.ai_family = AF_INET;
+                       if(!listen_create_if(NULL, front, base, port, 
+                               do_udp, do_tcp, &hints, bufsize, cb, cb_arg)) {
+                               listen_delete(front);
+                               return NULL;
+                       }
                }
        } else for(i = 0; i<num_ifs; i++) {
-               if(!listen_create_if(ifs[i], front, base, port, 
-                       do_udp, do_tcp, &hints, bufsize, cb, cb_arg)) {
-                       listen_delete(front);
-                       return NULL;
+               if(str_is_ip6(ifs[i])) {
+                       if(!do_ip6)
+                               continue;
+                       hints.ai_family = AF_INET6;
+                       if(!listen_create_if(ifs[i], front, base, port, 
+                               do_udp, do_tcp, &hints, bufsize, cb, cb_arg)) {
+                               listen_delete(front);
+                               return NULL;
+                       }
+               } else {
+                       if(!do_ip4)
+                               continue;
+                       hints.ai_family = AF_INET;
+                       if(!listen_create_if(ifs[i], front, base, port, 
+                               do_udp, do_tcp, &hints, bufsize, cb, cb_arg)) {
+                               listen_delete(front);
+                               return NULL;
+                       }
                }
        }
+       if(!front->cps) {
+               log_err("Could not open sockets to accept queries.");
+               listen_delete(front);
+               return NULL;
+       }
 
        return front;
 }
index 036fe0507baecfb4ce0413b4a2a67cd6d9e1a143..fd761dde23b3b2356ea981e2e84ffac2ef8f602b 100644 (file)
@@ -186,7 +186,7 @@ make_udp_range(struct comm_point** coms, const char* ifname,
 }
 
 /** returns true is string addr is an ip6 specced address. */
-static int str_is_ip6(const char* str)
+int str_is_ip6(const char* str)
 {
        if(strchr(str, ':'))
                return 1;
index 59136072d14e2acd009c6115b85904073aa9f70b..1176877d0a086ef1b999a05725ca63bcdcd46f51 100644 (file)
@@ -141,4 +141,11 @@ void pending_udp_query(struct outside_network* outnet, ldns_buffer* packet,
  */
 void pending_delete(struct outside_network* outnet, struct pending* p);
 
+/** 
+ * See if string is ip4 or ip6.
+ * @param str: IP specification.
+ * @return: true is string addr is an ip6 specced address. 
+ */
+int str_is_ip6(const char* str);
+
 #endif /* OUTSIDE_NETWORK_H */