From: Erik Winkels Date: Mon, 29 Jan 2018 15:33:12 +0000 (+0100) Subject: Move loading of RPZ zone to RPZIXFRTracker. X-Git-Tag: rec-4.1.2~4^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6dd5e1002dd6105ecff5870d7c52c7a54fec6b14;p=pdns Move loading of RPZ zone to RPZIXFRTracker. (cherry picked from commit bb8ffe202776f44722fa6333dbfc24c36c1d395e) --- diff --git a/pdns/filterpo.hh b/pdns/filterpo.hh index 69e1fc56b..c57fe9974 100644 --- a/pdns/filterpo.hh +++ b/pdns/filterpo.hh @@ -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); diff --git a/pdns/rec-lua-conf.cc b/pdns/rec-lua-conf.cc index 72eac5f00..671d6e2ea 100644 --- a/pdns/rec-lua-conf.cc +++ b/pdns/rec-lua-conf.cc @@ -145,9 +145,7 @@ void loadRecursorLuaConfig(const std::string& fname, bool checkOnly) uint32_t maxTTL = std::numeric_limits::max(); ComboAddress localAddress; ComboAddress master(master_, 53); - DNSName domain(zoneName); size_t zoneIdx; - std::shared_ptr 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()<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()< defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, shared_ptr oursr, size_t maxReceivedBytes, const ComboAddress& localAddress, const uint16_t axfrTimeout) +void RPZIXFRTracker(const ComboAddress& master, boost::optional defpol, uint32_t maxTTL, size_t zoneIdx, const TSIGTriplet& tt, size_t maxReceivedBytes, const ComboAddress& localAddress, std::shared_ptr 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 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()< zone = std::make_shared(); - 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()<(dr)->d_st.serial<(dr)->d_st.serial<, vector > > 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<(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 "<d_st.serial<(rr); // L<d_st.serial<d_st.serial<setSerial(oursr->d_st.serial); + L<d_st.serial<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, diff --git a/pdns/rpzloader.hh b/pdns/rpzloader.hh index e343f597d..900ea23b0 100644 --- a/pdns/rpzloader.hh +++ b/pdns/rpzloader.hh @@ -29,4 +29,4 @@ extern bool g_logRPZChanges; void loadRPZFromFile(const std::string& fname, std::shared_ptr zone, boost::optional defpol, uint32_t maxTTL); std::shared_ptr loadRPZFromServer(const ComboAddress& master, const DNSName& zoneName, std::shared_ptr zone, boost::optional 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 zone, bool addOrRemove, boost::optional defpol, uint32_t maxTTL); -void RPZIXFRTracker(const ComboAddress& master, const DNSName& zoneName, boost::optional defpol, uint32_t maxTTL, size_t polZone, const TSIGTriplet &tt, shared_ptr oursr, size_t maxReceivedBytes, const ComboAddress& localAddress, const uint16_t axfrTimeout); +void RPZIXFRTracker(const ComboAddress& master, boost::optional defpol, uint32_t maxTTL, size_t polZone, const TSIGTriplet &tt, size_t maxReceivedBytes, const ComboAddress& localAddress, std::shared_ptr zone, const uint16_t axfrTimeout);