]> granicus.if.org Git - pdns/commitdiff
Move loading of RPZ zone to RPZIXFRTracker.
authorErik Winkels <erik.winkels@powerdns.com>
Mon, 29 Jan 2018 15:33:12 +0000 (16:33 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Mon, 12 Mar 2018 14:18:49 +0000 (15:18 +0100)
(cherry picked from commit bb8ffe202776f44722fa6333dbfc24c36c1d395e)

pdns/filterpo.hh
pdns/rec-lua-conf.cc
pdns/reczones.cc
pdns/rpzloader.hh

index 69e1fc56be3b670fb0e3ab223efc939aefb50abe..c57fe9974fa54cf6dc6e5cf391e1cfb3fbf0ff94 100644 (file)
@@ -122,6 +122,14 @@ public:
     {
       return d_name;
     }
+    DNSName getDomain()
+    {
+      return d_domain;
+    }
+    uint32_t getRefresh()
+    {
+      return d_refresh;
+    }
     void dump(FILE * fp) const;
 
     void addClientTrigger(const Netmask& nm, Policy pol);
index 72eac5f00c73ae853de826b9a5e60b46600f76f5..671d6e2ea02ec21364dc69b8dd1edb4c58caa859 100644 (file)
@@ -145,9 +145,7 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly)
       uint32_t maxTTL = std::numeric_limits<uint32_t>::max();
       ComboAddress localAddress;
       ComboAddress master(master_, 53);
-      DNSName domain(zoneName);
       size_t zoneIdx;
-      std::shared_ptr<SOARecordContent> sr;
 
       try {
         std::string polName(zoneName);
@@ -182,46 +180,33 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly)
           throw PDNSException("Master address("+master.toString()+") is not of the same Address Family as the local address ("+localAddress.toString()+").");
         }
 
-        zone->setDomain(domain);
+        zone->setDomain(DNSName(zoneName));
         zone->setName(polName);
         zone->setRefresh(refresh);
         zoneIdx = lci.dfe.addZone(zone);
       }
       catch(const std::exception& e) {
         theL()<<Logger::Error<<"Problem configuring 'rpzMaster': "<<e.what()<<endl;
-        // FIXME exit program here
+        exit(1);  // FIXME proper exit code?
       }
       catch(const PDNSException& e) {
         theL()<<Logger::Error<<"Problem configuring 'rpzMaster': "<<e.reason<<endl;
-        // FIXME exit program here
+        exit(1);  // FIXME proper exit code?
       }
 
       try {
         if (!checkOnly) {
-          sr=loadRPZFromServer(master, domain, zone, defpol, maxTTL, tt, maxReceivedXFRMBytes * 1024 * 1024, localAddress, axfrTimeout);
-          if(refresh)
-            sr->d_st.refresh=refresh;
-          zone->setSerial(sr->d_st.serial);
+          std::thread t(RPZIXFRTracker, master, defpol, maxTTL, zoneIdx, tt, maxReceivedXFRMBytes * 1024 * 1024, localAddress, zone, axfrTimeout);
+          t.detach();
         }
       }
-      catch(const std::exception& e) {
-        theL()<<Logger::Warning<<"Unable to load RPZ zone '"<<zoneName<<"' from '"<<master_<<"': "<<e.what()<<"\nWill try again later."<<endl;
-      }
-      catch(const PDNSException& e) {
-        theL()<<Logger::Warning<<"Unable to load RPZ zone '"<<zoneName<<"' from '"<<master_<<"': "<<e.reason<<"\nWill try again later."<<endl;
-      }
-
-      try {
-        std::thread t(RPZIXFRTracker, master, DNSName(zoneName), defpol, maxTTL, zoneIdx, tt, sr, maxReceivedXFRMBytes * 1024 * 1024, localAddress, axfrTimeout);
-        t.detach();
-      }
       catch(const std::exception& e) {
         theL()<<Logger::Error<<"Problem starting RPZIXFRTracker thread: "<<e.what()<<endl;
-        // XXX exit program here?
+        exit(1);  // FIXME proper exit code?
       }
       catch(const PDNSException& e) {
         theL()<<Logger::Error<<"Problem starting RPZIXFRTracker thread: "<<e.reason<<endl;
-        // XXX exit program here?
+        exit(1);  // FIXME proper exit code?
       }
     });
 
