]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
views: improve interaction with old-style policies docs-develop-view-dyr92b/deployments/4866
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 25 Jul 2024 12:27:04 +0000 (14:27 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 13 Aug 2024 12:08:46 +0000 (14:08 +0200)
i.e. respect the old chain-rule notion in this case.
... because why not, and someone wanted to use it this way already.

Logically it makes sense in some cases, but I still implore to prefer
6.x -style rules where possible, as e.g. the interations are better.

NEWS
modules/policy/policy.lua

diff --git a/NEWS b/NEWS
index 92ebe3062ae263abcdc9260ea3598691bad5ceb1..a9540326384758fea834ee54f4f0e212f0a130b8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Improvements
   This means that the workers will be able to resume each other's TLS sessions, regardless of whether the user has configured it to do so.
 
 - answer NOTIMPL for meta-types and non-IN RR classes (!1589)
+- views: improve interaction with old-style policies (!1576)
 
 Bugfixes
 --------
index 60b034783aed70ecf6b43b95c425b5b896653ab9..f599e7d1a8c6d04506efcafd27d39dad6b0f0ddc 100644 (file)
@@ -857,10 +857,14 @@ function policy.TAGS_ASSIGN(names)
 end
 
 -- Perform a list of actions sequentially; meant for kr_view_insert_action().
+-- Return value of the last one is propagated.
 function policy.COMBINE(list)
        if #list == 1 then return list[1] end
        local r = 'function(state,req) '
-               for _, item in ipairs(list) do
+               for i, item in ipairs(list) do
+                       if i == #list then
+                               r = r .. 'return '
+                       end
                        r = r .. item .. '(state,req); '
                end
        return r .. 'end'
@@ -934,7 +938,11 @@ policy.layer = {
 
                if ffi.C.kr_view_select_action(req, view_action_buf) == 0 then
                        local act_str = ffi.string(view_action_buf[0].data, view_action_buf[0].len)
-                       return loadstring('return '..act_str)()(state, req)
+                       local new_state = loadstring('return '..act_str)()(state, req)
+                       -- We still respect the chain-rule notion, i.e. we skip
+                       -- lua-configured policy rules iff the action was "final"
+                       -- (`refused` and `noanswer` in the current 6.x)
+                       if new_state ~= nil then return new_state end
                end
 
                local qry = req:initial() -- same as :current() but more descriptive