]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
datamodel: templates: refactoring, clear code
authorAleš <ales.mrazek@nic.cz>
Mon, 29 Nov 2021 18:14:53 +0000 (19:14 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 8 Apr 2022 14:17:53 +0000 (16:17 +0200)
manager/knot_resolver_manager/datamodel/templates/config.lua.j2
manager/knot_resolver_manager/datamodel/templates/dns64.lua.j2 [new file with mode: 0644]
manager/knot_resolver_manager/datamodel/templates/dnssec.lua.j2
manager/knot_resolver_manager/datamodel/templates/network.lua.j2
manager/knot_resolver_manager/datamodel/templates/options.lua.j2
manager/knot_resolver_manager/datamodel/templates/server.lua.j2
manager/knot_resolver_manager/datamodel/templates/static_hints.lua.j2

index bfb311182b8b45a2f2aa42dd8263176647fe2221..836de89710b8c9eaa141cc3a6483873a1fa8a789 100644 (file)
@@ -1,31 +1,17 @@
 {% if not cfg.lua.script_only %}
 
--- MODULES
-modules = {
-    {{ "'rebinding < iterate'," if cfg.options.rebinding_protection }}
-    {{ "'workarounds < iterate'," if cfg.options.violators_workarounds }}
-    {{ "'serve_stale < cache'," if cfg.options.serve_stale }}
-    {{ "dns64 = '"+cfg.dns64.prefix+"'," if cfg.dns64 }}
-    'hints > iterate',
-{% if cfg.network.address_renumbering %}
--- network.address-renumbering
-    renumber = {
-{% for item in cfg.network.address_renumbering %}
-        {'{{ item.source }}', '{{ item.destination }}'},
-{% endfor %}
-    }
-{% endif %}
-}
+-- LOGGING section
+{% include "logging.lua.j2" %}
 
 -- SERVER section
 {% include "server.lua.j2" %}
 
--- NETWORK section
-{% include "network.lua.j2" %}
-
 -- OPTIONS section
 {% include "options.lua.j2" %}
 
+-- NETWORK section
+{% include "network.lua.j2" %}
+
 -- STATIC-HINTS section
 {% include "static_hints.lua.j2" %}
 
@@ -35,19 +21,19 @@ modules = {
 -- DNSSEC section
 {% include "dnssec.lua.j2" %}
 
--- LOGGING section
-{% include "logging.lua.j2" %}
+-- DNS64 section
+{% include "dns64.lua.j2" %}
 
 {% endif %}
 
 -- LUA section
+-- Custom Lua code cannot be validated
+
 {% if cfg.lua.script_file %}
 {% import cfg.lua.script_file as script_file %}
--- lua.script-file
 {{ script_file }}
 {% endif %}
 
 {% if cfg.lua.script %}
--- lua.script
 {{ cfg.lua.script }}
 {% endif %}
diff --git a/manager/knot_resolver_manager/datamodel/templates/dns64.lua.j2 b/manager/knot_resolver_manager/datamodel/templates/dns64.lua.j2
new file mode 100644 (file)
index 0000000..b5e774f
--- /dev/null
@@ -0,0 +1,7 @@
+{% if cfg.dns64 %}
+-- load dns64 module
+modules.load('dns64')
+
+-- dns64.prefix
+dns64.config('{{ cfg.dns64.prefix.to_std().network_address }}')
+{% endif %}
\ No newline at end of file
index 8d7008d64cf46db2be8a924210a0630a88edbbca..b26961bbec010547b7e2893d715803746f7b5d5a 100644 (file)
@@ -3,12 +3,34 @@
 trust_anchors.remove('.')
 {% endif %}
 
-{{ "modules.unload('ta_sentinel')" if not cfg.dnssec.trust_anchor_sentinel }}
-{{ "modules.unload('ta_signal_query')" if not cfg.dnssec.trust_anchor_signal_query }}
-{{ "modules.unload('detect_time_skew')" if not cfg.dnssec.time_skew_detection }}
+-- options.trust-anchor-sentinel
+{% if cfg.dnssec.trust_anchor_sentinel %}
+modules.load('ta_sentinel')
+{% else %}
+modules.unload('ta_sentinel')
+{% endif %}
+
+-- options.trust-anchor-signal-query
+{% if cfg.dnssec.trust_anchor_signal_query %}
+modules.load('ta_signal_query')
+{% else %}
+modules.unload('ta_signal_query')
+{% endif %}
 
+-- options.time-skew-detection
+{% if cfg.dnssec.time_skew_detection %}
+modules.load('detect_time_skew')
+{% else %}
+modules.unload('detect_time_skew')
+{% endif %}
+
+-- dnssec.keep-removed
 trust_anchors.keep_removed = {{ cfg.dnssec.keep_removed }}
-{{ "trust_anchors.refresh_time = "+cfg.dnssec.refresh_time.seconds()|string if cfg.dnssec.refresh_time }}
+
+{% if cfg.dnssec.refresh_time %}
+-- dnssec.refresh-time
+trust_anchors.refresh_time = {{ cfg.dnssec.refresh_time.seconds()|string  }}
+{% endif %}
 
 {% if cfg.dnssec.trust_anchors %}
 -- dnssec.trust-anchors
index 6cd91d57c2707c7198eaeafa50adc774fcb000f3..c023397881bd748c8ba3b7eb0088c04b05805739 100644 (file)
@@ -6,6 +6,7 @@ net.ipv6 = {{ 'true' if cfg.network.do_ipv6 else 'false' }}
 -- network.out-interface-v4
 net.outgoing_v4('{{ cfg.network.out_interface_v4 }}')
 {% endif %}
+
 {% if cfg.network.out_interface_v6 %}
 -- network.out-interface-v6
 net.outgoing_v6('{{ cfg.network.out_interface_v6 }}')
@@ -22,7 +23,10 @@ modules.unload('edns_keepalive')
 {% endif %}
 
 -- network.edns-buffer-size
-net.bufsize({{ cfg.network.edns_buffer_size.upstream.bytes() }}, {{ cfg.network.edns_buffer_size.downstream.bytes() }})
+net.bufsize(
+    {{ cfg.network.edns_buffer_size.upstream.bytes() }},
+    {{ cfg.network.edns_buffer_size.downstream.bytes() }}
+)
 
 {% if cfg.network.tls.cert_file and cfg.network.tls.key_file %}
 -- network.tls
index 3bac9d2bb89ce190fcffb86b13848c780516e67f..2996b63bb2e6aef83f275fffe830e982a6230f00 100644 (file)
@@ -1,11 +1,50 @@
 -- options.glue-checking
 mode('{{ cfg.options.glue_checking }}')
 
--- options
+{% if cfg.options.rebinding_protection %}
+-- options.rebinding-protection
+modules.load('rebinding < iterate')
+{% endif %}
+
+{% if cfg.options.violators_workarounds %}
+-- options.violators-workarounds
+modules.load('workarounds < iterate')
+{% endif %}
+
+{% if cfg.options.serve_stale %}
+-- options.serve-stale
+modules.load('serve_stale < cache')
+{% endif %}
+
+-- options.query-priming
+{% if cfg.options.query_priming %}
+modules.load('priming')
+{% else %}
+modules.unload('priming')
+{% endif %}
+
+-- options.time-jump-detection
+{% if cfg.options.time_jump_detection %}
+modules.load('detect_time_jump')
+{% else %}
+modules.unload('detect_time_jump')
+{% endif %}
+
+-- options.refuse-no-rd
+{% if cfg.options.refuse_no_rd %}
+modules.load('refuse_nord')
+{% else %}
+modules.unload('refuse_nord')
+{% endif %}
+
+-- options.qname-minimisation
 option('NO_MINIMIZE', {{ 'false' if cfg.options.qname_minimisation else 'true' }})
+
+-- options.query-loopback
 option('ALLOW_LOCAL', {{ 'true' if cfg.options.query_loopback else 'false' }})
+
+-- options.reorder-rrset
 option('REORDER_RR', {{ 'true' if cfg.options.reorder_rrset else 'false' }})
-option('NO_0X20', {{ 'false' if cfg.options.query_case_randomization else 'true' }})
-{{ "modules.unload('priming')" if not cfg.options.query_priming }}
-{{ "modules.unload('detect_time_jump')" if not cfg.options.time_jump_detection }}
-{{ "modules.unload('refuse_nord')" if not cfg.options.refuse_no_rd }}
+
+-- options.query-case-randomization
+option('NO_0X20', {{ 'false' if cfg.options.query_case_randomization else 'true' }})
\ No newline at end of file
index c01f05b07088ef1e4ee7d4f7fb9249e7081cea8c..49d89cfd34b2a1c40e92c25ad19f1f0cb28e01a1 100644 (file)
@@ -4,7 +4,7 @@ hostname('{{ cfg.server.hostname }}')
 {% if cfg.server.nsid %}
 -- server.nsid
 modules.load('nsid')
-nsid.name('{{ cfg.server.nsid }} ' .. worker.id)
+nsid.name('{{ cfg.server.nsid }}_' .. worker.id)
 {% endif %}
 
 {% if cfg.server.webmgmt %}
index e1d3bbae75dcb73665f521ae80c72895bf5360d3..eebdac993058c3bbdccff19f18ca95aad5497337 100644 (file)
@@ -1,7 +1,23 @@
-{{ "hints.ttl("+cfg.static_hints.ttl.seconds()|string+")" if cfg.static_hints.ttl }}
+{% if cfg.static_hints.etc_hosts or cfg.static_hints.root_hints_file or cfg.static_hints.hints_files or cfg.static_hints.root_hints or cfg.static_hints.hints %}
+modules.load('hints > iterate')
+
+{% if cfg.static_hints.ttl %}
+-- static-hints.ttl
+hints.ttl({{ cfg.static_hints.ttl.seconds()|string }})
+{% endif %}
+
+-- static-hints.no-data
 hints.use_nodata({{ 'true' if cfg.static_hints.no_data else 'false' }})
-{{ "hints.add_hosts()" if cfg.static_hints.etc_hosts }}
-{{ "hints.root_file('"+cfg.static_hints.root_hints_file+"')" if cfg.static_hints.root_hints_file }}
+
+{% if cfg.static_hints.etc_hosts %}
+-- static-hints.etc-hosts
+hints.add_hosts('/etc/hosts')
+{% endif %}
+
+{% if cfg.static_hints.root_hints_file %}
+-- static-hints.root-hints-file
+hints.root_file('{{ cfg.static_hints.root_hints_file }}')
+{% endif %}
 
 {% if cfg.static_hints.hints_files %}
 -- static-hints.hints-files
@@ -30,4 +46,6 @@ hints.root({
 hints.set('{{ name }} {{ addr }}')
 {% endfor %}
 {% endfor %}
+{% endif %}
+
 {% endif %}
\ No newline at end of file