]> granicus.if.org Git - pdns/commitdiff
add getregisteredname() function for recursor Lua scripts
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 6 Feb 2015 15:24:32 +0000 (10:24 -0500)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Fri, 6 Feb 2015 15:34:38 +0000 (16:34 +0100)
docs/markdown/changelog.md.raw
docs/markdown/recursor/scripting.md
pdns/lua-recursor.cc

index 50438baf8cd4ce5b1f16cbaeb99c7e0bb2cc0d95..627e76f526066d05112cd2b900a3c71107e42208 100644 (file)
@@ -111,6 +111,7 @@ New features:
 - Lua preoutquery filter 3457a2a0ec41d3b3aff7640f30008788e1228a6e
 - Lua IP-based filter (ipfilter) before parsing packets 4ea949413c495254acb0bd19335142761c1efc0c
 - `iputils` class for Lua, to quickly process IP addresses and netmasks in their native format
+- `getregisteredname` function for Lua, to find the registered domain for a given name
 - Various new ringbuffers: top-servfail-remotes, top-largeanswer-remotes, top-servfail-queries
 
 Speedups:
index 9e59303d8ff9f198aec8ac193a139d44e1d65afd..0452665575f55a6c41d2d50319454230d369ceae 100644 (file)
@@ -180,6 +180,10 @@ In `preoutquery`, `getlocaladdress()` returns the address of the client that cau
 To indicate that an answer should not be cached in the packet cache, use
 `setvariable()`.  Available since version 3.3.
 
+`getregisteredname('www.powerdns.com')` returns `powerdns.com.`, based on Mozilla's
+Public Suffix List. In general it will tell you the 'registered domain' for a given
+name.
+
 To get fake AAAA records for DNS64 usage, use `return "getFakeAAAARecords",
 domain, "fe80::21b:77ff:0:0"`.  Available since version 3.4.
 
index 9d08d08f821131bd2d5b15a8411cf08606f81eeb..de402f49dbd8b07987636e7c42b79d5f6d1eaaf6 100644 (file)
@@ -61,11 +61,20 @@ extern "C" {
 #include <boost/foreach.hpp>
 #include "logger.hh"
 #include "namespaces.hh"
+#include "rec_channel.hh"
+
+static int getRegisteredNameLua(lua_State *L) {
+  const char *name = luaL_checkstring(L, 1);
+  string regname=getRegisteredName(name);
+  lua_pushstring(L, regname.c_str());
+  return 1;
+}
 
 RecursorLua::RecursorLua(const std::string &fname)
   : PowerDNSLua(fname)
 {
-  // empty
+  lua_pushcfunction(d_lua, getRegisteredNameLua);
+  lua_setglobal(d_lua, "getregisteredname");
 }
 
 int followCNAMERecords(vector<DNSResourceRecord>& ret, const QType& qtype)