diff options
Diffstat (limited to 'python/vyos/ifconfig/interface.py')
-rw-r--r-- | python/vyos/ifconfig/interface.py | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 495e96600..e3c6beb8f 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -32,6 +32,7 @@ from netifaces import AF_INET6 from vyos import ConfigError from vyos.configdict import list_diff from vyos.configdict import dict_merge +from vyos.configdict import get_vlan_ids from vyos.template import render from vyos.util import mac2eui64 from vyos.util import dict_search @@ -887,6 +888,8 @@ class Interface(Control): # drop all interface addresses first self.flush_addrs() + + ifname = self.ifname for bridge, bridge_config in bridge_dict.items(): # add interface to bridge - use Section.klass to get BridgeIf class @@ -901,17 +904,25 @@ class Interface(Control): self.set_path_cost(bridge_config['priority']) vlan_filter = 0 - - vlan_del = set() vlan_add = set() + + del_ifname_vlan_ids = get_vlan_ids(ifname) + bridge_vlan_filter = Section.klass(bridge)(bridge, create=True).get_vlan_filter() + + if bridge_vlan_filter: + if 1 in del_ifname_vlan_ids: + del_ifname_vlan_ids.remove(1) + vlan_filter = 1 + + for vlan in del_ifname_vlan_ids: + cmd = f'bridge vlan del dev {ifname} vid {vlan}' + self._cmd(cmd) 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) @@ -926,32 +937,14 @@ class Interface(Control): self._cmd(cmd) vlan_add.add(vlan) - vlan_bridge_ids = Section.klass(bridge)(bridge, create=True).get_vlan_ids() - - apply_vlan_ids = set() - - # 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: - vlan_range = vlan.split('-') - apply_vlan_ids.add(int(vlan_range[0])) - if(len(vlan_range) == 2): - for vlan_id in range(int(vlan_range[0])+1,int(vlan_range[1]) + 1): - if int(vlan_id) not in vlan_bridge_ids: - apply_vlan_ids.add(int(vlan_id)) - - for vlan in apply_vlan_ids: - cmd = f'bridge vlan add dev {bridge} vid {vlan} self' - self._cmd(cmd) - - # enable/disable Vlan Filter - # When the VLAN aware option is not detected, the setting of `bridge` should not be overwritten if vlan_filter: + # Setting VLAN ID for the bridge + for vlan in vlan_add: + cmd = f'bridge vlan add dev {bridge} vid {vlan} self' + self._cmd(cmd) + + # enable/disable Vlan Filter + # When the VLAN aware option is not detected, the setting of `bridge` should not be overwritten Section.klass(bridge)(bridge, create=True).set_vlan_filter(vlan_filter) def set_dhcp(self, enable): |