Fix network interface display for VLANs and physical NICs
All checks were successful
Build and Release / build-and-release (push) Successful in 1m11s
All checks were successful
Build and Release / build-and-release (push) Successful in 1m11s
Agent changes: - Filter out ifb* interfaces from network display - Parse @parent notation for VLAN interfaces (e.g., lan@enp0s31f6) - Show physical interfaces even without IP addresses - Only filter virtual interfaces that have no IPs - Extract parent interface relationships for proper nesting Dashboard changes: - Nest VLAN/child interfaces under their physical parent - Show physical NICs with status icons even when down - Display child interfaces grouped under parent interface - Keep standalone virtual interfaces at root level Updated to version 0.1.169
This commit is contained in:
parent
748a9f3a3b
commit
8aefab83ae
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.168"
|
version = "0.1.169"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.168"
|
version = "0.1.169"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@ -324,7 +324,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.168"
|
version = "0.1.169"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.168"
|
version = "0.1.169"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -62,11 +62,19 @@ impl NetworkCollector {
|
|||||||
for iface in ifaces {
|
for iface in ifaces {
|
||||||
let name = iface["ifname"].as_str().unwrap_or("").to_string();
|
let name = iface["ifname"].as_str().unwrap_or("").to_string();
|
||||||
|
|
||||||
// Skip loopback and empty names
|
// Skip loopback, empty names, and ifb* interfaces
|
||||||
if name.is_empty() || name == "lo" {
|
if name.is_empty() || name == "lo" || name.starts_with("ifb") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse parent interface from @parent notation (e.g., lan@enp0s31f6)
|
||||||
|
let (interface_name, parent_interface) = if let Some(at_pos) = name.find('@') {
|
||||||
|
let (child, parent) = name.split_at(at_pos);
|
||||||
|
(child.to_string(), Some(parent[1..].to_string()))
|
||||||
|
} else {
|
||||||
|
(name.clone(), None)
|
||||||
|
};
|
||||||
|
|
||||||
let mut ipv4_addresses = Vec::new();
|
let mut ipv4_addresses = Vec::new();
|
||||||
let mut ipv6_addresses = Vec::new();
|
let mut ipv6_addresses = Vec::new();
|
||||||
|
|
||||||
@ -90,14 +98,15 @@ impl NetworkCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only add interfaces that have at least one IP address
|
// Determine if physical and get status
|
||||||
// This filters out ifb*, dummy interfaces, etc. that have no IPs
|
let is_physical = Self::is_physical_interface(&interface_name);
|
||||||
if ipv4_addresses.is_empty() && ipv6_addresses.is_empty() {
|
|
||||||
|
// Only filter out virtual interfaces without IPs
|
||||||
|
// Physical interfaces should always be shown even if down/no IPs
|
||||||
|
if !is_physical && ipv4_addresses.is_empty() && ipv6_addresses.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if physical and get status
|
|
||||||
let is_physical = Self::is_physical_interface(&name);
|
|
||||||
let link_status = if is_physical {
|
let link_status = if is_physical {
|
||||||
Self::get_link_status(&name)
|
Self::get_link_status(&name)
|
||||||
} else {
|
} else {
|
||||||
@ -105,12 +114,12 @@ impl NetworkCollector {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interfaces.push(NetworkInterfaceData {
|
interfaces.push(NetworkInterfaceData {
|
||||||
name,
|
name: interface_name,
|
||||||
ipv4_addresses,
|
ipv4_addresses,
|
||||||
ipv6_addresses,
|
ipv6_addresses,
|
||||||
is_physical,
|
is_physical,
|
||||||
link_status,
|
link_status,
|
||||||
parent_interface: None,
|
parent_interface,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.168"
|
version = "0.1.169"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -628,9 +628,14 @@ impl SystemWidget {
|
|||||||
let physical: Vec<_> = self.network_interfaces.iter().filter(|i| i.is_physical).collect();
|
let physical: Vec<_> = self.network_interfaces.iter().filter(|i| i.is_physical).collect();
|
||||||
let virtual_interfaces: Vec<_> = self.network_interfaces.iter().filter(|i| !i.is_physical).collect();
|
let virtual_interfaces: Vec<_> = self.network_interfaces.iter().filter(|i| !i.is_physical).collect();
|
||||||
|
|
||||||
// Render physical interfaces
|
// Find standalone virtual interfaces (those without a parent)
|
||||||
|
let standalone_virtual: Vec<_> = virtual_interfaces.iter()
|
||||||
|
.filter(|i| i.parent_interface.is_none())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Render physical interfaces with their children
|
||||||
for (phy_idx, interface) in physical.iter().enumerate() {
|
for (phy_idx, interface) in physical.iter().enumerate() {
|
||||||
let is_last_physical = phy_idx == physical.len() - 1 && virtual_interfaces.is_empty();
|
let is_last_physical = phy_idx == physical.len() - 1 && standalone_virtual.is_empty();
|
||||||
|
|
||||||
// Physical interface header with status icon
|
// Physical interface header with status icon
|
||||||
let mut header_spans = vec![];
|
let mut header_spans = vec![];
|
||||||
@ -640,36 +645,74 @@ impl SystemWidget {
|
|||||||
));
|
));
|
||||||
lines.push(Line::from(header_spans));
|
lines.push(Line::from(header_spans));
|
||||||
|
|
||||||
// Show IPs nested under the interface
|
// Find child interfaces for this physical interface
|
||||||
let ip_count = interface.ipv4_addresses.len() + interface.ipv6_addresses.len();
|
let children: Vec<_> = virtual_interfaces.iter()
|
||||||
let mut ip_index = 0;
|
.filter(|vi| {
|
||||||
|
if let Some(parent) = &vi.parent_interface {
|
||||||
|
parent == &interface.name
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
// IPv4 addresses
|
// Count total items under this physical interface (IPs + children)
|
||||||
|
let ip_count = interface.ipv4_addresses.len() + interface.ipv6_addresses.len();
|
||||||
|
let total_children = ip_count + children.len();
|
||||||
|
let mut child_index = 0;
|
||||||
|
|
||||||
|
// IPv4 addresses on the physical interface itself
|
||||||
for ipv4 in &interface.ipv4_addresses {
|
for ipv4 in &interface.ipv4_addresses {
|
||||||
ip_index += 1;
|
child_index += 1;
|
||||||
let is_last_ip = ip_index == ip_count && is_last_physical;
|
let is_last = child_index == total_children && is_last_physical;
|
||||||
let tree_symbol = if is_last_ip { " └─ " } else { " ├─ " };
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(tree_symbol, Typography::tree()),
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
Span::styled(format!("ip: {}", ipv4), Typography::secondary()),
|
Span::styled(format!("ip: {}", ipv4), Typography::secondary()),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPv6 addresses
|
// IPv6 addresses on the physical interface itself
|
||||||
for ipv6 in &interface.ipv6_addresses {
|
for ipv6 in &interface.ipv6_addresses {
|
||||||
ip_index += 1;
|
child_index += 1;
|
||||||
let is_last_ip = ip_index == ip_count && is_last_physical;
|
let is_last = child_index == total_children && is_last_physical;
|
||||||
let tree_symbol = if is_last_ip { " └─ " } else { " ├─ " };
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(tree_symbol, Typography::tree()),
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
Span::styled(format!("ip: {}", ipv6), Typography::secondary()),
|
Span::styled(format!("ip: {}", ipv6), Typography::secondary()),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Child virtual interfaces (VLANs, etc.)
|
||||||
|
for child in children {
|
||||||
|
child_index += 1;
|
||||||
|
let is_last = child_index == total_children && is_last_physical;
|
||||||
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
|
|
||||||
|
let ip_text = if !child.ipv4_addresses.is_empty() {
|
||||||
|
Self::compress_ipv4_addresses(&child.ipv4_addresses)
|
||||||
|
} else if !child.ipv6_addresses.is_empty() {
|
||||||
|
child.ipv6_addresses.join(", ")
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
let child_text = if !ip_text.is_empty() {
|
||||||
|
format!("{}: {}", child.name, ip_text)
|
||||||
|
} else {
|
||||||
|
format!("{}:", child.name)
|
||||||
|
};
|
||||||
|
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
|
Span::styled(child_text, Typography::secondary()),
|
||||||
|
]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render standalone virtual interfaces (those without a parent)
|
// Render standalone virtual interfaces (those without a parent)
|
||||||
for (virt_idx, interface) in virtual_interfaces.iter().enumerate() {
|
for (virt_idx, interface) in standalone_virtual.iter().enumerate() {
|
||||||
let is_last = virt_idx == virtual_interfaces.len() - 1;
|
let is_last = virt_idx == standalone_virtual.len() - 1;
|
||||||
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
|
|
||||||
// Virtual interface with IPs
|
// Virtual interface with IPs
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.168"
|
version = "0.1.169"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user