mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-01 07:47:15 +00:00
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 <archana.m.shinde@intel.com>
This commit is contained in:
parent
a32b21bd32
commit
2127288437
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user