]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
kres: added rr:rdcount() and tests
authorMarek Vavruša <marek@vavrusa.com>
Thu, 15 Mar 2018 21:38:43 +0000 (14:38 -0700)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 23 Apr 2018 12:34:40 +0000 (14:34 +0200)
daemon/lua/kres.lua
tests/config/basic.test.lua

index f7e0e18882247128944270017f87d0c1481069f5..78c85569681d5c11572c814be8380c01f2ff33b1 100644 (file)
@@ -256,7 +256,7 @@ end
 -- RR sets created in Lua must have a destructor to release allocated memory
 local function rrset_free(rr)
        if rr._owner ~= nil then ffi.C.free(rr._owner) end
-       if rr.rrs.rr_count > 0 then ffi.C.free(rr.rrs.data) end
+       if rr:rdcount() > 0 then ffi.C.free(rr.rrs.data) end
 end
 
 -- Metatype for RR set.  Beware, the indexing is 0-based (rdata, get, tostring).
@@ -311,7 +311,7 @@ ffi.metatype( knot_rrset_t, {
                end,
                tostring = function(rr, i)
                        assert(ffi.istype(knot_rrset_t, rr))
-                       if rr.rrs.rr_count > 0 then
+                       if rr:rdcount() > 0 then
                                local ret
                                if i ~= nil then
                                        ret = knot.knot_rrset_txt_dump_data(rr, i, rrset_buf, rrset_buflen, knot.KNOT_DUMP_STYLE_DEFAULT)
@@ -339,6 +339,11 @@ ffi.metatype( knot_rrset_t, {
                        C.free(dump[0])
                        return result
                end,
+               -- Return RDATA count for this RR set
+               rdcount = function(rr)
+                       assert(ffi.istype(knot_rrset_t, rr))
+                       return tonumber(rr.rrs.rr_count)
+               end,
                -- Add binary RDATA to the RR set
                add_rdata = function (rr, rdata, rdlen, ttl)
                        assert(ffi.istype(knot_rrset_t, rr))
@@ -528,7 +533,7 @@ ffi.metatype( knot_pkt_t, {
                        local section = knot.knot_pkt_section(pkt, section_id)
                        for i = 1, section.count do
                                local rrset = knot.knot_pkt_rr(section, i - 1)
-                               for k = 1, rrset.rrs.rr_count do
+                               for k = 1, rrset:rdcount() do
                                        table.insert(records, rrset:get(k - 1))
                                end
                        end
index 298fb5dc808f6aea676dbba3e453962c5dc4ecf0..47a06919a0079828e4d75d045e287fd43fb5d360 100644 (file)
@@ -52,6 +52,7 @@ local function test_rrset_functions()
        -- create a dummy rrsig
        local rrsig = kres.rrset(todname('com.'), kres.type.RRSIG, kres.class.IN)
        rrsig:add_rdata('\0\1', 2, 0)
+       same(rr:rdcount(), 1, 'add_rdata really added RDATA')
        -- check rrsig matching
        same(rr.type, rrsig:type_covered(), 'rrsig type covered matches covered RR type')
        ok(rr:is_covered_by(rrsig), 'rrsig is covering a record')
@@ -59,6 +60,7 @@ local function test_rrset_functions()
        local copy = kres.rrset(rr:owner(), rr.type)
        ok(copy:add_rdata('\4\3\2\1', 4, 66), 'adding second RDATA works')
        ok(rr:merge_rdata(copy), 'merge_rdata works')
+       same(rr:rdcount(), 2, 'RDATA count is correct after merge_rdata')
        expect = 'com.                  66      A       1.2.3.4\n' ..
                 'com.                  66      A       4.3.2.1\n'
        same(rr:txt_dump(), expect, 'merge_rdata actually merged RDATA')