]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: geoip, check weight only on matching QTypes 7219/head
authorBaptiste Courtois <b.courtois@criteo.com>
Sat, 24 Nov 2018 15:26:54 +0000 (16:26 +0100)
committerBaptiste Courtois <b.courtois@criteo.com>
Fri, 25 Jan 2019 18:45:45 +0000 (19:45 +0100)
This is a micro-optimization to avoid storing & computing probabilities
of non matching QTypes.

modules/geoipbackend/geoipbackend.cc

index b3e7480d3f0bebf7e389c37252503f0e3e8113f0..c07757034acc21a8f43a6bde12ba728f04ffcc20 100644 (file)
@@ -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) {