diff options
author | jack9603301 <jack9603301@163.com> | 2020-11-14 15:44:12 +0800 |
---|---|---|
committer | jack9603301 <jack9603301@163.com> | 2020-11-14 15:44:12 +0800 |
commit | 68b7cbe11dbe14109d9b4c564f2499b574309665 (patch) | |
tree | 1a1e7476cc77f54f2df34686f13a4f3b39b05b06 | |
parent | 7106e90daf7c15f167f38f7715facef37c141f4f (diff) | |
download | vyos-1x-68b7cbe11dbe14109d9b4c564f2499b574309665.tar.gz vyos-1x-68b7cbe11dbe14109d9b4c564f2499b574309665.zip |
bridge: T3042: Better fix implementation errors
In #601, I provided a basic patch. Under this patch, I rely on vif to
detect the vlan id range that the bridge should flow through,
which may lead to greater redundancy in the configuration,
so I am considering detecting effective vlan filters In setting the range
of vlan id that is required to flow through the bridge,
I use set() to complete the deduplication of this vlan id
and set it to the bridge uniformly (at the same time,
I slightly modified the smoke test script)
-rw-r--r-- | python/vyos/ifconfig/bridge.py | 37 | ||||
-rwxr-xr-x | smoketest/scripts/cli/test_interfaces_bridge.py | 2 |
2 files changed, 30 insertions, 9 deletions
diff --git a/python/vyos/ifconfig/bridge.py b/python/vyos/ifconfig/bridge.py index 7eac9b886..7c77e050a 100644 --- a/python/vyos/ifconfig/bridge.py +++ b/python/vyos/ifconfig/bridge.py @@ -255,6 +255,9 @@ class BridgeIf(Interface): if member in interfaces(): self.del_port(member) vlan_filter = 0 + + vlan_del = set() + vlan_add = set() tmp = dict_search('member.interface', config) if tmp: @@ -286,12 +289,13 @@ class BridgeIf(Interface): tmp = dict_search('native_vlan_removed', interface_config) - if tmp and 'native_vlan_removed' not in interface_config: - vlan_id = tmp - cmd = f'bridge vlan add dev {interface} vid 1 pvid untagged master' - self._cmd(cmd) + for vlan_id in (tmp or []): cmd = f'bridge vlan del dev {interface} vid {vlan_id}' self._cmd(cmd) + cmd = f'bridge vlan add dev {interface} vid 1 pvid untagged master' + self._cmd(cmd) + vlan_del.add(vlan_id) + vlan_add.add(1) tmp = dict_search('allowed_vlan_removed', interface_config) @@ -299,31 +303,48 @@ class BridgeIf(Interface): for vlan_id in (tmp or []): cmd = f'bridge vlan del dev {interface} vid {vlan_id}' self._cmd(cmd) + vlan_del.add(vlan_id) if 'native_vlan' in interface_config: vlan_filter = 1 cmd = f'bridge vlan del dev {interface} vid 1' self._cmd(cmd) + vlan_del.add(1) vlan_id = interface_config['native_vlan'] cmd = f'bridge vlan add dev {interface} vid {vlan_id} pvid untagged master' self._cmd(cmd) + vlan_add.add(vlan_id) else: cmd = f'bridge vlan del dev {interface} vid 1' self._cmd(cmd) + vlan_del.add(1) if 'allowed_vlan' in interface_config: vlan_filter = 1 for vlan in interface_config['allowed_vlan']: cmd = f'bridge vlan add dev {interface} vid {vlan} master' self._cmd(cmd) + vlan_add.add(vlan) - vif = dict_search('vif', config) - if vif: - for vlan_id,vif_config in vif.items(): - cmd = f'bridge vlan add dev {ifname} vid {vlan_id} self master' + for vlan in vlan_del: + if isinstance(vlan,str) and vlan.isnumeric(): + if int(vlan) == 1: + cmd = f'bridge vlan del dev {ifname} vid {vlan} self' + self._cmd(cmd) + cmd = f'bridge vlan add dev {ifname} vid {vlan} pvid untagged self' + self._cmd(cmd) + else: + cmd = f'bridge vlan del dev {ifname} vid {vlan} self' + self._cmd(cmd) + else: + cmd = f'bridge vlan del dev {ifname} vid {vlan} self' self._cmd(cmd) + for vlan in vlan_add: + cmd = f'bridge vlan add dev {ifname} vid {vlan} self' + self._cmd(cmd) + # enable/disable Vlan Filter self.set_vlan_filter(vlan_filter) diff --git a/smoketest/scripts/cli/test_interfaces_bridge.py b/smoketest/scripts/cli/test_interfaces_bridge.py index 3b7f1bc9a..3742491e8 100755 --- a/smoketest/scripts/cli/test_interfaces_bridge.py +++ b/smoketest/scripts/cli/test_interfaces_bridge.py @@ -87,7 +87,7 @@ class BridgeInterfaceTest(BasicInterfaceTest.BaseTest): """ Add member interface to bridge and set VLAN filter """ for interface in self._interfaces: base = self._base_path + [interface] - self.session.set(base + ['address', '192.0.2.1/24']) + self.session.set(base + ['vif', '1','address', '192.0.2.1/24']) self.session.set(base + ['vif', '2','address','192.0.3.1/24']) vlan_id = 101 |