Commit 4b7ebf54 authored by Marek Vavruša's avatar Marek Vavruša

modules: dns64 checks for records, all response status

fixes #42
parent 56db1f25
......@@ -12,6 +12,7 @@ end
-- Layers
mod.layer = {
consume = function (state, req, pkt)
if state == kres.FAIL then return state end
pkt = kres.pkt_t(pkt)
req = kres.request_t(req)
qry = req:current()
......@@ -24,13 +25,13 @@ mod.layer = {
if bit.band(qry.flags, MARK_DNS64) ~= 0 then -- Marked request
for i = 1, #answer do
local rr = answer[i]
-- Synthesise address
local rdata = ffi.new('char [16]')
ffi.copy(rdata, mod.proxy)
ffi.copy(rdata + 12, rr.rdata, 4)
rdata = ffi.string(rdata, 16)
-- Write to answer
req.answer:put(rr.owner, rr.ttl, rr.class, kres.type.AAAA, rdata)
-- Synthesise AAAA from A
if rr.type == kres.type.A then
local rdata = ffi.new('char [16]')
ffi.copy(rdata, mod.proxy)
ffi.copy(rdata + 12, rr.rdata, 4)
req.answer:put(rr.owner, rr.ttl, rr.class, kres.type.AAAA, ffi.string(rdata, 16))
end
end
return state
end
......
......@@ -45,14 +45,13 @@ end
-- Layers
mod.layer = {
finish = function (state, req)
if state == kres.FAIL then return state end
req = kres.request_t(req)
pkt = kres.pkt_t(req.answer)
-- Only successful answers
local records = pkt:section(kres.section.ANSWER)
local ancount = #records
if state ~= kres.DONE or ancount == 0 then
return state
end
if ancount == 0 then return state end
-- Find renumber candidates
local changed = false
for i = 1, ancount do
......
......@@ -53,6 +53,7 @@ end
-- @function Module layers
view.layer = {
begin = function(state, req)
if state == kres.FAIL then return state end
req = kres.request_t(req)
local match_cb = evaluate(view, req)
if match_cb ~= nil then
......
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