From: Baptiste Courtois Date: Mon, 26 Nov 2018 18:13:57 +0000 (+0100) Subject: auth: geoip - forbid 0 as weight value X-Git-Tag: rec-4.2.0-alpha1~78^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7227%2Fhead;p=thirdparty%2Fpdns.git auth: geoip - forbid 0 as weight value In the case where the weight of all records is set to zero, former code was trying to compute probability by dividing by 0. Another motivation to forbid the use of the "zero" weight is that the desired behavior was not clear. --- diff --git a/docs/backends/geoip.rst b/docs/backends/geoip.rst index b556bb1cc2..6667988c47 100644 --- a/docs/backends/geoip.rst +++ b/docs/backends/geoip.rst @@ -220,7 +220,7 @@ These placeholders disable caching for the record completely: Using the ``weight`` attribute ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -You can use record attributes to define weight. +You can use record attributes to define positive and non-zero weight. If this is given, only one record is chosen randomly based on the weight. Probability is calculated by summing up the weights and dividing each weight with the sum. diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index 5ed467b6dd..4baabe2fe7 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -150,9 +150,9 @@ void GeoIPBackend::initialize() { rr.content = content; } else if (attr == "weight") { rr.weight = iter->second.as(); - if (rr.weight < 0) { - g_log<