bool AuthPacketCache::get(DNSPacket& pkt, DNSPacket& cached, const std::string& view)
{
- if(!d_ttl) {
+ if (d_ttl == 0) {
return false;
}
void AuthPacketCache::insert(DNSPacket& query, DNSPacket& response, unsigned int maxTTL, const std::string& view)
{
- if(!d_ttl) {
+ if (d_ttl == 0) {
return;
}
/* clears the entire cache. */
uint64_t AuthPacketCache::purge()
{
- if(!d_ttl) {
+ if (d_ttl == 0) {
return 0;
}
return delcount;
}
-uint64_t AuthPacketCache::purgeExact(const std::string& view, const DNSName& qname)
-{
- uint64_t delcount = 0;
-
- {
- auto cache = d_cache.write_lock();
- if (auto iter = cache->find(view); iter != cache->end()) {
- auto& mc = getMap(iter->second, qname); // NOLINT(readability-identifier-length)
- delcount += purgeExactLockedCollection<NameTag>(mc, qname);
- }
- }
-
- *d_statnumentries -= delcount;
-
- return delcount;
-}
-
uint64_t AuthPacketCache::purgeView(const std::string& view)
{
uint64_t delcount = 0;
/* purges entries from the packetcache. If match ends on a $, it is treated as a suffix */
uint64_t AuthPacketCache::purge(const string &match)
{
- if(!d_ttl) {
+ if (d_ttl == 0) {
return 0;
}
return delcount;
}
+uint64_t AuthPacketCache::purge(const std::string& view, const std::string& match)
+{
+ if (d_ttl == 0) {
+ return 0;
+ }
+
+ uint64_t delcount = 0;
+
+ {
+ auto cache = d_cache.write_lock();
+ if (auto iter = cache->find(view); iter != cache->end()) {
+ if (boost::ends_with(match, "$")) {
+ auto *map = iter->second.get();
+ delcount += purgeLockedCollectionsVector<NameTag>(*map, match);
+ }
+ else {
+ DNSName qname(match);
+ auto& mc = getMap(iter->second, qname); // NOLINT(readability-identifier-length)
+ delcount += purgeExactLockedCollection<NameTag>(mc, qname);
+ }
+ }
+ }
+
+ *d_statnumentries -= delcount;
+
+ return delcount;
+}
+
void AuthPacketCache::cleanup()
{
uint64_t totErased = 0;
void cleanup(); //!< force the cache to preen itself from expired packets
uint64_t purge();
uint64_t purge(const std::string& match); // could be $ terminated. Is not a dnsname!
+ uint64_t purge(const std::string& view, const std::string& match); // same as above, but in the given view
uint64_t purgeExact(const DNSName& qname); // no wildcard matching here
- uint64_t purgeExact(const std::string& view, const DNSName& qname); // same as above, but in the given view
uint64_t purgeView(const std::string& view);
uint64_t size() const { return *d_statnumentries; };
BOOST_CHECK_EQUAL(queryPacketCache2(PC, ZC, ComboAddress("192.0.2.1"), qname, innerMask, view2, "2.2.2.2"), true);
// Purge view2
- BOOST_CHECK_EQUAL(PC.purgeExact(view2, qname), 1);
+ std::string purgeName = qname.toString();
+ purgeName.append("$");
+ BOOST_CHECK_EQUAL(PC.purge(view2, purgeName), 1);
BOOST_CHECK_EQUAL(PC.size(), 1);
// Check that requesting from view2 causes a cache miss
BOOST_CHECK_EQUAL(queryPacketCache2(PC, ZC, ComboAddress("192.0.2.128"), qname, outerMask, view1, "1.1.1.1"), true);
// Purge view1
- BOOST_CHECK_EQUAL(PC.purgeExact(view1, qname), 1);
+ purgeName = qname.toString();
+ purgeName.append("$");
+ BOOST_CHECK_EQUAL(PC.purge(view1, purgeName), 1);
BOOST_CHECK_EQUAL(PC.size(), 0);
// Check that requesting from view1 causes a cache miss
}
// Purge packet cache for that zone
if (PC.enabled()) {
- (void)PC.purgeExact(view, zonename.operator const DNSName&());
+ // Note that this relies upon ZoneName::toString NOT emitting the variant name.
+ std::string purgename = zonename.toString();
+ purgename.append("$");
+ (void)PC.purge(view, purgename);
}
resp->body = "";
(void)PC.purgeView(view);
}
else {
- (void)PC.purgeExact(view, zoneData.zoneName.operator const DNSName&());
+ // Note that this relies upon ZoneName::toString NOT emitting the variant name.
+ std::string purgename = zoneData.zoneName.toString();
+ purgename.append("$");
+ (void)PC.purge(view, purgename);
}
}