From bc462179fc0ec77b2307254229bc9dea2f853f06 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Wed, 9 Feb 2022 15:13:41 +0100 Subject: [PATCH] dnsdist: Add a Lua binding for the getResolvers() function --- pdns/dnsdistdist/dnsdist-lua-bindings-network.cc | 12 ++++++++++++ pdns/dnsdistdist/docs/reference/config.rst | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc index 2f60d3be2d..9f1b917270 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc @@ -82,4 +82,16 @@ void setupLuaBindingsNetwork(LuaContext& luaCtx, bool client) listener->start(); }); + + luaCtx.writeFunction("getResolvers", [](const std::string& resolvConfPath) -> LuaArray { + auto resolvers = getResolvers(resolvConfPath); + LuaArray result; + result.reserve(resolvers.size()); + int counter = 1; + for (const auto& resolver : resolvers) { + result.emplace_back(counter, resolver.toString()); + counter++; + } + return result; + }); }; diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 99c4e14593..1ad86fcf3b 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -1695,6 +1695,14 @@ These values can be set at configuration time via: Other functions --------------- +.. function:: getResolvers(path) + + .. versionadded:: 1.8.0 + + This function can be used to get a Lua table of name servers from a file in the resolv.conf format. + + :param str path: The path to the file, usually /etc/resolv.conf + .. function:: maintenance() If this function exists, it is called every second to do regular tasks. -- 2.47.2