From: Otto Moerbeek Date: Mon, 2 May 2022 06:47:49 +0000 (+0200) Subject: Throttle table cleanup task is now handler specific. X-Git-Tag: auth-4.8.0-alpha0~111^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0d0cce7471d881c6b278ee8ffab36587b7db382;p=thirdparty%2Fpdns.git Throttle table cleanup task is now handler specific. Also use QType consistently. --- diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 8aa412df3d..3b7805774c 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -1888,11 +1888,6 @@ static void houseKeeping(void*) SyncRes::pruneEDNSStatuses(now.tv_sec - 2 * 3600); }); - static thread_local PeriodicTask pruneThrottledTask{"pruneThrottledTask", 5}; - pruneThrottledTask.runIfDue(now, []() { - SyncRes::pruneThrottledServers(); - }); - static thread_local PeriodicTask pruneTCPTask{"pruneTCPTask", 5}; pruneTCPTask.runIfDue(now, [now]() { t_tcp_manager.cleanup(now); @@ -1946,6 +1941,11 @@ static void houseKeeping(void*) }); } + static PeriodicTask pruneThrottledTask{"pruneThrottledTask", 5}; + pruneThrottledTask.runIfDue(now, [now]() { + SyncRes::pruneThrottledServers(now.tv_sec); + }); + static PeriodicTask pruneFailedServersTask{"pruneFailedServerTask", 5}; pruneFailedServersTask.runIfDue(now, [now]() { SyncRes::pruneFailedServers(now.tv_sec - SyncRes::s_serverdownthrottletime * 10); diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 5b6ccec2ff..b519bb7d79 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -294,8 +294,7 @@ public: d_cont.clear(); } - void prune() { - time_t now = time(nullptr); + void prune(time_t now) { auto &ind = d_cont.template get(); ind.erase(ind.begin(), ind.upper_bound(now)); } @@ -1116,9 +1115,9 @@ uint64_t SyncRes::getThrottledServersSize() return s_throttle.lock()->size(); } -void SyncRes::pruneThrottledServers() +void SyncRes::pruneThrottledServers(time_t now) { - s_throttle.lock()->prune(); + s_throttle.lock()->prune(now); } void SyncRes::clearThrottle() @@ -1126,7 +1125,7 @@ void SyncRes::clearThrottle() s_throttle.lock()->clear(); } -bool SyncRes::isThrottled(time_t now, const ComboAddress& server, const DNSName& target, uint16_t qtype) +bool SyncRes::isThrottled(time_t now, const ComboAddress& server, const DNSName& target, QType qtype) { return s_throttle.lock()->shouldThrottle(now, std::make_tuple(server, target, qtype)); } @@ -3237,7 +3236,7 @@ bool SyncRes::throttledOrBlocked(const std::string& prefix, const ComboAddress& s_throttledqueries++; d_throttledqueries++; return true; } - else if (s_throttle.lock()->shouldThrottle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype.getCode()))) { + else if (s_throttle.lock()->shouldThrottle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype))) { LOG(prefix<throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype.getCode()), 60, 100); + s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype), 60, 100); } else { // timeout, 10 seconds or 5 queries - s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype.getCode()), 10, 5); + s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype), 10, 5); } } @@ -5080,10 +5079,10 @@ bool SyncRes::doResolveAtThisIP(const std::string& prefix, const DNSName& qname, if (doTCP) { // we can be more heavy-handed over TCP - s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype.getCode()), 60, 10); + s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype), 60, 10); } else { - s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype.getCode()), 10, 2); + s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype), 10, 2); } } return false; @@ -5100,7 +5099,7 @@ bool SyncRes::doResolveAtThisIP(const std::string& prefix, const DNSName& qname, s_nsSpeeds.lock()->find_or_enter(nsName.empty()? DNSName(remoteIP.toStringWithPort()) : nsName, d_now).submit(remoteIP, 1000000, d_now); // 1 sec } else { - s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype.getCode()), 60, 3); + s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype), 60, 3); } } return false; @@ -5119,7 +5118,7 @@ bool SyncRes::doResolveAtThisIP(const std::string& prefix, const DNSName& qname, LOG(prefix<throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype.getCode()), 60, 3); + s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(remoteIP, qname, qtype), 60, 3); } return false; } @@ -5531,7 +5530,7 @@ int SyncRes::doResolveAt(NsSet &nameservers, DNSName auth, bool flawedNSSet, con break; } /* was lame */ - s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(*remoteIP, qname, qtype.getCode()), 60, 100); + s_throttle.lock()->throttle(d_now.tv_sec, std::make_tuple(*remoteIP, qname, qtype), 60, 100); } if (gotNewServers) { diff --git a/pdns/syncres.hh b/pdns/syncres.hh index db215783b9..a02172f14b 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -257,9 +257,9 @@ public: } static uint64_t getThrottledServersSize(); - static void pruneThrottledServers(); + static void pruneThrottledServers(time_t now); static void clearThrottle(); - static bool isThrottled(time_t now, const ComboAddress& server, const DNSName& target, uint16_t qtype); + static bool isThrottled(time_t now, const ComboAddress& server, const DNSName& target, QType qtype); static bool isThrottled(time_t now, const ComboAddress& server); static void doThrottle(time_t now, const ComboAddress& server, time_t duration, unsigned int tries);