]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add a 'getMACAdress(ip)' Lua binding
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 3 May 2022 10:16:46 +0000 (12:16 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 3 May 2022 10:16:46 +0000 (12:16 +0200)
pdns/dnsdist-console.cc
pdns/dnsdist-lua-bindings.cc
pdns/dnsdistdist/docs/reference/config.rst

index 3a3073e3db1679ee73c7d56bad1d2126af858672..8d58c052ffdad65687f575c71486295234d5dd52 100644 (file)
@@ -510,6 +510,7 @@ const std::vector<ConsoleKeyword> 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" },
index 2ecae9d9abce2429bd0b0ec3fde8de097f50d6c8..6f64c341ceabbb449ae987038a9806d69a778722 100644 (file)
@@ -682,4 +682,8 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
     }
     return result;
   });
+
+  luaCtx.writeFunction("getMACAddress", [](const std::string& ip) {
+    return getMACAddress(ComboAddress(ip));
+  });
 }
index d77dfc168a0f14f91e3e7f271599b8b753c08bd8..afc476fb2711aa2a60bdc940c7b20f4b68a4e723 100644 (file)
@@ -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