return dnsdist::configuration::getImmutableConfiguration().d_frontends;
}
-std::vector<std::shared_ptr<DNSCryptContext>> getDNSCryptFrontends()
+std::vector<std::shared_ptr<DNSCryptContext>> getDNSCryptFrontends(bool udpOnly)
{
std::vector<std::shared_ptr<DNSCryptContext>> results;
for (const auto& frontend : getFrontends()) {
- if (frontend->getProtocol() == dnsdist::Protocol::DNSCryptUDP || frontend->getProtocol() == dnsdist::Protocol::DNSCryptTCP) {
+ if (frontend->getProtocol() == dnsdist::Protocol::DNSCryptUDP || (!udpOnly && frontend->getProtocol() == dnsdist::Protocol::DNSCryptTCP)) {
results.push_back(frontend->dnscryptCtx);
}
}
namespace dnsdist
{
const std::vector<std::shared_ptr<ClientState>>& getFrontends();
-std::vector<std::shared_ptr<DNSCryptContext>> getDNSCryptFrontends();
+std::vector<std::shared_ptr<DNSCryptContext>> getDNSCryptFrontends(bool udpOnly);
std::vector<std::shared_ptr<TLSFrontend>> getDoTFrontends();
std::vector<std::shared_ptr<DOHFrontend>> getDoHFrontends();
std::vector<std::shared_ptr<DOQFrontend>> getDoQFrontends();
luaCtx.writeFunction("getDNSCryptBind", [](uint64_t idx) {
setLuaNoSideEffect();
std::shared_ptr<DNSCryptContext> ret = nullptr;
- auto frontends = dnsdist::getDNSCryptFrontends();
+ /* we are only interested in distinct DNSCrypt binds,
+ and we have two frontends (UDP and TCP) per bind
+ sharing the same context so we need to retrieve
+ the UDP ones only . */
+ auto frontends = dnsdist::getDNSCryptFrontends(true);
if (idx < frontends.size()) {
ret = frontends.at(idx);
}
luaCtx.writeFunction("getDNSCryptBindCount", []() {
setLuaNoSideEffect();
- return dnsdist::getDNSCryptFrontends().size();
+ /* we are only interested in distinct DNSCrypt binds,
+ and we have two frontends (UDP and TCP) per bind
+ sharing the same context so we need to retrieve
+ the UDP ones only . */
+ return dnsdist::getDNSCryptFrontends(true).size();
});
#endif /* HAVE_DNSCRYPT */