]> granicus.if.org Git - pdns/commitdiff
dnsdist: Do not create socket/thread for fake DS in client mode
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 19 Jan 2016 09:25:42 +0000 (10:25 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 19 Jan 2016 09:25:42 +0000 (10:25 +0100)
While parsing the configuration in client mode, we create a fake
DownstreamState for each newServer() call, because we need it to
return a valid DownstreamState object. Unfortunately this leads
to the creation of a socket for 0.0.0.0, and a subsequent
connection attempt.
We now detect that the address does not make sense in this context
and do not create the associated socket.
Closes #3257.

pdns/dnsdist.cc
pdns/dnsdist.hh

index f380b3d505277389bc6b85c3ec86d019d14e1e3f..b24a99483317d7cee13af1260bbe35a4e9384214 100644 (file)
@@ -306,15 +306,17 @@ void* responderThread(std::shared_ptr<DownstreamState> state)
 
 DownstreamState::DownstreamState(const ComboAddress& remote_, const ComboAddress& sourceAddr_, unsigned int sourceItf_): remote(remote_), sourceAddr(sourceAddr_), sourceItf(sourceItf_)
 {
-  fd = SSocket(remote.sin4.sin_family, SOCK_DGRAM, 0);
-  if (!IsAnyAddress(sourceAddr)) {
-    SSetsockopt(fd, SOL_SOCKET, SO_REUSEADDR, 1);
-    SBind(fd, sourceAddr);
+  if (!IsAnyAddress(remote)) {
+    fd = SSocket(remote.sin4.sin_family, SOCK_DGRAM, 0);
+    if (!IsAnyAddress(sourceAddr)) {
+      SSetsockopt(fd, SOL_SOCKET, SO_REUSEADDR, 1);
+      SBind(fd, sourceAddr);
+    }
+    SConnect(fd, remote);
+    idStates.resize(g_maxOutstanding);
+    sw.start();
+    infolog("Added downstream server %s", remote.toStringWithPort());
   }
-  SConnect(fd, remote);
-  idStates.resize(g_maxOutstanding);
-  sw.start();
-  infolog("Added downstream server %s", remote.toStringWithPort());
 }
 
 std::mutex g_luamutex;
index cfd8b854babf33ae0b88e65379fde392de7c5220..c92ae9a322656d110b05fad93baaef934258fcc2 100644 (file)
@@ -286,7 +286,7 @@ struct DownstreamState
       close(fd);
   }
 
-  int fd;            
+  int fd{-1};
   std::thread tid;
   ComboAddress remote;
   QPSLimiter qps;