From 94b44bfa81bd93dbff8a69446ceafc28e6b2af6f Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sat, 5 Dec 2015 23:10:13 +0100 Subject: [PATCH] when installing new overlapping dynamic block, record old number of blocks and keep that. More pleasing to the eye. --- pdns/dnsdist-lua2.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 87db0854d8..21cf7f7ace 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -141,11 +141,22 @@ void moreLua() g_lua.writeFunction("addDynBlocks", [](const map& m, const std::string& msg, boost::optional 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); }); -- 2.47.2