]> granicus.if.org Git - pdns/commitdiff
Add a 'mustResolve' parameter to newServer()
authorRemi Gacogne <rgacogne-github@coredump.fr>
Thu, 5 Nov 2015 09:47:39 +0000 (10:47 +0100)
committerRemi Gacogne <rgacogne-github@coredump.fr>
Tue, 17 Nov 2015 09:36:09 +0000 (10:36 +0100)
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.

pdns/dnsdist-lua.cc
pdns/dnsdist.cc
pdns/dnsdist.hh

index 679b538ebf5ba8491fa6f73ead7d1b554bcfbbd3..1ff48e75b0fc2477001dc8abb16a48cfe3331805 100644 (file)
@@ -66,7 +66,7 @@ std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var)
 vector<std::function<void(void)>> setupLua(bool client, const std::string& config)
 {
   g_launchWork= new vector<std::function<void(void)>>();
-  typedef std::unordered_map<std::string, boost::variant<std::string, vector<pair<int, std::string> > > > newserver_t;
+  typedef std::unordered_map<std::string, boost::variant<bool, std::string, vector<pair<int, std::string> > > > newserver_t;
 
   g_lua.writeVariable("DNSAction", std::unordered_map<string,int>{
       {"Drop", (int)DNSAction::Action::Drop}, 
@@ -176,6 +176,10 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
                          ret->checkType=boost::get<string>(vars["checkType"]);
                        }
 
+                       if(vars.count("mustResolve")) {
+                         ret->mustResolve=boost::get<bool>(vars["mustResolve"]);
+                       }
+
                        if(g_launchWork) {
                          g_launchWork->push_back([ret]() {
                              ret->tid = move(thread(responderThread, ret));
index c35281f9ba5198b90449a6f036d6265228fed351..abc24eae6237fa062f602fa67b8926507454ab21 100644 (file)
@@ -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<uint8_t> 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;
     }
index 271364bf3762a5661756a76cfed3bd45c2f826cc..7cbefe71d161ea54948f896f2003b4002d3d6cce 100644 (file)
@@ -255,6 +255,7 @@ struct DownstreamState
   StopWatch sw;
   set<string> pools;
   enum class Availability { Up, Down, Auto} availability{Availability::Auto};
+  bool mustResolve;
   bool upStatus{false};
   bool isUp() const
   {