From 19d8415512dcf87dc3a87feabf128652ffc74594 Mon Sep 17 00:00:00 2001 From: Haim Gelfenbeyn Date: Thu, 30 May 2024 09:30:27 -0400 Subject: dns: T6422: allow multiple redundant NS records NS is unlike CNAME or PTR, multiple NS records are perfectly valid and is a common use case: multiple redundant DNS servers is a common configuration and should be supported. --- src/conf_mode/service_dns_forwarding.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/conf_mode/service_dns_forwarding.py b/src/conf_mode/service_dns_forwarding.py index 7e863073a..e8318a83e 100755 --- a/src/conf_mode/service_dns_forwarding.py +++ b/src/conf_mode/service_dns_forwarding.py @@ -102,7 +102,7 @@ def get_config(config=None): 'ttl': rdata['ttl'], 'value': address }) - elif rtype in ['cname', 'ptr', 'ns']: + elif rtype in ['cname', 'ptr']: if not 'target' in rdata: dns['authoritative_zone_errors'].append(f'{subnode}.{node}: target is required') continue @@ -113,6 +113,19 @@ def get_config(config=None): 'ttl': rdata['ttl'], 'value': '{}.'.format(rdata['target']) }) + elif rtype == 'ns': + if not 'target' in rdata: + dns['authoritative_zone_errors'].append(f'{subnode}.{node}: at leaast one target is required') + continue + + for target in rdata['target']: + zone['records'].append({ + 'name': subnode, + 'type': rtype.upper(), + 'ttl': rdata['ttl'], + 'value': '{}.'.format(target) + }) + elif rtype == 'mx': if not 'server' in rdata: dns['authoritative_zone_errors'].append(f'{subnode}.{node}: at least one server is required') -- cgit v1.2.3 From f2d0701f50061374b5a4f55d33201629b3293248 Mon Sep 17 00:00:00 2001 From: Haim Gelfenbeyn Date: Thu, 30 May 2024 12:13:42 -0400 Subject: T6422: Smoke test for NS record configration in authoritative DNS, typo & style fixes --- smoketest/scripts/cli/test_service_dns_forwarding.py | 10 ++++++++++ src/conf_mode/service_dns_forwarding.py | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/smoketest/scripts/cli/test_service_dns_forwarding.py b/smoketest/scripts/cli/test_service_dns_forwarding.py index 079c584ba..4db1d7495 100755 --- a/smoketest/scripts/cli/test_service_dns_forwarding.py +++ b/smoketest/scripts/cli/test_service_dns_forwarding.py @@ -291,5 +291,15 @@ class TestServicePowerDNS(VyOSUnitTestSHIM.TestCase): tmp = get_config_value('edns-subnet-allow-list') self.assertEqual(tmp, ','.join(options)) + def test_multiple_ns_records(self): + test_zone = 'example.com' + self.cli_set(base_path + ['authoritative-domain', test_zone, 'records', 'ns', 'test', 'target', f'ns1.{test_zone}']) + self.cli_set(base_path + ['authoritative-domain', test_zone, 'records', 'ns', 'test', 'target', f'ns2.{test_zone}']) + self.cli_commit() + zone_config = read_file(f'{PDNS_REC_RUN_DIR}/zone.{test_zone}.conf') + self.assertRegex(zone_config, fr'test\s+\d+\s+NS\s+ns1\.{test_zone}\.') + self.assertRegex(zone_config, fr'test\s+\d+\s+NS\s+ns2\.{test_zone}\.') + + if __name__ == '__main__': unittest.main(verbosity=2) diff --git a/src/conf_mode/service_dns_forwarding.py b/src/conf_mode/service_dns_forwarding.py index e8318a83e..70686534f 100755 --- a/src/conf_mode/service_dns_forwarding.py +++ b/src/conf_mode/service_dns_forwarding.py @@ -115,7 +115,7 @@ def get_config(config=None): }) elif rtype == 'ns': if not 'target' in rdata: - dns['authoritative_zone_errors'].append(f'{subnode}.{node}: at leaast one target is required') + dns['authoritative_zone_errors'].append(f'{subnode}.{node}: at least one target is required') continue for target in rdata['target']: @@ -123,7 +123,7 @@ def get_config(config=None): 'name': subnode, 'type': rtype.upper(), 'ttl': rdata['ttl'], - 'value': '{}.'.format(target) + 'value': f'{target}.' }) elif rtype == 'mx': -- cgit v1.2.3