From: Remi Gacogne Date: Wed, 9 Feb 2022 14:13:41 +0000 (+0100) Subject: dnsdist: Add a Lua binding for the getResolvers() function X-Git-Tag: dnsdist-1.8.0-rc1~285^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc462179fc0ec77b2307254229bc9dea2f853f06;p=thirdparty%2Fpdns.git dnsdist: Add a Lua binding for the getResolvers() function --- 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.