The issue is not now; it has always been broken in 6.x.
The model is that at most one view applies on any request.
If we need to do more things, they must happen as one meta-action.
test_view_insert_action(): dropped; can't see a suitable replacement
{%- endfor -%}
{%- endmacro -%}
-{% macro view_insert_action(view, subnet, action) -%}
-assert(C.kr_view_insert_action('{{ subnet }}', '{{ view.dst_subnet or '' }}',
- {{ get_proto_set(view.protocols) }}, {{ action }})==0)
-{%- endmacro %}
-
{% macro view_flags(options) -%}
{% if not options.minimize -%}
"NO_MINIMIZE",
{% from 'macros/common_macros.lua.j2' import quotes %}
-{% from 'macros/view_macros.lua.j2' import view_insert_action, view_flags, view_answer %}
+{% from 'macros/view_macros.lua.j2' import get_proto_set, view_flags, view_answer %}
{% from 'macros/policy_macros.lua.j2' import policy_flags, policy_tags_assign %}
{% if cfg.views %}
{% for view in cfg.views %}
{% for subnet in view.subnets %}
-{% if view.tags -%}
-{{ view_insert_action(view, subnet, policy_tags_assign(view.tags)) }}
-{% elif view.answer %}
-{{ view_insert_action(view, subnet, view_answer(view.answer)) }}
+assert(C.kr_view_insert_action('{{ subnet }}', '{{ view.dst_subnet or '' }}',
+ {{ get_proto_set(view.protocols) }}, policy.COMBINE({
+{%- set flags = view_flags(view.options) -%}
+{% if flags %}
+ {{ quotes(policy_flags(flags)) }},
{%- endif %}
-{%- set flags = view_flags(view.options) -%}
-{% if flags -%}
-{{ view_insert_action(view, subnet, quotes(policy_flags(flags))) }}
+{% if view.tags %}
+ {{ policy_tags_assign(view.tags) }},
+{% elif view.answer %}
+ {{ view_answer(view.answer) }},
{%- endif %}
+ })) == 0)
{% endfor %}
{% endfor %}
def _validate(self) -> None:
if bool(self.tags) == bool(self.answer):
- raise ValueError("only one of 'tags' and 'answer' options must be configured")
+ raise ValueError("exactly one of 'tags' and 'answer' must be configured")
from knot_resolver_manager.datamodel.view_schema import ViewOptionsSchema, ViewSchema
-def test_view_insert_action():
- subnet = "10.0.0.0/8"
- action = "policy.DENY"
- tmpl_str = """{% from 'macros/view_macros.lua.j2' import view_insert_action %}
-{{ view_insert_action(subnet, action) }}"""
-
- tmpl = template_from_str(tmpl_str)
- assert tmpl.render(subnet=subnet, action=action) == f"assert(C.kr_view_insert_action('{ subnet }',{ action })==0)"
-
-
def test_view_flags():
tmpl_str = """{% from 'macros/view_macros.lua.j2' import view_flags %}
{{ view_flags(options) }}"""
return 'policy.tags_assign_bitmap(' .. tostring(bitmap) .. ')'
end
+-- Perform a list of actions sequentially; meant for kr_view_insert_action().
+function policy.COMBINE(list)
+ if #list == 1 then return list[1] end
+ local r = 'function(state,req) '
+ for _, item in ipairs(list) do
+ r = r .. item .. '(state,req); '
+ end
+ return r .. 'end'
+end
+
--[[ Insert a forwarding rule, i.e. override upstream for one DNS subtree.
Throws lua exceptions when detecting something fishy.