]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
fall back to central bind if reuseport bind fails; improves #1715
authorPeter van Dijk <peter.van.dijk@netherlabs.nl>
Tue, 16 Sep 2014 19:45:56 +0000 (21:45 +0200)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Tue, 16 Sep 2014 19:45:56 +0000 (21:45 +0200)
pdns/common_startup.cc
pdns/nameserver.cc

index 550244387ecfda52e09bd78f1d0c1b1b21edd5ce..c7e89e19bab68100a17951e72a1e8ad51746ff2d 100644 (file)
@@ -256,7 +256,12 @@ void *qthread(void *number)
   // other than the first one.
   if( number != NULL && NS->canReusePort() ) {
     L<<Logger::Notice<<"Starting new listen thread on the same IPs/ports using SO_REUSEPORT"<<endl;
-    NS = new UDPNameserver( true );
+    try {
+      NS = new UDPNameserver( true );
+    } catch(PDNSException &e) {
+      L<<Logger::Error<<"Unable to reuse port, falling back to original bind"<<endl;
+      NS = N;
+    }
   }
 
   for(;;) {
index 98ce853ccc05895aa11fce7d066a0dddeb31200d..10331802df6cd790ca6913acd1c246506f445145 100644 (file)
@@ -135,12 +135,13 @@ void UDPNameserver::bindIPv4()
         g_localaddresses.push_back(locala);
 
     if(::bind(s, (sockaddr*)&locala, locala.getSocklen()) < 0) {
+      string binderror = strerror(errno);
       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;
       } else {
-        L<<Logger::Error<<"binding UDP socket to '"+locala.toStringWithPort()+": "<<strerror(errno)<<endl;
+        L<<Logger::Error<<"binding UDP socket to '"+locala.toStringWithPort()+"': "<<binderror<<endl;
         throw PDNSException("Unable to bind to UDP socket");
       }
     }