]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
policy.ANSWER: allow multiple RRs
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 30 Jun 2020 13:45:08 +0000 (15:45 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 30 Jun 2020 16:28:15 +0000 (18:28 +0200)
... by allowing .rdata to be a table.  Larger RRsets seem useful.

modules/policy/README.rst
modules/policy/policy.lua

index f0ff3540709bd3bb0341473e1bee8c878254f2e8..c93e725cb491641606a045aa63990e2d35ad9ec2 100644 (file)
@@ -148,11 +148,11 @@ Following actions stop the policy matching on the query, i.e. other rules are no
 
 .. function:: ANSWER({ type = { ttl=ttl, rdata=data} }, nodata)
 
-   Overwrite rr data in response. ``rdata`` takes just IP address. If `nodata` is `true` policy return `NODATA` when requested type from client isn't specified (default: ``nodata=false``).
+   Overwrite rr data in response. ``rdata`` takes just IP address or a lua list of addresses. If `nodata` is `true` policy return `NODATA` when requested type from client isn't specified (default: ``nodata=false``).
 
    .. code-block:: lua
 
-       -- this policy changes IPv4 adress and TTL for `exmaple.com`
+       -- this policy changes IPv4 adress and TTL for `example.com`
        policy.add(policy.suffix(policy.ANSWER({ [kres.type.A] = { ttl=300, rdata='\192\0\2\7' } }), { todname('example.com') }))
 
 More complex non-chain actions are described in their own chapters, namely:
index 1bb528d53e29196de52186a82f49303fcd4c6299..e839f1abc3ab984e0a7e7e5d7812a02ece0134fc 100644 (file)
@@ -228,7 +228,13 @@ function policy.ANSWER(rtable, nodata)
 
                        answer:rcode(kres.rcode.NOERROR)
                        answer:begin(kres.section.ANSWER)
-                       answer:put(qry.sname, ttl, qry.sclass, qry.stype, data.rdata)
+                       if type(data.rdata) == 'table' then
+                               for _, rdato in ipairs(data.rdata) do
+                                       answer:put(qry.sname, ttl, qry.sclass, qry.stype, rdato)
+                               end
+                       else
+                               answer:put(qry.sname, ttl, qry.sclass, qry.stype, data.rdata)
+                       end
 
                        return kres.DONE
                end