use std::sync::Arc;
use crate::netlink::genl::wireguard::{WireguardWatchOptions, WireguardWatcher};
use crate::netlink::namespace;
use crate::netlink::nftables::resync::OwnedResyncStream as NftablesResyncStream;
use crate::netlink::{Nftables, Route, Wireguard};
use crate::netlink::resync::ConnectionFactory;
use crate::netlink::route_resync::OwnedResyncStream as RouteResyncStream;
use crate::{Connection, Result};
pub async fn route_changes() -> Result<RouteResyncStream> {
let conn = Connection::<Route>::new()?;
let factory: ConnectionFactory<Route> =
Arc::new(|| Box::pin(async { Connection::<Route>::new() }));
conn.into_events_with_resync(factory).await
}
pub async fn route_changes_in_namespace(ns: &str) -> Result<RouteResyncStream> {
let conn = namespace::connection_for::<Route>(ns)?;
let ns_owned = ns.to_string();
let factory: ConnectionFactory<Route> = Arc::new(move || {
let ns = ns_owned.clone();
Box::pin(async move { namespace::connection_for::<Route>(&ns) })
});
conn.into_events_with_resync(factory).await
}
pub async fn nftables_changes() -> Result<NftablesResyncStream> {
let conn = Connection::<Nftables>::new()?;
let factory: ConnectionFactory<Nftables> =
Arc::new(|| Box::pin(async { Connection::<Nftables>::new() }));
conn.into_events_with_resync(factory).await
}
pub async fn nftables_changes_in_namespace(ns: &str) -> Result<NftablesResyncStream> {
let conn = namespace::connection_for::<Nftables>(ns)?;
let ns_owned = ns.to_string();
let factory: ConnectionFactory<Nftables> = Arc::new(move || {
let ns = ns_owned.clone();
Box::pin(async move { namespace::connection_for::<Nftables>(&ns) })
});
conn.into_events_with_resync(factory).await
}
pub async fn wireguard_changes(opts: WireguardWatchOptions) -> Result<WireguardWatcher> {
let conn = Connection::<Wireguard>::new_async().await?;
WireguardWatcher::new(conn, opts)
}
pub async fn wireguard_changes_in_namespace(
ns: &str,
opts: WireguardWatchOptions,
) -> Result<WireguardWatcher> {
let conn = namespace::connection_for_async::<Wireguard>(ns).await?;
WireguardWatcher::new(conn, opts)
}