summaryrefslogtreecommitdiff
path: root/src/conf_mode/dns_forwarding.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-03-29 10:33:30 +0200
committerGitHub <noreply@github.com>2023-03-29 10:33:30 +0200
commitc675fbf336365f70a7f783590daf70efca0f4941 (patch)
tree71acf469350c926780b1377d0dcc21568a290abd /src/conf_mode/dns_forwarding.py
parent454a49dfc1e2c08f72e9f9ae9a4a90818be76ae3 (diff)
parent2bb5c5d0fd9ed07649b81a61e9c1a78a9f222405 (diff)
downloadvyos-1x-c675fbf336365f70a7f783590daf70efca0f4941.tar.gz
vyos-1x-c675fbf336365f70a7f783590daf70efca0f4941.zip
Merge pull request #1915 from indrajitr/pdns-port-round2
dns: T5115: Support custom port for name servers for forwarding zones
Diffstat (limited to 'src/conf_mode/dns_forwarding.py')
-rwxr-xr-xsrc/conf_mode/dns_forwarding.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/conf_mode/dns_forwarding.py b/src/conf_mode/dns_forwarding.py
index 4d6b85d92..36c1098fe 100755
--- a/src/conf_mode/dns_forwarding.py
+++ b/src/conf_mode/dns_forwarding.py
@@ -59,6 +59,7 @@ def get_config(config=None):
# T2665 due to how defaults under tag nodes work, we must clear these out before we merge
del default_values['authoritative_domain']
del default_values['name_server']
+ del default_values['domain']['name_server']
dns = dict_merge(default_values, dns)
# T2665: we cleared default values for tag node 'name_server' above.
@@ -68,6 +69,15 @@ def get_config(config=None):
for server in dns['name_server']:
dns['name_server'][server] = dict_merge(default_values, dns['name_server'][server])
+ # T2665: we cleared default values for tag node 'domain' above.
+ # We now need to add them back back in a granular way.
+ if 'domain' in dns:
+ default_values = defaults(base + ['domain', 'name-server'])
+ for domain in dns['domain'].keys():
+ for server in dns['domain'][domain]['name_server']:
+ dns['domain'][domain]['name_server'][server] = dict_merge(
+ default_values, dns['domain'][domain]['name_server'][server])
+
# some additions to the default dictionary
if 'system' in dns:
base_nameservers = ['system', 'name-server']
@@ -271,7 +281,7 @@ def verify(dns):
# as a domain will contains dot's which is out dictionary delimiter.
if 'domain' in dns:
for domain in dns['domain']:
- if 'server' not in dns['domain'][domain]:
+ if 'name_server' not in dns['domain'][domain]:
raise ConfigError(f'No server configured for domain {domain}!')
if 'dns64_prefix' in dns:
@@ -337,9 +347,9 @@ def apply(dns):
# sources
hc.delete_name_servers([hostsd_tag])
if 'name_server' in dns:
- # 'name_server' is a dict of the form
+ # 'name_server' is of the form
# {'192.0.2.1': {'port': 53}, '2001:db8::1': {'port': 853}, ...}
- # canonicalize them as ['192.0.2.1:53', '[2001:db8::1]:853', ...] with IPv6 hosts bracketized
+ # canonicalize them as ['192.0.2.1:53', '[2001:db8::1]:853', ...]
nslist = [(lambda h, p: f"{bracketize_ipv6(h)}:{p['port']}")(h, p)
for (h, p) in dns['name_server'].items()]
hc.add_name_servers({hostsd_tag: nslist})
@@ -371,7 +381,14 @@ def apply(dns):
# the list and keys() are required as get returns a dict, not list
hc.delete_forward_zones(list(hc.get_forward_zones().keys()))
if 'domain' in dns:
- hc.add_forward_zones(dns['domain'])
+ zones = dns['domain']
+ for domain in zones.keys():
+ # 'name_server' is of the form
+ # {'192.0.2.1': {'port': 53}, '2001:db8::1': {'port': 853}, ...}
+ # canonicalize them as ['192.0.2.1:53', '[2001:db8::1]:853', ...]
+ zones[domain]['name_server'] = [(lambda h, p: f"{bracketize_ipv6(h)}:{p['port']}")(h, p)
+ for (h, p) in zones[domain]['name_server'].items()]
+ hc.add_forward_zones(zones)
# hostsd generates NTAs for the authoritative zones
# the list and keys() are required as get returns a dict, not list