runtime-rs: ignore unconfigured network interfaces

Fixes: #7020

Signed-off-by: soup <lqh348659137@outlook.com>
This commit is contained in:
soup 2023-06-02 14:48:31 +08:00
parent 22d4e4c5a6
commit 150e54d02b
2 changed files with 19 additions and 7 deletions

View File

@ -31,6 +31,7 @@ impl NetworkInfoFromLink {
pub async fn new(
handle: &rtnetlink::Handle,
link: &dyn link::Link,
addrs: Vec<IPAddress>,
hw_addr: &str,
) -> Result<Self> {
let attrs = link.attrs();
@ -40,9 +41,7 @@ impl NetworkInfoFromLink {
interface: Interface {
device: name.clone(),
name: name.clone(),
ip_addresses: handle_addresses(handle, attrs)
.await
.context("handle addresses")?,
ip_addresses: addrs.clone(),
mtu: attrs.mtu as u64,
hw_addr: hw_addr.to_string(),
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
.address()
.get()

View File

@ -26,7 +26,7 @@ use super::{
Endpoint, IPVlanEndpoint, MacVlanEndpoint, PhysicalEndpoint, VethEndpoint, VlanEndpoint,
},
network_entity::NetworkEntity,
network_info::network_info_from_link::NetworkInfoFromLink,
network_info::network_info_from_link::{handle_addresses, NetworkInfoFromLink},
utils::{link, netns},
Network,
};
@ -189,9 +189,18 @@ async fn get_entity_from_netns(
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 (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
.context("create endpoint")?;
@ -204,6 +213,7 @@ async fn get_entity_from_netns(
async fn create_endpoint(
handle: &rtnetlink::Handle,
link: &dyn link::Link,
addrs: Vec<agent::IPAddress>,
idx: u32,
config: &NetworkWithNetNsConfig,
d: Arc<RwLock<DeviceManager>>,
@ -270,7 +280,7 @@ async fn create_endpoint(
};
let network_info = Arc::new(
NetworkInfoFromLink::new(handle, link, &endpoint.hardware_addr().await)
NetworkInfoFromLink::new(handle, link, addrs, &endpoint.hardware_addr().await)
.await
.context("network info from link")?,
);