From: Wouter Wijngaards Date: Tue, 8 Dec 2009 16:31:56 +0000 (+0000) Subject: Specify port number in interface lines. X-Git-Tag: release-1.4.1~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c88952d4e0cba8c3eb83cf9d1f74cc75e6903a0f;p=thirdparty%2Funbound.git Specify port number in interface lines. git-svn-id: file:///svn/unbound/trunk@1930 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index 14cb1c981..2dea61dd1 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,8 @@ - Fix for lookup of parent-child disagreement domains, where the parent-side glue works but it does not provide proper NS, A or AAAA for itself, fixing domains such as motorcaravanners.eu. + - Feature: you can specify a port number in the interface: line, so + you can bind the same interface multiple times at different ports. 7 December 2009: Wouter - Bug#287: Fix segfault when unbound-control remove nonexistent local diff --git a/doc/example.conf.in b/doc/example.conf.in index d4ed1e332..484ea1c8a 100644 --- a/doc/example.conf.in +++ b/doc/example.conf.in @@ -32,7 +32,7 @@ server: # specify the interfaces to answer queries from by ip-address. # The default is to listen to localhost (127.0.0.1 and ::1). # specify 0.0.0.0 and ::0 to bind to all available interfaces. - # specify every interface on a new 'interface:' labelled line. + # specify every interface[@port] on a new 'interface:' labelled line. # The listen interfaces are not changed on reload, only on restart. # interface: 192.0.2.153 # interface: 192.0.2.154 diff --git a/doc/unbound.conf.5.in b/doc/unbound.conf.5.in index dea7023f4..6c7fba7ea 100644 --- a/doc/unbound.conf.5.in +++ b/doc/unbound.conf.5.in @@ -108,12 +108,15 @@ The number of threads to create to serve clients. Use 1 for no threading. .B port: \fI The port number, default 53, on which the server responds to queries. .TP -.B interface: \fI +.B interface: \fI Interface to use to connect to the network. This interface is listened to for queries from clients, and answers to clients are given from it. Can be given multiple times to work on several interfaces. If none are given the default is to listen to localhost. The interfaces are not changed on a reload (kill \-HUP) but only on restart. +A port number can be specified with @port (without spaces between +interface and port number), if not specified the default port (from +\fBport\fR) is used. .TP .B interface\-automatic: \fI Detect source interface on UDP queries and copy them to replies. This diff --git a/services/listen_dnsport.c b/services/listen_dnsport.c index 92ba88431..5ec2462b0 100644 --- a/services/listen_dnsport.c +++ b/services/listen_dnsport.c @@ -417,6 +417,35 @@ make_sock(int stype, const char* ifname, const char* port, return s; } +/** make socket and first see if ifname contains port override info */ +static int +make_sock_port(int stype, const char* ifname, const char* port, + struct addrinfo *hints, int v6only, int* noip6, size_t rcv) +{ + char* s = strchr(ifname, '@'); + if(s) { + /* override port with ifspec@port */ + char p[16]; + char newif[128]; + if((size_t)(s-ifname) >= sizeof(newif)) { + log_err("ifname too long: %s", ifname); + *noip6 = 0; + return -1; + } + if(strlen(s+1) >= sizeof(p)) { + log_err("portnumber too long: %s", ifname); + *noip6 = 0; + return -1; + } + strncpy(newif, ifname, sizeof(newif)); + newif[s-ifname] = 0; + strncpy(p, s+1, sizeof(p)); + p[strlen(s+1)]=0; + return make_sock(stype, newif, p, hints, v6only, noip6, rcv); + } + return make_sock(stype, ifname, port, hints, v6only, noip6, rcv); +} + /** * Add port to open ports list. * @param list: list head. changed. @@ -515,7 +544,7 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp, if(!do_udp && !do_tcp) return 0; if(do_auto) { - if((s = make_sock(SOCK_DGRAM, ifname, port, hints, 1, + if((s = make_sock_port(SOCK_DGRAM, ifname, port, hints, 1, &noip6, rcv)) == -1) { if(noip6) { log_warn("IPv6 protocol not available"); @@ -536,7 +565,7 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp, } } else if(do_udp) { /* regular udp socket */ - if((s = make_sock(SOCK_DGRAM, ifname, port, hints, 1, + if((s = make_sock_port(SOCK_DGRAM, ifname, port, hints, 1, &noip6, rcv)) == -1) { if(noip6) { log_warn("IPv6 protocol not available"); @@ -554,7 +583,7 @@ ports_create_if(const char* ifname, int do_auto, int do_udp, int do_tcp, } } if(do_tcp) { - if((s = make_sock(SOCK_STREAM, ifname, port, hints, 1, + if((s = make_sock_port(SOCK_STREAM, ifname, port, hints, 1, &noip6, 0)) == -1) { if(noip6) { /*log_warn("IPv6 protocol not available");*/