From 2e193a1509c5be794f918829206f44baf3663b63 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ale=C5=A1=20Mr=C3=A1zek?= Date: Thu, 6 Apr 2023 15:28:50 +0200 Subject: [PATCH] manager: datamodel: template/macros for local_data_schema --- .../datamodel/templates/config.lua.j2 | 12 +++--- .../datamodel/templates/local_data.lua.j2 | 39 +++++++++++++++++++ .../templates/macros/local_data_macros.lua.j2 | 7 ++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 manager/knot_resolver_manager/datamodel/templates/macros/local_data_macros.lua.j2 diff --git a/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 b/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 index 3b51bea77..bb7e5e341 100644 --- a/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 +++ b/manager/knot_resolver_manager/datamodel/templates/config.lua.j2 @@ -12,6 +12,9 @@ nsid.name('{{ cfg.nsid }}_' .. worker.id) -- LOGGING section ---------------------------------- {% include "logging.lua.j2" %} +-- MONITORING section ------------------------------- +{% include "monitoring.lua.j2" %} + -- WEBMGMT section ---------------------------------- {% include "webmgmt.lua.j2" %} @@ -24,8 +27,8 @@ nsid.name('{{ cfg.nsid }}_' .. worker.id) -- VIEWS section ------------------------------------ {# {% include "views.lua.j2" %} #} --- LOCAL-DATA section ----------------------------- -{% include "local_data.lua.j2" %} +-- LOCAL-DATA section ------------------------------- +{# {% include "local_data.lua.j2" %} #} -- SLICES section ----------------------------------- {# {% include "slices.lua.j2" %} #} @@ -36,7 +39,7 @@ nsid.name('{{ cfg.nsid }}_' .. worker.id) -- RPZ section -------------------------------------- {# {% include "rpz.lua.j2" %} #} --- FORWARD section ---------------------------- +-- FORWARD section ---------------------------------- {% include "forward.lua.j2" %} -- CACHE section ------------------------------------ @@ -61,6 +64,3 @@ nsid.name('{{ cfg.nsid }}_' .. worker.id) {% if cfg.lua.script %} {{ cfg.lua.script }} {% endif %} - --- manager's monitoring configuration -{% include "monitoring.lua.j2" %} \ No newline at end of file diff --git a/manager/knot_resolver_manager/datamodel/templates/local_data.lua.j2 b/manager/knot_resolver_manager/datamodel/templates/local_data.lua.j2 index e69de29bb..dbab321d7 100644 --- a/manager/knot_resolver_manager/datamodel/templates/local_data.lua.j2 +++ b/manager/knot_resolver_manager/datamodel/templates/local_data.lua.j2 @@ -0,0 +1,39 @@ +{% from 'macros/common_macros.lua.j2' import string_table %} +{% from 'macros/policy_macros.lua.j2' import policy_get_tagset, policy_todname %} +{% from 'macros/local_data_macros.lua.j2' import local_data_emptyzone, local_data_nxdomain %} + +local C = require('ffi').C + + +{# TODO: implemented all other options/features from local_data_schema #} + + +{% for subtree in cfg.local_data.subnets %} + +{# IF subtree.roots is not None #} +{% if subtree.roots -%} +{%- for root in subtree.roots -%} + + +{% if subtree.type == 'empty' -%} +{{ local_data_emptyzone(policy_todname(root), policy_get_tagset(string_table(subtree.tags))) }} +{%- elif subtree.type == 'nxdomain' -%} +{{ view_insert_action(policy_todname(root), policy_get_tagset(string_table(subtree.tags))) }} +{% else %} +{# TODO: implement other possible types #} +{%- endif %} + +{%- endfor -%} +{%- endif %} + +{# IF subtree.roots_file is not None #} +{% if subtree.roots_file -%} +{# TODO: not implemented yet #} +{%- endif %} + +{# IF subtree.roots_url is not None #} +{% if subtree.roots_url -%} +{# TODO: not implemented yet #} +{%- endif %} + +{% endfor %} diff --git a/manager/knot_resolver_manager/datamodel/templates/macros/local_data_macros.lua.j2 b/manager/knot_resolver_manager/datamodel/templates/macros/local_data_macros.lua.j2 new file mode 100644 index 000000000..cee9fcdc5 --- /dev/null +++ b/manager/knot_resolver_manager/datamodel/templates/macros/local_data_macros.lua.j2 @@ -0,0 +1,7 @@ +{% macro local_data_emptyzone(dname, tags) -%} +assert(C.kr_rule_local_data_emptyzone({{ dname }},{{ tags }})==0) +{%- endmacro %} + +{% macro local_data_nxdomain(dname, tags) -%} +assert(C.kr_rule_local_data_nxdomain({{ dname }},{{ tags }})==0) +{%- endmacro %} -- 2.47.3