Skip to content

Commit

Permalink
Correct cfg attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
hack3ric committed Nov 15, 2024
1 parent 3cc77ac commit 95fbc2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ tokio-util = "0.7.11"
nftables = { git = "https://github.com/hack3ric/rust-nftables", branch = "for-flow", features = [
"tokio",
] }

[target.'cfg(any(target_os = "linux", target_os = "freebsd"))'.dependencies]
rtnetlink = { git = "https://github.com/hack3ric/rust-rtnetlink", branch = "for-flow" }

[dev-dependencies]
Expand Down
5 changes: 5 additions & 0 deletions src/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub trait Kernel: Sized {
pending()
}

/// Drops the kernel interface and do asynchronous cleanups.
fn terminate(self) -> impl Future<Output = ()> {
ready(())
}
Expand Down Expand Up @@ -63,13 +64,15 @@ impl Kernel for KernelAdapter {
async fn apply(&mut self, spec: &Flowspec, info: &RouteInfo<'_>) -> Result<Self::Handle> {
match self {
Self::Noop => Ok(KernelHandle::Noop),
#[cfg(target_os = "linux")]
Self::Linux(linux) => Ok(KernelHandle::Linux(linux.apply(spec, info).await?)),
}
}

async fn remove(&mut self, handle: Self::Handle) -> Result<()> {
match (self, handle) {
(Self::Noop, KernelHandle::Noop) => Ok(()),
#[cfg(target_os = "linux")]
(Self::Linux(linux), KernelHandle::Linux(handle)) => linux.remove(handle).await,
_ => Err(Error::HandleMismatch),
}
Expand All @@ -78,13 +81,15 @@ impl Kernel for KernelAdapter {
async fn process(&mut self) -> Result<()> {
match self {
Self::Noop => pending().await,
#[cfg(target_os = "linux")]
Self::Linux(linux) => linux.process().await,
}
}

async fn terminate(self) {
match self {
Self::Noop => {}
#[cfg(target_os = "linux")]
Self::Linux(linux) => linux.terminate().await,
}
}
Expand Down

0 comments on commit 95fbc2a

Please sign in to comment.