From: Marek VavruĊĦa Date: Tue, 24 Nov 2015 15:02:01 +0000 (+0100) Subject: daemon/lua: doc cleanup, todname() call X-Git-Tag: v1.0.0-beta3~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=62606a2e899d10152f4555eab3d1aa99bcb0cf62;p=thirdparty%2Fknot-resolver.git daemon/lua: doc cleanup, todname() call policy has policy.todnames() for table of names --- diff --git a/daemon/engine.c b/daemon/engine.c index af457bceb..7dcb1ad1c 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -59,6 +59,12 @@ static int l_help(lua_State *L) "user(name[, group])\n change process user (and group)\n" "verbose(true|false)\n toggle verbose mode\n" "option(opt[, new_val])\n get/set server option\n" + "resolve(name, type[, class, flags, callback])\n resolve query, callback when it's finished\n" + "todname(name)\n convert name to wire format\n" + "net\n network configuration\n" + "cache\n network configuration\n" + "modules\n modules configuration\n" + "kres\n resolver services\n" ; lua_pushstring(L, help_str); return 1; diff --git a/daemon/lua/sandbox.lua b/daemon/lua/sandbox.lua index 4e736d7d7..87758828c 100644 --- a/daemon/lua/sandbox.lua +++ b/daemon/lua/sandbox.lua @@ -12,6 +12,7 @@ day = 24 * hour kres = require('kres') trust_anchors = require('trust_anchors') resolve = worker.resolve +todname = kres.str2dname -- Function aliases -- `env.VAR returns os.getenv(VAR)` diff --git a/modules/policy/README.rst b/modules/policy/README.rst index ebb936a27..4c04bff95 100644 --- a/modules/policy/README.rst +++ b/modules/policy/README.rst @@ -26,7 +26,7 @@ There are several defined actions: * ``TC`` - set TC=1 if the request came through UDP, forcing client to retry with TCP * ``FORWARD(ip)`` - forward query to given IP and proxy back response (stub mode) -.. note:: The module (and ``kres``) treats domain names as wire, not textual representation. So each label in name is prefixed with its length, e.g. "example.com" equals to ``"\7example\3com"``. +.. note:: The module (and ``kres``) expects domain names in wire format, not textual representation. So each label in name is prefixed with its length, e.g. "example.com" equals to ``"\7example\3com"``. You can use convenience function ``todname('example.com')`` for automatic conversion. Example configuration ^^^^^^^^^^^^^^^^^^^^^ @@ -134,6 +134,20 @@ Properties "NSDNAME", "no" "NS-IP", "no" +.. function:: policy.todnames({name, ...}) + + :param: names table of domain names in textual format + + Returns table of domain names in wire format converted from strings. + + .. code-block:: lua + + -- Convert single name + assert(todname('example.com') == '\7example\3com\0') + -- Convert table of names + policy.todnames({'example.com', 'me.cz'}) + { '\7example\3com\0', '\2me\2cz\0' } + .. _`Aho-Corasick`: https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm .. _`@jgrahamc`: https://github.com/jgrahamc/aho-corasick-lua .. _RPZ: https://dnsrpz.info/ diff --git a/modules/policy/policy.lua b/modules/policy/policy.lua index f67f5526c..8fcc089fb 100644 --- a/modules/policy/policy.lua +++ b/modules/policy/policy.lua @@ -167,10 +167,11 @@ function policy.add(policy, rule) end -- Convert list of string names to domain names -function policy.to_domains(names) +function policy.todnames(names) for i, v in ipairs(names) do names[i] = kres.str2dname(v) end + return names end -- RFC1918 Private, local, broadcast, test and special zones @@ -211,7 +212,7 @@ local private_zones = { 'b.e.f.ip6.arpa.', '8.b.d.0.1.0.0.2.ip6.arpa', } -policy.to_domains(private_zones) +policy.todnames(private_zones) -- @var Default rules policy.rules = { policy.suffix_common(policy.DENY, private_zones, '\4arpa\0') }