]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix failure to start RPZIXFRTracker tracker thread.
authorErik Winkels <erik.winkels@powerdns.com>
Fri, 26 Jan 2018 16:07:05 +0000 (17:07 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Mon, 12 Mar 2018 14:16:01 +0000 (15:16 +0100)
This is an initial commit and needs more work (but it's 17:07 on a
Friday, so yeah...).

(cherry picked from commit e9112b46b9d972aed25e1f1f9ec46253b6718d5c)

pdns/rec-lua-conf.cc
pdns/reczones.cc

index b73a3849340572956897e876f2c6e20cca6d5dae..72eac5f00c73ae853de826b9a5e60b46600f76f5 100644 (file)
@@ -135,16 +135,22 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly)
     });
 
   Lua.writeFunction("rpzMaster", [&lci, checkOnly](const string& master_, const string& zoneName, const boost::optional<std::unordered_map<string,boost::variant<uint32_t, string>>>& options) {
+
+      boost::optional<DNSFilterEngine::Policy> defpol;
+      std::shared_ptr<DNSFilterEngine::Zone> zone = std::make_shared<DNSFilterEngine::Zone>();
+      TSIGTriplet tt;
+      uint32_t refresh=0;
+      size_t maxReceivedXFRMBytes = 0;
+      uint16_t axfrTimeout = 20;
+      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 {
-        boost::optional<DNSFilterEngine::Policy> defpol;
-        std::shared_ptr<DNSFilterEngine::Zone> zone = std::make_shared<DNSFilterEngine::Zone>();
-        TSIGTriplet tt;
-        uint32_t refresh=0;
         std::string polName(zoneName);
-        size_t maxReceivedXFRMBytes = 0;
-        uint16_t axfrTimeout = 20;
-        uint32_t maxTTL = std::numeric_limits<uint32_t>::max();
-        ComboAddress localAddress;
         if(options) {
           auto& have = *options;
           size_t zoneSizeHint = 0;
@@ -171,35 +177,52 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly)
             axfrTimeout = static_cast<uint16_t>(boost::get<uint32_t>(constGet(have, "axfrTimeout")));
           }
         }
-        ComboAddress master(master_, 53);
         if (localAddress != ComboAddress() && localAddress.sin4.sin_family != master.sin4.sin_family) {
           // We were passed a localAddress, check if its AF matches the master's
           throw PDNSException("Master address("+master.toString()+") is not of the same Address Family as the local address ("+localAddress.toString()+").");
         }
 
-        DNSName domain(zoneName);
         zone->setDomain(domain);
         zone->setName(polName);
         zone->setRefresh(refresh);
-        size_t zoneIdx = lci.dfe.addZone(zone);
+        zoneIdx = lci.dfe.addZone(zone);
+      }
+      catch(const std::exception& e) {
+        theL()<<Logger::Error<<"Problem configuring 'rpzMaster': "<<e.what()<<endl;
+        // FIXME exit program here
+      }
+      catch(const PDNSException& e) {
+        theL()<<Logger::Error<<"Problem configuring 'rpzMaster': "<<e.reason<<endl;
+        // FIXME exit program here
+      }
 
+      try {
         if (!checkOnly) {
-          auto sr=loadRPZFromServer(master, domain, zone, defpol, maxTTL, tt, maxReceivedXFRMBytes * 1024 * 1024, localAddress, axfrTimeout);
+          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, DNSName(zoneName), defpol, maxTTL, zoneIdx, tt, sr, maxReceivedXFRMBytes * 1024 * 1024, localAddress, axfrTimeout);
-          t.detach();
         }
       }
       catch(const std::exception& e) {
-        theL()<<Logger::Error<<"Unable to load RPZ zone '"<<zoneName<<"' from '"<<master_<<"': "<<e.what()<<endl;
+        theL()<<Logger::Warning<<"Unable to load RPZ zone '"<<zoneName<<"' from '"<<master_<<"': "<<e.what()<<"\nWill try again later."<<endl;
       }
       catch(const PDNSException& e) {
-        theL()<<Logger::Error<<"Unable to load RPZ zone '"<<zoneName<<"' from '"<<master_<<"': "<<e.reason<<endl;
+        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?
+      }
+      catch(const PDNSException& e) {
+        theL()<<Logger::Error<<"Problem starting RPZIXFRTracker thread: "<<e.reason<<endl;
+        // XXX exit program here?
+      }
     });
 
   typedef vector<pair<int,boost::variant<string, vector<pair<int, string> > > > > argvec_t;
index 6f76419c88be681ab4dc3f1bd5c00953435ce5ac..f58239f0a27e5069d9e3b965fd9002aa2a09d930 100644 (file)
@@ -320,14 +320,40 @@ 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)
 {
-  uint32_t refresh = oursr->d_st.refresh;
+  uint32_t refresh = 5;  // FIXME properly init from somewhere
+  if (oursr != 0) {  // FIXME replace with 'official' null check
+      refresh = oursr->d_st.refresh;
+  }
+
   for(;;) {
     DNSRecord dr;
     dr.d_content=oursr;
 
     sleep(refresh);
-    
-    L<<Logger::Info<<"Getting IXFR deltas for "<<zoneName<<" from "<<master.toStringWithPort()<<", our serial: "<<getRR<SOARecordContent>(dr)->d_st.serial<<endl;
+
+    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;
+    }
     vector<pair<vector<DNSRecord>, vector<DNSRecord> > > deltas;
 
     ComboAddress local(localAddress);
@@ -335,7 +361,9 @@ void RPZIXFRTracker(const ComboAddress& master, const DNSName& zoneName, boost::
       local = getQueryLocalAddress(master.sin4.sin_family, 0);
 
     try {
-      deltas = getIXFRDeltas(master, zoneName, dr, tt, &local, maxReceivedBytes);
+      if (oursr != 0) {  // FIXME replace with 'official' null check
+          deltas = getIXFRDeltas(master, zoneName, dr, tt, &local, maxReceivedBytes);
+      }
     } catch(std::runtime_error& e ){
       L<<Logger::Warning<<e.what()<<endl;
       continue;