From 36e763fa9b8731886dd46b1358167f2a68b7d56e Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 11 Jan 2017 13:24:58 +0100 Subject: [PATCH] dnsdist: Add `setWHashedPertubation()` for consistent `whashed` results --- pdns/README-dnsdist.md | 1 + pdns/dnsdist-lua2.cc | 5 +++++ pdns/dnsdist.cc | 2 +- pdns/dnsdist.hh | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pdns/README-dnsdist.md b/pdns/README-dnsdist.md index 59d12320c..436dcc740 100644 --- a/pdns/README-dnsdist.md +++ b/pdns/README-dnsdist.md @@ -1407,6 +1407,7 @@ instantiate a server with additional parameters function with the parameter `dr`, which returns an action to be taken on this response packet. Good for rare packets but where you want to do a lot of processing. * Server selection policy related: + * `setWHashedPertubation(value)`: set the hash perturbation value to be used in the `whashed` policy instead of a random one, allowing to have consistent `whashed` results on different instances * `setServerPolicy(policy)`: set server selection policy to that policy * `setServerPolicyLua(name, function)`: set server selection policy to one named 'name' and provided by 'function' * `showServerPolicy()`: show name of currently operational server selection policy diff --git a/pdns/dnsdist-lua2.cc b/pdns/dnsdist-lua2.cc index 507a99daa..0350806ed 100644 --- a/pdns/dnsdist-lua2.cc +++ b/pdns/dnsdist-lua2.cc @@ -1160,4 +1160,9 @@ void moreLua(bool client) return std::shared_ptr(new RDRule()); }); + g_lua.writeFunction("setWHashedPertubation", [](uint32_t pertub) { + setLuaSideEffect(); + g_hashperturb = pertub; + }); + } diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 2002e6d0b..5627cb6ae 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -610,7 +610,7 @@ shared_ptr wrandom(const NumberedServerVector& servers, const D return valrandom(random(), servers, dq); } -static uint32_t g_hashperturb; +uint32_t g_hashperturb; shared_ptr whashed(const NumberedServerVector& servers, const DNSQuestion* dq) { return valrandom(dq->qname->hash(g_hashperturb), servers, dq); diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index ba2f8b72c..b9ddc6722 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -637,6 +637,7 @@ extern uint32_t g_staleCacheEntriesTTL; extern bool g_apiReadWrite; extern std::string g_apiConfigDirectory; extern bool g_servFailOnNoPolicy; +extern uint32_t g_hashperturb; struct ConsoleKeyword { std::string name; -- 2.40.0