From 3c3ef9aadf0e22f1c9ba88b13dd8d228b0535be1 Mon Sep 17 00:00:00 2001 From: Otto Moerbeek Date: Wed, 1 Mar 2023 09:16:52 +0100 Subject: [PATCH] Call the right wipe function for negcache --- pdns/recursordist/negcache.cc | 2 +- pdns/recursordist/negcache.hh | 2 +- pdns/recursordist/test-negcache_cc.cc | 38 +++++++++++++++++++++++++++ pdns/syncres.cc | 2 +- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/pdns/recursordist/negcache.cc b/pdns/recursordist/negcache.cc index 7153c6ce17..50b01abe95 100644 --- a/pdns/recursordist/negcache.cc +++ b/pdns/recursordist/negcache.cc @@ -242,7 +242,7 @@ size_t NegCache::wipe(const DNSName& name, bool subtree) return ret; } -size_t NegCache::wipe(const DNSName& qname, QType qtype) +size_t NegCache::wipeTyped(const DNSName& qname, QType qtype) { size_t ret = 0; auto& map = getMap(qname); diff --git a/pdns/recursordist/negcache.hh b/pdns/recursordist/negcache.hh index 97e9be32a9..2e989aadef 100644 --- a/pdns/recursordist/negcache.hh +++ b/pdns/recursordist/negcache.hh @@ -96,7 +96,7 @@ public: void clear(); size_t doDump(int fd, size_t maxCacheEntries); size_t wipe(const DNSName& name, bool subtree = false); - size_t wipe(const DNSName& name, QType qtype); + size_t wipeTyped(const DNSName& name, QType qtype); size_t size() const; private: diff --git a/pdns/recursordist/test-negcache_cc.cc b/pdns/recursordist/test-negcache_cc.cc index 3306df1da8..e050097ec1 100644 --- a/pdns/recursordist/test-negcache_cc.cc +++ b/pdns/recursordist/test-negcache_cc.cc @@ -438,6 +438,44 @@ BOOST_AUTO_TEST_CASE(test_wipe_subtree) BOOST_CHECK_EQUAL(cache.size(), 400U); } +BOOST_AUTO_TEST_CASE(test_wipe_typed) +{ + string qname(".powerdns.com"); + DNSName auth("powerdns.com"); + + struct timeval now; + Utility::gettimeofday(&now, 0); + + NegCache cache; + NegCache::NegCacheEntry ne; + ne = genNegCacheEntry(auth, auth, now, QType::A); + cache.add(ne); + + for (int i = 0; i < 400; i++) { + ne = genNegCacheEntry(DNSName(std::to_string(i) + qname), auth, now, QType::A); + cache.add(ne); + } + + BOOST_CHECK_EQUAL(cache.size(), 401U); + + // Should only wipe the powerdns.com entry + cache.wipeTyped(auth, QType::A); + BOOST_CHECK_EQUAL(cache.size(), 400U); + + NegCache::NegCacheEntry ne2; + bool ret = cache.get(auth, QType(1), now, ne2); + + BOOST_CHECK_EQUAL(ret, false); + + cache.wipeTyped(DNSName("1.powerdns.com"), QType::A); + BOOST_CHECK_EQUAL(cache.size(), 399U); + + NegCache::NegCacheEntry ne3; + ret = cache.get(auth, QType(1), now, ne3); + + BOOST_CHECK_EQUAL(ret, false); +} + BOOST_AUTO_TEST_CASE(test_clear) { string qname(".powerdns.com"); diff --git a/pdns/syncres.cc b/pdns/syncres.cc index c01a6ff1c9..ad976bf51b 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -4601,7 +4601,7 @@ RCode::rcodes_ SyncRes::updateCacheFromRecords(unsigned int depth, LWResult& lwr // Delete potential negcache entry. When a record recovers with serve-stale the negcache entry can cause the wrong entry to // be served, as negcache entries are checked before record cache entries if (NegCache::s_maxServedStaleExtensions > 0) { - g_negCache->wipe(i->first.name, i->first.type); + g_negCache->wipeTyped(i->first.name, i->first.type); } if (g_aggressiveNSECCache && needWildcardProof && recordState == vState::Secure && i->first.place == DNSResourceRecord::ANSWER && i->first.name == qname && !i->second.signatures.empty() && !d_routingTag && !ednsmask) { -- 2.47.2