diff options
| author | Christian Breunig <christian@breunig.cc> | 2025-10-17 18:37:45 +0200 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2025-10-17 18:46:00 +0200 |
| commit | cf46662573525e0f0791c69405bbf10cde917184 (patch) | |
| tree | a3e9801fecac2c0b5fa15b128608edcc17c4e0c9 /python | |
| parent | b9edbc4f913598baca90e22a943f90635ceb7a29 (diff) | |
| download | vyos-1x-cf46662573525e0f0791c69405bbf10cde917184.tar.gz vyos-1x-cf46662573525e0f0791c69405bbf10cde917184.zip | |
frrender: T7927: de-nest DHCP and PPPoE interface section for VRFs
This update refactors the code path to eliminate unnecessary nesting when
processing interfaces using PPPoE or DHCP that are bound to a VRF.
Previously, the configuration dictionary was only populated if a static route
was defined under the corresponding VRF node. This behavior was incorrect, as
interfaces tied to a VRF can receive dynamic routes - such as a default route
via DHCP - without having any static routing configuration. A typical use case
is a VRF dedicated to out-of-band management.
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/frrender.py | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/python/vyos/frrender.py b/python/vyos/frrender.py index e619cf67c..decec8aa2 100644 --- a/python/vyos/frrender.py +++ b/python/vyos/frrender.py @@ -23,10 +23,16 @@ Will fail early if the rendered configuration has any errors. import os +from copy import deepcopy from time import sleep +from vyos.config import Config +from vyos.config import config_dict_merge +from vyos.configdict import get_dhcp_interfaces +from vyos.configdict import get_pppoe_interfaces from vyos.defaults import frr_debug_enable from vyos.utils.dict import dict_search +from vyos.utils.dict import dict_set_nested from vyos.utils.file import write_file from vyos.utils.process import cmd from vyos.utils.process import rc_cmd @@ -62,12 +68,7 @@ ripng_daemon = 'ripngd' zebra_daemon = 'zebra' nhrp_daemon = 'nhrpd' -def get_frrender_dict(conf, argv=None) -> dict: - from copy import deepcopy - from vyos.config import config_dict_merge - from vyos.configdict import get_dhcp_interfaces - from vyos.configdict import get_pppoe_interfaces - +def get_frrender_dict(conf: Config, argv=None) -> dict: # We need to re-set the CLI path to the root level, as this function uses # conf.exists() with an absolute path form the CLI root conf.set_level([]) @@ -439,17 +440,10 @@ def get_frrender_dict(conf, argv=None) -> dict: # T3680 - get a list of all interfaces currently configured to use DHCP tmp = get_dhcp_interfaces(conf) - if tmp: - if 'static' in dict: - dict['static'].update({'dhcp' : tmp}) - else: - dict.update({'static' : {'dhcp' : tmp}}) + if tmp: dict_set_nested('static.dhcp', tmp, dict) + tmp = get_pppoe_interfaces(conf) - if tmp: - if 'static' in dict: - dict['static'].update({'pppoe' : tmp}) - else: - dict.update({'static' : {'pppoe' : tmp}}) + if tmp: dict_set_nested('static.pppoe', tmp, dict) # keep a re-usable list of dependent VRFs dependent_vrfs_default = {} @@ -577,16 +571,17 @@ def get_frrender_dict(conf, argv=None) -> dict: static = conf.get_config_dict(static_vrf_path, key_mangling=('-', '_'), get_first_key=True, no_tag_node_value_mangle=True) - # T3680 - get a list of all interfaces currently configured to use DHCP - tmp = get_dhcp_interfaces(conf, vrf_name) - if tmp: static.update({'dhcp' : tmp}) - tmp = get_pppoe_interfaces(conf, vrf_name) - if tmp: static.update({'pppoe' : tmp}) - vrf['name'][vrf_name]['protocols'].update({'static': static}) elif conf.exists_effective(static_vrf_path): vrf['name'][vrf_name]['protocols'].update({'static': {'deleted' : ''}}) + # T3680 - get a list of all interfaces currently configured to use DHCP + tmp = get_dhcp_interfaces(conf, vrf_name) + if tmp: dict_set_nested(f'name.{vrf_name}.protocols.static.dhcp', tmp, vrf) + + tmp = get_pppoe_interfaces(conf, vrf_name) + if tmp: dict_set_nested(f'name.{vrf_name}.protocols.static.pppoe', tmp, vrf) + vrf_vni_path = ['vrf', 'name', vrf_name, 'vni'] if conf.exists(vrf_vni_path): vrf_config.update({'vni': conf.return_value(vrf_vni_path)}) |
