summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndrajit Raychaudhuri <irc@indrajit.com>2023-09-12 23:31:43 -0500
committerIndrajit Raychaudhuri <irc@indrajit.com>2023-11-30 21:42:23 -0600
commitf24763c416a3726e1a20c76947c3cd6801a9d0f2 (patch)
tree25b4d666b706d96f129d26bfc411d36c07d3effa
parentbda5d89e7483cae1ce74022b1065b53c669dd758 (diff)
downloadvyos-1x-f24763c416a3726e1a20c76947c3cd6801a9d0f2.tar.gz
vyos-1x-f24763c416a3726e1a20c76947c3cd6801a9d0f2.zip
ddclient: T5612: Fix VRF support for ddclient service
Fix VRF support interface definition and configuration mode for ddclient to actually capture the VRF name and pass it to the template.
-rw-r--r--data/templates/dns-dynamic/override.conf.j22
-rw-r--r--interface-definitions/dns-dynamic.xml.in1
-rwxr-xr-xsmoketest/scripts/cli/test_service_dns_dynamic.py34
-rwxr-xr-xsrc/conf_mode/dns_dynamic.py5
4 files changed, 41 insertions, 1 deletions
diff --git a/data/templates/dns-dynamic/override.conf.j2 b/data/templates/dns-dynamic/override.conf.j2
index 6ca1b8a45..4a6851cef 100644
--- a/data/templates/dns-dynamic/override.conf.j2
+++ b/data/templates/dns-dynamic/override.conf.j2
@@ -7,4 +7,4 @@ After=vyos-router.service
PIDFile={{ config_file | replace('.conf', '.pid') }}
EnvironmentFile=
ExecStart=
-ExecStart=/usr/bin/ddclient -file {{ config_file }}
+ExecStart={{ vrf_command }}/usr/bin/ddclient -file {{ config_file }}
diff --git a/interface-definitions/dns-dynamic.xml.in b/interface-definitions/dns-dynamic.xml.in
index a0720f3aa..94e0645d4 100644
--- a/interface-definitions/dns-dynamic.xml.in
+++ b/interface-definitions/dns-dynamic.xml.in
@@ -164,6 +164,7 @@
</properties>
<defaultValue>300</defaultValue>
</leafNode>
+ #include <include/interface/vrf.xml.i>
</children>
</node>
</children>
diff --git a/smoketest/scripts/cli/test_service_dns_dynamic.py b/smoketest/scripts/cli/test_service_dns_dynamic.py
index 357c3dfb1..366b063c7 100755
--- a/smoketest/scripts/cli/test_service_dns_dynamic.py
+++ b/smoketest/scripts/cli/test_service_dns_dynamic.py
@@ -17,6 +17,8 @@
import os
import unittest
import tempfile
+import random
+import string
from base_vyostest_shim import VyOSUnitTestSHIM
@@ -24,8 +26,10 @@ from vyos.configsession import ConfigSessionError
from vyos.utils.process import cmd
from vyos.utils.process import process_running
+DDCLIENT_SYSTEMD_UNIT = '/run/systemd/system/ddclient.service.d/override.conf'
DDCLIENT_CONF = '/run/ddclient/ddclient.conf'
DDCLIENT_PID = '/run/ddclient/ddclient.pid'
+DDCLIENT_PNAME = 'ddclient'
base_path = ['service', 'dns', 'dynamic']
hostname = 'test.ddns.vyos.io'
@@ -188,5 +192,35 @@ class TestServiceDDNS(VyOSUnitTestSHIM.TestCase):
self.assertIn(f'password={key_file.name}', ddclient_conf)
self.assertIn(f'ttl={ttl}', ddclient_conf)
+ def test_05_dyndns_vrf(self):
+ vrf_name = f'vyos-test-{"".join(random.choices(string.ascii_letters + string.digits, k=5))}'
+ svc_path = ['address', interface, 'service', 'cloudflare']
+
+ # Always start with a clean CLI instance
+ self.cli_delete(base_path)
+
+ self.cli_set(['vrf', 'name', vrf_name, 'table', '12345'])
+ self.cli_set(base_path + ['vrf', vrf_name])
+
+ self.cli_set(base_path + svc_path + ['protocol', 'cloudflare'])
+ self.cli_set(base_path + svc_path + ['host-name', hostname])
+ self.cli_set(base_path + svc_path + ['zone', zone])
+ self.cli_set(base_path + svc_path + ['password', password])
+
+ # commit changes
+ self.cli_commit()
+
+ # Check for process in VRF
+ systemd_override = cmd(f'cat {DDCLIENT_SYSTEMD_UNIT}')
+ self.assertIn(f'ExecStart=ip vrf exec {vrf_name} /usr/bin/ddclient -file {DDCLIENT_CONF}',
+ systemd_override)
+
+ # Check for process in VRF
+ proc = cmd(f'ip vrf pids {vrf_name}')
+ self.assertIn(DDCLIENT_PNAME, proc)
+
+ # Cleanup VRF
+ self.cli_delete(['vrf', 'name', vrf_name])
+
if __name__ == '__main__':
unittest.main(verbosity=2)
diff --git a/src/conf_mode/dns_dynamic.py b/src/conf_mode/dns_dynamic.py
index 4b1aed742..712889f68 100755
--- a/src/conf_mode/dns_dynamic.py
+++ b/src/conf_mode/dns_dynamic.py
@@ -19,6 +19,7 @@ import os
from sys import exit
from vyos.config import Config
+from vyos.configverify import verify_interface_exists
from vyos.template import render
from vyos.utils.process import call
from vyos import ConfigError
@@ -61,6 +62,10 @@ def verify(dyndns):
return None
for address in dyndns['address']:
+ # If dyndns address is an interface, ensure it exists
+ if address != 'web':
+ verify_interface_exists(address)
+
# RFC2136 - configuration validation
if 'rfc2136' in dyndns['address'][address]:
for config in dyndns['address'][address]['rfc2136'].values():