From f5ad09dc539661c89da2697be4d08728cac7a370 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Mon, 28 Oct 2019 12:35:05 +0100 Subject: [PATCH] Auth: Remove local-ipv6 setting Treat listen address as equally as possible. This removes a bunch of duplicate code. --- docs/guides/recursion.rst | 2 - docs/settings.rst | 13 +- pdns/common_startup.cc | 4 +- pdns/nameserver.cc | 130 ++++-------------- pdns/nameserver.hh | 3 +- pdns/tcpreceiver.cc | 100 +++----------- regression-tests.api/runtests.py | 2 +- regression-tests.auth-py/authtests.py | 1 - regression-tests.nobackend/counters/command | 2 +- .../distributor/command | 2 +- .../supermaster-signed/command | 4 +- .../supermaster-unsigned/command | 4 +- .../recursortests.py | 2 +- regression-tests.recursor/config.sh | 2 +- 14 files changed, 71 insertions(+), 200 deletions(-) diff --git a/docs/guides/recursion.rst b/docs/guides/recursion.rst index ea35f6c6f0..a1756ed976 100644 --- a/docs/guides/recursion.rst +++ b/docs/guides/recursion.rst @@ -52,7 +52,6 @@ and port 5300 change the following in ``pdns.conf``: .. code-block:: ini - local-ipv6= local-address=127.0.0.1 local-port=5300 @@ -135,7 +134,6 @@ and port 5300 change the following in ``pdns.conf``: .. code-block:: ini - local-ipv6= local-address=127.0.0.1 local-port=5300 diff --git a/docs/settings.rst b/docs/settings.rst index 17e7e7f631..a5d7b2b9c4 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -745,10 +745,13 @@ available in non-static distributions. ``local-address`` ----------------- +.. versionchanged:: 4.3.0 + Before 4.3.0, this setting only supported IPv4. + - IPv4 Addresses, separated by commas or whitespace -- Default: 0.0.0.0 +- Default: 0.0.0.0, ``::`` -Local IP address to which we bind. It is highly advised to bind to +Local IP addresses to which we bind. It is highly advised to bind to specific interfaces and not use the default 'bind to any'. This causes big problems if you have multiple IP addresses. Unix does not provide a way of figuring out what IP address a packet was sent to when binding to @@ -770,6 +773,9 @@ Fail to start if one or more of the ``local-ipv6`` -------------- +.. deprecated:: 4.3.0 + This setting has been removed, use :ref:`setting-localaddress` + - IPv6 Addresses, separated by commas or whitespace - Default: '::' @@ -782,6 +788,9 @@ big problems if you have multiple IP addresses. ``local-ipv6-nonexist-fail`` ---------------------------- +.. deprecated:: 4.3.0 + This setting has been removed, use :ref:`setting-localaddress-nonexist-fail` + - Boolean - Default: no diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 1a383c71fa..9ad7459e21 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -84,12 +84,10 @@ void declareArguments() ::arg().setSwitch("forward-dnsupdate","A global setting to allow DNS update packages that are for a Slave domain, to be forwarded to the master.")="yes"; ::arg().setSwitch("log-dns-details","If PDNS should log DNS non-erroneous details")="no"; ::arg().setSwitch("log-dns-queries","If PDNS should log all incoming DNS queries")="no"; - ::arg().set("local-address","Local IP addresses to which we bind")="0.0.0.0"; + ::arg().set("local-address","Local IP addresses to which we bind")="0.0.0.0, ::"; ::arg().setSwitch("local-address-nonexist-fail","Fail to start if one or more of the local-address's do not exist on this server")="yes"; ::arg().setSwitch("non-local-bind", "Enable binding to non-local addresses by using FREEBIND / BINDANY socket options")="no"; - ::arg().set("local-ipv6","Local IP address to which we bind")="::"; ::arg().setSwitch("reuseport","Enable higher performance on compliant kernels by using SO_REUSEPORT allowing each receiver thread to open its own socket")="no"; - ::arg().setSwitch("local-ipv6-nonexist-fail","Fail to start if one or more of the local-ipv6 addresses do not exist on this server")="yes"; ::arg().set("query-local-address","Source IP address for sending queries")="0.0.0.0"; ::arg().set("query-local-address6","Source IPv6 address for sending queries")="::"; ::arg().set("overload-queue-length","Maximum queuelength moving to packetcache only")="0"; diff --git a/pdns/nameserver.cc b/pdns/nameserver.cc index 77344b5219..427089702e 100644 --- a/pdns/nameserver.cc +++ b/pdns/nameserver.cc @@ -86,7 +86,7 @@ extern StatBag S; vector g_localaddresses; // not static, our unit tests need to poke this -void UDPNameserver::bindIPv4() +void UDPNameserver::bindAddresses() { vectorlocals; stringtok(locals,::arg()["local-address"]," ,"); @@ -96,33 +96,36 @@ void UDPNameserver::bindIPv4() throw PDNSException("No local address specified"); int s; - for(vector::const_iterator i=locals.begin();i!=locals.end();++i) { - string localname(*i); - ComboAddress locala; + // for(vector::const_iterator i=locals.begin();i!=locals.end();++i) { + for (const auto &local : locals) { + ComboAddress locala(local, ::arg().asNum("local-port")); - s=socket(AF_INET,SOCK_DGRAM,0); + s = socket(locala.sin4.sin_family, SOCK_DGRAM, 0); - if(s<0) { - int err = errno; - g_log< locals; - stringtok(locals,::arg()["local-ipv6"]," ,"); - int one=1; - - if(locals.empty()) - return; - - int s; - for(vector::const_iterator i=locals.begin();i!=locals.end();++i) { - string localname(*i); - - s=socket(AF_INET6,SOCK_DGRAM,0); - if(s<0) { - if( errno == EAFNOSUPPORT ) { - g_log< d_sockets; - void bindIPv4(); - void bindIPv6(); + void bindAddresses(); vector d_rfds; }; diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index 5634318ded..b49b362d3c 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -1196,125 +1196,67 @@ TCPNameserver::TCPNameserver() d_connectionroom_sem = make_unique( ::arg().asNum( "max-tcp-connections" )); d_maxTCPConnections = ::arg().asNum( "max-tcp-connections" ); d_tid=0; + vectorlocals; stringtok(locals,::arg()["local-address"]," ,"); - - vectorlocals6; - stringtok(locals6,::arg()["local-ipv6"]," ,"); - - if(locals.empty() && locals6.empty()) - throw PDNSException("No local address specified"); + if(locals.empty()) + throw PDNSException("No local addresses specified"); d_ng.toMasks(::arg()["allow-axfr-ips"] ); signal(SIGPIPE,SIG_IGN); - for(vector::const_iterator laddr=locals.begin();laddr!=locals.end();++laddr) { - int s=socket(AF_INET,SOCK_STREAM,0); - - if(s<0) - throw PDNSException("Unable to acquire TCP socket: "+stringerror()); + for(auto const &laddr : locals) { + ComboAddress local(laddr, ::arg().asNum("local-port")); + int s=socket(local.sin4.sin_family, SOCK_STREAM, 0); + if(s<0) + throw PDNSException("Unable to acquire TCP socket: "+stringerror()); setCloseOnExec(s); - ComboAddress local(*laddr, ::arg().asNum("local-port")); - int tmp=1; - if(setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0) { + if(setsockopt(s, SOL_SOCKET,SO_REUSEADDR, (char*)&tmp, sizeof tmp) < 0) { g_log< 0) { #ifdef TCP_FASTOPEN int fastOpenQueueSize = ::arg().asNum("tcp-fast-open"); if (setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN, &fastOpenQueueSize, sizeof fastOpenQueueSize) < 0) { - g_log<::const_iterator laddr=locals6.begin();laddr!=locals6.end();++laddr) { - int s=socket(AF_INET6,SOCK_STREAM,0); - - if(s<0) - throw PDNSException("Unable to acquire TCPv6 socket: "+stringerror()); - - setCloseOnExec(s); - - ComboAddress local(*laddr, ::arg().asNum("local-port")); - - int tmp=1; - if(setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char*)&tmp,sizeof tmp)<0) { - g_log< 0) { -#ifdef TCP_FASTOPEN - int fastOpenQueueSize = ::arg().asNum("tcp-fast-open"); - if (setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN, &fastOpenQueueSize, sizeof fastOpenQueueSize) < 0) { - g_log<> $dir/pdns.conf -- 2.47.2