Commit 62606a2e authored by Marek Vavruša's avatar Marek Vavruša

daemon/lua: doc cleanup, todname() call

policy has policy.todnames() for table of names
parent bbdd3771
......@@ -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;
......
......@@ -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)`
......
......@@ -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/
......
......@@ -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') }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment