]> granicus.if.org Git - pdns/commitdiff
Allow custom DNSName and QType for dnsdist healthchecks
authorRemi Gacogne <rgacogne-github@coredump.fr>
Tue, 3 Nov 2015 10:54:15 +0000 (11:54 +0100)
committerRemi Gacogne <rgacogne-github@coredump.fr>
Tue, 17 Nov 2015 09:34:52 +0000 (10:34 +0100)
pdns/dnsdist-lua.cc
pdns/dnsdist.cc
pdns/dnsdist.hh

index 21ac9931b0606a381ce5133a75fb674dcf6e2ba1..679b538ebf5ba8491fa6f73ead7d1b554bcfbbd3 100644 (file)
@@ -168,6 +168,14 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
                          ret->name=boost::get<string>(vars["name"]);
                        }
 
+                       if(vars.count("checkName")) {
+                         ret->checkName=DNSName(boost::get<string>(vars["checkName"]));
+                       }
+
+                       if(vars.count("checkType")) {
+                         ret->checkType=boost::get<string>(vars["checkType"]);
+                       }
+
                        if(g_launchWork) {
                          g_launchWork->push_back([ret]() {
                              ret->tid = move(thread(responderThread, ret));
index b9a2e1c5d1cafafd21b42d067bc8af3aaef23214..c35281f9ba5198b90449a6f036d6265228fed351 100644 (file)
@@ -214,7 +214,8 @@ bool operator<(const struct timespec&a, const struct timespec& b)
 }
 
 
-DownstreamState::DownstreamState(const ComboAddress& remote_)
+DownstreamState::DownstreamState(const ComboAddress& remote_):
+checkName("a.root-servers.net."), checkType(QType::A)
 {
   remote = remote_;
   
@@ -556,11 +557,11 @@ catch(...)
 }
 
 
-bool upCheck(const ComboAddress& remote)
+bool upCheck(const ComboAddress& remote, const DNSName& checkName, const QType& checkType)
 try
 {
   vector<uint8_t> packet;
-  DNSPacketWriter dpw(packet, DNSName("a.root-servers.net."), QType::A);
+  DNSPacketWriter dpw(packet, checkName, checkType.getCode());
   dnsheader * requestHeader = dpw.getHeader();
   requestHeader->rd=true;
 
@@ -612,7 +613,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);
+       bool newState=upCheck(dss->remote, dss->checkName, dss->checkType);
        if(newState != dss->upStatus) {
          warnlog("Marking downstream %s as '%s'", dss->getName(), newState ? "up" : "down");
        }
@@ -1124,8 +1125,8 @@ 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);
-      warnlog("Marking downstream %s as '%s'", dss->getName(), newState ? "up" : "down");
+      bool newState=upCheck(dss->remote, dss->checkName, dss->checkType);
+      warnlog("Marking downstream %s as '%s'", dss->remote.toStringWithPort(), newState ? "up" : "down");
       dss->upStatus = newState;
     }
   }
index cc6502ad7f509d171ab3e4740f820ce1eae1c964..271364bf3762a5661756a76cfed3bd45c2f826cc 100644 (file)
@@ -231,6 +231,8 @@ struct DownstreamState
   ComboAddress remote;
   QPSLimiter qps;
   vector<IDState> idStates;
+  DNSName checkName;
+  QType checkType;
   std::atomic<uint64_t> idOffset{0};
   std::atomic<uint64_t> sendErrors{0};
   std::atomic<uint64_t> outstanding{0};