From: Remi Gacogne Date: Tue, 3 May 2022 10:16:46 +0000 (+0200) Subject: dnsdist: Add a 'getMACAdress(ip)' Lua binding X-Git-Tag: auth-4.8.0-alpha0~93^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c42c99b0ddc4eb7c32b5748e7542daca22b821ff;p=thirdparty%2Fpdns.git dnsdist: Add a 'getMACAdress(ip)' Lua binding --- diff --git a/pdns/dnsdist-console.cc b/pdns/dnsdist-console.cc index 3a3073e3db..8d58c052ff 100644 --- a/pdns/dnsdist-console.cc +++ b/pdns/dnsdist-console.cc @@ -510,6 +510,7 @@ const std::vector g_consoleKeywords{ { "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" }, + { "getMACAddress", true, "IP addr", "return the link-level address (MAC) corresponding to the supplied remote IP address, if known by the kernel" }, { "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 2ecae9d9ab..6f64c341ce 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -682,4 +682,8 @@ void setupLuaBindings(LuaContext& luaCtx, bool client) } return result; }); + + luaCtx.writeFunction("getMACAddress", [](const std::string& ip) { + return getMACAddress(ComboAddress(ip)); + }); } diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index d77dfc168a..afc476fb27 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -983,9 +983,18 @@ Status, Statistics and More .. versionadded:: 1.8.0 - Return the list of network interfaces configured on the system, as strings + 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:: getMacAddress(ip) + + .. versionadded:: 1.8.0 + + Return the link-level address (MAC) corresponding to the supplied remote IP address, if known by the kernel. + This function is only implemented on Linux. + + :param str ip: The IP address, IPv4 or IPv6, to look up the corresponding link-level address for. + .. function:: getOutgoingTLSSessionCacheSize() .. versionadded:: 1.7.0