diff --git a/lnst/Controller/Namespace.py b/lnst/Controller/Namespace.py index 5db1686fa..88e8930e8 100644 --- a/lnst/Controller/Namespace.py +++ b/lnst/Controller/Namespace.py @@ -265,3 +265,9 @@ def _update_device_id(self, value, name): return dev._id = name + + def keep_addrs_on_dev_down(self, device: Device) -> None: + self.run(f"echo 1 > /proc/sys/net/ipv6/conf/{device.name}/keep_addr_on_down") + + def remove_addrs_on_dev_down(self, device: Device): + self.run(f"echo 0 > /proc/sys/net/ipv6/conf/{device.name}/keep_addr_on_down") diff --git a/lnst/Devices/RemoteDevice.py b/lnst/Devices/RemoteDevice.py index b37391a4f..cc23ac9ea 100644 --- a/lnst/Devices/RemoteDevice.py +++ b/lnst/Devices/RemoteDevice.py @@ -188,6 +188,13 @@ def __repr__(self): return "{}({})".format(self._dev_cls.__name__, ", ".join(args)) + def keep_addrs_on_down(self) -> None: + self.netns.run(f"echo 1 > /proc/sys/net/ipv6/conf/{self.name}/keep_addr_on_down") + + def remove_addrs_on_down(self): + self.netns.run(f"echo 0 > /proc/sys/net/ipv6/conf/{self.name}/keep_addr_on_down") + + class PairedRemoteDevice(RemoteDevice): """RemoteDevice class for paired Devices (such as veth)""" def __init__(self, peer, dev_cls, args=[], kwargs={}):