]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add a Lua binding for the getResolvers() function
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 9 Feb 2022 14:13:41 +0000 (15:13 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 7 Oct 2022 15:48:51 +0000 (17:48 +0200)
pdns/dnsdistdist/dnsdist-lua-bindings-network.cc
pdns/dnsdistdist/docs/reference/config.rst

index 2f60d3be2d97594a9ff4285b565586010e47d601..9f1b9172706df4e80ff1f99da0ebfc852a4780d4 100644 (file)
@@ -82,4 +82,16 @@ void setupLuaBindingsNetwork(LuaContext& luaCtx, bool client)
 
     listener->start();
   });
+
+  luaCtx.writeFunction("getResolvers", [](const std::string& resolvConfPath) -> LuaArray<std::string> {
+    auto resolvers = getResolvers(resolvConfPath);
+    LuaArray<std::string> result;
+    result.reserve(resolvers.size());
+    int counter = 1;
+    for (const auto& resolver : resolvers) {
+      result.emplace_back(counter, resolver.toString());
+      counter++;
+    }
+    return result;
+  });
 };
index 99c4e1459303e4c499e8a48de1a7c408b255f4af..1ad86fcf3bea22aaeba4aafb1bd8895336d4509a 100644 (file)
@@ -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.