mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-15 06:34:03 +00:00
runtime-rs: ignore unconfigured network interfaces
Fixes: #7020 Signed-off-by: soup <lqh348659137@outlook.com>
This commit is contained in:
parent
22d4e4c5a6
commit
150e54d02b
@ -31,6 +31,7 @@ impl NetworkInfoFromLink {
|
|||||||
pub async fn new(
|
pub async fn new(
|
||||||
handle: &rtnetlink::Handle,
|
handle: &rtnetlink::Handle,
|
||||||
link: &dyn link::Link,
|
link: &dyn link::Link,
|
||||||
|
addrs: Vec<IPAddress>,
|
||||||
hw_addr: &str,
|
hw_addr: &str,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let attrs = link.attrs();
|
let attrs = link.attrs();
|
||||||
@ -40,9 +41,7 @@ impl NetworkInfoFromLink {
|
|||||||
interface: Interface {
|
interface: Interface {
|
||||||
device: name.clone(),
|
device: name.clone(),
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
ip_addresses: handle_addresses(handle, attrs)
|
ip_addresses: addrs.clone(),
|
||||||
.await
|
|
||||||
.context("handle addresses")?,
|
|
||||||
mtu: attrs.mtu as u64,
|
mtu: attrs.mtu as u64,
|
||||||
hw_addr: hw_addr.to_string(),
|
hw_addr: hw_addr.to_string(),
|
||||||
pci_addr: Default::default(),
|
pci_addr: Default::default(),
|
||||||
@ -59,7 +58,10 @@ impl NetworkInfoFromLink {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_addresses(handle: &rtnetlink::Handle, attrs: &LinkAttrs) -> Result<Vec<IPAddress>> {
|
pub async fn handle_addresses(
|
||||||
|
handle: &rtnetlink::Handle,
|
||||||
|
attrs: &LinkAttrs,
|
||||||
|
) -> Result<Vec<IPAddress>> {
|
||||||
let mut addr_msg_list = handle
|
let mut addr_msg_list = handle
|
||||||
.address()
|
.address()
|
||||||
.get()
|
.get()
|
||||||
|
@ -26,7 +26,7 @@ use super::{
|
|||||||
Endpoint, IPVlanEndpoint, MacVlanEndpoint, PhysicalEndpoint, VethEndpoint, VlanEndpoint,
|
Endpoint, IPVlanEndpoint, MacVlanEndpoint, PhysicalEndpoint, VethEndpoint, VlanEndpoint,
|
||||||
},
|
},
|
||||||
network_entity::NetworkEntity,
|
network_entity::NetworkEntity,
|
||||||
network_info::network_info_from_link::NetworkInfoFromLink,
|
network_info::network_info_from_link::{handle_addresses, NetworkInfoFromLink},
|
||||||
utils::{link, netns},
|
utils::{link, netns},
|
||||||
Network,
|
Network,
|
||||||
};
|
};
|
||||||
@ -189,9 +189,18 @@ async fn get_entity_from_netns(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ip_addresses = handle_addresses(&handle, attrs)
|
||||||
|
.await
|
||||||
|
.context("handle addresses")?;
|
||||||
|
// Ignore unconfigured network interfaces. These are either base tunnel devices that are not namespaced
|
||||||
|
// like gre0, gretap0, sit0, ipip0, tunl0 or incorrectly setup interfaces.
|
||||||
|
if ip_addresses.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let idx = idx.fetch_add(1, Ordering::Relaxed);
|
let idx = idx.fetch_add(1, Ordering::Relaxed);
|
||||||
let (endpoint, network_info) =
|
let (endpoint, network_info) =
|
||||||
create_endpoint(&handle, link.as_ref(), idx, config, d.clone())
|
create_endpoint(&handle, link.as_ref(), ip_addresses, idx, config, d.clone())
|
||||||
.await
|
.await
|
||||||
.context("create endpoint")?;
|
.context("create endpoint")?;
|
||||||
|
|
||||||
@ -204,6 +213,7 @@ async fn get_entity_from_netns(
|
|||||||
async fn create_endpoint(
|
async fn create_endpoint(
|
||||||
handle: &rtnetlink::Handle,
|
handle: &rtnetlink::Handle,
|
||||||
link: &dyn link::Link,
|
link: &dyn link::Link,
|
||||||
|
addrs: Vec<agent::IPAddress>,
|
||||||
idx: u32,
|
idx: u32,
|
||||||
config: &NetworkWithNetNsConfig,
|
config: &NetworkWithNetNsConfig,
|
||||||
d: Arc<RwLock<DeviceManager>>,
|
d: Arc<RwLock<DeviceManager>>,
|
||||||
@ -270,7 +280,7 @@ async fn create_endpoint(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let network_info = Arc::new(
|
let network_info = Arc::new(
|
||||||
NetworkInfoFromLink::new(handle, link, &endpoint.hardware_addr().await)
|
NetworkInfoFromLink::new(handle, link, addrs, &endpoint.hardware_addr().await)
|
||||||
.await
|
.await
|
||||||
.context("network info from link")?,
|
.context("network info from link")?,
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user