From: Remi Gacogne Date: Wed, 4 Dec 2024 14:29:45 +0000 (+0100) Subject: dnsdist: Fix the consistency check for the balancing factors X-Git-Tag: rec-5.2.0-rc1~6^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2ff6e9fa81deced9d4e76d22456dc0925b3c527;p=thirdparty%2Fpdns.git dnsdist: Fix the consistency check for the balancing factors Zero is the initial value, but until now it was only possible to pass a value greater than or equal to 1.0 to `setWeightedBalancingFactor()` so it was not possible to reset it to the default value. --- diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index fa0940a988..04c5f1acac 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -903,7 +903,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) { const std::string name; const std::function mutator; - const double maximumValue{1.0}; + const double minimumValue{1.0}; }; static const std::vector doubleImmutableConfigItems{ {"setConsistentHashingBalancingFactor", [](dnsdist::configuration::ImmutableConfiguration& config, double newValue) { config.d_consistentHashBalancingFactor = newValue; }, 1.0}, @@ -940,7 +940,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } for (const auto& item : doubleImmutableConfigItems) { luaCtx.writeFunction(item.name, [&item](double value) { - if (value > item.maximumValue) { + if (value != 0 && value < item.minimumValue) { g_outputBuffer = "Invalid value passed to " + item.name + "()!\n"; errlog("Invalid value passed to %s()!", item.name); return; diff --git a/regression-tests.dnsdist/test_Routing.py b/regression-tests.dnsdist/test_Routing.py index 1f32f98d73..4ee5e7d570 100644 --- a/regression-tests.dnsdist/test_Routing.py +++ b/regression-tests.dnsdist/test_Routing.py @@ -650,6 +650,9 @@ class TestRoutingWRandom(DNSDistTest): _config_params = ['_testServerPort', '_testServer2Port'] _config_template = """ setServerPolicy(wrandom) + setWeightedBalancingFactor(1.5) + -- this is the default, but let's ensure we can reset it to the initial value + setWeightedBalancingFactor(0) s1 = newServer{address="127.0.0.1:%s", weight=1} s1:setUp() s2 = newServer{address="127.0.0.1:%s", weight=2}