From 2f5ced44d12f3e92a22cc43eb5f4e7df4b7f062f Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Tue, 4 Nov 2025 16:16:25 +0100 Subject: veth: T7990: fix stale DHCP clients when removing virtual Ethernet pairs When removing a veth interface, the kernel automatically deletes its peer interface, since veth devices always exist in pairs. However, this automatic removal does not trigger the remove() helper in vyos.ifconfig.interfaces, which can leave associated DHCP(v6) clients running indefinitely. For example: ip link add veth0 type veth peer name veth1 ip link del dev veth1 Removing veth1 will also delete veth0 in the kernel, but the VyOS cleanup routines are never called for veth0. This patch ensures that peer removal correctly purges both interfaces and their associated state. This drops the workarounds in veth smoketest and falls back to the common interface smoketests from the inherited base class. --- python/vyos/ifconfig/interface.py | 12 ++++++++++-- python/vyos/ifconfig/veth.py | 18 +++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 761ba1799..491651aac 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -371,7 +371,7 @@ class Interface(Control): if 'netns' in self.config: cmd = f'ip netns exec {netns} {cmd}' self._cmd(cmd) - def remove(self): + def remove(self, skip_delete=False): """ Remove interface from operating system. Removing the interface deconfigures all assigned IP addresses and clear possible DHCP(v6) @@ -388,12 +388,20 @@ class Interface(Control): # remove all assigned IP addresses from interface - this is a bit redundant # as the kernel will remove all addresses on interface deletion, but we - # can not delete ALL interfaces, see below + # can not delete ALL interfaces, see below. + # + # This will internally stop DHCP(v6) if running self.flush_addrs() # remove interface from conntrack VRF interface map self._del_interface_from_ct_iface_map() + # Some interfaces - mainly veth pairs - should be properly de-configured + # but not deleted. Deleting one veth pair member will delete the other, + # we need need a way to skip the deletion. + if skip_delete: + return + # --------------------------------------------------------------------- # Any class can define an eternal regex in its definition # interface matching the regex will not be deleted diff --git a/python/vyos/ifconfig/veth.py b/python/vyos/ifconfig/veth.py index f4075fa02..9868ea526 100644 --- a/python/vyos/ifconfig/veth.py +++ b/python/vyos/ifconfig/veth.py @@ -14,7 +14,8 @@ # License along with this library. If not, see . from vyos.ifconfig.interface import Interface - +from vyos.utils.dict import dict_search +from vyos.utils.network import get_interface_config @Interface.register class VethIf(Interface): @@ -51,3 +52,18 @@ class VethIf(Interface): # interface is always A/D down. It needs to be enabled explicitly self.set_admin_state('down') + + def remove(self): + # The oddity with virtual-ethernet pairs is, if you delete one - the OS + # Kernel will immediately delete the other interface, leaving no + # possibility to properly shutdown the peer-interface. + # + # We deconfigure the second veth pair interface during deletion, but + # skip it's actual call to "ip link del dev ..." + tmp = get_interface_config(self.ifname) + peer = tmp.get('link', dict_search('linkinfo.info_kind', tmp)) + if peer != None: + Interface(peer).remove(skip_delete=True) + + # always forward to the base class + super().remove() -- cgit v1.2.3