]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add "reuseport" to recursor as a switch, off by default
authorbert hubert <bert.hubert@netherlabs.nl>
Wed, 24 Feb 2016 11:55:38 +0000 (12:55 +0100)
committerbert hubert <bert.hubert@powerdns.com>
Wed, 24 Feb 2016 13:37:11 +0000 (14:37 +0100)
pdns/pdns_recursor.cc

index 960afb6929b284b249f36a2005cc5f1b1710e27e..4a254ef2ba4b23d1bf54ee542953a0f353b939da 100644 (file)
@@ -1367,6 +1367,14 @@ void makeTCPServerSockets()
     if( ::arg().mustDo("non-local-bind") )
        Utility::setBindAny(AF_INET, fd);
 
+#ifdef SO_REUSEPORT
+    if(::arg().mustDo("reuseport")) {
+      int one=1;
+      if(setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) < 0)
+        throw PDNSException("SO_REUSEPORT: "+stringerror());
+    }
+#endif
+
     sin.sin4.sin_port = htons(st.port);
     int socklen=sin.sin4.sin_family==AF_INET ? sizeof(sin.sin4) : sizeof(sin.sin6);
     if (::bind(fd, (struct sockaddr *)&sin, socklen )<0)
@@ -1438,8 +1446,15 @@ void makeUDPServerSockets()
     setSocketReceiveBuffer(fd, 250000);
     sin.sin4.sin_port = htons(st.port);
 
-    int socklen=sin.getSocklen();
-
+  
+#ifdef SO_REUSEPORT  
+    if(::arg().mustDo("reuseport")) {
+      int one=1;
+      if(setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) < 0)
+        throw PDNSException("SO_REUSEPORT: "+stringerror());
+    }
+#endif
+  int socklen=sin.getSocklen();      
     if (::bind(fd, (struct sockaddr *)&sin, socklen)<0)
       throw PDNSException("Resolver binding to server socket on port "+ std::to_string(st.port) +" for "+ st.host+": "+stringerror());
 
@@ -2663,6 +2678,8 @@ int main(int argc, char **argv)
 
     ::arg().set("include-dir","Include *.conf files from this directory")="";
     ::arg().set("security-poll-suffix","Domain name from which to query security update notifications")="secpoll.powerdns.com.";
+    
+    ::arg().setSwitch("reuseport","Enable SO_REUSEPORT allowing multiple recursors processes to listen to 1 address")="no";
 
     ::arg().setCmd("help","Provide a helpful message");
     ::arg().setCmd("version","Print version string");