return selectedBackend;
}
+
+namespace dnsdist::lbpolicies
+{
+const std::vector<std::shared_ptr<ServerPolicy>>& getBuiltInPolicies()
+{
+ static const std::vector<std::shared_ptr<ServerPolicy>> s_policies{
+ std::make_shared<ServerPolicy>("firstAvailable", firstAvailable, false),
+ std::make_shared<ServerPolicy>("roundrobin", roundrobin, false),
+ std::make_shared<ServerPolicy>("wrandom", wrandom, false),
+ std::make_shared<ServerPolicy>("whashed", whashed, false),
+ std::make_shared<ServerPolicy>("chashed", chashed, false),
+ std::make_shared<ServerPolicy>("leastOutstanding", leastOutstanding, false)};
+ return s_policies;
+}
+}
std::shared_ptr<DownstreamState> chashed(const ServerPolicy::NumberedServerVector& servers, const DNSQuestion* dq);
std::shared_ptr<DownstreamState> chashedFromHash(const ServerPolicy::NumberedServerVector& servers, size_t hash);
std::shared_ptr<DownstreamState> roundrobin(const ServerPolicy::NumberedServerVector& servers, const DNSQuestion* dq);
+
+#include <unordered_map>
+
+namespace dnsdist::lbpolicies
+{
+const std::vector<std::shared_ptr<ServerPolicy>>& getBuiltInPolicies();
+}
luaCtx.registerFunction("toString", &ServerPolicy::toString);
luaCtx.registerFunction("__tostring", &ServerPolicy::toString);
- const std::array<std::shared_ptr<ServerPolicy>, 6> policies = {
- std::make_shared<ServerPolicy>("firstAvailable", firstAvailable, false),
- std::make_shared<ServerPolicy>("roundrobin", roundrobin, false),
- std::make_shared<ServerPolicy>("wrandom", wrandom, false),
- std::make_shared<ServerPolicy>("whashed", whashed, false),
- std::make_shared<ServerPolicy>("chashed", chashed, false),
- std::make_shared<ServerPolicy>("leastOutstanding", leastOutstanding, false)};
- for (const auto& policy : policies) {
+ for (const auto& policy : dnsdist::lbpolicies::getBuiltInPolicies()) {
luaCtx.writeVariable(policy->d_name, policy);
}