From 8cd4851beb78bc6ab320926fb5cb6a09282016b1 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Fri, 6 Feb 2015 10:24:32 -0500 Subject: [PATCH] add getregisteredname() function for recursor Lua scripts --- docs/markdown/changelog.md.raw | 1 + docs/markdown/recursor/scripting.md | 4 ++++ pdns/lua-recursor.cc | 11 ++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/markdown/changelog.md.raw b/docs/markdown/changelog.md.raw index 50438baf8..627e76f52 100644 --- a/docs/markdown/changelog.md.raw +++ b/docs/markdown/changelog.md.raw @@ -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: diff --git a/docs/markdown/recursor/scripting.md b/docs/markdown/recursor/scripting.md index 9e59303d8..045266557 100644 --- a/docs/markdown/recursor/scripting.md +++ b/docs/markdown/recursor/scripting.md @@ -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. diff --git a/pdns/lua-recursor.cc b/pdns/lua-recursor.cc index 9d08d08f8..de402f49d 100644 --- a/pdns/lua-recursor.cc +++ b/pdns/lua-recursor.cc @@ -61,11 +61,20 @@ extern "C" { #include #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& ret, const QType& qtype) -- 2.40.0