From f99e3aaf0f20707bd88765d022956c2425fea853 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 19 Jan 2016 10:25:42 +0100 Subject: [PATCH] dnsdist: Do not create socket/thread for fake DS in client mode 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 | 18 ++++++++++-------- pdns/dnsdist.hh | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index f380b3d505..b24a994833 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -306,15 +306,17 @@ void* responderThread(std::shared_ptr 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; diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index cfd8b854ba..c92ae9a322 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -286,7 +286,7 @@ struct DownstreamState close(fd); } - int fd; + int fd{-1}; std::thread tid; ComboAddress remote; QPSLimiter qps; -- 2.47.2