From: Baptiste Courtois Date: Sat, 24 Nov 2018 15:26:54 +0000 (+0100) Subject: auth: geoip, check weight only on matching QTypes X-Git-Tag: auth-4.2.0-rc1~16^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d129860b47e03fbb0278a4bef5f14043ef36efd2;p=thirdparty%2Fpdns.git auth: geoip, check weight only on matching QTypes This is a micro-optimization to avoid storing & computing probabilities of non matching QTypes. --- diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index b3e7480d3f..c07757034a 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -318,6 +318,8 @@ bool GeoIPBackend::lookup_static(const GeoIPDomain &dom, const DNSName &search, if (i != dom.records.end()) { // return static value for(const auto& rr : i->second) { + if (qtype != QType::ANY && rr.qtype != qtype) continue; + if (rr.has_weight) { gl.netmask = (v6?128:32); int comp = cumul_probabilities[rr.qtype.getCode()]; @@ -325,13 +327,11 @@ bool GeoIPBackend::lookup_static(const GeoIPDomain &dom, const DNSName &search, if (rr.weight == 0 || probability_rnd < comp || probability_rnd > (comp + rr.weight)) continue; } - if (qtype == QType::ANY || rr.qtype == qtype) { - const string& content = format2str(rr.content, ip, v6, gl); - if (rr.qtype != QType::ENT && rr.qtype != QType::TXT && content.empty()) continue; - d_result.push_back(rr); - d_result.back().content = content; - d_result.back().qname = qdomain; - } + const string& content = format2str(rr.content, ip, v6, gl); + if (rr.qtype != QType::ENT && rr.qtype != QType::TXT && content.empty()) continue; + d_result.push_back(rr); + d_result.back().content = content; + d_result.back().qname = qdomain; } // ensure we get most strict netmask for(DNSResourceRecord& rr: d_result) {