From f2c4f873c33c059fe87a6f1dbd512732f7808374 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 23 Sep 2021 15:15:15 +0200 Subject: [PATCH] rec: Update the stats (serial, number of records, timestamp) for RPZ files We used to only update these for RPZ loaded via XFR, which does not really makes sense. --- pdns/rpzloader.cc | 78 +++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/pdns/rpzloader.cc b/pdns/rpzloader.cc index e3874b21a3..df5de4b4e1 100644 --- a/pdns/rpzloader.cc +++ b/pdns/rpzloader.cc @@ -238,6 +238,44 @@ static shared_ptr loadRPZFromServer(const shared_ptr > > s_rpzStats; + +shared_ptr getRPZZoneStats(const std::string& zone) +{ + auto stats = s_rpzStats.lock(); + auto it = stats->find(zone); + if (it == stats->end()) { + auto stat = std::make_shared(); + (*stats)[zone] = stat; + return stat; + } + return it->second; +} + +static void incRPZFailedTransfers(const std::string& zone) +{ + auto stats = getRPZZoneStats(zone); + if (stats != nullptr) + stats->d_failedTransfers++; +} + +static void setRPZZoneNewState(const std::string& zone, uint32_t serial, uint64_t numberOfRecords, bool fromFile, bool wasAXFR) +{ + auto stats = getRPZZoneStats(zone); + if (stats == nullptr) { + return; + } + if (!fromFile) { + stats->d_successfulTransfers++; + if (wasAXFR) { + stats->d_fullTransfers++; + } + } + stats->d_lastUpdate = time(nullptr); + stats->d_serial = serial; + stats->d_numberOfRecords = numberOfRecords; +} + // this function is silent - you do the logging std::shared_ptr loadRPZFromFile(const std::string& fname, std::shared_ptr zone, const boost::optional& defpol, bool defpolOverrideLocal, uint32_t maxTTL) { @@ -271,45 +309,11 @@ std::shared_ptr loadRPZFromFile(const std::string& fname, std: if (sr != nullptr) { zone->setRefresh(sr->d_st.refresh); + setRPZZoneNewState(zone->getName(), sr->d_st.serial, zone->size(), true, false); } return sr; } -static LockGuarded > > s_rpzStats; - -shared_ptr getRPZZoneStats(const std::string& zone) -{ - auto stats = s_rpzStats.lock(); - auto it = stats->find(zone); - if (it == stats->end()) { - auto stat = std::make_shared(); - (*stats)[zone] = stat; - return stat; - } - return it->second; -} - -static void incRPZFailedTransfers(const std::string& zone) -{ - auto stats = getRPZZoneStats(zone); - if (stats != nullptr) - stats->d_failedTransfers++; -} - -static void setRPZZoneNewState(const std::string& zone, uint32_t serial, uint64_t numberOfRecords, bool wasAXFR) -{ - auto stats = getRPZZoneStats(zone); - if (stats == nullptr) - return; - stats->d_successfulTransfers++; - if (wasAXFR) { - stats->d_fullTransfers++; - } - stats->d_lastUpdate = time(nullptr); - stats->d_serial = serial; - stats->d_numberOfRecords = numberOfRecords; -} - static bool dumpZoneToDisk(const shared_ptr& plogger, const DNSName& zoneName, const std::shared_ptr& newZone, const std::string& dumpZoneFileName) { auto logger = plogger->v(1); @@ -395,7 +399,7 @@ void RPZIXFRTracker(const std::vector& primaries, const boost::opt newZone->setSerial(sr->d_st.serial); newZone->setRefresh(sr->d_st.refresh); refresh = std::max(refreshFromConf ? refreshFromConf : newZone->getRefresh(), 1U); - setRPZZoneNewState(polName, sr->d_st.serial, newZone->size(), true); + setRPZZoneNewState(polName, sr->d_st.serial, newZone->size(), false, true); g_luaconfs.modify([zoneIdx, &newZone](LuaConfigItems& lci) { lci.dfe.setZone(zoneIdx, newZone); @@ -545,7 +549,7 @@ void RPZIXFRTracker(const std::vector& primaries, const boost::opt g_log<d_st.serial<setSerial(sr->d_st.serial); newZone->setRefresh(sr->d_st.refresh); - setRPZZoneNewState(polName, sr->d_st.serial, newZone->size(), fullUpdate); + setRPZZoneNewState(polName, sr->d_st.serial, newZone->size(), false, fullUpdate); /* we need to replace the existing zone with the new one, but we don't want to touch anything else, especially other zones, -- 2.47.2