use std::net::IpAddr;
use async_trait::async_trait;
use crate::OverlayError;
#[cfg(target_os = "linux")]
pub(crate) mod linux;
#[cfg(target_os = "macos")]
pub(crate) mod macos;
#[cfg(windows)]
pub(crate) mod windows;
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
pub(crate) mod stub;
#[async_trait]
pub(crate) trait InterfaceOps: Send + Sync {
#[allow(dead_code)]
async fn link_exists(&self, name: &str) -> Result<bool, OverlayError>;
#[allow(dead_code)]
async fn delete_link(&self, name: &str) -> Result<(), OverlayError>;
async fn set_link_up(&self, name: &str) -> Result<(), OverlayError>;
async fn add_address(
&self,
name: &str,
addr: IpAddr,
prefix_len: u8,
) -> Result<(), OverlayError>;
async fn add_route_via_dev(
&self,
dest: IpAddr,
prefix_len: u8,
name: &str,
) -> Result<(), OverlayError>;
}
pub(crate) fn platform_ops() -> Box<dyn InterfaceOps> {
#[cfg(target_os = "linux")]
{
Box::new(linux::LinuxNetlinkOps::new())
}
#[cfg(target_os = "macos")]
{
Box::new(macos::MacIfconfigOps::new())
}
#[cfg(windows)]
{
Box::new(windows::WindowsIpHelperOps::new())
}
#[cfg(not(any(target_os = "linux", target_os = "macos", windows)))]
{
Box::new(stub::StubOps)
}
}