diff options
author | jack9603301 <jack9603301@163.com> | 2021-01-13 13:33:29 +0800 |
---|---|---|
committer | jack9603301 <jack9603301@163.com> | 2021-01-15 16:26:33 +0800 |
commit | fddf7daf9f5177c11f3bac911f477e3063f69786 (patch) | |
tree | e1f696db4e3e080ca6f6e289120e01fa7b8da1d5 /python/vyos/ifconfig/interface.py | |
parent | 38566b8fbdec60b1601ed127fd759c85802909e9 (diff) | |
download | vyos-1x-fddf7daf9f5177c11f3bac911f477e3063f69786.tar.gz vyos-1x-fddf7daf9f5177c11f3bac911f477e3063f69786.zip |
bridge: T3137: Better implementation of VLAN aware Bridge
Diffstat (limited to 'python/vyos/ifconfig/interface.py')
-rw-r--r-- | python/vyos/ifconfig/interface.py | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index ffe55648c..433d19dbf 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -900,29 +900,46 @@ class Interface(Control): if 'priority' in bridge_config: self.set_path_cost(bridge_config['priority']) - del_ifname_vlan_ids = get_vlan_ids(ifname) - bridge_vlan_filter = int(Section.klass(bridge)(bridge, create=True).get_vlan_filter()) + bridge_vlan_filter = Section.klass(bridge)(bridge, create=True).get_vlan_filter() - if bridge_vlan_filter: - - # Delete all VLAN IDS configured in the interface first - for vlan in del_ifname_vlan_ids: - cmd = f'bridge vlan del dev {ifname} vid {vlan} master' - self._cmd(cmd) + if int(bridge_vlan_filter): + cur_vlan_ids = get_vlan_ids(ifname) + add_vlan = [] + native_vlan_id = None + allowed_vlan_ids= [] if 'native_vlan' in bridge_config: vlan_id = bridge_config['native_vlan'] - cmd = f'bridge vlan add dev {ifname} vid {vlan_id} pvid untagged master' - self._cmd(cmd) + add_vlan.append(vlan_id) + native_vlan_id = vlan_id else: # VLAN 1 is the default VLAN for all unlabeled packets - cmd = f'bridge vlan add dev {ifname} vid 1 pvid untagged master' - self._cmd(cmd) + add_vlan.append(1) + native_vlan_id = 1 if 'allowed_vlan' in bridge_config: for vlan in bridge_config['allowed_vlan']: - cmd = f'bridge vlan add dev {ifname} vid {vlan} master' - self._cmd(cmd) + 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) + + # Remove redundant VLANs from the system + for vlan in list_diff(cur_vlan_ids, add_vlan): + cmd = f'bridge vlan del dev {ifname} vid {vlan} master' + self._cmd(cmd) + + for vlan in allowed_vlan_ids: + cmd = f'bridge vlan add dev {ifname} vid {vlan} master' + self._cmd(cmd) + + # Setting native VLAN to system + cmd = f'bridge vlan add dev {ifname} vid {native_vlan_id} pvid untagged master' + self._cmd(cmd) def set_dhcp(self, enable): """ |