]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix the consistency check for the balancing factors
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 4 Dec 2024 14:29:45 +0000 (15:29 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 4 Dec 2024 14:29:45 +0000 (15:29 +0100)
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
regression-tests.dnsdist/test_Routing.py

index fa0940a988a2bdaaf7b3ea465661a91874933f1f..04c5f1acac13f9b04aba89746bd333bb505071eb 100644 (file)
@@ -903,7 +903,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
   {
     const std::string name;
     const std::function<void(dnsdist::configuration::ImmutableConfiguration& config, double value)> mutator;
-    const double maximumValue{1.0};
+    const double minimumValue{1.0};
   };
   static const std::vector<DoubleImmutableConfigurationItems> 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;
index 1f32f98d7399e05ac338e267f65c4a64f959d5cf..4ee5e7d5702dd5bb2facd54759a38f58997496c0 100644 (file)
@@ -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}