diff options
Diffstat (limited to 'python/vyos/ifconfig/bridge.py')
-rw-r--r-- | python/vyos/ifconfig/bridge.py | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/python/vyos/ifconfig/bridge.py b/python/vyos/ifconfig/bridge.py index d0d5da881..9bd4a22e7 100644 --- a/python/vyos/ifconfig/bridge.py +++ b/python/vyos/ifconfig/bridge.py @@ -14,12 +14,14 @@ # License along with this library. If not, see <http://www.gnu.org/licenses/>. from netifaces import interfaces +import json from vyos.ifconfig.interface import Interface from vyos.validate import assert_boolean from vyos.validate import assert_positive from vyos.util import cmd from vyos.util import dict_search +from vyos.configdict import get_vlan_ids @Interface.register class BridgeIf(Interface): @@ -44,6 +46,14 @@ class BridgeIf(Interface): 'vlan': True, }, } + + _sysfs_get = { + **Interface._sysfs_get,**{ + 'vlan_filter': { + 'location': '/sys/class/net/{ifname}/bridge/vlan_filtering' + } + } + } _sysfs_set = {**Interface._sysfs_set, **{ 'ageing_time': { @@ -92,6 +102,13 @@ class BridgeIf(Interface): 'shellcmd': 'ip link set dev {value} nomaster', }, }} + + def get_vlan_filter(self): + """ + Get the status of the bridge VLAN filter + """ + + return self.get_interface('vlan_filter') def set_ageing_time(self, time): @@ -260,6 +277,14 @@ class BridgeIf(Interface): tmp = dict_search('member.interface', config) if tmp: + if self.get_vlan_filter(): + bridge_vlan_ids = get_vlan_ids(ifname) + # Delete VLAN ID for the bridge + if 1 in bridge_vlan_ids: + bridge_vlan_ids.remove(1) + for vlan in bridge_vlan_ids: + vlan_del.add(str(vlan)) + for interface, interface_config in tmp.items(): # if interface does yet not exist bail out early and # add it later @@ -309,42 +334,32 @@ class BridgeIf(Interface): cmd = f'bridge vlan del dev {interface} vid 1' self._cmd(cmd) vlan_id = interface_config['native_vlan'] - if vlan_id != 1: + if int(vlan_id) != 1: + if 1 in vlan_add: + vlan_add.remove(1) vlan_del.add(1) cmd = f'bridge vlan add dev {interface} vid {vlan_id} pvid untagged master' self._cmd(cmd) vlan_add.add(vlan_id) + if vlan_id in vlan_del: + vlan_del.remove(vlan_id) if 'allowed_vlan' in interface_config: vlan_filter = 1 - - if vlan_filter: if 'native_vlan' not in interface_config: cmd = f'bridge vlan del dev {interface} vid 1' self._cmd(cmd) - - if 'allowed_vlan' in interface_config: + vlan_del.add(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) - - - + if vlan in vlan_del: + vlan_del.remove(vlan) 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) + 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' |