mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-10 04:18:26 +00:00
Merge pull request #6860 from lifupan/main
netlink: Fix the issue of update_interface
This commit is contained in:
commit
5231aff90f
@ -89,6 +89,27 @@ impl Handle {
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we need to update the link's interface name, thus we should rename the existed link whose name
|
||||||
|
// is the same with the link's request name, otherwise, it would update the link failed with the
|
||||||
|
// name conflicted.
|
||||||
|
let mut new_link = None;
|
||||||
|
if link.name() != iface.name {
|
||||||
|
if let Ok(link) = self.find_link(LinkFilter::Name(iface.name.as_str())).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();
|
||||||
|
|
||||||
|
request
|
||||||
|
.name(format!("{}_temp", link.name()))
|
||||||
|
.up()
|
||||||
|
.execute()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
new_link = Some(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update link
|
// Update link
|
||||||
let mut request = self.handle.link().set(link.index());
|
let mut request = self.handle.link().set(link.index());
|
||||||
request.message_mut().header = link.header.clone();
|
request.message_mut().header = link.header.clone();
|
||||||
@ -101,6 +122,14 @@ impl Handle {
|
|||||||
.execute()
|
.execute()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// swap the updated iface's name.
|
||||||
|
if let Some(nlink) = new_link {
|
||||||
|
let mut request = self.handle.link().set(nlink.index());
|
||||||
|
request.message_mut().header = nlink.header.clone();
|
||||||
|
|
||||||
|
request.name(link.name()).up().execute().await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user