From 1e88212c728d7b51d4680d93d6ec0852cdb0b412 Mon Sep 17 00:00:00 2001 From: Jan Tluka Date: Thu, 9 May 2024 15:45:39 +0200 Subject: [PATCH 1/3] Controller/Machine.py: pass the peer name when moving device to netns In particular for veth device pair, when first device from the pair is moved to netns, the peer name is generated from the device name with additional index suffix that is incorrect. For example for the devicepair of {lveth0, peer_lveth0}, when lveth0 is moved to a namespace, the peer is set to peer_lveth00. To fix this, we can pass the peer name directly in the remap_device call. Signed-off-by: Jan Tluka --- lnst/Controller/Machine.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py index 8dd7f4f6c..3fabcaf0b 100644 --- a/lnst/Controller/Machine.py +++ b/lnst/Controller/Machine.py @@ -135,6 +135,9 @@ def remote_device_set_netns(self, dev, dst, src): dev_args = dev._dev_args dev_kwargs = dev._dev_kwargs + if dev.peer_name: + dev_kwargs['peer_name'] = dev.peer_name + self.rpc_call("remap_device", dev.ifindex, clsname=dev_clsname, From 1e45557963d21cd417d722230f057b8008152b72 Mon Sep 17 00:00:00 2001 From: Jan Tluka Date: Thu, 9 May 2024 15:51:14 +0200 Subject: [PATCH 2/3] Agent/InterfaceManager: clear _nl_link_update when remapping a device Resolves an issue when moving a veth device to a namespace. The device will have _nl_link_update populated with data from generic Device creation (device appears in the namespace). This data may cause issues for certain device operations like setting the link up. To avoid this, clearing the _nl_link_update while remapping the device solves the issue. Fixes #367 Signed-off-by: Jan Tluka --- lnst/Agent/InterfaceManager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lnst/Agent/InterfaceManager.py b/lnst/Agent/InterfaceManager.py index 5de6ed91c..f13729ef5 100644 --- a/lnst/Agent/InterfaceManager.py +++ b/lnst/Agent/InterfaceManager.py @@ -247,6 +247,7 @@ def remap_device(self, ifindex, clsname, args=[], kwargs={}): except KeyError as e: raise DeviceConfigError("%s is a mandatory argument" % e) remapped_device._bulk_enabled = False + remapped_device._nl_link_update = {} remapped_device.ifindex = ifindex self.replace_dev(ifindex, remapped_device) self.rescan_devices() From 52bbb5d8f9d35a22f54674f098149a24657d2cb4 Mon Sep 17 00:00:00 2001 From: Jan Tluka Date: Thu, 9 May 2024 16:42:39 +0200 Subject: [PATCH 3/3] Controller/Machine.py: handle exceptions when accessing peer_name attribute Signed-off-by: Jan Tluka --- lnst/Controller/Machine.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lnst/Controller/Machine.py b/lnst/Controller/Machine.py index 3fabcaf0b..9555fc1a7 100644 --- a/lnst/Controller/Machine.py +++ b/lnst/Controller/Machine.py @@ -135,8 +135,11 @@ def remote_device_set_netns(self, dev, dst, src): dev_args = dev._dev_args dev_kwargs = dev._dev_kwargs - if dev.peer_name: - dev_kwargs['peer_name'] = dev.peer_name + try: + if dev.peer_name: + dev_kwargs['peer_name'] = dev.peer_name + except AttributeError: + pass self.rpc_call("remap_device", dev.ifindex,