"instances": 4
},
"dns64": {
- "prefix": "64:ff9b::/96"
+ "prefix": "64:ff9b::"
},
"logging": {
"level": 4
},
"lua": {
"script": [
- "-- SPDX-License-Identifier: CC0-1.0",
- "-- vim:syntax=lua:set ts=4 sw=4:",
- "-- Refer to manual: https://knot-resolver.readthedocs.org/en/stable/",
- "-- Network interface configuration","net.listen('127.0.0.1', 53, { kind = 'dns' })",
+ "net.listen('127.0.0.1', 53, { kind = 'dns' })",
"net.listen('127.0.0.1', 853, { kind = 'tls' })",
- "--net.listen('127.0.0.1', 443, { kind = 'doh2' })",
"net.listen('::1', 53, { kind = 'dns', freebind = true })",
"net.listen('::1', 853, { kind = 'tls', freebind = true })",
- "--net.listen('::1', 443, { kind = 'doh2' })",
- "-- Load useful modules","modules = {",
- "'hints > iterate', -- Load /etc/hosts and allow custom root hints",
- "'stats', -- Track internal statistics",
- "'predict', -- Prefetch expiring/frequent records",
- "}",
"-- Cache size",
"cache.size = 100 * MB"
]
instances: 1
dns64:
- prefix: "64:ff9b::/96"
+ prefix: "64:ff9b::"
logging:
level: 4
lua:
script: |
"""
- -- SPDX-License-Identifier: CC0-1.0
- -- vim:syntax=lua:set ts=4 sw=4:
- -- Refer to manual: https://knot-resolver.readthedocs.org/en/stable/
-
- -- Network interface configuration
net.listen('127.0.0.1', 53, { kind = 'dns' })
net.listen('127.0.0.1', 853, { kind = 'tls' })
- --net.listen('127.0.0.1', 443, { kind = 'doh2' })
net.listen('::1', 53, { kind = 'dns', freebind = true })
net.listen('::1', 853, { kind = 'tls', freebind = true })
- --net.listen('::1', 443, { kind = 'doh2' })
-
- -- Load useful modules
- modules = {
- 'hints > iterate', -- Load /etc/hosts and allow custom root hints
- 'stats', -- Track internal statistics
- 'predict', -- Prefetch expiring/frequent records
- }
-- Cache size
cache.size = 100 * MB
modules = {
+ 'hints > iterate', -- Load /etc/hosts and allow custom root hints",
+ 'stats', -- Track internal statistics",
+ 'predict', -- Prefetch expiring/frequent records",
{%- if cfg.dns64 %}
- dns64 = '{{ cfg.dns64.prefix }}' } -- dns64
+ dns64 = '{{ cfg.dns64.prefix }}', -- dns64
{%- endif %}
}
},
"lua": {
"script_list": [
- "-- SPDX-License-Identifier: CC0-1.0",
- "-- vim:syntax=lua:set ts=4 sw=4:",
- "-- Refer to manual: https://knot-resolver.readthedocs.org/en/stable/",
- "-- Network interface configuration","net.listen('127.0.0.1', 53, { kind = 'dns' })",
+ "net.listen('127.0.0.1', 53, { kind = 'dns' })",
"net.listen('127.0.0.1', 853, { kind = 'tls' })",
- "--net.listen('127.0.0.1', 443, { kind = 'doh2' })",
"net.listen('::1', 53, { kind = 'dns', freebind = true })",
"net.listen('::1', 853, { kind = 'tls', freebind = true })",
- "--net.listen('::1', 443, { kind = 'doh2' })",
- "-- Load useful modules","modules = {",
- "'hints > iterate', -- Load /etc/hosts and allow custom root hints",
- "'stats', -- Track internal statistics",
- "'predict', -- Prefetch expiring/frequent records",
- "}",
"-- Cache size",
"cache.size = 100 * MB"
]
"instances": 1
},
"dns64": {
- "prefix": "64:ff9b::/96"
+ "prefix": "64:ff9b::"
},
"logging": {
"level": 4
},
"lua": {
"script_list": [
- "-- SPDX-License-Identifier: CC0-1.0",
- "-- vim:syntax=lua:set ts=4 sw=4:",
- "-- Refer to manual: https://knot-resolver.readthedocs.org/en/stable/",
- "-- Network interface configuration","net.listen('127.0.0.1', 53, { kind = 'dns' })",
+ "net.listen('127.0.0.1', 53, { kind = 'dns' })",
"net.listen('127.0.0.1', 853, { kind = 'tls' })",
- "--net.listen('127.0.0.1', 443, { kind = 'doh2' })",
"net.listen('::1', 53, { kind = 'dns', freebind = true })",
"net.listen('::1', 853, { kind = 'tls', freebind = true })",
- "--net.listen('::1', 443, { kind = 'doh2' })",
- "-- Load useful modules",
- "modules = {",
- " 'hints > iterate', -- Load /etc/hosts and allow custom root hints",
- " 'stats', -- Track internal statistics",
- " 'predict', -- Prefetch expiring/frequent records",
- "}",
"-- Cache size",
"cache.size = 100 * MB"
]
# assert that any kresd process is running
systemctl status | grep kresd
-
-# see the rendered Lua configuration
-echo "Lua config in '/etc/knot-resolver/kresd.conf':"
-cat /etc/knot-resolver/kresd.conf
},
"lua": {
"script_list": [
- "-- SPDX-License-Identifier: CC0-1.0",
- "-- vim:syntax=lua:set ts=4 sw=4:",
- "-- Refer to manual: https://knot-resolver.readthedocs.org/en/stable/",
- "-- Network interface configuration","net.listen('127.0.0.1', 53, { kind = 'dns' })",
+ "net.listen('127.0.0.1', 53, { kind = 'dns' })",
"net.listen('127.0.0.1', 853, { kind = 'tls' })",
- "--net.listen('127.0.0.1', 443, { kind = 'doh2' })",
"net.listen('::1', 53, { kind = 'dns', freebind = true })",
"net.listen('::1', 853, { kind = 'tls', freebind = true })",
- "--net.listen('::1', 443, { kind = 'doh2' })",
- "-- Load useful modules","modules = {",
- "'hints > iterate', -- Load /etc/hosts and allow custom root hints",
- "'stats', -- Track internal statistics",
- "'predict', -- Prefetch expiring/frequent records",
- "}",
"-- Cache size",
"cache.size = 100 * MB"
]
_LUA_TEMPLATE_STR = """
modules = {
+ 'hints > iterate', -- Load /etc/hosts and allow custom root hints",
+ 'stats', -- Track internal statistics",
+ 'predict', -- Prefetch expiring/frequent records",
{%- if cfg.dns64 %}
- dns64 = '{{ cfg.dns64.prefix }}' } -- dns64
+ dns64 = '{{ cfg.dns64.prefix }}', -- dns64
{%- endif %}
}
+++ /dev/null
-from typing import List, Optional
-
-from knot_resolver_manager.utils.dataclasses_parservalidator import DataclassParserValidatorMixin
-
-from .compat.dataclasses import dataclass
-from .datamodel_types import IPV6_PREFIX_96
-
-
-class DataValidationError(Exception):
- pass
-
-
-@dataclass
-class ServerConfig(DataclassParserValidatorMixin):
- instances: int = 1
-
- def validate(self):
- if not 0 < self.instances <= 256:
- raise DataValidationError("number of kresd 'instances' must be in range 1..256")
-
-
-@dataclass
-class Dns64Config(DataclassParserValidatorMixin):
- prefix: str = "64:ff9b::"
-
- def validate(self):
- if not bool(IPV6_PREFIX_96.match(self.prefix)):
- raise DataValidationError("'dns64.prefix' must be valid IPv6 address and '/96' CIDR")
-
-
-@dataclass
-class LoggingConfig(DataclassParserValidatorMixin):
- level: int = 3
-
- def validate(self):
- if not 0 <= self.level <= 7:
- raise DataValidationError("logging 'level' must be in range 0..7")
-
-
-@dataclass
-class LuaConfig(DataclassParserValidatorMixin):
- script_list: Optional[List[str]] = None
- script: Optional[str] = None
-
- def __post_init__(self):
- # Concatenate array to single string
- if self.script_list is not None:
- self.script = "\n".join(self.script_list)
-
- def validate(self):
- assert self.script_list is not None or self.script is not None
-
-
-@dataclass
-class KresConfig(DataclassParserValidatorMixin):
- server: ServerConfig = ServerConfig()
- dns64: Optional[Dns64Config] = None
- logging: LoggingConfig = LoggingConfig()
- lua: LuaConfig = LuaConfig()
-
- def validate(self):
- self.server.validate()
- if self.dns64 is not None:
- self.dns64.validate()
- self.lua.validate()
--- /dev/null
+from .config import KresConfig
+from .errors import DataValidationError
+
+__all__ = [
+ "KresConfig",
+ "DataValidationError",
+]
--- /dev/null
+from knot_resolver_manager.compat.dataclasses import dataclass
+from knot_resolver_manager.utils.dataclasses_parservalidator import DataclassParserValidatorMixin
+
+
+@dataclass
+class CacheConfig(DataclassParserValidatorMixin):
+ def validate(self):
+ pass
--- /dev/null
+from typing import Optional
+
+from knot_resolver_manager.compat.dataclasses import dataclass
+from knot_resolver_manager.utils.dataclasses_parservalidator import DataclassParserValidatorMixin
+
+from .cache_config import CacheConfig
+from .dns64_config import Dns64Config
+from .logging_config import LoggingConfig
+from .lua_config import LuaConfig
+from .network_config import NetworkConfig
+from .server_config import ServerConfig
+
+
+@dataclass
+class KresConfig(DataclassParserValidatorMixin):
+ server: ServerConfig = ServerConfig()
+ network: Optional[NetworkConfig] = None
+ cache: CacheConfig = CacheConfig()
+ dns64: Optional[Dns64Config] = None
+ logging: LoggingConfig = LoggingConfig()
+ lua: LuaConfig = LuaConfig()
+
+ def validate(self):
+ self.server.validate()
+ if self.network is not None:
+ self.network.validate()
+ self.cache.validate()
+ if self.dns64 is not None:
+ self.dns64.validate()
+ self.logging.validate()
+ self.lua.validate()
--- /dev/null
+from knot_resolver_manager.compat.dataclasses import dataclass
+from knot_resolver_manager.utils.dataclasses_parservalidator import DataclassParserValidatorMixin
+
+from .errors import DataValidationError
+from .types import IPV6_PREFIX_96
+
+
+@dataclass
+class Dns64Config(DataclassParserValidatorMixin):
+ prefix: str = "64:ff9b::"
+
+ def validate(self):
+ if not bool(IPV6_PREFIX_96.match(self.prefix)):
+ raise DataValidationError("'dns64.prefix' must be valid IPv6 /96 prefix")
--- /dev/null
+class DataValidationError(Exception):
+ pass
--- /dev/null
+from knot_resolver_manager.compat.dataclasses import dataclass
+from knot_resolver_manager.utils.dataclasses_parservalidator import DataclassParserValidatorMixin
+
+from .errors import DataValidationError
+
+
+@dataclass
+class LoggingConfig(DataclassParserValidatorMixin):
+ level: int = 3
+
+ def validate(self):
+ if not 0 <= self.level <= 7:
+ raise DataValidationError("logging 'level' must be in range 0..7")
--- /dev/null
+from typing import List, Optional
+
+from knot_resolver_manager.compat.dataclasses import dataclass
+from knot_resolver_manager.utils.dataclasses_parservalidator import DataclassParserValidatorMixin
+
+
+@dataclass
+class LuaConfig(DataclassParserValidatorMixin):
+ script_list: Optional[List[str]] = None
+ script: Optional[str] = None
+
+ def __post_init__(self):
+ # Concatenate array to single string
+ if self.script_list is not None:
+ self.script = "\n".join(self.script_list)
+
+ def validate(self):
+ assert self.script_list is not None or self.script is not None
--- /dev/null
+from knot_resolver_manager.compat.dataclasses import dataclass
+from knot_resolver_manager.utils.dataclasses_parservalidator import DataclassParserValidatorMixin
+
+
+@dataclass
+class NetworkConfig(DataclassParserValidatorMixin):
+ def validate(self):
+ pass
--- /dev/null
+from knot_resolver_manager.compat.dataclasses import dataclass
+from knot_resolver_manager.utils.dataclasses_parservalidator import DataclassParserValidatorMixin
+
+from .errors import DataValidationError
+
+
+@dataclass
+class ServerConfig(DataclassParserValidatorMixin):
+ instances: int = 1
+
+ def validate(self):
+ if not 0 < self.instances <= 256:
+ raise DataValidationError("number of kresd instances must be in range 1..256")
--- /dev/null
+import re
+
+IPV6_PREFIX_96 = re.compile(r"^([0-9A-Fa-f]{1,4}:){2}:$")
+++ /dev/null
-import re
-
-IPV4ADDR = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
-
-IPV6_PREFIX_96 = re.compile(r"^([0-9A-Fa-f]{1,4}:){2}:($|/96)$")