diff options
| -rw-r--r-- | data/templates/dns-dynamic/ddclient.conf.j2 | 2 | ||||
| -rw-r--r-- | interface-definitions/dns-dynamic.xml.in | 1 | ||||
| -rw-r--r-- | interface-definitions/dns-forwarding.xml.in | 30 | ||||
| -rw-r--r-- | interface-definitions/include/dns/time-to-live.xml.i | 1 | ||||
| -rwxr-xr-x | smoketest/scripts/cli/test_service_dns_dynamic.py | 19 | ||||
| -rwxr-xr-x | src/conf_mode/dns_dynamic.py | 6 | 
6 files changed, 53 insertions, 6 deletions
| diff --git a/data/templates/dns-dynamic/ddclient.conf.j2 b/data/templates/dns-dynamic/ddclient.conf.j2 index f2a20d4b8..5905b19ea 100644 --- a/data/templates/dns-dynamic/ddclient.conf.j2 +++ b/data/templates/dns-dynamic/ddclient.conf.j2 @@ -66,7 +66,7 @@ use=no  # Web service dynamic DNS configuration for {{ name }}: [{{ config.protocol }}, {{ host }}]  {{ render_config(host, address, service_cfg.web_options, ip_suffixes,                   protocol=config.protocol, server=config.server, zone=config.zone, -                 login=config.username, password=config.password) }} +                 login=config.username, password=config.password, ttl=config.ttl) }}  {%                 endfor %}  {%             endfor %} diff --git a/interface-definitions/dns-dynamic.xml.in b/interface-definitions/dns-dynamic.xml.in index 8d08bf37d..ba7f426c1 100644 --- a/interface-definitions/dns-dynamic.xml.in +++ b/interface-definitions/dns-dynamic.xml.in @@ -90,6 +90,7 @@                        #include <include/dns/dynamic-service-host-name-server.xml.i>                        #include <include/generic-username.xml.i>                        #include <include/generic-password.xml.i> +                      #include <include/dns/time-to-live.xml.i>                        <leafNode name="protocol">                          <properties>                            <help>ddclient protocol used for Dynamic DNS service</help> diff --git a/interface-definitions/dns-forwarding.xml.in b/interface-definitions/dns-forwarding.xml.in index 86dc47a47..c4295317a 100644 --- a/interface-definitions/dns-forwarding.xml.in +++ b/interface-definitions/dns-forwarding.xml.in @@ -158,6 +158,9 @@                              </properties>                            </leafNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> @@ -195,6 +198,9 @@                              </properties>                            </leafNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> @@ -227,6 +233,9 @@                              </properties>                            </leafNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> @@ -274,6 +283,9 @@                              </children>                            </tagNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> @@ -302,6 +314,9 @@                              </properties>                            </leafNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> @@ -334,6 +349,9 @@                              </properties>                            </leafNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> @@ -364,6 +382,9 @@                              </properties>                            </leafNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> @@ -393,6 +414,9 @@                              </properties>                            </leafNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> @@ -477,6 +501,9 @@                              </children>                            </tagNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> @@ -585,6 +612,9 @@                              </children>                            </tagNode>                            #include <include/dns/time-to-live.xml.i> +                          <leafNode name="ttl"> +                              <defaultValue>300</defaultValue> +                          </leafNode>                            #include <include/generic-disable-node.xml.i>                          </children>                        </tagNode> diff --git a/interface-definitions/include/dns/time-to-live.xml.i b/interface-definitions/include/dns/time-to-live.xml.i index 5c1a1472d..000eea108 100644 --- a/interface-definitions/include/dns/time-to-live.xml.i +++ b/interface-definitions/include/dns/time-to-live.xml.i @@ -10,6 +10,5 @@        <validator name="numeric" argument="--range 0-2147483647"/>      </constraint>    </properties> -  <defaultValue>300</defaultValue>  </leafNode>  <!-- include end --> diff --git a/smoketest/scripts/cli/test_service_dns_dynamic.py b/smoketest/scripts/cli/test_service_dns_dynamic.py index 366b063c7..aa4891829 100755 --- a/smoketest/scripts/cli/test_service_dns_dynamic.py +++ b/smoketest/scripts/cli/test_service_dns_dynamic.py @@ -63,18 +63,29 @@ class TestServiceDDNS(VyOSUnitTestSHIM.TestCase):              self.cli_set(base_path + ddns + [svc, 'host-name', hostname])              self.cli_set(base_path + ddns + [svc, 'password', password])              self.cli_set(base_path + ddns + [svc, 'zone', zone]) +            self.cli_set(base_path + ddns + [svc, 'ttl', ttl])              for opt, value in details.items():                  self.cli_set(base_path + ddns + [svc, opt, value]) -            # commit changes +            # 'zone' option is supported and required by 'cloudfare', but not 'freedns' and 'zoneedit' +            self.cli_set(base_path + ddns + [svc, 'zone', zone]) +            if details['protocol'] == 'cloudflare': +                pass +            else: +                # exception is raised for unsupported ones +                with self.assertRaises(ConfigSessionError): +                    self.cli_commit() +                self.cli_delete(base_path + ddns + [svc, 'zone']) + +            # 'ttl' option is supported by 'cloudfare', but not 'freedns' and 'zoneedit' +            self.cli_set(base_path + ddns + [svc, 'ttl', ttl])              if details['protocol'] == 'cloudflare':                  pass              else: -                # zone option does not work on all protocols, an exception is -                # raised for all others +                # exception is raised for unsupported ones                  with self.assertRaises(ConfigSessionError):                      self.cli_commit() -                self.cli_delete(base_path + ddns + [svc, 'zone', zone]) +                self.cli_delete(base_path + ddns + [svc, 'ttl'])              # commit changes              self.cli_commit() diff --git a/src/conf_mode/dns_dynamic.py b/src/conf_mode/dns_dynamic.py index 84c983ee3..5150574a8 100755 --- a/src/conf_mode/dns_dynamic.py +++ b/src/conf_mode/dns_dynamic.py @@ -35,6 +35,9 @@ zone_required = ['cloudflare', 'godaddy', 'hetzner', 'gandi', 'nfsn']  # Protocols that do not require username  username_unnecessary = ['1984', 'cloudflare', 'cloudns', 'duckdns', 'freemyip', 'hetzner', 'keysystems', 'njalla'] +# Protocols that support TTL +ttl_supported = ['cloudflare', 'gandi', 'hetzner', 'dnsexit', 'godaddy', 'nfsn'] +  # Protocols that support both IPv4 and IPv6  dualstack_supported = ['cloudflare', 'dyndns2', 'freedns', 'njalla'] @@ -97,6 +100,9 @@ def verify(dyndns):                      if 'username' not in config:                          raise ConfigError(f'"username" {error_msg}') +                if config['protocol'] not in ttl_supported and 'ttl' in config: +                    raise ConfigError(f'"{config["protocol"]}" does not support "ttl"') +                  if config['ip_version'] == 'both':                      if config['protocol'] not in dualstack_supported:                          raise ConfigError(f'"{config["protocol"]}" does not support ' | 
