From: bert hubert Date: Wed, 24 Feb 2016 11:55:38 +0000 (+0100) Subject: add "reuseport" to recursor as a switch, off by default X-Git-Tag: auth-4.0.0-alpha2~6^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2332f42d64ba29fce56e4952ad0e47cd26f32f4e;p=thirdparty%2Fpdns.git add "reuseport" to recursor as a switch, off by default --- diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 960afb6929..4a254ef2ba 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -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");