]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: do not waste SOA queries in getDomaininfo() for a serial we never use
authorKees Monshouwer <mind04@monshouwer.org>
Wed, 29 Nov 2017 23:25:10 +0000 (00:25 +0100)
committermind04 <mind04@monshouwer.org>
Sat, 31 Mar 2018 21:40:20 +0000 (23:40 +0200)
18 files changed:
modules/bindbackend/bindbackend2.cc
modules/bindbackend/bindbackend2.hh
modules/geoipbackend/geoipbackend.cc
modules/geoipbackend/geoipbackend.hh
modules/ldapbackend/ldapbackend.cc
modules/ldapbackend/ldapbackend.hh
modules/luabackend/luabackend.hh
modules/luabackend/slave.cc
modules/opendbxbackend/odbxbackend.cc
modules/opendbxbackend/odbxbackend.hh
modules/remotebackend/remotebackend.cc
modules/remotebackend/remotebackend.hh
pdns/backends/gsql/gsqlbackend.cc
pdns/backends/gsql/gsqlbackend.hh
pdns/dnsbackend.hh
pdns/packethandler.cc
pdns/ueberbackend.cc
pdns/ueberbackend.hh

index 4baab252bd4b2308121d21e78498a4864db93169..b262a03075323e21b85b210d6796d0982ae7d785 100644 (file)
@@ -401,7 +401,7 @@ void Bind2Backend::getUnfreshSlaveInfos(vector<DomainInfo> *unfreshDomains)
   }
 }
 
