From: Marek VavruĊĦa Date: Tue, 2 Jan 2018 23:03:22 +0000 (-0800) Subject: support text conversion of unknown RR types X-Git-Tag: v2.0.0~46^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d99afffe8d374d4b6cb2ef74995bf2bb2ce729ce;p=thirdparty%2Fknot-resolver.git support text conversion of unknown RR types --- diff --git a/daemon/lua/kres.lua b/daemon/lua/kres.lua index 205f10ba1..8578b057b 100644 --- a/daemon/lua/kres.lua +++ b/daemon/lua/kres.lua @@ -203,6 +203,15 @@ setmetatable(const_type, { end }) +-- Metatype for RR types to allow anonymous string types +setmetatable(const_type_str, { + __index = function (t, k) + local v = rawget(t, k) + if v then return v end + return string.format('TYPE%d', k) + end +}) + -- Metatype for sockaddr local addr_buf = ffi.new('char[16]') local sockaddr_t = ffi.typeof('struct sockaddr') diff --git a/tests/config/basic_test.lua b/tests/config/basic_test.lua index b929bfe5d..df4fff710 100644 --- a/tests/config/basic_test.lua +++ b/tests/config/basic_test.lua @@ -10,6 +10,7 @@ local function test_constants() -- Test inverset tables to convert constants to text same(kres.tostring.class[1], 'IN', 'text class constants work') same(kres.tostring.type[2], 'NS', 'text record type constants work') + same(kres.tostring.type[65535], 'TYPE65535', 'text record type undefined constants work') same(kres.tostring.section[0], 'ANSWER', 'text section constants work') same(kres.tostring.rcode[2], 'SERVFAIL', 'text rcode constants work') same(kres.tostring.opcode[5], 'UPDATE', 'text opcode constants work')