Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix feature flags #234

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ cargo fmt -- --check \
&& cargo clippy --all-targets --all-features -- -D warnings \
&& RUSTDOCFLAGS="-D warnings" cargo doc \
&& cargo build \
&& cargo build --no-default-features \
&& cargo build --no-default-features --features=async \
&& cargo build --all-targets --all-features \
&& cargo build --examples \
&& ./target/debug/examples/getips \
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ jobs:
- cargo fmt -- --check
- cargo build
- RUSTDOCFLAGS="-D warnings" cargo doc
- cargo build --features=async
- cargo build --no-default-features
- cargo build --no-default-features --features=async
- cargo build --all-features
- cargo build --examples
- cargo build --examples --all-features
Expand Down Expand Up @@ -89,7 +90,8 @@ jobs:
matrix:
task:
- cargo build
- cargo build --features=async
- cargo build --no-default-features
- cargo build --no-default-features --features=async
- cargo build --all-features
- cargo build --examples
- cargo build --examples --all-features
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ features = ["macros", "rt-multi-thread"]
[features]
default = ["sync"]
sync = ["parking_lot"]
async = ["tokio"]
async = ["parking_lot", "tokio"]
netfilter = []
1 change: 1 addition & 0 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl<T, P, B> NlBufferIter<T, P, B>
where
B: AsRef<[u8]>,
{
#[cfg(any(feature = "sync", feature = "async"))]
pub(crate) fn new(buffer: Cursor<B>) -> Self {
NlBufferIter {
buffer,
Expand Down
2 changes: 1 addition & 1 deletion src/socket/asynchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{

/// Tokio-enabled Netlink socket struct
pub struct NlSocketHandle {
socket: AsyncFd<super::NlSocket>,
pub(super) socket: AsyncFd<super::NlSocket>,
pool: BufferPool,
pid: u32,
}
Expand Down
17 changes: 14 additions & 3 deletions src/socket/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ use std::{

use libc::{c_int, c_void, sockaddr, sockaddr_nl};

#[cfg(feature = "async")]
use crate::socket::asynchronous;
#[cfg(feature = "sync")]
use crate::socket::synchronous;
use crate::{
consts::socket::*,
socket::synchronous::NlSocketHandle,
utils::{Groups, NetlinkBitArray},
};

Expand Down Expand Up @@ -269,12 +272,20 @@ impl NlSocket {
}
}

impl From<NlSocketHandle> for NlSocket {
fn from(s: NlSocketHandle) -> Self {
#[cfg(feature = "sync")]
impl From<synchronous::NlSocketHandle> for NlSocket {
fn from(s: synchronous::NlSocketHandle) -> Self {
s.socket
}
}

#[cfg(feature = "async")]
impl From<asynchronous::NlSocketHandle> for NlSocket {
fn from(s: asynchronous::NlSocketHandle) -> Self {
s.socket.into_inner()
}
}

impl AsRawFd for NlSocket {
fn as_raw_fd(&self) -> RawFd {
self.fd
Expand Down
2 changes: 2 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use std::mem::size_of;

#[cfg(any(feature = "sync", feature = "async"))]
use crate::consts::MAX_NL_LENGTH;

type BitArrayType = u32;
Expand Down Expand Up @@ -184,6 +185,7 @@ impl Groups {
}

/// Synchronous (blocking) utils.
#[cfg(feature = "sync")]
pub mod synchronous {
use super::*;

Expand Down
Loading