Page MenuHomeVyOS Platform

Extend template filter range_to_regex
Closed, ResolvedPublicFEATURE REQUEST

Description

The template filter range_to_regex should accept and correctly detect list arguments

For now, the values for the lists are not correct

>>> range_to_regex('2000-3000')
'(200\\d|20[1-9]\\d|2[1-9]\\d{2}|3000)'
>>> 
>>> 
>>> range_to_regex(['2000-3000', '3002-3005'])
['2000-3000', '3002-3005']
>>>

As the use case, it is T5057, for example, if we have several vlan-range interfaces
For example:

set service ipoe-server authentication mode 'noauth'
set service ipoe-server interface eth1 client-subnet '100.64.24.0/24'
set service ipoe-server interface eth1 network 'vlan'
set service ipoe-server interface eth1 vlan '2000-3000'
set service ipoe-server interface eth1 vlan '3002-3005'

We expect one regex for all listen to interfaces

Details

Difficulty level
Normal (likely a few hours)
Version
VyOS 1.4-rolling-202303060908
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Unspecified (possibly destroys the router)
Issue type
Improvement (missing useful functionality)

Event Timeline

Viacheslav changed the subtype of this task from "Bug" to "Feature Request".
Viacheslav updated the task description. (Show Details)
Viacheslav renamed this task from Extent template filter range_to_regex to Extend template filter range_to_regex.Mar 6 2023, 5:36 PM
Viacheslav changed the task status from Open to In progress.
Viacheslav claimed this task.

PR https://github.com/vyos/vyos-1x/pull/1870

>>> from vyos.template import range_to_regex
>>> 
>>> range_to_regex(['11-12', '14-15'])
'(1[1-2]|1[4-5])'
>>> 
>>>
Viacheslav changed the task status from In progress to Needs testing.Mar 7 2023, 10:12 AM
Viacheslav moved this task from Need Triage to Finished on the VyOS 1.4 Sagitta board.
Viacheslav reopened this task as Needs testing.EditedMar 10 2023, 10:16 AM

If we add vlan to range we get error

set service ipoe-server authentication mode 'noauth'
set service ipoe-server client-ip-pool name POOL1 gateway-address '192.0.2.1'
set service ipoe-server client-ip-pool name POOL1 subnet '192.0.2.0/24'
set service ipoe-server interface eth1 vlan '2000-3000'
commit
set service ipoe-server interface eth1 vlan '50'
commit

The second commit:

vyos@r14# commit
[ service ipoe-server ]
{'authentication': {'mode': 'noauth',
                    'radius': {'acct_timeout': '3',
                               'dynamic_author': {'port': '1700'},
                               'max_try': '3',
                               'rate_limit': {'attribute': 'Filter-Id',
                                              'multiplier': '1'},
                               'timeout': '3'}},
 'chap_secrets_file': '/run/accel-pppd/ipoe.chap-secrets',
 'client_ip_pool': {'name': {'POOL1': {'gateway_address': '192.0.2.1',
                                       'subnet': '192.0.2.0/24'}}},
 'interface': {'eth1': {'mode': 'l2',
                        'network': 'shared',
                        'vlan': ['2000-3000', '50']}},
 'thread_count': 2}


Traceback (most recent call last):
  File "/usr/libexec/vyos/conf_mode/service_ipoe-server.py", line 99, in <module>
    generate(c)
  File "/usr/libexec/vyos/conf_mode/service_ipoe-server.py", line 75, in generate
    render(ipoe_conf, 'accel-ppp/ipoe.config.j2', ipoe)
  File "/usr/lib/python3/dist-packages/vyos/template.py", line 141, in render
    rendered = render_to_string(template, content, formater, location)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/vyos/template.py", line 110, in render_to_string
    rendered = template.render(content)
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/lib/python3/dist-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/usr/share/vyos/templates/accel-ppp/ipoe.config.j2", line 28, in top-level template code
    {%             set tmp = tmp ~ 're:^' ~ iface ~ '\.' ~ iface_config.vlan | range_to_regex ~ '$' %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/vyos/template.py", line 679, in range_to_regex
    return f'({"|".join(data)})'
               ^^^^^^^^^^^^^^
TypeError: sequence item 1: expected str instance, NoneType found



[[service ipoe-server]] failed
Commit failed
[edit]
vyos@r14#

PR https://github.com/vyos/vyos-1x/pull/1884

>>> range_to_regex(['10-20', '22-35', '50'])
'(1\\d|20|2[2-9]|3[0-5]|50)'
>>>