diff options
| -rw-r--r-- | data/templates/dhcp-server/dhcpd.conf.tmpl | 10 | ||||
| -rw-r--r-- | interface-definitions/dhcp-server.xml.in | 29 | ||||
| -rwxr-xr-x | smoketest/scripts/cli/test_service_dhcp-server.py | 3 | ||||
| -rwxr-xr-x | src/conf_mode/dhcp_server.py | 7 | ||||
| -rwxr-xr-x | src/migration-scripts/dhcp-server/5-to-6 | 61 | 
5 files changed, 85 insertions, 25 deletions
| diff --git a/data/templates/dhcp-server/dhcpd.conf.tmpl b/data/templates/dhcp-server/dhcpd.conf.tmpl index f0bfa468c..3ac92d3c9 100644 --- a/data/templates/dhcp-server/dhcpd.conf.tmpl +++ b/data/templates/dhcp-server/dhcpd.conf.tmpl @@ -110,9 +110,13 @@ shared-network {{ network | replace('_','-') }} {  {%           if subnet_config.default_router and subnet_config.default_router is not none %}  {%             set static_default_route = ', ' + '0.0.0.0/0' | isc_static_route(subnet_config.default_router) %}  {%           endif %} -{%           if subnet_config.static_route.router is defined and subnet_config.static_route.router is not none and subnet_config.static_route.destination_subnet is defined and subnet_config.static_route.destination_subnet is not none %} -        option rfc3442-static-route {{ subnet_config.static_route.destination_subnet | isc_static_route(subnet_config.static_route.router) }}{{ static_default_route }}; -        option windows-static-route {{ subnet_config.static_route.destination_subnet | isc_static_route(subnet_config.static_route.router) }}; +{%           if subnet_config.static_route is defined and subnet_config.static_route is not none %} +{%           set rfc3442_routes = [] %} +{%           for route, route_options in subnet_config.static_route.items() %} +{%             set rfc3442_routes = rfc3442_routes.append(route | isc_static_route(route_options.next_hop)) %} +{%           endfor %} +        option rfc3442-static-route {{ rfc3442_routes | join(', ') }}{{ static_default_route }}; +        option windows-static-route {{ rfc3442_routes | join(', ') }};  {%           endif %}  {%         endif %}  {%         if subnet_config.ip_forwarding is defined %} diff --git a/interface-definitions/dhcp-server.xml.in b/interface-definitions/dhcp-server.xml.in index bafd6f6a2..c0f72dd86 100644 --- a/interface-definitions/dhcp-server.xml.in +++ b/interface-definitions/dhcp-server.xml.in @@ -357,26 +357,21 @@                        </leafNode>                      </children>                    </tagNode> -                  <node name="static-route"> +                  <tagNode name="static-route">                      <properties> -                      <help>Classless static route</help> +                      <help>Classless static route destination subnet [REQUIRED]</help> +                      <valueHelp> +                        <format>ipv4net</format> +                        <description>IPv4 address and prefix length</description> +                      </valueHelp> +                      <constraint> +                        <validator name="ipv4-prefix"/> +                      </constraint>                      </properties>                      <children> -                      <leafNode name="destination-subnet"> -                        <properties> -                          <help>Destination subnet [REQUIRED]</help> -                          <valueHelp> -                            <format>ipv4net</format> -                            <description>IPv4 address and prefix length</description> -                          </valueHelp> -                          <constraint> -                            <validator name="ipv4-prefix"/> -                          </constraint> -                        </properties> -                      </leafNode> -                      <leafNode name="router"> +                      <leafNode name="next-hop">                          <properties> -                          <help>IP address of router to be used to reach the destination subnet [REQUIRED]</help> +                          <help>IP address of router to be used to reach the destination subnet</help>                            <valueHelp>                              <format>ipv4</format>                              <description>IPv4 address of router</description> @@ -387,7 +382,7 @@                          </properties>                        </leafNode>                      </children> -                  </node> +                  </tagNode >                    <leafNode name="subnet-parameters">                      <properties>                        <help>Additional subnet parameters for DHCP server. You must diff --git a/smoketest/scripts/cli/test_service_dhcp-server.py b/smoketest/scripts/cli/test_service_dhcp-server.py index 815bd333a..40977bb04 100755 --- a/smoketest/scripts/cli/test_service_dhcp-server.py +++ b/smoketest/scripts/cli/test_service_dhcp-server.py @@ -123,8 +123,7 @@ class TestServiceDHCPServer(VyOSUnitTestSHIM.TestCase):          self.cli_set(pool + ['wpad-url', wpad])          self.cli_set(pool + ['server-identifier', server_identifier]) -        self.cli_set(pool + ['static-route', 'destination-subnet', '10.0.0.0/24']) -        self.cli_set(pool + ['static-route', 'router', '192.0.2.1']) +        self.cli_set(pool + ['static-route', '10.0.0.0/24', 'next-hop', '192.0.2.1'])          # check validate() - No DHCP address range or active static-mapping set          with self.assertRaises(ConfigSessionError): diff --git a/src/conf_mode/dhcp_server.py b/src/conf_mode/dhcp_server.py index cdee72e09..8d6cef8b7 100755 --- a/src/conf_mode/dhcp_server.py +++ b/src/conf_mode/dhcp_server.py @@ -159,9 +159,10 @@ def verify(dhcp):                                'lease subnet must be configured.')          for subnet, subnet_config in network_config['subnet'].items(): -            if 'static_route' in subnet_config and len(subnet_config['static_route']) != 2: -                raise ConfigError('Missing DHCP static-route parameter(s):\n' \ -                                  'destination-subnet | router must be defined!') +            if 'static_route' in subnet_config: +                for route, route_option in subnet_config['static_route'].items(): +                    if 'next_hop' not in route_option: +                        raise ConfigError(f'DHCP static-route "{route}" requires router to be defined!')              # Check if DHCP address range is inside configured subnet declaration              if 'range' in subnet_config: diff --git a/src/migration-scripts/dhcp-server/5-to-6 b/src/migration-scripts/dhcp-server/5-to-6 new file mode 100755 index 000000000..4cd2ec07a --- /dev/null +++ b/src/migration-scripts/dhcp-server/5-to-6 @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2021 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + + +import sys +from vyos.configtree import ConfigTree + +if (len(sys.argv) < 1): +    print("Must specify file name!") +    sys.exit(1) + +file_name = sys.argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +base = ['service', 'dhcp-server', 'shared-network-name'] +config = ConfigTree(config_file) + +if not config.exists(base): +    # Nothing to do +    exit(0) + +# Run this for every instance if 'shared-network-name' +for network in config.list_nodes(base): +    base_network = base + [network] + +    if not config.exists(base_network + ['subnet']): +        continue + +    # Run this for every specified 'subnet' +    for subnet in config.list_nodes(base_network + ['subnet']): +        base_subnet = base_network + ['subnet', subnet] + +        if config.exists(base_subnet + ['static-route']): +            prefix = config.return_value(base_subnet + ['static-route', 'destination-subnet']) +            router = config.return_value(base_subnet + ['static-route', 'router']) +            config.delete(base_subnet + ['static-route']) + +            config.set(base_subnet + ['static-route', prefix, 'next-hop'], value=router) +            config.set_tag(base_subnet + ['static-route']) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print("Failed to save the modified config: {}".format(e)) +    exit(1) | 
