]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add Lua bindings to get the list of network interfaces, addresses
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 22 Nov 2021 11:05:30 +0000 (12:05 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 3 Dec 2021 15:27:18 +0000 (16:27 +0100)
pdns/dnsdist-console.cc
pdns/dnsdist-lua-bindings.cc
pdns/dnsdistdist/docs/reference/config.rst

index a052779e3801e228c432b786f0de35d9ffc1d853..09be3c0132f1c0287049b84b843266122feca1a3 100644 (file)
@@ -457,6 +457,8 @@ const std::vector<ConsoleKeyword> g_consoleKeywords{
   { "getDNSCryptBindCount", true, "", "returns the number of DNSCrypt listeners" },
   { "getDOHFrontend", true, "n", "returns the DOH frontend with index n" },
   { "getDOHFrontendCount", true, "", "returns the number of DoH listeners" },
+  { "getListOfAddressesOfNetworkInterface", true, "itf", "returns the list of addresses configured on a given network interface, as strings" },
+  { "getListOfNetworkInterfaces", true, "", "returns the list of network interfaces present on the system, as strings" },
   { "getOutgoingTLSSessionCacheSize", true, "", "returns the number of TLS sessions (for outgoing connections) currently cached" },
   { "getPool", true, "name", "return the pool named `name`, or \"\" for the default pool" },
   { "getPoolServers", true, "pool", "return servers part of this pool" },
index ae44c7b63123621128d547c6100bce1d5d2b39c9..5e51e192649cda19b375d9d3494764980f9c14af 100644 (file)
@@ -616,4 +616,24 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
 
     return parameters;
   });
+
+  luaCtx.writeFunction("getListOfNetworkInterfaces", []() {
+    std::vector<std::pair<int, std::string>> result;
+    auto itfs = getListOfNetworkInterfaces();
+    int counter = 1;
+    for (const auto& itf : itfs) {
+      result.push_back({counter++, itf});
+    }
+    return result;
+  });
+
+  luaCtx.writeFunction("getListOfAddressesOfNetworkInterface", [](const std::string& itf) {
+    std::vector<std::pair<int, std::string>> result;
+    auto addrs = getListOfAddressesOfNetworkInterface(itf);
+    int counter = 1;
+    for (const auto& addr : addrs) {
+      result.push_back({counter++, addr.toString()});
+    }
+    return result;
+  });
 }
index 5b5cc0cf83ae1033a874865b23a99deb926c8fb0..e0b6db8f7284c23dc1abda16d34c5fe9ae16d44d 100644 (file)
@@ -950,6 +950,22 @@ Status, Statistics and More
 
   Return the number of DOHFrontend binds.
 
+.. function:: getListOfAddressesOfNetworkInterface(itf)
+
+  .. versionadded:: 1.8.0
+
+  Return the list of addresses configured on a given network interface, as strings.
+  This function requires support for ``getifaddrs``, which is known to be present on FreeBSD, Linux, and OpenBSD at least.
+
+  :param str itf: The name of the network interface
+
+.. function:: getListOfNetworkInterfaces()
+
+  .. versionadded:: 1.8.0
+
+  Return the list of network interfaces configured on the system, as strings
+  This function requires support for ``getifaddrs``, which is known to be present on FreeBSD, Linux, and OpenBSD at least.
+
 .. function:: getOutgoingTLSSessionCacheSize()
 
   .. versionadded:: 1.7.0