summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-09-24 21:41:27 +0200
committerChristian Poessinger <christian@poessinger.com>2019-09-24 21:53:26 +0200
commit1dc92ac5a36b2e1f3e1f8dc2248e68892bfda248 (patch)
tree95f97fb9cc349fc294fd5335543607bd34e6ed58 /python
parent3aed7f2dad9326ae094edc94b996db4fce2e0b18 (diff)
downloadvyos-1x-1dc92ac5a36b2e1f3e1f8dc2248e68892bfda248.tar.gz
vyos-1x-1dc92ac5a36b2e1f3e1f8dc2248e68892bfda248.zip
Python/ifconfig: T1557: bugfix removing Q-in-Q VLAN interfaces
VLAN interfaces have not been removed "in order". What does it mean? We need to delete Q-in-Q interfaces prior to deleting the underlaying VLAN interface (vif-s). This was not the case and that triggered an exception that a non existing interface was about to be removed. Tested using adding and deleting the following config: set interfaces ethernet eth2 address 192.0.2.1/24 set interfaces ethernet eth2 description "VyOS bonding" set interfaces ethernet eth2 disable-link-detect set interfaces ethernet eth2 mac 00:91:00:00:00:01 set interfaces ethernet eth2 mtu 9000 set interfaces ethernet eth2 vif-s 100 address 192.168.10.1/24 set interfaces ethernet eth2 vif-s 100 description "802.1ad service VLAN 100" set interfaces ethernet eth2 vif-s 100 mtu 1500 set interfaces ethernet eth2 vif-s 100 mac 00:91:00:00:00:02 set interfaces ethernet eth2 vif-s 100 vif-c 110 address "192.168.110.1/24" set interfaces ethernet eth2 vif-s 100 vif-c 110 description "client VLAN 110" set interfaces ethernet eth2 vif-s 100 vif-c 120 address "192.168.120.1/24" set interfaces ethernet eth2 vif-s 100 vif-c 120 description "client VLAN 120" set interfaces ethernet eth2 vif-s 100 vif-c 130 address "192.168.130.1/24" set interfaces ethernet eth2 vif-s 100 vif-c 130 description "client VLAN 130" set interfaces ethernet eth2 vif 400 address 192.168.40.1/24 set interfaces ethernet eth2 vif 400 description "802.1q VLAN 400" set interfaces ethernet eth2 vif 400 mtu 1500 set interfaces ethernet eth2 vif 400 mac 00:91:00:00:00:03
Diffstat (limited to 'python')
-rw-r--r--python/vyos/ifconfig.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py
index 8f81bc9f6..a959e55d8 100644
--- a/python/vyos/ifconfig.py
+++ b/python/vyos/ifconfig.py
@@ -818,12 +818,22 @@ class VLANIf(Interface):
>>> i = Interface('eth0')
>>> i.remove()
"""
- # do we have sub interfaces (VLANs)?
- # we apply a regex matching subinterfaces (indicated by a .) of a
- # parent interface. 'bond0(?:\.\d+){1,2}' will match vif and vif-s/vif-c
- # subinterfaces
+ # Do we have sub interfaces (VLANs)? We apply a regex matching
+ # subinterfaces (indicated by a .) of a parent interface.
+ #
+ # As interfaces need to be deleted "in order" starting from Q-in-Q
+ # we delete them first.
+ vlan_ifs = [f for f in os.listdir(r'/sys/class/net') \
+ if re.match(self._ifname + r'(?:\.\d+)(?:\.\d+)', f)]
+
+ for vlan in vlan_ifs:
+ Interface(vlan).remove()
+
+ # After deleting all Q-in-Q interfaces delete other VLAN interfaces
+ # which probably acted as parent to Q-in-Q or have been regular 802.1q
+ # interface.
vlan_ifs = [f for f in os.listdir(r'/sys/class/net') \
- if re.match(self._ifname + r'(?:\.\d+){1,2}', f)]
+ if re.match(self._ifname + r'(?:\.\d+)', f)]
for vlan in vlan_ifs:
Interface(vlan).remove()
@@ -897,8 +907,7 @@ class VLANIf(Interface):
>>> i.del_vlan()
"""
vlan_ifname = self._ifname + '.' + str(vlan_id)
- tmp = VLANIf(vlan_ifname)
- tmp.remove()
+ VLANIf(vlan_ifname).remove()
class EthernetIf(VLANIf):