diff options
author | Daniil Baturin <daniil@vyos.io> | 2025-04-22 15:50:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-22 15:50:34 +0100 |
commit | be0ce3a33d717fe06bc52fe1f30a544a62ae5552 (patch) | |
tree | f9aba30863ef33b4ce607cdada31101118412984 /python | |
parent | 35e3a3722b5f420384e6d4a3fbf140210815f65c (diff) | |
parent | 1d636f4c3779f4b5b08ccb1643dd80bc86c10fbf (diff) | |
download | vyos-1x-be0ce3a33d717fe06bc52fe1f30a544a62ae5552.tar.gz vyos-1x-be0ce3a33d717fe06bc52fe1f30a544a62ae5552.zip |
Merge pull request #4444 from l0crian1/T7322-fix-allowed-vlan
bridge: T7322: fix slow performance of allowed vlan
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/configdict.py | 17 | ||||
-rw-r--r-- | python/vyos/ifconfig/bridge.py | 14 |
2 files changed, 21 insertions, 10 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py index 78b98a3eb..586ddf632 100644 --- a/python/vyos/configdict.py +++ b/python/vyos/configdict.py @@ -626,6 +626,23 @@ def get_vlan_ids(interface): return vlan_ids +def get_vlans_ids_and_range(interface): + vlan_ids = set() + + vlan_filter_status = json.loads(cmd(f'bridge -j -d vlan show dev {interface}')) + + if vlan_filter_status is not None: + for interface_status in vlan_filter_status: + for vlan_entry in interface_status.get("vlans", []): + start = vlan_entry["vlan"] + end = vlan_entry.get("vlanEnd") + if end: + vlan_ids.add(f"{start}-{end}") + else: + vlan_ids.add(str(start)) + + return vlan_ids + def get_accel_dict(config, base, chap_secrets, with_pki=False): """ Common utility function to retrieve and mangle the Accel-PPP configuration diff --git a/python/vyos/ifconfig/bridge.py b/python/vyos/ifconfig/bridge.py index d534dade7..f81026965 100644 --- a/python/vyos/ifconfig/bridge.py +++ b/python/vyos/ifconfig/bridge.py @@ -19,7 +19,7 @@ from vyos.utils.assertion import assert_list from vyos.utils.assertion import assert_positive from vyos.utils.dict import dict_search from vyos.utils.network import interface_exists -from vyos.configdict import get_vlan_ids +from vyos.configdict import get_vlans_ids_and_range from vyos.configdict import list_diff @Interface.register @@ -380,7 +380,7 @@ class BridgeIf(Interface): add_vlan = [] native_vlan_id = None allowed_vlan_ids= [] - cur_vlan_ids = get_vlan_ids(interface) + cur_vlan_ids = get_vlans_ids_and_range(interface) if 'native_vlan' in interface_config: vlan_id = interface_config['native_vlan'] @@ -389,14 +389,8 @@ class BridgeIf(Interface): if 'allowed_vlan' in interface_config: for vlan in interface_config['allowed_vlan']: - vlan_range = vlan.split('-') - if len(vlan_range) == 2: - for vlan_add in range(int(vlan_range[0]),int(vlan_range[1]) + 1): - add_vlan.append(str(vlan_add)) - allowed_vlan_ids.append(str(vlan_add)) - else: - add_vlan.append(vlan) - allowed_vlan_ids.append(vlan) + add_vlan.append(vlan) + allowed_vlan_ids.append(vlan) # Remove redundant VLANs from the system for vlan in list_diff(cur_vlan_ids, add_vlan): |