From 209dc64ca31ff1ef5e431c6f52454df30f43eded Mon Sep 17 00:00:00 2001 From: Viacheslav Hletenko Date: Sun, 12 Feb 2023 18:33:01 +0000 Subject: T4971: Add accel-ppp include client-ip-pool-name Add accel-ppp include client-ip-pool-name.xml.i Can be used in other accep-ppp CLI as "include" --- .../include/accel-ppp/client-ip-pool-name.xml.i | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 interface-definitions/include/accel-ppp/client-ip-pool-name.xml.i (limited to 'interface-definitions') diff --git a/interface-definitions/include/accel-ppp/client-ip-pool-name.xml.i b/interface-definitions/include/accel-ppp/client-ip-pool-name.xml.i new file mode 100644 index 000000000..654b6727e --- /dev/null +++ b/interface-definitions/include/accel-ppp/client-ip-pool-name.xml.i @@ -0,0 +1,18 @@ + + + + Pool name + + txt + Name of IP pool + + + [-_a-zA-Z0-9.]+ + + + + #include + #include + + + -- cgit v1.2.3 From e7e81746e6ad01ce644cd7b584233464f91d9380 Mon Sep 17 00:00:00 2001 From: Viacheslav Hletenko Date: Sun, 12 Feb 2023 18:34:49 +0000 Subject: T4971: PPPoE server add named ip pool and attr Framed-Pool Add a new feature to allow to use named pools Also it can be used with RADIUS attribute 'Framed-Pool' set service pppoe-server client-ip-pool name POOL1 gateway-address '192.0.2.1' set service pppoe-server client-ip-pool name POOL1 subnet '192.0.2.0/24' --- data/templates/accel-ppp/config_ip_pool.j2 | 10 +++++++ data/templates/accel-ppp/pppoe.config.tmpl | 15 +++++++++++ interface-definitions/service_ipoe-server.xml.in | 14 +--------- interface-definitions/service_pppoe-server.xml.in | 1 + python/vyos/configverify.py | 16 ++++++++--- smoketest/scripts/cli/test_service_pppoe-server.py | 31 +++++++++++++++++++++- 6 files changed, 70 insertions(+), 17 deletions(-) (limited to 'interface-definitions') diff --git a/data/templates/accel-ppp/config_ip_pool.j2 b/data/templates/accel-ppp/config_ip_pool.j2 index 3b0f68084..f61a4f148 100644 --- a/data/templates/accel-ppp/config_ip_pool.j2 +++ b/data/templates/accel-ppp/config_ip_pool.j2 @@ -11,4 +11,14 @@ gw-ip-address={{ gateway_address }} {{ subnet }} {% endfor %} {% endif %} +{% if client_ip_pool.name is defined and client_ip_pool.name is not none %} +{% for pool, pool_config in client_ip_pool.name.items() %} +{% if pool_config.subnet is defined and pool_config.subnet is not none %} +{{ pool_config.subnet }},name={{ pool }} +{% endif %} +{% if pool_config.gateway_address is defined and pool_config.gateway_address is not none %} +gw-ip-address={{ pool_config.gateway_address }} +{% endif %} +{% endfor %} +{% endif %} {% endif %} diff --git a/data/templates/accel-ppp/pppoe.config.tmpl b/data/templates/accel-ppp/pppoe.config.tmpl index 46f462166..b37004f5b 100644 --- a/data/templates/accel-ppp/pppoe.config.tmpl +++ b/data/templates/accel-ppp/pppoe.config.tmpl @@ -136,6 +136,21 @@ pado-delay={{ pado_delay_param.value }} called-sid={{ authentication.radius.called_sid_format }} {% endif %} +{% if authentication is defined and authentication.mode is defined and authentication.mode == 'local' %} +{% if client_ip_pool is defined and client_ip_pool is not none %} +{% if client_ip_pool.name is defined and client_ip_pool.name is not none %} +{% for pool, pool_config in client_ip_pool.name.items() %} +{% if pool_config.subnet is defined and pool_config.subnet is not none %} +ip-pool={{ pool }} +{% if pool_config.gateway_address is defined and pool_config.gateway_address is not none %} +gw-ip-address={{ pool_config.gateway_address }}/{{ pool_config.subnet.split('/')[1] }} +{% endif %} +{% endif %} +{% endfor %} +{% endif %} +{% endif %} +{% endif %} + {% if limits is defined %} [connlimit] {% if limits.connection_limit is defined and limits.connection_limit is not none %} diff --git a/interface-definitions/service_ipoe-server.xml.in b/interface-definitions/service_ipoe-server.xml.in index b9279793c..d81ec99f9 100644 --- a/interface-definitions/service_ipoe-server.xml.in +++ b/interface-definitions/service_ipoe-server.xml.in @@ -117,19 +117,7 @@ Client IP pools and gateway setting - - - Pool name - - [-_a-zA-Z0-9]+ - - Client IP pool is limited to alphanumerical characters and can contain hyphen and underscores - - - #include - #include - - + #include #include diff --git a/interface-definitions/service_pppoe-server.xml.in b/interface-definitions/service_pppoe-server.xml.in index ba053ea75..a00125752 100644 --- a/interface-definitions/service_pppoe-server.xml.in +++ b/interface-definitions/service_pppoe-server.xml.in @@ -56,6 +56,7 @@ #include #include + #include #include diff --git a/python/vyos/configverify.py b/python/vyos/configverify.py index a35ea0b74..47cf218ee 100644 --- a/python/vyos/configverify.py +++ b/python/vyos/configverify.py @@ -1,4 +1,4 @@ -# Copyright 2020-2021 VyOS maintainers and contributors +# Copyright 2020-2023 VyOS maintainers and contributors # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -23,6 +23,7 @@ from vyos import ConfigError from vyos.util import dict_search +from vyos.util import dict_search_recursive def verify_mtu(config): """ @@ -355,7 +356,17 @@ def verify_accel_ppp_base_service(config): if 'key' not in radius_config: raise ConfigError(f'Missing RADIUS secret key for server "{server}"') - if 'gateway_address' not in config: + # Check global gateway or gateway in named pool + gateway = False + if 'gateway_address' in config: + gateway = True + else: + if dict_search_recursive(config, 'gateway_address', ['client_ip_pool', 'name']): + for _, v in config['client_ip_pool']['name'].items(): + if 'gateway_address' in v: + gateway = True + break + if not gateway: raise ConfigError('Server requires gateway-address to be configured!') if 'name_server_ipv4' in config: @@ -427,4 +438,3 @@ def verify_common_route_maps(config): for protocol, protocol_config in config['redistribute'].items(): if 'route_map' in protocol_config: verify_route_map(protocol_config['route_map'], config) - diff --git a/smoketest/scripts/cli/test_service_pppoe-server.py b/smoketest/scripts/cli/test_service_pppoe-server.py index 21d1028ce..fa596d33c 100755 --- a/smoketest/scripts/cli/test_service_pppoe-server.py +++ b/smoketest/scripts/cli/test_service_pppoe-server.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2020 VyOS maintainers and contributors +# Copyright (C) 2020-2023 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 @@ -172,6 +172,35 @@ class TestServicePPPoEServer(BasicAccelPPPTest.TestCase): self.assertTrue(process_named_running(self._process_name)) + def test_pppoe_server_client_ip_pool_name(self): + # Test configuration of named client pools + self.basic_config() + + subnet = '192.0.2.0/24' + gateway = '192.0.2.1' + pool = 'VYOS' + + subnet_name = f'{subnet},name' + gw_ip_prefix = f'{gateway}/24' + + self.set(['client-ip-pool', 'name', pool, 'subnet', subnet]) + self.set(['client-ip-pool', 'name', pool, 'gateway-address', gateway]) + self.cli_delete(self._base_path + ['gateway-address']) + + # commit changes + self.cli_commit() + + # Validate configuration values + conf = ConfigParser(allow_no_value=True, delimiters='=') + conf.read(self._config_file) + + # Validate configuration + self.assertEqual(conf['ip-pool'][subnet_name], pool) + self.assertEqual(conf['ip-pool']['gw-ip-address'], gateway) + self.assertEqual(conf['pppoe']['ip-pool'], pool) + self.assertEqual(conf['pppoe']['gw-ip-address'], gw_ip_prefix) + + def test_pppoe_server_client_ipv6_pool(self): # Test configuration of IPv6 client pools self.basic_config() -- cgit v1.2.3