From d99afffe8d374d4b6cb2ef74995bf2bb2ce729ce Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Vavru=C5=A1a?= Date: Tue, 2 Jan 2018 15:03:22 -0800 Subject: [PATCH] support text conversion of unknown RR types --- daemon/lua/kres.lua | 9 +++++++++ tests/config/basic_test.lua | 1 + 2 files changed, 10 insertions(+) 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') -- 2.47.2