index f58239f0a27e5069d9e3b965fd9002aa2a09d930..fd42fe9b9e2ea2450a5d2e01c750c087c2453fbb 100644 (file)
@@ -318,42 +318,39 @@ string reloadAuthAndForwards()
 }
 
 
-void RPZIXFRTracker(const ComboAddress& master, const DNSName& zoneName, boost::optional<DNSFilterEngine::Policy> defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, shared_ptr<SOARecordContent> oursr, size_t maxReceivedBytes, const ComboAddress& localAddress, const uint16_t axfrTimeout)
+void RPZIXFRTracker(const ComboAddress& master, boost::optional<DNSFilterEngine::Policy> defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, std::shared_ptr<DNSFilterEngine::Zone> zone, const uint16_t axfrTimeout)
 {
-  uint32_t refresh = 5;  // FIXME properly init from somewhere
-  if (oursr != 0) {  // FIXME replace with 'official' null check
-      refresh = oursr->d_st.refresh;
+  uint32_t refresh = zone->getRefresh();
+  DNSName zoneName = zone->getDomain();
+  shared_ptr<SOARecordContent> sr;
+
+  while (!sr) {
+    try {
+      sr=loadRPZFromServer(master, zoneName, zone, defpol, maxTTL, tt, maxReceivedBytes, localAddress);
+      if(refresh) {
+        sr->d_st.refresh=refresh;
+      }
+      zone->setSerial(sr->d_st.serial);
+    }
+    catch(const std::exception& e) {
+      theL()<<Logger::Warning<<"Unable to load RPZ zone '"<<zoneName<<"' from '"<<master<<"': '"<<e.what()<<"'. (Will try again in "<<refresh<<" seconds...)"<<endl;
+    }
+    catch(const PDNSException& e) {
+      theL()<<Logger::Warning<<"Unable to load RPZ zone '"<<zoneName<<"' from '"<<master<<"': '"<<e.reason<<"'. (Will try again in "<<refresh<<" seconds...)"<<endl;
+    }
+
+    if (!sr) {
+      sleep(refresh);
+    }
   }
 
   for(;;) {
     DNSRecord dr;
-    dr.d_content=oursr;
+    dr.d_content=sr;
 
     sleep(refresh);
 
-    if (oursr == 0) {  // FIXME replace with 'official' null check
-        theL()<<Logger::Info<<"Trying to do initial RPZ load from server again..."<<endl;
-        try {
-            std::shared_ptr<DNSFilterEngine::Zone> zone = std::make_shared<DNSFilterEngine::Zone>();
-            DNSName domain(zoneName);
-            zone->setDomain(domain);
-            zone->setName("FIXMECHANGEME");
-            zone->setRefresh(refresh);
-            oursr=loadRPZFromServer(master, domain, zone, defpol, maxTTL, tt, maxReceivedBytes, localAddress);
-            refresh = oursr->d_st.refresh;
-            dr.d_content=oursr;
-        }
-        catch(const std::exception& e) {
-            theL()<<Logger::Warning<<"Unable to load RPZ zone '"<<zoneName<<"' from '"<<master<<"': "<<e.what()<<"\nWill try again later."<<endl;
-        }
-        catch(const PDNSException& e) {
-            theL()<<Logger::Warning<<"Unable to load RPZ zone '"<<zoneName<<"' from '"<<master<<"': "<<e.reason<<"\nWill try again later."<<endl;
-        }
-    }
-
-    if (oursr != 0) {  // FIXME replace with 'official' null check
-        L<<Logger::Info<<"Getting IXFR deltas for "<<zoneName<<" from "<<master.toStringWithPort()<<", our serial: "<<getRR<SOARecordContent>(dr)->d_st.serial<<endl;
-    }
+    L<<Logger::Info<<"Getting IXFR deltas for "<<zoneName<<" from "<<master.toStringWithPort()<<", our serial: "<<getRR<SOARecordContent>(dr)->d_st.serial<<endl;
     vector<pair<vector<DNSRecord>, vector<DNSRecord> > > deltas;
 
     ComboAddress local(localAddress);
@@ -361,9 +358,7 @@ void RPZIXFRTracker(const ComboAddress& master, const DNSName& zoneName, boost::
       local = getQueryLocalAddress(master.sin4.sin_family, 0);
 
     try {
-      if (oursr != 0) {  // FIXME replace with 'official' null check
-          deltas = getIXFRDeltas(master, zoneName, dr, tt, &local, maxReceivedBytes);
-      }
+      deltas = getIXFRDeltas(master, zoneName, dr, tt, &local, maxReceivedBytes);
     } catch(std::runtime_error& e ){
       L<<Logger::Warning<<e.what()<<endl;
       continue;
@@ -390,7 +385,7 @@ void RPZIXFRTracker(const ComboAddress& master, const DNSName& zoneName, boost::
           continue;
        if(rr.d_type == QType::SOA) {
          auto oldsr = getRR<SOARecordContent>(rr);
-         if(oldsr && oldsr->d_st.serial == oursr->d_st.serial) {
+         if(oldsr && oldsr->d_st.serial == sr->d_st.serial) {
            //      cout<<"Got good removal of SOA serial "<<oldsr->d_st.serial<<endl;
          }
          else
@@ -410,7 +405,7 @@ void RPZIXFRTracker(const ComboAddress& master, const DNSName& zoneName, boost::
          auto newsr = getRR<SOARecordContent>(rr);
          //      L<<Logger::Info<<"New SOA serial for "<<zoneName<<": "<<newsr->d_st.serial<<endl;
          if (newsr) {
-           oursr = newsr;
+           sr = newsr;
          }
        }
        else {
@@ -420,8 +415,8 @@ void RPZIXFRTracker(const ComboAddress& master, const DNSName& zoneName, boost::
        }
       }
     }
-    L<<Logger::Info<<"Had "<<totremove<<" RPZ removal"<<addS(totremove)<<", "<<totadd<<" addition"<<addS(totadd)<<" for "<<zoneName<<" New serial: "<<oursr->d_st.serial<<endl;
-    newZone->setSerial(oursr->d_st.serial);
+    L<<Logger::Info<<"Had "<<totremove<<" RPZ removal"<<addS(totremove)<<", "<<totadd<<" addition"<<addS(totadd)<<" for "<<zoneName<<" New serial: "<<sr->d_st.serial<<endl;
+    newZone->setSerial(sr->d_st.serial);
 
     /* we need to replace the existing zone with the new one,
        but we don't want to touch anything else, especially other zones,
index e343f597d2a6462d975ddb61aad03e14f1d7d5f3..900ea23b0555b9e0f1029be69b17fe175e954d13 100644 (file)
@@ -29,4 +29,4 @@ extern bool g_logRPZChanges;
 void loadRPZFromFile(const std::string& fname, std::shared_ptr<DNSFilterEngine::Zone> zone, boost::optional<DNSFilterEngine::Policy> defpol, uint32_t maxTTL);
 std::shared_ptr<SOARecordContent> loadRPZFromServer(const ComboAddress& master, const DNSName& zoneName, std::shared_ptr<DNSFilterEngine::Zone> zone, boost::optional<DNSFilterEngine::Policy> defpol, uint32_t maxTTL, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, const uint16_t axfrTimeout);
 void RPZRecordToPolicy(const DNSRecord& dr, std::shared_ptr<DNSFilterEngine::Zone> zone, bool addOrRemove, boost::optional<DNSFilterEngine::Policy> defpol, uint32_t maxTTL);
-void RPZIXFRTracker(const ComboAddress& master, const DNSName& zoneName, boost::optional<DNSFilterEngine::Policy> defpol, uint32_t maxTTL, size_t polZone, const TSIGTriplet &tt, shared_ptr<SOARecordContent> oursr, size_t maxReceivedBytes, const ComboAddress& localAddress, const uint16_t axfrTimeout);
+void RPZIXFRTracker(const ComboAddress& master, boost::optional<DNSFilterEngine::Policy> defpol, uint32_t maxTTL, size_t polZone, const TSIGTriplet &tt, size_t maxReceivedBytes, const ComboAddress& localAddress, std::shared_ptr<DNSFilterEngine::Zone> zone, const uint16_t axfrTimeout);