From: Remi Gacogne Date: Thu, 5 Nov 2015 09:47:39 +0000 (+0100) Subject: Add a 'mustResolve' parameter to newServer() X-Git-Tag: dnsdist-1.0.0-alpha1~210^2~10^2~1^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a6e02424969145a706434c8b3336135ae7446140;p=pdns Add a 'mustResolve' parameter to newServer() The default is to consider any response with a rcode different from Servfail as valid. Passing true to mustResolve requires a rcode different from NXDomain, Servfail and Refused. --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 679b538eb..1ff48e75b 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -66,7 +66,7 @@ std::shared_ptr makeRule(const luadnsrule_t& var) vector> setupLua(bool client, const std::string& config) { g_launchWork= new vector>(); - typedef std::unordered_map > > > newserver_t; + typedef std::unordered_map > > > newserver_t; g_lua.writeVariable("DNSAction", std::unordered_map{ {"Drop", (int)DNSAction::Action::Drop}, @@ -176,6 +176,10 @@ vector> setupLua(bool client, const std::string& confi ret->checkType=boost::get(vars["checkType"]); } + if(vars.count("mustResolve")) { + ret->mustResolve=boost::get(vars["mustResolve"]); + } + if(g_launchWork) { g_launchWork->push_back([ret]() { ret->tid = move(thread(responderThread, ret)); diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index c35281f9b..abc24eae6 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -214,8 +214,7 @@ bool operator<(const struct timespec&a, const struct timespec& b) } -DownstreamState::DownstreamState(const ComboAddress& remote_): -checkName("a.root-servers.net."), checkType(QType::A) +DownstreamState::DownstreamState(const ComboAddress& remote_): checkName("a.root-servers.net."), checkType(QType::A), mustResolve(false) { remote = remote_; @@ -557,7 +556,7 @@ catch(...) } -bool upCheck(const ComboAddress& remote, const DNSName& checkName, const QType& checkType) +bool upCheck(const ComboAddress& remote, const DNSName& checkName, const QType& checkType, bool mustResolve) try { vector packet; @@ -592,6 +591,8 @@ try return false; if (responseHeader.rcode == RCode::ServFail) return false; + if (mustResolve && (responseHeader.rcode == RCode::NXDomain || responseHeader.rcode == RCode::Refused)) + return false; // XXX fixme do bunch of checking here etc return true; @@ -613,7 +614,7 @@ void* maintThread() for(auto& dss : g_dstates.getCopy()) { // this points to the actual shared_ptrs! if(dss->availability==DownstreamState::Availability::Auto) { - bool newState=upCheck(dss->remote, dss->checkName, dss->checkType); + bool newState=upCheck(dss->remote, dss->checkName, dss->checkType, dss->mustResolve); if(newState != dss->upStatus) { warnlog("Marking downstream %s as '%s'", dss->getName(), newState ? "up" : "down"); } @@ -1125,7 +1126,7 @@ try for(auto& dss : g_dstates.getCopy()) { // it is a copy, but the internal shared_ptrs are the real deal if(dss->availability==DownstreamState::Availability::Auto) { - bool newState=upCheck(dss->remote, dss->checkName, dss->checkType); + bool newState=upCheck(dss->remote, dss->checkName, dss->checkType, dss->mustResolve); warnlog("Marking downstream %s as '%s'", dss->remote.toStringWithPort(), newState ? "up" : "down"); dss->upStatus = newState; } diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 271364bf3..7cbefe71d 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -255,6 +255,7 @@ struct DownstreamState StopWatch sw; set pools; enum class Availability { Up, Down, Auto} availability{Availability::Auto}; + bool mustResolve; bool upStatus{false}; bool isUp() const {