From: Fred Morcos Date: Thu, 26 Oct 2023 12:27:28 +0000 (+0200) Subject: Refactor UeberBackend::cacheHas and introduce UeberBackend::CacheResult X-Git-Tag: rec-5.0.0-beta1~16^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e9d4b0de45673b41a3993cd17b67bf35e48d52e;p=thirdparty%2Fpdns.git Refactor UeberBackend::cacheHas and introduce UeberBackend::CacheResult --- diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index da29c062a8..1902d925bd 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -383,7 +383,6 @@ bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* s // If a backend has no match it may respond with an empty qname. bool found = false; - int cstat = 0; DNSName shorter(target); vector> bestMatches(backends.size(), pair(target.wirelength() + 1, SOAData())); @@ -410,9 +409,9 @@ bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* s // Check cache. if (cachedOk && (d_cache_ttl != 0 || d_negcache_ttl != 0)) { - cstat = cacheHas(d_question, d_answers); + auto cacheResult = cacheHas(d_question, d_answers); - if (cstat == 1 && !d_answers.empty() && d_cache_ttl != 0) { + if (cacheResult == CacheResult::Hit && !d_answers.empty() && d_cache_ttl != 0) { DLOG(g_log << Logger::Error << "has pos cache entry: " << shorter << endl); fillSOAData(d_answers[0], *soaData); @@ -421,7 +420,7 @@ bool UeberBackend::getAuth(const DNSName& target, const QType& qtype, SOAData* s goto found; } - else if (cstat == 0 && d_negcache_ttl != 0) { + else if (cacheResult == CacheResult::NegativeMatch && d_negcache_ttl != 0) { DLOG(g_log << Logger::Error << "has neg cache entry: " << shorter << endl); continue; } @@ -612,26 +611,26 @@ void UeberBackend::cleanup() } // returns -1 for miss, 0 for negative match, 1 for hit -int UeberBackend::cacheHas(const Question& q, vector& rrs) const +enum UeberBackend::CacheResult UeberBackend::cacheHas(const Question& question, vector& resourceRecords) const { extern AuthQueryCache QC; if (d_cache_ttl == 0 && d_negcache_ttl == 0) { - return -1; + return CacheResult::Miss; } - rrs.clear(); + resourceRecords.clear(); // g_log<lookup(d_handle.qtype, d_handle.qname, d_handle.zoneId, d_handle.pkt_p); ++(*s_backendQueries); } - else if (cstat == 0) { + else if (cacheResult == CacheResult::NegativeMatch) { // cout<<"UeberBackend::lookup("<& rrs) const; + enum CacheResult + { + Miss = -1, + NegativeMatch = 0, + Hit = 1, + }; + + CacheResult cacheHas(const Question& question, vector& resourceRecords) const; void addNegCache(const Question& q) const; void addCache(const Question& q, vector&& rrs) const;