mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 12:14:48 +00:00
netlink: Fix the issue of update_interface
When updating an interface, there's maybe an existed interface whose name would be the same with the updated required name, thus it would update failed with interface name existed error. Thus we should rename the existed interface with an temporary name and swap it with the previouse interface name last. Fixes: #6842 Signed-off-by: fupan <fupan.lfp@antgroup.com>
This commit is contained in:
parent
3ccc29030d
commit
2bda92face
@ -89,6 +89,27 @@ impl Handle {
|
||||
.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
|
||||
let mut request = self.handle.link().set(link.index());
|
||||
request.message_mut().header = link.header.clone();
|
||||
@ -101,6 +122,14 @@ impl Handle {
|
||||
.execute()
|
||||
.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(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user