From 21272884371fbb3115bdb4448c55181e9a6e2d6d Mon Sep 17 00:00:00 2001 From: Archana Shinde Date: Mon, 24 Jun 2024 19:18:31 -0700 Subject: [PATCH] agent: Bring interface down before renaming it. In case we are dealing with multiple interfaces and there exists a network interface with a conflicting name, we temporarily rename it to avoid name conflicts. Before doing this, we need to rename bring the interface down. Failure to do so results in netlink returning Resource busy errors. The resource needs to be down for subsequent operation when the name is swapped back as well. This solves the issue of passing multiple networks in case of nerdctl as: nerdctl run --rm --net foo --net bar docker.io/library/busybox:latest ip a Fixes: #9900 Signed-off-by: Archana Shinde --- src/agent/src/netlink.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/agent/src/netlink.rs b/src/agent/src/netlink.rs index b41cf9b096..bb5be32f58 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/src/netlink.rs @@ -95,16 +95,30 @@ impl Handle { let mut new_link = None; if link.name() != iface.name { if let Ok(link) = self.find_link(LinkFilter::Name(iface.name.as_str())).await { + // Bring down interface if it is UP + if link.is_up() { + self.enable_link(link.index(), false).await?; + } + // update the existing interface name with a temporary name, otherwise // it would failed to udpate this interface with an existing name. let mut request = self.handle.link().set(link.index()); request.message_mut().header = link.header.clone(); + let link_name = link.name(); + let temp_name = link_name.clone() + "_temp"; request - .name(format!("{}_temp", link.name())) - .up() + .name(temp_name.clone()) .execute() - .await?; + .await + .map_err(|err| { + anyhow!( + "Failed to rename interface {} to {}with error: {}", + link_name, + temp_name, + err + ) + })?; new_link = Some(link); }