diff options
-rw-r--r-- | interface-definitions/service_ipoe-server.xml.in | 68 | ||||
-rwxr-xr-x | src/conf_mode/service_ipoe-server.py | 30 | ||||
-rwxr-xr-x | src/migration-scripts/ipoe-server/0-to-1 | 66 |
3 files changed, 97 insertions, 67 deletions
diff --git a/interface-definitions/service_ipoe-server.xml.in b/interface-definitions/service_ipoe-server.xml.in index 3948627d7..f0651d53d 100644 --- a/interface-definitions/service_ipoe-server.xml.in +++ b/interface-definitions/service_ipoe-server.xml.in @@ -111,60 +111,24 @@ </leafNode> </children> </tagNode> - <node name="dns-server"> + <leafNode name="name-server"> <properties> - <help>DNS servers offered via internal DHCP</help> + <help>Domain Name Server (DNS) propagated to client</help> + <valueHelp> + <format>ipv4</format> + <description>Domain Name Server (DNS) IPv4 address</description> + </valueHelp> + <valueHelp> + <format>ipv6</format> + <description>Domain Name Server (DNS) IPv6 address</description> + </valueHelp> + <constraint> + <validator name="ipv4-address"/> + <validator name="ipv6-address"/> + </constraint> + <multi/> </properties> - <children> - <leafNode name="server-1"> - <properties> - <help>IP address of the primary DNS server</help> - <constraint> - <validator name="ipv4-address"/> - </constraint> - </properties> - </leafNode> - <leafNode name="server-2"> - <properties> - <help>IP address of the secondary DNS server</help> - <constraint> - <validator name="ipv4-address"/> - </constraint> - </properties> - </leafNode> - </children> - </node> - <node name="dnsv6-server"> - <properties> - <help>DNSv6 servers offered via internal DHCPv6</help> - </properties> - <children> - <leafNode name="server-1"> - <properties> - <help>IP address of the primary DNS server</help> - <constraint> - <validator name="ipv6-address"/> - </constraint> - </properties> - </leafNode> - <leafNode name="server-2"> - <properties> - <help>IP address of the secondary DNS server</help> - <constraint> - <validator name="ipv6-address"/> - </constraint> - </properties> - </leafNode> - <leafNode name="server-3"> - <properties> - <help>IP address of the tertiary DNS server</help> - <constraint> - <validator name="ipv6-address"/> - </constraint> - </properties> - </leafNode> - </children> - </node> + </leafNode> <node name="client-ipv6-pool"> <properties> <help>Pool of client IPv6 addresses</help> diff --git a/src/conf_mode/service_ipoe-server.py b/src/conf_mode/service_ipoe-server.py index e0a607629..25c33cc6d 100755 --- a/src/conf_mode/service_ipoe-server.py +++ b/src/conf_mode/service_ipoe-server.py @@ -22,9 +22,10 @@ from stat import S_IRUSR, S_IWUSR, S_IRGRP from sys import exit from vyos.config import Config -from vyos import ConfigError -from vyos.util import call, get_half_cpus from vyos.template import render +from vyos.util import call, get_half_cpus +from vyos.validate import is_ipv4 +from vyos import ConfigError ipoe_conf = '/run/accel-pppd/ipoe.conf' ipoe_chap_secrets = '/run/accel-pppd/ipoe.chap-secrets' @@ -94,15 +95,13 @@ def get_config(): ipoe['interfaces'].append(tmp) conf.set_level(base_path) - for server in ['server-1', 'server-2']: - if conf.exists(['dns-server', server]): - tmp = conf.return_value(['dns-server', server]) - ipoe['dnsv4'].append(tmp) - for server in ['server-1', 'server-2', 'server-3']: - if conf.exists(['dnsv6-server', server]): - tmp = conf.return_value(['dnsv6-server', server]) - ipoe['dnsv6'].append(tmp) + if conf.exists(['name-server']): + for name_server in conf.return_values(['name-server']): + if is_ipv4(name_server): + ipoe['dnsv4'].append(name_server) + else: + ipoe['dnsv6'].append(name_server) if conf.exists(['authentication', 'mode']): ipoe['auth_mode'] = conf.return_value(['authentication', 'mode']) @@ -215,9 +214,6 @@ def verify(ipoe): if not ipoe: return None - import pprint - pprint.pprint(ipoe) - if not ipoe['interfaces']: raise ConfigError('No IPoE interface configured') @@ -225,6 +221,12 @@ def verify(ipoe): if not interface['range']: raise ConfigError(f'No IPoE client subnet defined on interface "{{ interface }}"') + if len(ipoe['dnsv4']) > 2: + raise ConfigError('Not more then two IPv4 DNS name-servers can be configured') + + if len(ipoe['dnsv6']) > 3: + raise ConfigError('Not more then three IPv6 DNS name-servers can be configured') + if ipoe['auth_mode'] == 'radius': if len(ipoe['radius_server']) == 0: raise ConfigError('RADIUS authentication requires at least one server') @@ -272,8 +274,6 @@ def apply(ipoe): call('systemctl restart accel-ppp@ipoe.service') - raise ConfigError("faslkdjfhaslkjdfhklsjahdf") - if __name__ == '__main__': try: c = get_config() diff --git a/src/migration-scripts/ipoe-server/0-to-1 b/src/migration-scripts/ipoe-server/0-to-1 new file mode 100755 index 000000000..94addcbdb --- /dev/null +++ b/src/migration-scripts/ipoe-server/0-to-1 @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 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/>. + +# - remove primary/secondary identifier from nameserver + +import os +import sys + +from sys import argv, exit +from vyos.configtree import ConfigTree + +if (len(argv) < 1): + print("Must specify file name!") + exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: + config_file = f.read() + +config = ConfigTree(config_file) +base = ['service', 'ipoe-server'] +if not config.exists(base): + # Nothing to do + exit(0) +else: + + # Migrate IPv4 DNS servers + dns_base = base + ['dns-servers'] + if config.exists(dns_base): + for server in ['server-1', 'server-2']: + if config.exists(dns_base + [server]): + dns = config.return_value(dns_base + [server]) + config.set(base + ['name-server'], value=dns, replace=False) + + config.delete(dns_base) + + # Migrate IPv6 DNS servers + dns_base = base + ['dnsv6-servers'] + if config.exists(dns_base): + for server in ['server-1', 'server-2', 'server-3']: + if config.exists(dns_base + [server]): + dns = config.return_value(dns_base + [server]) + config.set(base + ['name-server'], value=dns, replace=False) + + config.delete(dns_base) + + 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) |