]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
policy docs: replace incorrect example
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 24 Apr 2018 14:14:29 +0000 (16:14 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 9 May 2018 15:02:28 +0000 (17:02 +0200)
The example didn't work and I don't immediately see how to quickly fix
it, so let's have another more complex example instead (fished from an
older forum post of mine).

modules/policy/README.rst

index 034aeba844683e60fe770b3530341d061bce2581..73d8feebe1092491a19a5f59f58637b4271653c1 100644 (file)
@@ -108,12 +108,23 @@ Policy examples
        policy.add(policy.pattern(policy.PASS, '\4www[0-9]\6badboy\2cz'))
        -- Block all names below badboy.cz
        policy.add(policy.suffix(policy.DENY, {todname('badboy.cz.')}))
+
        -- Custom rule
-       policy.add(function (req, query)
-               if query:qname():find('%d.%d.%d.224\7in-addr\4arpa') then
-                       return policy.DENY
+       local ffi = require('ffi')
+       local function genRR (state, req)
+               local answer = req.answer
+               local qry = req:current()
+               if qry.stype ~= kres.type.A then
+                       return state
                end
-       end)
+               ffi.C.kr_pkt_make_auth_header(answer)
+               answer:rcode(kres.rcode.NOERROR)
+               answer:begin(kres.section.ANSWER)
+               answer:put(qry.sname, 900, answer:qclass(), kres.type.A, '\192\168\1\3')
+               return kres.DONE
+       end
+       policy.add(policy.suffix(genRR, { todname('my.example.cz.') }))
+
        -- Disallow ANY queries
        policy.add(function (req, query)
                if query.stype == kres.type.ANY then