Skip to content

Commit

Permalink
dnsdist: Improve consistency of the Lua types used in our configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rgacogne committed Jul 5, 2024
1 parent 3fd7c56 commit 1a79e4f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-lua-inspection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void setupLuaInspection(LuaContext& luaCtx)
}
totalEntries += rings.back().size();
}
vector<std::unordered_map<string, boost::variant<string, unsigned int>>> ret;
vector<std::unordered_map<string, boost::variant<unsigned int, string>>> ret;
ret.reserve(totalEntries);
for (const auto& ring : rings) {
for (const auto& entry : ring) {
Expand Down
6 changes: 3 additions & 3 deletions pdns/dnsdistdist/dnsdist-lua-rules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ static LuaArray<T> toLuaArray(std::vector<T>&& rules)
}

template <typename T>
static boost::optional<T> getRuleFromSelector(const std::vector<T>& rules, const boost::variant<int, std::string>& selector)
static boost::optional<T> getRuleFromSelector(const std::vector<T>& rules, const boost::variant<unsigned int, std::string>& selector)
{
if (const auto* str = boost::get<std::string>(&selector)) {
/* let's see if this a UUID */
Expand All @@ -283,7 +283,7 @@ static boost::optional<T> getRuleFromSelector(const std::vector<T>& rules, const
}
}
}
else if (const auto* pos = boost::get<int>(&selector)) {
else if (const auto* pos = boost::get<unsigned int>(&selector)) {
/* this will throw a std::out_of_range exception if the
supplied position is out of bounds, this is fine */
return rules.at(*pos);
Expand Down Expand Up @@ -346,7 +346,7 @@ void setupLuaRules(LuaContext& luaCtx)
luaCtx.writeFunction("mv" + chain.prefix + "ResponseRule", [&chain](unsigned int from, unsigned int dest) {
mvRule(&chain.holder, from, dest);
});
luaCtx.writeFunction("get" + chain.prefix + "ResponseRule", [&chain](const boost::variant<int, std::string>& selector) -> boost::optional<dnsdist::rules::ResponseRuleAction> {
luaCtx.writeFunction("get" + chain.prefix + "ResponseRule", [&chain](const boost::variant<unsigned int, std::string>& selector) -> boost::optional<dnsdist::rules::ResponseRuleAction> {
auto rules = chain.holder.getLocal();
return getRuleFromSelector(*rules, selector);
});
Expand Down
12 changes: 6 additions & 6 deletions pdns/dnsdistdist/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
return *poolServers;
});

luaCtx.writeFunction("getServer", [client](boost::variant<int, std::string> identifier) {
luaCtx.writeFunction("getServer", [client](boost::variant<unsigned int, std::string> identifier) {
if (client) {
return std::make_shared<DownstreamState>(ComboAddress());
}
Expand All @@ -1053,7 +1053,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
}
}
}
else if (auto* pos = boost::get<int>(&identifier)) {
else if (auto* pos = boost::get<unsigned int>(&identifier)) {
return states.at(*pos);
}

Expand Down Expand Up @@ -2464,7 +2464,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
return result;
});

luaCtx.writeFunction("addDOHLocal", [client](const std::string& addr, boost::optional<boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>>> certFiles, boost::optional<boost::variant<std::string, LuaArray<std::string>>> keyFiles, boost::optional<LuaTypeOrArrayOf<std::string>> urls, boost::optional<localbind_t> vars) {
luaCtx.writeFunction("addDOHLocal", [client](const std::string& addr, boost::optional<boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>>> certFiles, boost::optional<LuaTypeOrArrayOf<std::string>> keyFiles, boost::optional<LuaTypeOrArrayOf<std::string>> urls, boost::optional<localbind_t> vars) {
if (client) {
return;
}
Expand Down Expand Up @@ -2630,7 +2630,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
});

// NOLINTNEXTLINE(performance-unnecessary-value-param): somehow clang-tidy gets confused about the fact vars could be const while it cannot
luaCtx.writeFunction("addDOH3Local", [client](const std::string& addr, const boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>>& certFiles, const boost::variant<std::string, LuaArray<std::string>>& keyFiles, boost::optional<localbind_t> vars) {
luaCtx.writeFunction("addDOH3Local", [client](const std::string& addr, const boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>>& certFiles, const LuaTypeOrArrayOf<std::string>& keyFiles, boost::optional<localbind_t> vars) {
if (client) {
return;
}
Expand Down Expand Up @@ -2705,7 +2705,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
});

// NOLINTNEXTLINE(performance-unnecessary-value-param): somehow clang-tidy gets confused about the fact vars could be const while it cannot
luaCtx.writeFunction("addDOQLocal", [client](const std::string& addr, const boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>>& certFiles, const boost::variant<std::string, LuaArray<std::string>>& keyFiles, boost::optional<localbind_t> vars) {
luaCtx.writeFunction("addDOQLocal", [client](const std::string& addr, const boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>>& certFiles, const LuaTypeOrArrayOf<std::string>& keyFiles, boost::optional<localbind_t> vars) {
if (client) {
return;
}
Expand Down Expand Up @@ -2989,7 +2989,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
}
});

luaCtx.registerFunction<void (std::shared_ptr<DOHFrontend>::*)(boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>> certFiles, boost::variant<std::string, LuaArray<std::string>> keyFiles)>("loadNewCertificatesAndKeys", [](const std::shared_ptr<DOHFrontend>& frontend, const boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>>& certFiles, const boost::variant<std::string, LuaArray<std::string>>& keyFiles) {
luaCtx.registerFunction<void (std::shared_ptr<DOHFrontend>::*)(boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>> certFiles, LuaTypeOrArrayOf<std::string> keyFiles)>("loadNewCertificatesAndKeys", [](const std::shared_ptr<DOHFrontend>& frontend, const boost::variant<std::string, std::shared_ptr<TLSCertKeyPair>, LuaArray<std::string>, LuaArray<std::shared_ptr<TLSCertKeyPair>>>& certFiles, const LuaTypeOrArrayOf<std::string>& keyFiles) {
#ifdef HAVE_DNS_OVER_HTTPS
if (frontend != nullptr) {
if (loadTLSCertificateAndKeys("DOHFrontend::loadNewCertificatesAndKeys", frontend->d_tlsContext.d_tlsConfig.d_certKeyPairs, certFiles, keyFiles)) {
Expand Down

0 comments on commit 1a79e4f

Please sign in to comment.