summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorVladimír Čunát <vladimir.cunat@nic.cz>2024-07-25 14:27:04 +0200
committerVladimír Čunát <vladimir.cunat@nic.cz>2024-08-13 14:08:46 +0200
commit1764752eebf5d025cd39cb4cc2f0f61beb586b55 (patch)
treebbaaa9e55aea318e39a972f2e99b8f8575eff7ac /modules
parentMerge !1585: daemon,lib: sync EDE codes supported by libknot 3.3 (diff)
downloadknot-resolver-1764752eebf5d025cd39cb4cc2f0f61beb586b55.tar.xz
knot-resolver-1764752eebf5d025cd39cb4cc2f0f61beb586b55.zip
views: improve interaction with old-style policies
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.
Diffstat (limited to 'modules')
-rw-r--r--modules/policy/policy.lua12
1 files changed, 10 insertions, 2 deletions
diff --git a/modules/policy/policy.lua b/modules/policy/policy.lua
index 60b03478..f599e7d1 100644
--- a/modules/policy/policy.lua
+++ b/modules/policy/policy.lua
@@ -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