]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Switch priority over to an enum, and implement it in various places + one small nitpi...
authorRobin Geuze <robing@transip.nl>
Fri, 19 Mar 2021 14:28:35 +0000 (15:28 +0100)
committerRobin Geuze <robing@transip.nl>
Wed, 24 Mar 2021 10:10:36 +0000 (11:10 +0100)
pdns/communicator.hh
pdns/dnsbackend.hh
pdns/dynhandler.cc
pdns/packethandler.cc
pdns/slavecommunicator.cc
pdns/ws-auth.cc

index 384ae2c669b2975422463aaa6501069034e7fa2a..a8a6a77b012d7f35e192edd356bbfac55318db10 100644 (file)
@@ -46,7 +46,8 @@ struct SuckRequest
   DNSName domain;
   ComboAddress master;
   bool force;
-  std::pair<uint8_t, uint64_t> priorityAndOrder;
+  enum RequestPriority : uint8_t { PdnsControl, Api, Notify, SerialRefresh, SignaturesRefresh };
+  std::pair<RequestPriority, uint64_t> priorityAndOrder;
   bool operator<(const SuckRequest& b) const
   {
     return tie(domain, master) < tie(b.domain, b.master);
@@ -59,7 +60,7 @@ struct QueueTag{};
 typedef multi_index_container<
   SuckRequest,
   indexed_by<
-    ordered_unique<tag<QueueTag>, member<SuckRequest,std::pair<uint8_t,uint64_t>,&SuckRequest::priorityAndOrder>>,
+    ordered_unique<tag<QueueTag>, member<SuckRequest,std::pair<SuckRequest::RequestPriority,uint64_t>,&SuckRequest::priorityAndOrder>>,
     ordered_unique<tag<IDTag>, identity<SuckRequest> >
   >
 > UniQueue;
@@ -166,7 +167,7 @@ public:
   
   void drillHole(const DNSName &domain, const string &ip);
   bool justNotified(const DNSName &domain, const string &ip);
-  void addSuckRequest(const DNSName &domain, const ComboAddress& master, bool force=false, uint8_t priority = 0);
+  void addSuckRequest(const DNSName &domain, const ComboAddress& master, SuckRequest::RequestPriority, bool force=false);
   void addSlaveCheckRequest(const DomainInfo& di, const ComboAddress& remote);
   void addTrySuperMasterRequest(const DNSPacket& p);
   void notify(const DNSName &domain, const string &ip);
index b339b229e095a768edfae6b8f06d76104cfb68ca..f200a0526a6436706f23e61f33ae78bd781fe1a7 100644 (file)
@@ -46,7 +46,7 @@ class DNSPacket;
 class DNSBackend;  
 struct DomainInfo
 {
-  DomainInfo() : last_check(0), backend(nullptr), id(0), notified_serial(0), serial(0), kind(DomainInfo::Native) {}
+  DomainInfo() : last_check(0), backend(nullptr), id(0), notified_serial(0), receivedNotify(false), serial(0), kind(DomainInfo::Native) {}
 
   DNSName zone;
   time_t last_check;
@@ -57,6 +57,8 @@ struct DomainInfo
   uint32_t id;
   uint32_t notified_serial;
 
+  bool receivedNotify;
+
   uint32_t serial;
   enum DomainKind : uint8_t { Master, Slave, Native } kind;
   
index 8926738f5673cc9612c9d3eb046bbb2be10d31f3..3c05f13072e72317b1446b548e9b5be5edceb337 100644 (file)
@@ -278,7 +278,7 @@ string DLNotifyRetrieveHandler(const vector<string>&parts, Utility::pid_t ppid)
 
   shuffle(di.masters.begin(), di.masters.end(), pdns::dns_random_engine());
   const auto& master = di.masters.front();
-  Communicator.addSuckRequest(domain, master, override_master);
+  Communicator.addSuckRequest(domain, master, SuckRequest::PdnsControl, override_master);
   g_log<<Logger::Warning<<"Retrieval request for domain '"<<domain<<"' from master '"<<master<<"' received from operator"<<endl;
   return "Added retrieval request for '"+domain.toLogString()+"' from master "+master.toLogString();
 }
index fb3ed7a8837cd001f18643efa0e972fd717887ae..939a28b1333cd0d2aebfea011ff415c9df2c1979 100644 (file)
@@ -1030,6 +1030,7 @@ int PacketHandler::processNotify(const DNSPacket& p)
 
   if(::arg().mustDo("slave")) {
     g_log<<Logger::Notice<<"Received NOTIFY for "<<p.qdomain<<" from "<<p.getRemote()<<" - queueing check"<<endl;
+    di.receivedNotify = true;
     Communicator.addSlaveCheckRequest(di, p.d_remote);
   }
   return 0;
index 9197c649cd02938c1c58c5eab75836fd57f7814a..635695e5b65ee05dd747ffde1f008c80b522a64b 100644 (file)
@@ -48,7 +48,7 @@
 
 #include "ixfr.hh"
 
-void CommunicatorClass::addSuckRequest(const DNSName &domain, const ComboAddress& master, bool force, uint8_t priority)
+void CommunicatorClass::addSuckRequest(const DNSName &domain, const ComboAddress& master, SuckRequest::RequestPriority priority, bool force)
 {
   std::lock_guard<std::mutex> l(d_lock);
   SuckRequest sr;
@@ -63,14 +63,7 @@ void CommunicatorClass::addSuckRequest(const DNSName &domain, const ComboAddress
   if(res.second) {
     d_suck_sem.post();
   } else {
-    // Domain is already in there, we should check the priority and whether its forced
-    domains_by_name_t& nameindex=boost::multi_index::get<IDTag>(d_suckdomains);
-    auto iter = nameindex.find(sr);
-    if (iter == nameindex.end()) {
-      // bit weird, but ok
-      return;
-    }
-    nameindex.modify(iter, [priorityAndOrder = sr.priorityAndOrder] (SuckRequest& so) {
+    d_suckdomains.modify(res.first, [priorityAndOrder = sr.priorityAndOrder] (SuckRequest& so) {
       if (priorityAndOrder.first < so.priorityAndOrder.first) {
         so.priorityAndOrder = priorityAndOrder;
       }
@@ -1003,6 +996,12 @@ void CommunicatorClass::slaveRefresh(PacketHandler *P)
           }
         }
       }
+
+      SuckRequest::RequestPriority prio = SuckRequest::SignaturesRefresh;
+      if (di.receivedNotify) {
+        prio = SuckRequest::Notify;
+      }
+
       if(! maxInception && ! ssr.d_freshness[di.id].theirInception) {
         g_log<<Logger::Info<<"Domain '"<< di.zone << "' is fresh (no DNSSEC), serial is " << ourserial << " (checked master " << remote.toStringWithPortExcept(53) << ")" << endl;
         di.backend->setFresh(di.id);
@@ -1017,25 +1016,30 @@ void CommunicatorClass::slaveRefresh(PacketHandler *P)
       }
       else if(maxInception && ! ssr.d_freshness[di.id].theirInception ) {
         g_log<<Logger::Notice<<"Domain '"<< di.zone << "' is stale, master " << remote.toStringWithPortExcept(53) << " is no longer signed and all signatures have expired, serial is " << ourserial << endl;
-        addSuckRequest(di.zone, remote);
+        addSuckRequest(di.zone, remote, prio);
       }
       else if(dk.doesDNSSEC() && ! maxInception && ssr.d_freshness[di.id].theirInception) {
         g_log<<Logger::Notice<<"Domain '"<< di.zone << "' is stale, master " << remote.toStringWithPortExcept(53) << " has signed, serial is " << ourserial << endl;
-        addSuckRequest(di.zone, remote);
+        addSuckRequest(di.zone, remote, prio);
       }
       else {
         g_log<<Logger::Notice<<"Domain '"<< di.zone << "' is fresh, but RRSIGs differ on master" << remote.toStringWithPortExcept(53)<<", so DNSSEC is stale, serial is " << ourserial << endl;
-        addSuckRequest(di.zone, remote);
+        addSuckRequest(di.zone, remote, prio);
       }
     }
     else {
+      SuckRequest::RequestPriority prio = SuckRequest::SerialRefresh;
+      if (di.receivedNotify) {
+        prio = SuckRequest::Notify;
+      }
+
       if (hasSOA) {
         g_log<<Logger::Notice<<"Domain '"<< di.zone << "' is stale, master " << remote.toStringWithPortExcept(53) << " serial " << theirserial << ", our serial " << ourserial << endl;
       }
       else {
         g_log<<Logger::Notice<<"Domain '"<< di.zone << "' is empty, master " << remote.toStringWithPortExcept(53) << " serial " << theirserial << endl;
       }
-      addSuckRequest(di.zone, remote);
+      addSuckRequest(di.zone, remote, prio);
     }
   }
 }
index a17e05814fa9ab8ba35ed3e122cba40d34d5ad2c..b1f8140ef792ed045ea3ae940f80bb7ec428a617 100644 (file)
@@ -1876,7 +1876,7 @@ static void apiServerZoneAxfrRetrieve(HttpRequest* req, HttpResponse* resp) {
     throw ApiException("Domain '"+zonename.toString()+"' is not a slave domain (or has no master defined)");
 
   shuffle(di.masters.begin(), di.masters.end(), pdns::dns_random_engine());
-  Communicator.addSuckRequest(zonename, di.masters.front());
+  Communicator.addSuckRequest(zonename, di.masters.front(), SuckRequest::Api);
   resp->setSuccessResult("Added retrieval request for '"+zonename.toString()+"' from master "+di.masters.front().toLogString());
 }