-bool Bind2Backend::getDomainInfo(const DNSName& domain, DomainInfo &di)
+bool Bind2Backend::getDomainInfo(const DNSName& domain, DomainInfo &di, bool getSerial)
 {
   BB2DomainInfo bbd;
   if(!safeGetBBDomainInfo(domain, &bbd))
@@ -414,14 +414,16 @@ bool Bind2Backend::getDomainInfo(const DNSName& domain, DomainInfo &di)
   di.backend=this;
   di.kind=bbd.d_kind;
   di.serial=0;
-  try {
-    SOAData sd;
-    sd.serial=0;
-    
-    getSOA(bbd.d_name,sd); // we might not *have* a SOA yet
-    di.serial=sd.serial;
+  if(getSerial) {
+    try {
+      SOAData sd;
+      sd.serial=0;
+
+      getSOA(bbd.d_name,sd); // we might not *have* a SOA yet
+      di.serial=sd.serial;
+    }
+    catch(...){}
   }
-  catch(...){}
   
   return true;
 }
index a3825e025d7091dcfca12e6d3054b5378e0b9677..1f3b5cbd46ac839cfa301699bba3d42ffb99b77f 100644 (file)
@@ -191,7 +191,7 @@ public:
   ~Bind2Backend();
   void getUnfreshSlaveInfos(vector<DomainInfo> *unfreshDomains) override;
   void getUpdatedMasters(vector<DomainInfo> *changedDomains) override;
-  bool getDomainInfo(const DNSName &domain, DomainInfo &di) override;
+  bool getDomainInfo(const DNSName &domain, DomainInfo &di, bool getSerial=true ) override;
   time_t getCtime(const string &fname);
    // DNSSEC
   bool getBeforeAndAfterNamesAbsolute(uint32_t id, const DNSName& qname, DNSName& unhashed, DNSName& before, DNSName& after) override;
index 1953da6cdf285d43017be98410e2be1bae7c1960..9bf646e5f6c3c36cffcb313b8ef7c6a4ec89a4cd 100644 (file)
@@ -602,7 +602,7 @@ void GeoIPBackend::rediscover(string* status) {
   reload();
 }
 
-bool GeoIPBackend::getDomainInfo(const DNSName& domain, DomainInfo &di) {
+bool GeoIPBackend::getDomainInfo(const DNSName& domain, DomainInfo &di, bool getSerial) {
   ReadLock rl(&s_state_lock);
 
   for(GeoIPDomain dom :  s_domains) {
index 56774da7b907daae39cf4e69757f282cf97d55fa..a938240c39405fdc2bb4017255e8114234099c1d 100644 (file)
@@ -54,7 +54,7 @@ public:
   bool get(DNSResourceRecord &r) override;
   void reload() override;
   void rediscover(string *status = 0) override;
-  bool getDomainInfo(const DNSName& domain, DomainInfo &di) override;
+  bool getDomainInfo(const DNSName& domain, DomainInfo &di, bool getSerial=true) override;
 
   // dnssec support
   bool doesDNSSEC() override { return d_dnssec; };
index 723dba1d6f0110c46f46bbd4cbb2ea306ef5ef43..f974b82c0d28019e1fa0b631a904786364003b34 100644 (file)
@@ -675,7 +675,7 @@ void LdapBackend::setNotified( uint32_t id, uint32_t serial )
 
 
 
-bool LdapBackend::getDomainInfo( const DNSName& domain, DomainInfo& di )
+bool LdapBackend::getDomainInfo( const DNSName& domain, DomainInfo& di, bool getSerial )
 {
   string filter;
   SOAData sd;
index d836ce8a9c13cea02b38a83309dd8bf10e7b433d..3fb5861f96694883468e680c9a6c838995ce7632 100644 (file)
@@ -152,7 +152,7 @@ class LdapBackend : public DNSBackend
     void lookup( const QType& qtype, const DNSName& qdomain, DNSPacket* p = 0, int zoneid = -1 ) override;
     bool get( DNSResourceRecord& rr ) override;
 
-    bool getDomainInfo( const DNSName& domain, DomainInfo& di ) override;
+    bool getDomainInfo( const DNSName& domain, DomainInfo& di, bool getSerial=true ) override;
 
     // Master backend
     void getUpdatedMasters( vector<DomainInfo>* domains ) override;
index 5e1f3ac95298bfb5783b9704d7428171652d45a6..6d19d084af6ce9d06001e8b670d53a9d68a107bd 100644 (file)
@@ -68,7 +68,7 @@ public:
 
 //  SLAVE BACKEND
 
-    bool getDomainInfo(const DNSName& domain, DomainInfo &di) override;
+    bool getDomainInfo(const DNSName& domain, DomainInfo &di, bool getSerial=true) override;
     bool isMaster(const DNSName& name, const string &ip) override;
     void getUnfreshSlaveInfos(vector<DomainInfo>* domains) override;
     void setFresh(uint32_t id) override;
index 26d2a3a5ead00f3cfccfee5ebe732bc5bf22fdbb..22d6aa672c85fde483d07fe9d560f634580427a8 100644 (file)
@@ -258,7 +258,7 @@ bool LUABackend::isMaster(const DNSName& domain, const string &ip) {
     return ok;
 }
 
-bool LUABackend::getDomainInfo(const DNSName&domain, DomainInfo &di) {
+bool LUABackend::getDomainInfo(const DNSName&domain, DomainInfo &di, bool getSerial) {
     if (f_lua_getdomaininfo == 0)
         return false;
 
index ae05d5397b9eb46d5617ca33fd0057a8da795ed4..7b23b47b61a25eca84eee74e6be2294946920c30 100644 (file)
@@ -93,7 +93,7 @@ OdbxBackend::~OdbxBackend()
 
 
 
-bool OdbxBackend::getDomainInfo( const DNSName& domain, DomainInfo& di )
+bool OdbxBackend::getDomainInfo( const DNSName& domain, DomainInfo& di, bool getSerial )
 {
         const char* tmp;
 
@@ -119,7 +119,7 @@ bool OdbxBackend::getDomainInfo( const DNSName& domain, DomainInfo& di )
                        di.backend = this;
                        di.serial = 0;
 
-                       if( ( tmp = odbx_field_value( m_result, 6 ) ) != NULL )
+                       if( getSerial && ( tmp = odbx_field_value( m_result, 6 ) ) != NULL )
                        {
                                SOAData sd;
 
index 550e93f205d3ac8ff08eaa85e7bed0b2605a5f86..08d1c44c41f3d7a163ec47048091b9f34da97cb6 100644 (file)
@@ -86,7 +86,7 @@ public:
         bool abortTransaction() override;
 
         bool isMaster( const DNSName& domain, const string& ip ) override;
-        bool getDomainInfo( const DNSName& domain, DomainInfo& di ) override;
+        bool getDomainInfo( const DNSName& domain, DomainInfo& di, bool getSerial=true ) override;
         bool feedRecord( const DNSResourceRecord& rr, const DNSName& ordername ) override;
         bool createSlaveDomain( const string& ip, const DNSName& domain, const string &nameserver, const string& account ) override;
         bool superMasterBackend( const string& ip, const DNSName& domain, const vector<DNSResourceRecord>& nsset, string *nameserver, string* account, DNSBackend** ddb ) override;
index f422fd6cbc5b2516c1fe4bbbb109c22dc9a178ec..d8f8fdce8b34b7a4ea14179a2d1d13d4af4a8d44 100644 (file)
@@ -577,7 +577,7 @@ void RemoteBackend::parseDomainInfo(const Json &obj, DomainInfo &di)
    di.backend = this;
 }
 
-bool RemoteBackend::getDomainInfo(const DNSName& domain, DomainInfo &di) {
+bool RemoteBackend::getDomainInfo(const DNSName& domain, DomainInfo &di, bool getSerial) {
    if (domain.empty()) return false;
    Json query = Json::object{
      { "method", "getDomainInfo" },
index efec16bfdcf9292f0fb6fd1b1822f20385497441..2d0d1b7822a886d8ad52bd708c854ad03d461e18 100644 (file)
@@ -167,7 +167,7 @@ class RemoteBackend : public DNSBackend
   bool addDomainKey(const DNSName& name, const KeyData& key, int64_t& id) override;
   bool activateDomainKey(const DNSName& name, unsigned int id) override;
   bool deactivateDomainKey(const DNSName& name, unsigned int id) override;
-  bool getDomainInfo(const DNSName& domain, DomainInfo& di) override;
+  bool getDomainInfo(const DNSName& domain, DomainInfo& di, bool getSerial=true ) override;
   void setNotified(uint32_t id, uint32_t serial) override;
   bool doesDNSSEC() override;
   bool isMaster(const DNSName& name, const string &ip) override;
index 21453f1699050c710c184e5eb5d8865025ac0405..4dbc9697054942c663d9ce10ee06928f094f40dc 100644 (file)
@@ -300,7 +300,7 @@ bool GSQLBackend::setAccount(const DNSName &domain, const string &account)
   return true;
 }
 
-bool GSQLBackend::getDomainInfo(const DNSName &domain, DomainInfo &di)
+bool GSQLBackend::getDomainInfo(const DNSName &domain, DomainInfo &di, bool getSerial)
 {
   /* fill DomainInfo from database info:
      id,name,master IP(s),last_check,notified_serial,type,account */
@@ -337,15 +337,17 @@ bool GSQLBackend::getDomainInfo(const DNSName &domain, DomainInfo &di)
   di.backend=this;
 
   di.serial = 0;
-  try {
-    SOAData sd;
-    if(!getSOA(domain, sd))
-      g_log<<Logger::Notice<<"No serial for '"<<domain<<"' found - zone is missing?"<<endl;
-    else
-      di.serial = sd.serial;
-  }
-  catch(PDNSException &ae){
-    g_log<<Logger::Error<<"Error retrieving serial for '"<<domain<<"': "<<ae.reason<<endl;
+  if(getSerial) {
+    try {
+      SOAData sd;
+      if(!getSOA(domain, sd))
+        g_log<<Logger::Notice<<"No serial for '"<<domain<<"' found - zone is missing?"<<endl;
+      else
+        di.serial = sd.serial;
+    }
+    catch(PDNSException &ae){
+      g_log<<Logger::Error<<"Error retrieving serial for '"<<domain<<"': "<<ae.reason<<endl;
+    }
   }
 
   di.kind = DomainInfo::stringToKind(type);
index cd591076f004f4bc78d965789e17507293e44b01..f1ce75e244e0a36f47d719a7ac544499f42a2ca0 100644 (file)
@@ -195,7 +195,7 @@ public:
   void setFresh(uint32_t domain_id) override;
   void getUnfreshSlaveInfos(vector<DomainInfo> *domains) override;
   void getUpdatedMasters(vector<DomainInfo> *updatedDomains) override;
-  bool getDomainInfo(const DNSName &domain, DomainInfo &di) override;
+  bool getDomainInfo(const DNSName &domain, DomainInfo &di, bool getSerial=true) override;
   void setNotified(uint32_t domain_id, uint32_t serial) override;
   bool setMaster(const DNSName &domain, const string &ip) override;
   bool setKind(const DNSName &domain, const DomainInfo::DomainKind kind) override;
index 4b14f57b8f308a867f7b8b5bf18b4c37723cfd45..2d0d178b3a7cc62bd34d3a43cbf08a8acc032fde 100644 (file)
@@ -282,7 +282,7 @@ public:
   }
 
   //! if this returns true, DomainInfo di contains information about the domain
-  virtual bool getDomainInfo(const DNSName &domain, DomainInfo &di)
+  virtual bool getDomainInfo(const DNSName &domain, DomainInfo &di, bool getSerial=true)
   {
     return false;
   }
index ad59c9f249e3cc48a22f6b3c837f61aef134b309..7b0d182cab9475638b1236bed8c1228e3049c912 100644 (file)
@@ -819,8 +819,7 @@ int PacketHandler::processNotify(DNSPacket *p)
 
   DNSBackend *db=0;
   DomainInfo di;
-  di.serial = 0;
-  if(!B.getDomainInfo(p->qdomain, di) || !(db=di.backend)) {
+  if(!B.getDomainInfo(p->qdomain, di, false) || !(db=di.backend)) {
     g_log<<Logger::Error<<"Received NOTIFY for "<<p->qdomain<<" from "<<p->getRemote()<<" for which we are not authoritative"<<endl;
     return trySuperMaster(p, p->getTSIGKeyname());
   }
@@ -856,9 +855,6 @@ int PacketHandler::processNotify(DNSPacket *p)
     return RCode::Refused;
   }
     
-  // ok, we've done our checks
-  di.backend = 0;
-
   if(!s_forwardNotify.empty()) {
     set<string> forwardNotify(s_forwardNotify);
     for(set<string>::const_iterator j=forwardNotify.begin();j!=forwardNotify.end();++j) {
index 3b7e3ff8f80d7cd04b145219bb55b98d4a7ad4be..bfb5605db2c644a28544b88124d8561251c87f1a 100644 (file)
@@ -80,10 +80,10 @@ void UeberBackend::go(void)
   pthread_mutex_unlock(&d_mut);
 }
 
-bool UeberBackend::getDomainInfo(const DNSName &domain, DomainInfo &di)
+bool UeberBackend::getDomainInfo(const DNSName &domain, DomainInfo &di, bool getSerial)
 {
   for(vector<DNSBackend *>::const_iterator i=backends.begin();i!=backends.end();++i)
-    if((*i)->getDomainInfo(domain, di))
+    if((*i)->getDomainInfo(domain, di, getSerial))
       return true;
   return false;
 }
index 9ce54b0c1aa1dd2f6af03a96d3bf777af82ecbdd..811152b765d3d746114f30c7e1c8fdb84e6cb70a 100644 (file)
@@ -109,7 +109,7 @@ public:
 
   void getUnfreshSlaveInfos(vector<DomainInfo>* domains);
   void getUpdatedMasters(vector<DomainInfo>* domains);
-  bool getDomainInfo(const DNSName &domain, DomainInfo &di);
+  bool getDomainInfo(const DNSName &domain, DomainInfo &di, bool getSerial=true);
   bool createDomain(const DNSName &domain);
   
   bool doesDNSSEC();