pub use net_lattice_core::{Error, Id, PlatformErrorCode, Result};
pub use net_lattice_ip::{
Ipv4Address, Ipv4Network, Ipv4PrefixLength, Ipv6Address, Ipv6Network, Ipv6PrefixLength,
};
pub use net_lattice_model::dns::DnsConfig;
pub use net_lattice_model::event::{ChangeKind, Event};
pub use net_lattice_model::ifaddr::{InterfaceAddress, InterfaceAddressId, NewInterfaceAddress};
pub use net_lattice_model::interface::{
AdminState, Interface, InterfaceId, InterfaceKind, OperationalState,
};
pub use net_lattice_model::mac::MacAddress;
pub use net_lattice_model::neighbor::{NeighborEntry, NeighborId, NeighborState};
pub use net_lattice_model::route::{Route, RouteId};
pub use net_lattice_model::{IpAddress, Network};
pub use net_lattice_platform::{
AddressMutator, AddressProvider, Capability, CapabilityProvider, DnsProvider, EventProvider,
EventReceiver, InterfaceProvider, NeighborProvider, RouteProvider,
};
pub trait LatticeBackend:
RouteProvider<Route = Route>
+ InterfaceProvider<Interface = Interface>
+ DnsProvider<DnsConfig = DnsConfig>
+ NeighborProvider<NeighborEntry = NeighborEntry>
+ AddressProvider<InterfaceAddress = InterfaceAddress>
+ AddressMutator<NewInterfaceAddress = NewInterfaceAddress, InterfaceAddress = InterfaceAddress>
+ EventProvider<Event = Event>
+ CapabilityProvider
{
}
impl<B> LatticeBackend for B where
B: RouteProvider<Route = Route>
+ InterfaceProvider<Interface = Interface>
+ DnsProvider<DnsConfig = DnsConfig>
+ NeighborProvider<NeighborEntry = NeighborEntry>
+ AddressProvider<InterfaceAddress = InterfaceAddress>
+ AddressMutator<
NewInterfaceAddress = NewInterfaceAddress,
InterfaceAddress = InterfaceAddress,
> + EventProvider<Event = Event>
+ CapabilityProvider
{
}
pub struct Lattice<B: LatticeBackend> {
backend: B,
}
impl<B: LatticeBackend> Lattice<B> {
pub fn routes(&self) -> Result<Vec<Route>> {
self.backend.routes()
}
pub fn add_route(&self, route: Route) -> Result<()> {
self.backend.add_route(route)
}
pub fn remove_route(&self, route: Route) -> Result<()> {
self.backend.remove_route(route)
}
pub fn interfaces(&self) -> Result<Vec<Interface>> {
self.backend.interfaces()
}
pub fn dns_config(&self) -> Result<DnsConfig> {
self.backend.dns_config()
}
pub fn neighbors(&self) -> Result<Vec<NeighborEntry>> {
self.backend.neighbors()
}
pub fn addresses(&self) -> Result<Vec<InterfaceAddress>> {
self.backend.addresses()
}
pub fn add_address(&self, address: NewInterfaceAddress) -> Result<InterfaceAddress> {
self.backend.add_address(address)
}
pub fn remove_address(&self, address: InterfaceAddress) -> Result<()> {
self.backend.remove_address(address)
}
pub fn capabilities(&self) -> Capability {
self.backend.capabilities()
}
pub fn supports(&self, capability: Capability) -> bool {
self.backend.capabilities().contains(capability)
}
pub fn watch(&self) -> Result<EventReceiver<Event>> {
self.backend.watch()
}
}
#[cfg(target_os = "linux")]
impl Lattice<net_lattice_backend_linux::LinuxBackend> {
pub fn connect() -> Result<Self> {
Ok(Self {
backend: net_lattice_backend_linux::LinuxBackend::new()?,
})
}
}
#[cfg(target_os = "windows")]
impl Lattice<net_lattice_backend_windows::WindowsBackend> {
pub fn connect() -> Result<Self> {
Ok(Self {
backend: net_lattice_backend_windows::WindowsBackend::new()?,
})
}
}
#[cfg(target_os = "macos")]
impl Lattice<net_lattice_backend_darwin::DarwinBackend> {
pub fn connect() -> Result<Self> {
Ok(Self {
backend: net_lattice_backend_darwin::DarwinBackend::new()?,
})
}
}