From bfe5459835e30f9161ad48138b5a8a3da9290388 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Fri, 2 Feb 2007 10:31:25 +0000 Subject: [PATCH] Listen to both 4 and 6. git-svn-id: file:///svn/unbound/trunk@57 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 1 + services/listen_dnsport.c | 62 +++++++++++++++++++++++++++----------- services/outside_network.c | 2 +- services/outside_network.h | 7 +++++ 4 files changed, 53 insertions(+), 19 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index fc7f0c319..b3aa8349b 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -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. diff --git a/services/listen_dnsport.c b/services/listen_dnsport.c index 31b07ee7b..d4966de96 100644 --- a/services/listen_dnsport.c +++ b/services/listen_dnsport.c @@ -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; icps) { + log_err("Could not open sockets to accept queries."); + listen_delete(front); + return NULL; + } return front; } diff --git a/services/outside_network.c b/services/outside_network.c index 036fe0507..fd761dde2 100644 --- a/services/outside_network.c +++ b/services/outside_network.c @@ -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; diff --git a/services/outside_network.h b/services/outside_network.h index 59136072d..1176877d0 100644 --- a/services/outside_network.h +++ b/services/outside_network.h @@ -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 */ -- 2.47.2