Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipoe_server: T6649: Accel-ppp separate vlan-mon from listen interfaces #3987

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/templates/accel-ppp/ipoe.config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ verbose=1
{% set relay = ',' ~ 'relay=' ~ iface_config.external_dhcp.dhcp_relay if iface_config.external_dhcp.dhcp_relay is vyos_defined else '' %}
{% set giaddr = ',' ~ 'giaddr=' ~ iface_config.external_dhcp.giaddr if iface_config.external_dhcp.giaddr is vyos_defined else '' %}
{{ tmp }},{{ shared }}mode={{ iface_config.mode | upper }},ifcfg=1,{{ range }}start=dhcpv4,ipv6=1{{ relay }}{{ giaddr }}
{% if iface_config.vlan is vyos_defined %}
{% if iface_config.vlan_mon is vyos_defined %}
vlan-mon={{ iface }},{{ iface_config.vlan | join(',') }}
{% endif %}
{% endfor %}
Expand Down
2 changes: 2 additions & 0 deletions data/templates/accel-ppp/pppoe.config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ interface={{ iface }}
{% for vlan in iface_config.vlan %}
interface=re:^{{ iface }}\.{{ vlan | range_to_regex }}$
{% endfor %}
{% if iface_config.vlan_mon is vyos_defined %}
vlan-mon={{ iface }},{{ iface_config.vlan | join(',') }}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
Expand Down
8 changes: 8 additions & 0 deletions interface-definitions/include/accel-ppp/vlan-mon.xml.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- include start from accel-ppp/vlan-mon.xml.i -->
<leafNode name="vlan-mon">
<properties>
<help>Automatically create VLAN interfaces</help>
<valueless/>
</properties>
</leafNode>
<!-- include end -->
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- include start from include/version/ipoe-server-version.xml.i -->
<syntaxVersion component='ipoe-server' version='3'></syntaxVersion>
<syntaxVersion component='ipoe-server' version='4'></syntaxVersion>
<!-- include end -->
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- include start from include/version/pppoe-server-version.xml.i -->
<syntaxVersion component='pppoe-server' version='10'></syntaxVersion>
<syntaxVersion component='pppoe-server' version='11'></syntaxVersion>
<!-- include end -->
1 change: 1 addition & 0 deletions interface-definitions/service_ipoe-server.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
</children>
</node>
#include <include/accel-ppp/vlan.xml.i>
#include <include/accel-ppp/vlan-mon.xml.i>
</children>
</tagNode>
#include <include/accel-ppp/client-ip-pool.xml.i>
Expand Down
1 change: 1 addition & 0 deletions interface-definitions/service_pppoe-server.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
</properties>
<children>
#include <include/accel-ppp/vlan.xml.i>
#include <include/accel-ppp/vlan-mon.xml.i>
</children>
</tagNode>
<leafNode name="service-name">
Expand Down
32 changes: 32 additions & 0 deletions smoketest/scripts/cli/test_service_ipoe-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from base_accel_ppp_test import BasicAccelPPPTest
from vyos.configsession import ConfigSessionError
from vyos.utils.process import cmd
from vyos.template import range_to_regex
from configparser import ConfigParser
from configparser import RawConfigParser

Expand Down Expand Up @@ -228,6 +229,37 @@ def test_accel_ipv6_pool(self):
delegate={delegate_2_prefix},{delegate_mask},name={pool_name}"""
self.assertIn(pool_config, config)

def test_ipoe_server_vlan(self):
vlans = ['100', '200', '300-310']

# Test configuration of local authentication for PPPoE server
self.basic_config()
# cannot use "client-subnet" option with "vlan" option
# have to delete it
self.delete(['interface', interface, 'client-subnet'])
self.cli_commit()

self.set(['interface', interface, 'vlan-mon'])

# cannot use option "vlan-mon" if no "vlan" set
with self.assertRaises(ConfigSessionError):
self.cli_commit()

for vlan in vlans:
self.set(['interface', interface, 'vlan', vlan])

# commit changes
self.cli_commit()

# Validate configuration values
conf = ConfigParser(allow_no_value=True, delimiters='=', strict=False)
conf.read(self._config_file)
tmp = range_to_regex(vlans)
self.assertIn(f're:^{interface}\.{tmp}$', conf['ipoe']['interface'])

tmp = ','.join(vlans)
self.assertIn(f'{interface},{tmp}', conf['ipoe']['vlan-mon'])

@unittest.skip("PPP is not a part of IPoE")
def test_accel_ppp_options(self):
pass
Expand Down
7 changes: 7 additions & 0 deletions smoketest/scripts/cli/test_service_pppoe-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from configparser import ConfigParser
from vyos.utils.file import read_file
from vyos.template import range_to_regex
from vyos.configsession import ConfigSessionError

local_if = ['interfaces', 'dummy', 'dum667']
ac_name = 'ACN'
Expand Down Expand Up @@ -133,6 +134,12 @@ def test_pppoe_server_vlan(self):
# Test configuration of local authentication for PPPoE server
self.basic_config()

self.set(['interface', interface, 'vlan-mon'])

# cannot use option "vlan-mon" if no "vlan" set
with self.assertRaises(ConfigSessionError):
self.cli_commit()

for vlan in vlans:
self.set(['interface', interface, 'vlan', vlan])

Expand Down
2 changes: 2 additions & 0 deletions src/conf_mode/service_ipoe-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def verify(ipoe):
if 'client_subnet' in iface_config and 'vlan' in iface_config:
raise ConfigError('Option "client-subnet" and "vlan" are mutually exclusive, '
'use "client-ip-pool" instead!')
if 'vlan_mon' in iface_config and not 'vlan' in iface_config:
raise ConfigError('Option "vlan-mon" requires "vlan" to be set!')

verify_accel_ppp_authentication(ipoe, local_users=False)
verify_accel_ppp_ip_pool(ipoe)
Expand Down
5 changes: 4 additions & 1 deletion src/conf_mode/service_pppoe-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ def verify(pppoe):
raise ConfigError('At least one listen interface must be defined!')

# Check is interface exists in the system
for interface in pppoe['interface']:
for interface, interface_config in pppoe['interface'].items():
verify_interface_exists(pppoe, interface, warning_only=True)

if 'vlan_mon' in interface_config and not 'vlan' in interface_config:
raise ConfigError('Option "vlan-mon" requires "vlan" to be set!')

return None


Expand Down
30 changes: 30 additions & 0 deletions src/migration-scripts/ipoe-server/3-to-4
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.

# Add the "vlan-mon" option to the configuration to prevent it
# from disappearing from the configuration file

from vyos.configtree import ConfigTree

base = ['service', 'ipoe-server']

def migrate(config: ConfigTree) -> None:
if not config.exists(base):
return

for interface in config.list_nodes(base + ['interface']):
base_path = base + ['interface', interface]
if config.exists(base_path + ['vlan']):
config.set(base_path + ['vlan-mon'])
30 changes: 30 additions & 0 deletions src/migration-scripts/pppoe-server/10-to-11
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.

# Add the "vlan-mon" option to the configuration to prevent it
# from disappearing from the configuration file

from vyos.configtree import ConfigTree

base = ['service', 'pppoe-server']

def migrate(config: ConfigTree) -> None:
if not config.exists(base):
return

for interface in config.list_nodes(base + ['interface']):
base_path = base + ['interface', interface]
if config.exists(base_path + ['vlan']):
config.set(base_path + ['vlan-mon'])
Loading