From bc282425088455198a7a99511c75914477d4ed32 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 23:14:51 +0200 Subject: Merging upstream version 1.9.3. Signed-off-by: Daniel Baumann --- dnsdist-lbpolicies.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'dnsdist-lbpolicies.cc') diff --git a/dnsdist-lbpolicies.cc b/dnsdist-lbpolicies.cc index 70fec89..b4e3532 100644 --- a/dnsdist-lbpolicies.cc +++ b/dnsdist-lbpolicies.cc @@ -25,6 +25,7 @@ #include "dnsdist-lua.hh" #include "dnsdist-lua-ffi.hh" #include "dolog.hh" +#include "dns_random.hh" GlobalStateHolder g_policy; bool g_roundrobinFailOnNoServer{false}; @@ -40,7 +41,7 @@ template static std::shared_ptr getLeastOutstanding(c size_t usableServers = 0; for (const auto& d : servers) { if (d.second->isUp()) { - poss[usableServers] = std::make_pair(std::make_tuple(d.second->outstanding.load(), d.second->d_config.order, d.second->getRelevantLatencyUsec()), d.first); + poss.at(usableServers) = std::pair(std::tuple(d.second->outstanding.load(), d.second->d_config.order, d.second->getRelevantLatencyUsec()), d.first); usableServers++; } } @@ -100,7 +101,7 @@ template static std::shared_ptr getValRandom(const Se sum += d.second->d_config.d_weight; } - poss[usableServers] = std::make_pair(sum, d.first); + poss.at(usableServers) = std::pair(sum, d.first); usableServers++; } } @@ -153,7 +154,7 @@ static shared_ptr valrandom(const unsigned int val, const Serve shared_ptr wrandom(const ServerPolicy::NumberedServerVector& servers, const DNSQuestion* dq) { - return valrandom(random(), servers); + return valrandom(dns_random_uint32(), servers); } uint32_t g_hashperturb; @@ -289,7 +290,7 @@ void setPoolPolicy(pools_t& pools, const string& poolName, std::shared_ptrgetName()); } - pool->policy = policy; + pool->policy = std::move(policy); } void addServerToPool(pools_t& pools, const string& poolName, std::shared_ptr server) @@ -378,6 +379,11 @@ std::shared_ptr ServerPolicy::getSelectedBackend(const ServerPo selected = policy(&serversList, &dnsq); } + if (selected >= servers.size()) { + /* invalid offset, meaning that there is no server available */ + return {}; + } + selectedBackend = servers.at(selected).second; } } -- cgit v1.2.3