]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
TMP WIP modules/dns64: allow specifying force=true dns64-force
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 3 Aug 2021 14:54:34 +0000 (16:54 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 3 Aug 2021 14:56:16 +0000 (16:56 +0200)
Also accept settings as a table.

Example:
  modules = { 'dns64' }
  dns64.config({ prefix = 'fe80::21b:77ff:0:0', force = true })

modules/dns64/dns64.lua

index a389b7837276b4af37d03f7b4e6435081f045075..fe9517ec02be3f28d0af3ac43a47f569299478ae 100644 (file)
@@ -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.