From: Vladimír Čunát Date: Tue, 3 Aug 2021 14:54:34 +0000 (+0200) Subject: TMP WIP modules/dns64: allow specifying force=true X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fdns64-force;p=thirdparty%2Fknot-resolver.git TMP WIP modules/dns64: allow specifying force=true Also accept settings as a table. Example: modules = { 'dns64' } dns64.config({ prefix = 'fe80::21b:77ff:0:0', force = true }) --- diff --git a/modules/dns64/dns64.lua b/modules/dns64/dns64.lua index a389b7837..fe9517ec0 100644 --- a/modules/dns64/dns64.lua +++ b/modules/dns64/dns64.lua @@ -19,9 +19,19 @@ Missing parts of the RFC: ]] -- Config -function M.config (confstr) - M.proxy = kres.str2ip(confstr or '64:ff9b::') +function M.config(conf) + if type(conf) ~= 'table' then + conf = { prefix = conf } + end + M.proxy = kres.str2ip(conf.prefix or '64:ff9b::') if M.proxy == nil then error('[dns64] "'..confstr..'" is not a valid address') end + + -- Force overwriting the answer even if AAAA records exist. + -- Inefficient implementation for now: it still asks upstream for AAAA. + M.force = conf.force or false + if type(M.force) ~= 'boolean' then + error('[dns64] invalid .force parameter: ' .. tostring(conf.force)) + end end -- Layers @@ -38,7 +48,7 @@ function M.layer.consume(state, req, pkt) local answer = pkt:section(kres.section.ANSWER) -- Observe final AAAA NODATA responses to the current SNAME. - local is_nodata = pkt:rcode() == kres.rcode.NOERROR and #answer == 0 + local is_nodata = pkt:rcode() == kres.rcode.NOERROR and (#answer == 0 or M.force) if pkt:qtype() == kres.type.AAAA and is_nodata and pkt:qname() == qry:name() and qry.flags.RESOLVED and not qry.flags.CNAME and qry.parent == nil then -- Start a *marked* corresponding A sub-query.