use std::net::Ipv4Addr;
use std::time::SystemTime;
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum LanInterfaceKind {
Wifi,
Ethernet,
Bridge,
Tunnel,
Virtual,
Loopback,
#[default]
Unknown,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum LanIpv4Completeness {
Complete,
Partial,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum LanIpv4Exclusion {
InterfaceDown,
InterfaceStateUnknown,
PointToPoint,
PointToPointStateUnknown,
VirtualInterfaceNameHint,
PlatformVirtualOrTunnel,
LinkInactive,
Loopback,
LinkLocal,
Unspecified,
Broadcast,
Multicast,
ThisNetwork,
Reserved,
SharedAddressSpace,
BenchmarkRange,
}
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum LanIpv4RecommendationReason {
ActiveLanDefaultRoute,
ActiveWifiOrEthernet,
ActiveBridge,
LanLinkUnknown,
MetadataUnknown,
BridgeLinkUnknown,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LanIpv4Candidate {
pub(crate) interface_id: String,
pub(crate) interface_name: String,
pub(crate) interface_index: Option<u32>,
pub(crate) address: Ipv4Addr,
pub(crate) netmask: Ipv4Addr,
pub(crate) prefix_len: u8,
pub(crate) interface_kind: LanInterfaceKind,
pub(crate) oper_up: Option<bool>,
pub(crate) point_to_point: Option<bool>,
pub(crate) link_active: Option<bool>,
pub(crate) default_route: Option<bool>,
pub(crate) exclusions: Vec<LanIpv4Exclusion>,
pub(crate) recommendation: Option<LanIpv4RecommendationReason>,
}
impl LanIpv4Candidate {
pub fn interface_id(&self) -> &str {
&self.interface_id
}
pub fn interface_name(&self) -> &str {
&self.interface_name
}
pub fn interface_index(&self) -> Option<u32> {
self.interface_index
}
pub fn address(&self) -> Ipv4Addr {
self.address
}
pub fn netmask(&self) -> Ipv4Addr {
self.netmask
}
pub fn prefix_len(&self) -> u8 {
self.prefix_len
}
pub fn interface_kind(&self) -> LanInterfaceKind {
self.interface_kind
}
pub fn is_oper_up(&self) -> Option<bool> {
self.oper_up
}
pub fn is_point_to_point(&self) -> Option<bool> {
self.point_to_point
}
pub fn link_active(&self) -> Option<bool> {
self.link_active
}
pub fn is_default_route(&self) -> Option<bool> {
self.default_route
}
pub fn default_exclusions(&self) -> &[LanIpv4Exclusion] {
&self.exclusions
}
pub fn recommendation_reason(&self) -> Option<LanIpv4RecommendationReason> {
self.recommendation
}
pub fn is_recommended(&self) -> bool {
self.recommendation.is_some()
}
}
#[derive(Clone, Debug)]
pub struct LanIpv4Snapshot {
pub(crate) candidates: Vec<LanIpv4Candidate>,
pub(crate) completeness: LanIpv4Completeness,
pub(crate) diagnostics: Vec<String>,
pub(crate) query_started_at: SystemTime,
pub(crate) observed_at: SystemTime,
}
impl LanIpv4Snapshot {
pub fn candidates(&self) -> &[LanIpv4Candidate] {
&self.candidates
}
pub fn recommended(&self) -> Option<&LanIpv4Candidate> {
self.candidates
.iter()
.find(|candidate| candidate.is_recommended())
}
pub fn completeness(&self) -> LanIpv4Completeness {
self.completeness
}
pub fn diagnostics(&self) -> &[String] {
&self.diagnostics
}
pub fn query_started_at(&self) -> SystemTime {
self.query_started_at
}
pub fn observed_at(&self) -> SystemTime {
self.observed_at
}
}