Skip to content

DNS64 with multiple prefixes

Peter van Dijk edited this page Sep 3, 2020 · 3 revisions

Script provided by a user, released into the public domain.

-- an example from trex.fi dns64 resolver that implements round robin between two prefixes

local i = true
local msmicprefix = "2001:67c:2b0:db32:0:0::"
local msmiczone = newDN("0.0.0.0.0.0.0.0.2.3.b.d.0.b.2.0.c.7.6.0.1.0.0.2.ip6.arpa.")
local taygaprefix = "2001:67c:2b0:db32:0:1::"
local taygazone = newDN("1.0.0.0.0.0.0.0.2.3.b.d.0.b.2.0.c.7.6.0.1.0.0.2.ip6.arpa.")
        
function preresolve(dq)
        if dq.qtype == pdns.PTR then
                if dq.qname:isPartOf(msmiczone) then
                    dq.followupFunction = "getFakePTRRecords"
                    dq.followupPrefix = msmicprefix
                    dq.followupName = dq.qname
                    return true
                end 
                if dq.qname:isPartOf(taygazone) then
                    dq.followupFunction = "getFakePTRRecords"
                    dq.followupPrefix = taygaprefix
                    dq.followupName = dq.qname
                    return true
                end
        end
 
        return false
end
        
function nodata ( dq )
        if dq.qtype == pdns.AAAA then
                dq.followupFunction="getFakeAAAARecords"
                dq.followupName=dq.qname
                i = not i
                if i and not dq.qname:equal("ipv4only.arpa") then
                        dq.followupPrefix=msmicprefix
                else
                        dq.followupPrefix=taygaprefix
                end
                return true
        end
        return false
end