]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
policy.rpz: support local data with larger RRsets
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 30 Jun 2020 14:11:18 +0000 (16:11 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 30 Jun 2020 16:28:15 +0000 (18:28 +0200)
modules/policy/policy.lua
modules/policy/policy.rpz.test.lua
modules/policy/policy.test.rpz

index e839f1abc3ab984e0a7e7e5d7812a02ece0134fc..070b2c08b6ba08702ca4bbf8c421addad849646a 100644 (file)
@@ -445,7 +445,20 @@ local function rpz_parse(action, path)
                                                path, tonumber(parser.line_counter), kres.tostring.type[parser.r_type])
                                elseif is_bad == nil then
                                        if new_actions[name] == nil then new_actions[name] = {} end
-                                       new_actions[name][parser.r_type] = { ttl=parser.r_ttl, rdata=rdata }
+                                       local act = new_actions[name][parser.r_type]
+                                       if act == nil then
+                                               new_actions[name][parser.r_type] = { ttl=parser.r_ttl, rdata=rdata }
+                                       else -- mutiple RRs: no reordering or deduplication
+                                               if type(act.rdata) ~= 'table' then
+                                                       act.rdata = { act.rdata }
+                                               end
+                                               table.insert(act.rdata, rdata)
+                                               if parser.r_ttl ~= act.ttl then -- be conservative
+                                                       log('[poli] RPZ %s:%d warning: different TTLs in a set (minimum taken)',
+                                                               path, tonumber(parser.line_counter))
+                                                       act.ttl = math.min(act.ttl, parser.r_ttl)
+                                               end
+                                       end
                                else
                                        assert(is_bad == false and prefix_labels == 0)
                                end
index 761282fb6db75f194bd4703ccf234416cb30573e..047b27f5cd1fb069da3754a97413e03e40f41607 100644 (file)
@@ -39,6 +39,9 @@ local function test_rpz()
                'case.sensitive.', kres.type.A, kres.rcode.NOERROR, '192.168.8.8')
        check_answer('"A 192.168.8.8" and domain with uppercase and lowercase letters',
                'CASe.SENSItivE.', kres.type.A, kres.rcode.NOERROR, '192.168.8.8')
+       check_answer('two AAAA records',
+               'two.records.', kres.type.AAAA, kres.rcode.NOERROR,
+               {'2001:db8::2', '2001:db8::1'})
 end
 
 net.ipv4 = false
index 8c07efc2e1fb182f5f9c8e6aab3509c2a46b9137..80b7106f40170b44e2773e1ed62def6181d7c124 100644 (file)
@@ -13,3 +13,6 @@ rra-zonename-suffix                   A       192.168.6.6
 testdomain.rra.testdomain.     A       192.168.7.7
 CaSe.SeNSiTiVe         A       192.168.8.8
 
+two.records            AAAA    2001:db8::2
+two.records            AAAA    2001:db8::1
+