]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
geoipbackend: propagate weighted rounding gap fix 8564/head
authorJeremy Clerc <j.clerc@criteo.com>
Wed, 20 Nov 2019 15:08:01 +0000 (16:08 +0100)
committerJeremy Clerc <j.clerc@criteo.com>
Wed, 20 Nov 2019 15:36:42 +0000 (16:36 +0100)
618824cb73db384d52cf379c7d49744dbb5b8f6d (PR#7219) fixed computation
of weighted round robin computation per Qtype.

That commit also introduced a bug on the removal of the rounding gap.

Because it works on a copy of a GeoIPDNSResourceRecord, the updated
weight of the last record is not propagated to the domain object.

The bug is as follow:
  1. The total weight is < 1000
  2. The random probabability gives 1000
  3. There is no resource to be given

This commit restore the original behavior of ensuring the gap is added
to the last resource so we always have 1000.

modules/geoipbackend/geoipbackend.cc

index b56d16f5d9279827e9b013beecef1d4632dd4de0..35a62c8d410601273ce19e43ec69b1ec642bcf48 100644 (file)
@@ -263,7 +263,7 @@ void GeoIPBackend::initialize() {
     for(auto &item: dom.records) {
       map<uint16_t, float> weights;
       map<uint16_t, float> sums;
-      map<uint16_t, GeoIPDNSResourceRecord> lasts;
+      map<uint16_t, GeoIPDNSResourceRecord*> lasts;
       bool has_weight=false;
       // first we look for used weight
       for(const auto &rr: item.second) {
@@ -277,13 +277,13 @@ void GeoIPBackend::initialize() {
           rr.weight=static_cast<int>((static_cast<float>(rr.weight) / weights[rr_type])*1000.0);
           sums[rr_type] += rr.weight;
           rr.has_weight = has_weight;
-          lasts[rr_type] = rr;
+          lasts[rr_type] = &rr;
         }
         // remove rounding gap
         for(auto &x: lasts) {
           float sum = sums[x.first];
           if (sum < 1000)
-            x.second.weight += (1000-sum);
+            x.second->weight += (1000-sum);
         }
       }
     }