From: Bert Hubert Date: Sun, 5 Oct 2008 09:49:53 +0000 (+0000) Subject: reported by Andreas Jakum & investigated by Stefan Schmidt - make sure we don't hamme... X-Git-Tag: rec-3.2~257 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2b4f72f6ecb475753a77eb950b9301c51539adb;p=pdns reported by Andreas Jakum & investigated by Stefan Schmidt - make sure we don't hammer parent zones in case of failed delegations to servers that don't exist at all. Only invalidate once every 10 seconds git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1265 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index b49effa72..0c92f127c 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -233,7 +233,7 @@ int MemRecursorCache::get(time_t now, const string &qname, const QType& qt, set< } // cerr<<"time left : "<size() : 0) <<"\n"; - return (unsigned int)ttd-now; + return (int)ttd-now; } return -1; } @@ -362,6 +362,34 @@ int MemRecursorCache::doWipeCache(const string& name, uint16_t qtype) return count; } +bool MemRecursorCache::doAgeCache(time_t now, const string& name, uint16_t qtype, int32_t newTTL) +{ + cache_t::iterator iter = d_cache.find(tie(name, qtype)); + if(iter == d_cache.end()) + return false; + + int32_t ttl = iter->getTTD() - now; + if(ttl < 0) + return false; // would be dead anyhow + + if(ttl > newTTL) { + d_cachecachevalid=false; + + ttl = newTTL; + uint32_t newTTD = now + ttl; + + CacheEntry ce = *iter; + for(vector::iterator j = ce.d_records.begin() ; j != ce.d_records.end(); ++j) { + j->d_ttd = newTTD; + } + + d_cache.replace(iter, ce); + return true; + } + return false; +} + + void MemRecursorCache::doDumpAndClose(int fd) { FILE* fp=fdopen(fd, "w"); diff --git a/pdns/recursor_cache.hh b/pdns/recursor_cache.hh index d5b1f5385..f78daf288 100644 --- a/pdns/recursor_cache.hh +++ b/pdns/recursor_cache.hh @@ -39,6 +39,7 @@ public: void doSlash(int perc); void doDumpAndClose(int fd); int doWipeCache(const string& name, uint16_t qtype=0xffff); + bool doAgeCache(time_t now, const string& name, uint16_t qtype, int32_t newTTL); uint64_t cacheHits, cacheMisses; bool d_followRFC2181; diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 1527c4106..3195a31c3 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -607,9 +607,9 @@ int SyncRes::doResolveAt(set nameservers, string auth, if(tns==rnameservers.end()) { LOG<