Commit 6fca9bcb authored by Vladimír Čunát's avatar Vladimír Čunát

modules, docs: omit casting parameters of lua layers

Thanks to changes in this branch the functions are called with correctly
typed parameters already, so these weird casts can be deleted.
parent 3eec662e
......@@ -348,9 +348,8 @@ Environment
-- Query for AAAA record
resolve('example.com', kres.type.AAAA, kres.class.IN, 0,
function (answer, req)
function (pkt, req)
-- Check answer RCODE
local pkt = kres.pkt_t(answer)
if pkt:rcode() == kres.rcode.NOERROR then
-- Print matching records
local records = pkt:section(kres.section.ANSWER)
......
......@@ -43,7 +43,6 @@ worker.resolve_pkt = function (pkt, options, finish, init)
finish_cb = ffi.cast('trace_callback_f',
function (req)
jit.off(true, true) -- JIT for (C -> lua)^2 nesting isn't allowed
req = kres.request_t(req)
finish(req.answer, req)
finish_cb:free()
end)
......
......@@ -40,9 +40,7 @@ Layers can also change course of resolution, for example by appending additional
.. code-block:: lua
consume = function (state, req, answer)
answer = kres.pkt_t(answer)
if answer:qtype() == kres.type.NS then
req = kres.request_t(req)
local qry = req:push(answer:qname(), kres.type.SOA, kres.class.IN)
qry.flags.AWAIT_CUT = true
end
......@@ -54,13 +52,11 @@ This **doesn't** block currently processed query, and the newly created sub-requ
.. code-block:: lua
consume = function (state, req, answer)
answer = kres.pkt_t(answer)
if state == kres.YIELD then
print('continuing yielded layer')
return kres.DONE
else
if answer:qtype() == kres.type.NS then
req = kres.request_t(req)
local qry = req:push(answer:qname(), kres.type.SOA, kres.class.IN)
qry.flags.AWAIT_CUT = true
print('planned SOA query, yielding')
......@@ -200,7 +196,6 @@ First you need to convert it to a type known to FFI and check basic properties.
.. code-block:: lua
consume = function (state, req, pkt)
pkt = kres.pkt_t(answer)
print('rcode:', pkt:rcode())
print('query:', kres.dname2str(pkt:qname()), pkt:qclass(), pkt:qtype())
if pkt:rcode() ~= kres.rcode.NOERROR then
......@@ -245,7 +240,6 @@ You primarily need to retrieve currently processed query.
.. code-block:: lua
consume = function (state, req, pkt)
req = kres.request_t(req)
print(req.options)
print(req.state)
......
......@@ -8,7 +8,6 @@ local event_id = nil
-- Check time validity of RRSIGs in priming query
-- luacheck: no unused args
local function check_time_callback(pkt, req)
pkt = kres.pkt_t(pkt)
if pkt:rcode() ~= kres.rcode.NOERROR then
warn("[detect_time_skew] cannot resolve '.' NS")
return nil
......
......@@ -27,8 +27,6 @@ end
M.layer = { }
function M.layer.consume(state, req, pkt)
if state == kres.FAIL then return state end
pkt = kres.pkt_t(pkt)
req = kres.request_t(req)
local qry = req:current()
-- Observe only final answers in IN class where request has no CD flag.
if M.proxy == nil or not qry.flags.RESOLVED
......
......@@ -15,7 +15,6 @@ local function wait_resolve(qname, qtype)
name = qname,
type = qtype,
finish = function (answer, _)
answer = kres.pkt_t(answer)
rcode = answer:rcode()
answers = answer:section(kres.section.ANSWER)
-- Signal as completed
......
......@@ -69,9 +69,8 @@ end
-- Handle DoT signalling NS domains.
function M.layer.consume(state, _, pkt)
if state == kres.FAIL then return state end
-- Only successful answers
pkt = kres.pkt_t(pkt)
if state == kres.FAIL then return state end
-- log("%s", pkt:tostring())
local authority = pkt:section(kres.section.AUTHORITY)
local additional = pkt:section(kres.section.ADDITIONAL)
......
......@@ -60,7 +60,6 @@ local function serve_trace(h, _)
local cond = condition.new()
local waiting, done = false, false
local finish_cb = ffi.cast('trace_callback_f', function (req)
req = kres.request_t(req)
add_selected_records(answers, req.answ_selected)
add_selected_records(authority, req.auth_selected)
if waiting then
......@@ -75,7 +74,6 @@ local function serve_trace(h, _)
type = qtype,
options = {'TRACE'},
init = function (req)
req = kres.request_t(req)
req.trace_log = buffer_log_cb
req.trace_finish = finish_cb
end
......@@ -106,4 +104,4 @@ return {
endpoints = {
['/trace'] = {'text/plain', serve_trace},
}
}
\ No newline at end of file
}
......@@ -523,8 +523,6 @@ policy.layer = {
begin = function(state, req)
-- Don't act on "resolved" cases.
if bit.band(state, bit.bor(kres.FAIL, kres.DONE)) ~= 0 then return state end
req = kres.request_t(req)
return policy.evaluate(policy.rules, req, req:current(), state) or
policy.evaluate(policy.special_names, req, req:current(), state) or
state
......@@ -532,8 +530,6 @@ policy.layer = {
finish = function(state, req)
-- Don't act on "resolved" cases.
if bit.band(state, bit.bor(kres.FAIL, kres.DONE)) ~= 0 then return state end
req = kres.request_t(req)
return policy.evaluate(policy.postrules, req, req:current(), state) or state
end
}
......
......@@ -175,7 +175,6 @@ predict.layer = {
-- Prefetch all expiring (sub-)queries immediately after the request finishes.
-- Doing that immediately is simplest and avoids creating (new) large bursts of activity.
finish = function (_, req)
req = kres.request_t(req)
local qrys = req.rplan.resolved
for i = 0, (tonumber(qrys.len) - 1) do -- size_t doesn't work for some reason
local qry = qrys.at[i]
......
......@@ -41,8 +41,6 @@ end
-- When all response is processed internal.nsset is published in resolver engine
-- luacheck: no unused args
local function address_callback(pkt, req)
pkt = kres.pkt_t(pkt)
-- req = kres.request_t(req)
if pkt:rcode() ~= kres.rcode.NOERROR then
warn("[priming] cannot resolve address '%s', type: %d", kres.dname2str(pkt:qname()), pkt:qtype())
else
......@@ -81,8 +79,6 @@ end
-- These new queries should be resolved from cache.
-- luacheck: no unused args
local function priming_callback(pkt, req)
pkt = kres.pkt_t(pkt)
-- req = kres.request_t(req)
if pkt:rcode() ~= kres.rcode.NOERROR then
warn("[priming] cannot resolve '.' NS, next priming query in %d seconds", priming.retry_time / sec)
internal.event = event.after(priming.retry_time, internal.prime)
......
......@@ -90,12 +90,10 @@ function M.layer.consume(state, req, pkt)
if state == kres.FAIL then
return state end
req = kres.request_t(req)
local qry = req:current()
if qry.flags.CACHED then -- do not slow down cached queries
return state end
pkt = kres.pkt_t(pkt)
local bad_rr = check_pkt(pkt)
if not bad_rr then
return state end
......
......@@ -64,8 +64,7 @@ end
local function rule()
return function (state, req)
if state == kres.FAIL then return state end
req = kres.request_t(req)
local pkt = kres.pkt_t(req.answer)
local pkt = req.answer
-- Only successful answers
local records = pkt:section(kres.section.ANSWER)
local ancount = #records
......
......@@ -18,7 +18,6 @@ M.callback = ffi.cast("kr_stale_cb",
M.layer = {
produce = function (state, req)
req = kres.request_t(req)
local qry = req:current()
-- Don't do anything for priming, prefetching, etc.
-- TODO: not all cases detected ATM.
......
......@@ -3,17 +3,14 @@ M.layer = {}
local ffi = require('ffi')
function M.layer.finish(state, req, pkt)
local kreq = kres.request_t(req)
if bit.band(state, kres.DONE) == 0 then
return state end -- not resolved yet, exit
local qry = kreq:resolved()
local qry = req:resolved()
if qry.parent ~= nil then
return state end -- an internal query, exit
local kpkt = kres.pkt_t(pkt)
if not (kpkt:qtype() == kres.type.A or kpkt:qtype() == kres.type.AAAA) then
if not (pkt:qtype() == kres.type.A or pkt:qtype() == kres.type.AAAA) then
return state end
-- fast filter by the length of the first label
......@@ -33,7 +30,7 @@ function M.layer.finish(state, req, pkt)
end
if not keytag then return state end
if kreq.rank ~= ffi.C.KR_RANK_SECURE or kreq.answer:cd() then
if req.rank ~= ffi.C.KR_RANK_SECURE or req.answer:cd() then
if verbose() then
log('[ta_sentinel] name+type OK but not AD+CD conditions')
end
......@@ -78,9 +75,9 @@ function M.layer.finish(state, req, pkt)
end
if sentype ~= found then -- expected key is not there, or unexpected key is there
kpkt:clear_payload()
kpkt:rcode(kres.rcode.SERVFAIL)
kpkt:ad(false)
pkt:clear_payload()
pkt:rcode(kres.rcode.SERVFAIL)
pkt:ad(false)
end
return state -- do not break resolution process
end
......
......@@ -51,7 +51,6 @@ end
-- act on DNSKEY queries which were not answered from cache
function M.layer.consume(state, req, _)
req = kres.request_t(req)
local qry = req:current()
if qry.stype == kres.type.DNSKEY and not qry.flags.CACHED then
send_ta_query(qry:name())
......
......@@ -237,7 +237,7 @@ local function refresh_plan(keyset, delay)
resolve(owner_str, kres.type.DNSKEY, kres.class.IN, 'NO_CACHE',
function (pkt)
-- Schedule itself with updated timeout
local delay_new = active_refresh(keyset, kres.pkt_t(pkt))
local delay_new = active_refresh(keyset, pkt)
delay_new = keyset.refresh_time or ta_update.refresh_time or delay_new
log('[ta_update] next refresh for ' .. owner_str .. ' in '
.. delay_new/hour .. ' hours')
......
......@@ -109,7 +109,6 @@ view.layer = {
-- Don't act on "resolved" cases.
if bit.band(state, bit.bor(kres.FAIL, kres.DONE)) ~= 0 then return state end
req = kres.request_t(req)
evaluate(state, req)
return req.state
end
......
......@@ -22,7 +22,6 @@ end
-- Just listing the *.in-addr.arpa suffixes would be tedious, as there are many.
M.layer = {
produce = function (state, req)
req = kres.request_t(req)
local qry = req:current()
if qry.stype ~= kres.type.PTR
or bit.band(state, bit.bor(kres.FAIL, kres.DONE)) ~= 0
......
......@@ -10,8 +10,6 @@ option("ALWAYS_CUT", true)
%s
return resolve("%s", kres.type.%s, kres.class.%s, 0,
function (pkt, req)
pkt = kres.pkt_t(pkt)
req = kres.request_t(req)
local ok, err = pcall(function () %s end)
if not ok then
print(err)
......
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