diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/conf_mode/service_dhcp-server.py | 9 | ||||
| -rwxr-xr-x | src/conf_mode/service_dhcpv6-server.py | 9 | ||||
| -rwxr-xr-x | src/migration-scripts/dhcp-server/8-to-9 | 14 | ||||
| -rwxr-xr-x | src/migration-scripts/dhcpv6-server/3-to-4 | 55 | 
4 files changed, 83 insertions, 4 deletions
| diff --git a/src/conf_mode/service_dhcp-server.py b/src/conf_mode/service_dhcp-server.py index ceaba019e..2418c8faa 100755 --- a/src/conf_mode/service_dhcp-server.py +++ b/src/conf_mode/service_dhcp-server.py @@ -165,6 +165,7 @@ def verify(dhcp):      shared_networks =  len(dhcp['shared_network_name'])      disabled_shared_networks = 0 +    subnet_ids = []      # A shared-network requires a subnet definition      for network, network_config in dhcp['shared_network_name'].items(): @@ -176,6 +177,14 @@ def verify(dhcp):                                'lease subnet must be configured.')          for subnet, subnet_config in network_config['subnet'].items(): +            if 'subnet_id' not in subnet_config: +                raise ConfigError(f'Unique subnet ID not specified for subnet "{subnet}"') + +            if subnet_config['subnet_id'] in subnet_ids: +                raise ConfigError(f'Subnet ID for subnet "{subnet}" is not unique') + +            subnet_ids.append(subnet_config['subnet_id']) +              # All delivered static routes require a next-hop to be set              if 'static_route' in subnet_config:                  for route, route_option in subnet_config['static_route'].items(): diff --git a/src/conf_mode/service_dhcpv6-server.py b/src/conf_mode/service_dhcpv6-server.py index 9cc57dbcf..7cd801cdd 100755 --- a/src/conf_mode/service_dhcpv6-server.py +++ b/src/conf_mode/service_dhcpv6-server.py @@ -63,6 +63,7 @@ def verify(dhcpv6):      # Inspect shared-network/subnet      subnets = [] +    subnet_ids = []      listen_ok = False      for network, network_config in dhcpv6['shared_network_name'].items():          # A shared-network requires a subnet definition @@ -72,6 +73,14 @@ def verify(dhcpv6):                                'each shared network!')          for subnet, subnet_config in network_config['subnet'].items(): +            if 'subnet_id' not in subnet_config: +                raise ConfigError(f'Unique subnet ID not specified for subnet "{subnet}"') + +            if subnet_config['subnet_id'] in subnet_ids: +                raise ConfigError(f'Subnet ID for subnet "{subnet}" is not unique') + +            subnet_ids.append(subnet_config['subnet_id']) +              if 'address_range' in subnet_config:                  if 'start' in subnet_config['address_range']:                      range6_start = [] diff --git a/src/migration-scripts/dhcp-server/8-to-9 b/src/migration-scripts/dhcp-server/8-to-9 index 908420c18..810e403a6 100755 --- a/src/migration-scripts/dhcp-server/8-to-9 +++ b/src/migration-scripts/dhcp-server/8-to-9 @@ -16,6 +16,7 @@  # T3316:  # - Migrate dhcp options under new option node +# - Add subnet IDs to existing subnets  import sys  import re @@ -44,6 +45,8 @@ option_nodes = ['bootfile-name', 'bootfile-server', 'bootfile-size', 'captive-po                  'tftp-server-name', 'time-offset', 'time-server', 'time-zone',                  'vendor-option', 'wins-server', 'wpad-url'] +subnet_id = 1 +  for network in config.list_nodes(base):      for option in option_nodes:          if config.exists(base + [network, option]): @@ -56,10 +59,13 @@ for network in config.list_nodes(base):              base_subnet = base + [network, 'subnet', subnet]              for option in option_nodes: -                if config.exists(base + [network, 'subnet', subnet, option]): -                    config.set(base + [network, 'subnet', subnet, 'option']) -                    config.copy(base + [network, 'subnet', subnet, option], base + [network, 'subnet', subnet, 'option', option]) -                    config.delete(base + [network, 'subnet', subnet, option]) +                if config.exists(base_subnet + [option]): +                    config.set(base_subnet + ['option']) +                    config.copy(base_subnet + [option], base_subnet + ['option', option]) +                    config.delete(base_subnet + [option]) + +            config.set(base_subnet + ['subnet-id'], value=subnet_id) +            subnet_id += 1  try:      with open(file_name, 'w') as f: diff --git a/src/migration-scripts/dhcpv6-server/3-to-4 b/src/migration-scripts/dhcpv6-server/3-to-4 new file mode 100755 index 000000000..c065e3d43 --- /dev/null +++ b/src/migration-scripts/dhcpv6-server/3-to-4 @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2024 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/>. + +# T3316: +# - Add subnet IDs to existing subnets + +import sys +import re +from vyos.configtree import ConfigTree + +if len(sys.argv) < 2: +    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', 'dhcpv6-server', 'shared-network-name'] +config = ConfigTree(config_file) + +if not config.exists(base): +    # Nothing to do +    sys.exit(0) + +subnet_id = 1 + +for network in config.list_nodes(base): +    if config.exists(base + [network, 'subnet']): +        for subnet in config.list_nodes(base + [network, 'subnet']): +            base_subnet = base + [network, 'subnet', subnet] + +            config.set(base_subnet + ['subnet-id'], value=subnet_id) +            subnet_id += 1 + +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) | 
