From 7d8fbf9d6c6af0cb6a88dbbd0097dd101c57d00d Mon Sep 17 00:00:00 2001 From: Samuel Dobron Date: Fri, 21 Jun 2024 17:06:47 +0200 Subject: [PATCH] RemoteDevice: added {keep,remove}_on_down functions Added functions that can set/unset device's flag to either keep or remove IPv6 addresses on shutting-down device. --- lnst/Controller/Namespace.py | 6 ++++++ lnst/Devices/RemoteDevice.py | 7 +++++++ 2 files changed, 13 insertions(+) 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={}):