From 8c82c02db52398907377ea02f84527e5f29158ee Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 4 Dec 2017 12:22:19 +0100 Subject: [PATCH] dnsdist: Sort the servers based on their 'order' after it has been set We keep the servers ordered inside their pools because it's easier for the policies that way, so we sort them whenever a new one is added. However we were doing the sorting _before_ the order of the new server had been set, resulting in the last added server to be sorted based on an order of 0, regardless of its actual order. Reported by Frank Even (thanks!). --- pdns/dnsdist-lua.cc | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 571c78a08..d6a2b294f 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -400,24 +400,6 @@ vector> setupLua(bool client, const std::string& confi ret->qps=QPSLimiter(qpsVal, qpsVal); } - auto localPools = g_pools.getCopy(); - if(vars.count("pool")) { - if(auto* pool = boost::get(&vars["pool"])) - ret->pools.insert(*pool); - else { - auto pools = boost::get > >(vars["pool"]); - for(auto& p : pools) - ret->pools.insert(p.second); - } - for(const auto& poolName: ret->pools) { - addServerToPool(localPools, poolName, ret); - } - } - else { - addServerToPool(localPools, "", ret); - } - g_pools.setState(localPools); - if(vars.count("order")) { ret->order=std::stoi(boost::get(vars["order"])); } @@ -491,6 +473,28 @@ vector> setupLua(bool client, const std::string& confi } } + /* this needs to be done _AFTER_ the order has been set, + since the server are kept ordered inside the pool */ + auto localPools = g_pools.getCopy(); + if(vars.count("pool")) { + if(auto* pool = boost::get(&vars["pool"])) { + ret->pools.insert(*pool); + } + else { + auto pools = boost::get > >(vars["pool"]); + for(auto& p : pools) { + ret->pools.insert(p.second); + } + } + for(const auto& poolName: ret->pools) { + addServerToPool(localPools, poolName, ret); + } + } + else { + addServerToPool(localPools, "", ret); + } + g_pools.setState(localPools); + if (ret->connected) { if(g_launchWork) { g_launchWork->push_back([ret,cpus]() { -- 2.40.0