From f2ff6e9fa81deced9d4e76d22456dc0925b3c527 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 4 Dec 2024 15:29:45 +0100 Subject: [PATCH] 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. --- pdns/dnsdistdist/dnsdist-lua.cc | 4 ++-- regression-tests.dnsdist/test_Routing.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) 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} -- 2.47.2