]> granicus.if.org Git - pdns/commitdiff
Merge pull request #1133 from mzealey/so-reuseport
authorPeter van Dijk <peter@7bits.nl>
Tue, 14 Jan 2014 16:07:06 +0000 (08:07 -0800)
committerPeter van Dijk <peter@7bits.nl>
Tue, 14 Jan 2014 16:07:06 +0000 (08:07 -0800)
fixes PowerDNS/pdns#666

1  2 
pdns/common_startup.cc
pdns/docs/pdns.xml
pdns/nameserver.cc

Simple merge
Simple merge
index 1be9663ebad64be05155fafb405903b3941ae96f,3f044190ce41f8156799979abdbfe52328ab18ab..7535ce4eb28cb28604cf3fc26f6829c14b23c867
@@@ -126,9 -132,10 +132,11 @@@ void UDPNameserver::bindIPv4(
      if(locala.sin4.sin_family != AF_INET) 
        throw PDNSException("Attempting to bind IPv4 socket to IPv6 address");
  
-     g_localaddresses.push_back(locala);
+     if( !d_additional_socket )
+         g_localaddresses.push_back(locala);
      if(::bind(s, (sockaddr*)&locala, locala.getSocklen()) < 0) {
 +      close(s);
        if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-address-nonexist-fail") ) {
          L<<Logger::Error<<"IPv4 Address " << localname << " does not exist on this server - skipping UDP bind" << endl;
          continue;
@@@ -218,14 -226,20 +227,21 @@@ void UDPNameserver::bindIPv6(
      ComboAddress locala(localname, ::arg().asNum("local-port"));
      
      if(IsAnyAddress(locala)) {
-       int val=1;
-       setsockopt(s, IPPROTO_IP, GEN_IP_PKTINFO, &val, sizeof(val));     // linux supports this, so why not - might fail on other systems
-       setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &val, sizeof(val)); 
-       setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val));      // if this fails, we report an error in tcpreceiver too
+       setsockopt(s, IPPROTO_IP, GEN_IP_PKTINFO, &one, sizeof(one));     // linux supports this, so why not - might fail on other systems
+       setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &one, sizeof(one)); 
+       setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one));      // if this fails, we report an error in tcpreceiver too
      }
-     g_localaddresses.push_back(locala);
+ #ifdef SO_REUSEPORT
+     if( d_can_reuseport )
+         if( setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) )
+           d_can_reuseport = false;
+ #endif
+     if( !d_additional_socket )
+         g_localaddresses.push_back(locala);
      if(::bind(s, (sockaddr*)&locala, sizeof(locala))<0) {
 +      close(s);
        if( errno == EADDRNOTAVAIL && ! ::arg().mustDo("local-ipv6-nonexist-fail") ) {
          L<<Logger::Error<<"IPv6 Address " << localname << " does not exist on this server - skipping UDP bind" << endl;
          continue;