diff options
author | Vladimír Čunát <vladimir.cunat@nic.cz> | 2022-07-04 13:35:50 +0200 |
---|---|---|
committer | Vladimír Čunát <vladimir.cunat@nic.cz> | 2023-06-12 10:32:28 +0200 |
commit | 2f51749d2b5614c8ee4e90c1ca0bb5d69c18e5d5 (patch) | |
tree | 71917d6646b904656befcc88f4ad69b507792832 /modules | |
parent | lib/rules: add basic view capability (diff) | |
download | knot-resolver-2f51749d2b5614c8ee4e90c1ca0bb5d69c18e5d5.tar.xz knot-resolver-2f51749d2b5614c8ee4e90c1ca0bb5d69c18e5d5.zip |
lib/rules: add usable tagging
Diffstat (limited to 'modules')
-rw-r--r-- | modules/policy/policy.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/modules/policy/policy.lua b/modules/policy/policy.lua index 1990837a..cc77e487 100644 --- a/modules/policy/policy.lua +++ b/modules/policy/policy.lua @@ -834,6 +834,29 @@ end policy.rules = {} policy.postrules = {} +-- This certainly isn't perfect, but it allows lua config like: +-- kr_view_insert_action('127.0.0.0/24', policy.TAGS_ASSIGN({'t01', 't02'})) +local kr_rule_tags_t = ffi.typeof('kr_rule_tags_t[1]') +function policy.get_tagset(names) + local result = ffi.new(kr_rule_tags_t, 0) + for _, name in pairs(names) do + if ffi.C.kr_rule_tag_add(name, result) ~= 0 then + error('converting tagset failed') + end + end + return result[0] -- it's atomic value fortunately +end +function policy.tags_assign_bitmap(bitmap) + return function (_, req) + req.rule_tags = bitmap + end +end +function policy.TAGS_ASSIGN(names) + local bitmap = policy.get_tagset(names) + return 'policy.tags_assign_bitmap(' .. tostring(bitmap) .. ')' +end + + local view_action_buf = ffi.new('knot_db_val_t[1]') -- Top-down policy list walk until we hit a match |