]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/lua: doc cleanup, todname() call
authorMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 24 Nov 2015 15:02:01 +0000 (16:02 +0100)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Tue, 24 Nov 2015 15:02:01 +0000 (16:02 +0100)
policy has policy.todnames() for table of names

daemon/engine.c
daemon/lua/sandbox.lua
modules/policy/README.rst
modules/policy/policy.lua

index af457bcebb39eaca78e5ecc52d790ed21265ba09..7dcb1ad1c3fe8262933619774fad8c31384a86d9 100644 (file)
@@ -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;
index 4e736d7d78086e860e3b173e7e70ebfb438a6738..87758828cc90548c0d095d475ba155517f909816 100644 (file)
@@ -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)`
index ebb936a2737d9458085706a7d9bc5512fc477cbe..4c04bff95630c087e9bc20a70f972033977007f0 100644 (file)
@@ -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/
index f67f5526cc6b5dd2f40e4c7f02c3e343f73fac72..8fcc089fbfd855c0813aa1516c7627e73caabc1e 100644 (file)
@@ -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') }