Commit 0bd0793f authored by Vladimír Čunát's avatar Vladimír Čunát

lua: finish fixing the mess around passing rdata

parent 9f59520a
......@@ -349,7 +349,7 @@ ffi.metatype( knot_rrset_t, {
ttl or 0)
return ffi.gc(rr, rrset_free)
end,
-- beware: `owner` and `rdata` are typed as a plain lua strings
-- BEWARE: `owner` and `rdata` are typed as a plain lua strings
-- and not the real types they represent.
__tostring = function(rr)
assert(ffi.istype(knot_rrset_t, rr))
......@@ -371,13 +371,17 @@ ffi.metatype( knot_rrset_t, {
end
return tonumber(rr.rclass)
end,
rdata_pt = function(rr, i)
assert(ffi.istype(knot_rrset_t, rr) and i >= 0 and i < rr:rdcount())
return knot.knot_rdataset_at(rr.rrs, i)
end,
rdata = function(rr, i)
assert(ffi.istype(knot_rrset_t, rr))
local rdata = knot.knot_rdataset_at(rr.rrs, i)
return ffi.string(rdata.data, rdata.len)
local rd = rr:rdata_pt(i)
return ffi.string(rd.data, rd.len)
end,
get = function(rr, i)
assert(ffi.istype(knot_rrset_t, rr))
assert(ffi.istype(knot_rrset_t, rr) and i >= 0 and i < rr:rdcount())
return {owner = rr:owner(),
ttl = rr:ttl(),
class = tonumber(rr.rclass),
......@@ -385,7 +389,8 @@ ffi.metatype( knot_rrset_t, {
rdata = rr:rdata(i)}
end,
tostring = function(rr, i)
assert(ffi.istype(knot_rrset_t, rr))
assert(ffi.istype(knot_rrset_t, rr)
and (i == nil or (i >= 0 and i < rr:rdcount())) )
if rr:rdcount() > 0 then
local ret
if i ~= nil then
......@@ -480,14 +485,17 @@ local function pkt_bit(pkt, byteoff, bitmask, val)
end
local function knot_pkt_rr(section, i)
assert(section and ffi.istype('knot_pktsection_t', section))
return section.pkt.rr + section.pos + i;
assert(section and ffi.istype('knot_pktsection_t', section)
and i >= 0 and i < section.count)
local ret = section.pkt.rr + section.pos + i
assert(ffi.istype(knot_rrset_pt, ret))
return ret
end
-- Helpers for converting packet to text
local function section_tostring(pkt, section_id)
local data = {}
local section = pkt.sections[section_id]
local section = pkt.sections + section_id
if section.count > 0 then
table.insert(data, string.format('\n;; %s\n', const_section_str[section_id]))
for j = 0, section.count - 1 do
......@@ -603,17 +611,17 @@ ffi.metatype( knot_pkt_t, {
rrsets = function (pkt, section_id)
assert(ffi.istype(knot_pkt_t, pkt))
local records = {}
local section = pkt.sections[section_id]
local section = pkt.sections + section_id
for i = 1, section.count do
local rrset = knot_pkt_rr(section, i - 1)
table.insert(records, ffi.cast(knot_rrset_pt, rrset))
table.insert(records, rrset)
end
return records
end,
section = function (pkt, section_id)
assert(ffi.istype(knot_pkt_t, pkt))
local records = {}
local section = pkt.sections[section_id]
local section = pkt.sections + section_id
for i = 1, section.count do
local rrset = knot_pkt_rr(section, i - 1)
for k = 1, rrset:rdcount() do
......
......@@ -4,8 +4,6 @@ local ffi = require('ffi')
local mod = {}
local event_id = nil
local knot_rdata_pt = ffi.typeof('knot_rdata_t *');
-- Resolve callback
-- Check time validity of RRSIGs in priming query
-- luacheck: no unused args
......@@ -24,10 +22,11 @@ local function check_time_callback(pkt, req)
local expiration = 0
for i = 1, #section do
local rr = section[i]
assert(rr.type)
if rr.type == kres.type.RRSIG then
for k = 0, rr.rrs.count - 1 do
seen_rrsigs = seen_rrsigs + 1
local rdata = ffi.cast(knot_rdata_pt, rr:rdata(k));
local rdata = rr:rdata_pt(k)
inception = ffi.C.kr_rrsig_sig_inception(rdata)
expiration = ffi.C.kr_rrsig_sig_expiration(rdata)
if now > expiration then
......
......@@ -12,8 +12,6 @@ internal.to_resolve = 0 -- number of pending queries to A or AAAA
internal.prime = {} -- function triggering priming query
internal.event = nil -- stores event id
local knot_rdata_pt = ffi.typeof('knot_rdata_t *');
-- Copy hints from nsset table to resolver engine
-- These addresses replace root hints loaded by default from file.
-- They are stored outside cache and cache flush will not affect them.
......@@ -21,9 +19,9 @@ local function publish_hints(nsset)
local roothints = kres.context().root_hints
-- reset zone cut and clear address list
ffi.C.kr_zonecut_set(roothints, kres.str2dname("."))
for dname, addresses in pairs(nsset) do
for _, rdata_addr in pairs(addresses) do
ffi.C.kr_zonecut_add(roothints, dname, ffi.cast(knot_rdata_pt, rdata_addr))
for dname, addrsets in pairs(nsset) do
for i = 0, addrsets:rdcount() - 1 do
ffi.C.kr_zonecut_add(roothints, dname, addrsets:rdata_pt(i))
end
end
end
......@@ -31,8 +29,8 @@ end
-- Count A and AAAA addresses in nsset
local function count_addresses(nsset)
local count = 0
for _, addresses in pairs(nsset) do
count = count + #addresses
for _, addrset in pairs(nsset) do
count = count + addrset:rdcount()
end
return count
end
......@@ -49,11 +47,16 @@ local function address_callback(pkt, req)
else
local section = pkt:rrsets(kres.section.ANSWER)
for i = 1, #section do
local rr = section[i]
if rr.type == kres.type.A or rr.type == kres.type.AAAA then
for k = 0, rr.rrs.count-1 do
table.insert(internal.nsset[rr:owner()], rr:rdata(k))
local rrset_new = section[i]
if rrset_new.type == kres.type.A or rrset_new.type == kres.type.AAAA then
local owner = rrset_new:owner()
local rrset_comb = internal.nsset[owner]
if rrset_comb == nil then
rrset_comb = kres.rrset(nil, rrset_new.type)
internal.nsset[owner] = rrset_comb
end
assert(ffi.istype(kres.rrset, rrset_new))
rrset_comb:merge_rdata(rrset_new)
end
end
end
......@@ -92,8 +95,6 @@ local function priming_callback(pkt, req)
internal.to_resolve = internal.to_resolve + 2 * rr.rrs.count
for k = 0, rr.rrs.count-1 do
local nsname_text = rr:tostring(k)
local nsname_wire = rr:rdata(k) -- FIXME: something is wrong
internal.nsset[nsname_wire] = {}
resolve(nsname_text, kres.type.A, kres.class.IN, 0, address_callback)
resolve(nsname_text, kres.type.AAAA, kres.class.IN, 0, address_callback)
end
......
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