::arg().set("urlredirector","Where we send hosts to that need to be url redirected")="127.0.0.1";
::arg().set("smtpredirector","Our smtpredir MX host")="a.misconfigured.powerdns.smtp.server";
::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().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";
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) {
- L<<Logger::Error<<"binding UDP socket to '"+locala.toStringWithPort()+": "<<strerror(errno)<<endl;
- throw PDNSException("Unable to bind to UDP socket");
+ 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;
+ throw PDNSException("Unable to bind to UDP socket");
+ }
}
d_sockets.push_back(s);
L<<Logger::Error<<"UDP server bound to "<<locala.toStringWithPort()<<endl;
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) {
- L<<Logger::Error<<"binding to UDP ipv6 socket: "<<strerror(errno)<<endl;
- throw PDNSException("Unable to bind to UDP ipv6 socket");
+ 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;
+ } else {
+ L<<Logger::Error<<"binding to UDP ipv6 socket "<< localname <<": "<<strerror(errno)<<endl;
+ throw PDNSException("Unable to bind to UDP ipv6 socket");
+ }
}
d_sockets.push_back(s);
struct pollfd pfd;