]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
datamodel: static-hints section added
authorAleš <ales.mrazek@nic.cz>
Fri, 1 Oct 2021 12:12:40 +0000 (14:12 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 8 Apr 2022 14:17:53 +0000 (16:17 +0200)
manager/knot_resolver_manager/datamodel/config_schema.py
manager/knot_resolver_manager/datamodel/lua_template.j2
manager/knot_resolver_manager/datamodel/static_hints_schema.py [new file with mode: 0644]

index 53195add86d0264a7d5b8217ed83b384bdb3fd1e..f73fb867b7aa75c631f32fdf83e688ba5e297807 100644 (file)
@@ -12,6 +12,7 @@ from knot_resolver_manager.datamodel.lua_schema import LuaSchema
 from knot_resolver_manager.datamodel.network_schema import NetworkSchema
 from knot_resolver_manager.datamodel.options_schema import OptionsSchema
 from knot_resolver_manager.datamodel.server_schema import ServerSchema
+from knot_resolver_manager.datamodel.static_hints_schema import StaticHintsSchema
 from knot_resolver_manager.utils import SchemaNode
 
 
@@ -31,6 +32,7 @@ class KresConfig(SchemaNode):
         server: ServerSchema = ServerSchema()
         options: OptionsSchema = OptionsSchema()
         network: NetworkSchema = NetworkSchema()
+        static_hints: StaticHintsSchema = StaticHintsSchema()
         cache: CacheSchema = CacheSchema()
         dnssec: Union[bool, DnssecSchema] = True
         dns64: Union[bool, Dns64Schema] = False
@@ -42,6 +44,7 @@ class KresConfig(SchemaNode):
     server: ServerSchema
     options: OptionsSchema
     network: NetworkSchema
+    static_hints: StaticHintsSchema
     cache: CacheSchema
     dnssec: Union[Literal[False], DnssecSchema]
     dns64: Union[Literal[False], Dns64Schema]
index 578238ce3fbf178e66c91277aa563b2e6df73967..cac364685f24e82951caccaf19845dd402e75090 100644 (file)
@@ -6,6 +6,7 @@ modules = {
     {{ "'workarounds < iterate'," if cfg.options.violators_workarounds }}
     {{ "'serve_stale < cache'," if cfg.options.serve_stale }}
     {{ "dns64 = '"+cfg.dns64.prefix+"'," if cfg.dns64 }}
+    'hints > iterate'
 }
 
 -- SERVER section
@@ -57,6 +58,41 @@ option('NO_0X20', {{ 'false' if cfg.options.query_case_randomization else 'true'
 {{ "modules.unload('detect_time_jump')" if not cfg.options.time_jump_detection }}
 {{ "modules.unload('refuse_nord')" if not cfg.options.refuse_no_rd }}
 
+-- STATIC-HINTS section
+{{ "hints.ttl("+cfg.static_hints.ttl.seconds()|string+")" if cfg.static_hints.ttl }}
+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 }}
+
+-- static-hints.hints-files
+{% if cfg.static_hints.hints_files %}
+{% for item in cfg.static_hints.hints_files %}
+hints.add_hosts('{{ item }}')
+{% endfor %}
+{% endif %}
+
+-- static-hints.root-hints
+{% if cfg.static_hints.root_hints %}
+hints.root({
+{% for item in cfg.static_hints.root_hints %}
+    ['{{ item.name }}'] = {
+{% for addr in item.addresses %}
+        '{{ addr }}',
+{% endfor %}
+    },
+{% endfor %}
+})
+{% endif %}
+
+-- static-hints.hints
+{% if cfg.static_hints.hints %}
+{% for item in cfg.static_hints.hints %}
+{% for addr in item.addresses %}
+hints.set('{{ item.name }} {{ addr }}')
+{% endfor %}
+{% endfor %}
+{% endif %}
+
 -- CACHE section
 cache.open({{ cfg.cache.size_max.bytes() }}, 'lmdb://{{ cfg.cache.storage }}')
 cache.min_ttl({{ cfg.cache.ttl_min.seconds() }})
diff --git a/manager/knot_resolver_manager/datamodel/static_hints_schema.py b/manager/knot_resolver_manager/datamodel/static_hints_schema.py
new file mode 100644 (file)
index 0000000..5432165
--- /dev/null
@@ -0,0 +1,19 @@
+from typing import List, Optional
+
+from knot_resolver_manager.datamodel.types import AnyPath, TimeUnit
+from knot_resolver_manager.utils import SchemaNode
+
+
+class Hint(SchemaNode):
+    name: str
+    addresses: List[str]
+
+
+class StaticHintsSchema(SchemaNode):
+    ttl: Optional[TimeUnit] = None
+    no_data: bool = True
+    etc_hosts: bool = False
+    root_hints_file: Optional[AnyPath] = None
+    hints_files: Optional[List[AnyPath]] = None
+    root_hints: Optional[List[Hint]] = None
+    hints: Optional[List[Hint]] = None