Skip to content

Commit 5d94687

Browse files
committed
ethernet: T7813: remove VLAN interfaces first on deletion
When an Ethernet interface is deleted from the configuration, its associated VLAN subinterfaces must be removed first. This ordering allows VLAN interfaces to gracefully release any active DHCP or DHCPv6 leases before the parent interface disappears, ensuring proper cleanup and avoiding potential lease retention issues.
1 parent 6a47b69 commit 5d94687

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

python/vyos/ifconfig/ethernet.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,17 @@ def remove(self):
131131
>>> i.remove()
132132
"""
133133

134+
# T7813: we do need to remove the VLAN subinterfaces first so we can
135+
# properly stop the DHCP client and inform the DHCP server that we are
136+
# returning the lease.
137+
for vlan in Section.sub_interfaces(self.ifname):
138+
Interface(vlan).remove()
139+
134140
if self.exists(self.ifname):
135141
# interface is placed in A/D state when removed from config! It
136142
# will remain visible for the operating system.
137143
self.set_admin_state('down')
138144

139-
# Remove all VLAN subinterfaces - filter with the VLAN dot
140-
for vlan in [
141-
x
142-
for x in Section.interfaces('ethernet')
143-
if x.startswith(f'{self.ifname}.')
144-
]:
145-
Interface(vlan).remove()
146-
147145
super().remove()
148146

149147
def set_flow_control(self, enable):

python/vyos/ifconfig/section.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,17 @@ def interfaces(cls, section='', vlan=True):
144144
if no section is provided, then it returns all configured interfaces.
145145
If vlan is True, also Vlan subinterfaces will be returned
146146
"""
147-
148147
return cls._sort_interfaces(cls._intf_under_section(section, vlan))
149148

149+
@classmethod
150+
def sub_interfaces(cls, interface : str) -> list:
151+
"""
152+
return a list of subinterfaces (e.g. VLAN) derived from a given interface
153+
"""
154+
if_type = cls.section(interface)
155+
res = [x for x in cls.interfaces(if_type) if x.startswith(f'{interface}.')]
156+
return res
157+
150158
@classmethod
151159
def _intf_with_feature(cls, feature=''):
152160
"""

0 commit comments

Comments
 (0)