From: Remi Gacogne Date: Mon, 22 Nov 2021 11:05:30 +0000 (+0100) Subject: dnsdist: Add Lua bindings to get the list of network interfaces, addresses X-Git-Tag: auth-4.7.0-alpha1~118^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6e95c425ea85de587c6c95592652f7ee3a32b7f;p=thirdparty%2Fpdns.git dnsdist: Add Lua bindings to get the list of network interfaces, addresses --- diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index a052779e38..09be3c0132 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -457,6 +457,8 @@ const std::vector 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" }, diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc index ae44c7b631..5e51e19264 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -616,4 +616,24 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) return parameters; }); + + luaCtx.writeFunction("getListOfNetworkInterfaces", []() { + std::vector> 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> result; + auto addrs = getListOfAddressesOfNetworkInterface(itf); + int counter = 1; + for (const auto& addr : addrs) { + result.push_back({counter++, addr.toString()}); + } + return result; + }); } diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 5b5cc0cf83..e0b6db8f72 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -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