diff options
author | jack9603301 <jack9603301@163.com> | 2020-12-10 23:23:44 +0800 |
---|---|---|
committer | jack9603301 <jack9603301@163.com> | 2020-12-13 02:12:45 +0800 |
commit | c4048b2047f693436b38196632cddf65beb67a86 (patch) | |
tree | 62a140416830d1c9f72636f3e72680f15279dbb3 /python/vyos/ifconfig/interface.py | |
parent | e6e87c839f8dc458dcf2962ea936329e972fbafc (diff) | |
download | vyos-1x-c4048b2047f693436b38196632cddf65beb67a86.tar.gz vyos-1x-c4048b2047f693436b38196632cddf65beb67a86.zip |
interfaces: T3114: Fix VLAN-aware bridge setting failure
Diffstat (limited to 'python/vyos/ifconfig/interface.py')
-rw-r--r-- | python/vyos/ifconfig/interface.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 6e6a83f36..eda3fadd6 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -731,6 +731,7 @@ class Interface(Control): >>> Interface('eth0').set_proxy_arp_pvlan(1) """ self.set_interface('proxy_arp_pvlan', enable) + def get_addr(self): """ @@ -898,6 +899,64 @@ class Interface(Control): # set bridge port path priority if 'priority' in bridge_config: self.set_path_cost(bridge_config['priority']) + + vlan_filter = 0 + + vlan_del = set() + vlan_add = set() + + if 'native_vlan' in bridge_config: + vlan_filter = 1 + cmd = f'bridge vlan del dev {self.ifname} vid 1' + self._cmd(cmd) + vlan_id = bridge_config['native_vlan'] + if int(vlan_id) != 1: + vlan_del.add(1) + cmd = f'bridge vlan add dev {self.ifname} vid {vlan_id} pvid untagged master' + self._cmd(cmd) + vlan_add.add(vlan_id) + + if 'allowed_vlan' in bridge_config: + vlan_filter = 1 + + if vlan_filter: + if 'native_vlan' not in bridge_config: + cmd = f'bridge vlan del dev {self.ifname} vid 1' + self._cmd(cmd) + + if 'allowed_vlan' in bridge_config: + for vlan in bridge_config['allowed_vlan']: + cmd = f'bridge vlan add dev {self.ifname} vid {vlan} master' + self._cmd(cmd) + vlan_add.add(vlan) + + vlan_bridge_ids = Section.klass(bridge)(bridge, create=True).get_vlan_ids() + + # Delete VLAN ID for the bridge + for vlan in vlan_del: + if int(vlan) == 1: + cmd = f'bridge vlan del dev {bridge} vid {vlan} self' + self._cmd(cmd) + + # Setting VLAN ID for the bridge + for vlan in vlan_add: + if isinstance(vlan,str) and vlan.isnumeric(): + if int(vlan) not in vlan_bridge_ids: + cmd = f'bridge vlan add dev {bridge} vid {vlan} self' + self._cmd(cmd) + elif isinstance(vlan,str) and not vlan.isnumeric(): + vlan_range = vlan.split('-') + for vlan_id in range(int(vlan_range[0]),int(vlan_range[1]) + 1): + if int(vlan_id) not in vlan_bridge_ids: + cmd = f'bridge vlan add dev {bridge} vid {vlan_id} self' + self._cmd(cmd) + else: + if vlan not in vlan_bridge_ids: + cmd = f'bridge vlan add dev {bridge} vid {vlan} self' + self._cmd(cmd) + + # enable/disable Vlan Filter + Section.klass(bridge)(bridge, create=True).set_vlan_filter(vlan_filter) def set_dhcp(self, enable): """ |