]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
when installing new overlapping dynamic block, record old number of blocks and keep...
authorbert hubert <bert.hubert@netherlabs.nl>
Sat, 5 Dec 2015 22:10:13 +0000 (23:10 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sat, 5 Dec 2015 22:10:13 +0000 (23:10 +0100)
pdns/dnsdist-lua2.cc

index 87db0854d8d352f0778da6b529213cd6c8cb63e7..21cf7f7acee3888046e43cb27f092aa3221954d6 100644 (file)
@@ -141,11 +141,22 @@ void moreLua()
   g_lua.writeFunction("addDynBlocks", 
                          [](const map<ComboAddress,int>& m, const std::string& msg, boost::optional<int> seconds) { 
                           auto slow = g_dynblockNMG.getCopy();
-                          struct timespec until;
-                          clock_gettime(CLOCK_MONOTONIC, &until);
+                          struct timespec until, now;
+                          clock_gettime(CLOCK_MONOTONIC, &now);
+                          until=now;
                           until.tv_sec += seconds ? *seconds : 10;
-                          for(const auto& capair : m)
-                            slow.insert(Netmask(capair.first)).second={msg, until};
+                          for(const auto& capair : m) {
+                            unsigned int count;
+                            if(auto got = slow.lookup(Netmask(capair.first))) {
+                              if(until < got->second.until) // had a longer policy
+                                continue;
+                              if(now < got->second.until) // don't inherit count on expired entry
+                                count=got->second.blocks;
+                            }
+                            DynBlock db{msg,until};
+                            db.blocks=count;
+                            slow.insert(Netmask(capair.first)).second=db;
+                          }
                           g_dynblockNMG.setState(slow);
                         });