diff --git a/Cargo.toml b/Cargo.toml index 2352cfe..22c3e87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,20 +9,34 @@ crate-type = ["rlib", "cdylib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -boxcar = "0.2.5" +boxcar = { version = "0.2.5", optional = true } ctor = { version = "0.2.8", optional = true } -filetime = "0.2.24" -ipnet = { version = "2.9.0", features = ["serde"] } -iptrie = "0.8.5" -libc = "0.2.155" -mnl = { version = "0.2.2", features = ["mnl-1-0-4"] } -nftnl = { version = "0.6.2", features = ["nftnl-1-1-2"] } -nix = { version = "0.29.0", features = ["poll", "user"] } -radix_trie = "0.2.1" -serde = { version = "1.0.205", features = ["derive"] } -serde_json = "1.0.122" -smallvec = "1.13.2" +filetime = { version = "0.2.24", optional = true } +ipnet = { version = "2.9.0", features = ["serde"], optional = true } +iptrie = { version = "0.8.5", optional = true } +libc = { version = "0.2.155", optional = true } +mnl = { version = "0.2.2", features = ["mnl-1-0-4"], optional = true } +nftnl = { version = "0.6.2", features = ["nftnl-1-1-2"], optional = true } +nix = { version = "0.29.0", features = ["poll", "user"], optional = true } +radix_trie = { version = "0.2.1", optional = true } +serde = { version = "1.0.205", features = ["derive"], optional = true } +serde_json = { version = "1.0.122", optional = true } +smallvec = { version = "1.13.2", optional = true } [features] -example = ["ctor"] +example = [ + "boxcar", + "ctor", + "filetime", + "ipnet", + "iptrie", + "libc", + "mnl", + "nftnl", + "nix", + "radix_trie", + "serde", + "serde_json", + "smallvec", +] default = ["example"] diff --git a/src/domain_tree.rs b/src/example/domain_tree.rs similarity index 100% rename from src/domain_tree.rs rename to src/example/domain_tree.rs diff --git a/src/example.rs b/src/example/mod.rs similarity index 99% rename from src/example.rs rename to src/example/mod.rs index 7b38fe6..4f19360 100644 --- a/src/example.rs +++ b/src/example/mod.rs @@ -22,15 +22,23 @@ use serde::{ use smallvec::SmallVec; use crate::{ - domain_tree::PrefixSet, - nftables::{nftables_thread, NftData}, unbound::{rr_class, rr_type, ModuleEvent, ModuleExtState, ReplyInfo}, UnboundMod, }; +use domain_tree::PrefixSet; +use nftables::{nftables_thread, NftData}; + +mod domain_tree; +mod nftables; type Domain = SmallVec<[u8; 32]>; type DomainSeg = SmallVec<[u8; 16]>; +#[ctor] +fn setup() { + crate::set_unbound_mod::(); +} + struct IpNetDeser(IpNet); struct IpNetVisitor; impl<'de> Visitor<'de> for IpNetVisitor { @@ -738,11 +746,6 @@ impl UnboundMod for ExampleMod { } } -#[ctor] -fn setup() { - crate::set_unbound_mod::(); -} - #[cfg(test)] mod test { use std::{net::Ipv4Addr, os::unix::fs::MetadataExt, path::PathBuf, str::FromStr, sync::mpsc}; diff --git a/src/nftables.rs b/src/example/nftables.rs similarity index 99% rename from src/nftables.rs rename to src/example/nftables.rs index 61a0b93..8a85c05 100644 --- a/src/nftables.rs +++ b/src/example/nftables.rs @@ -471,7 +471,7 @@ pub(crate) fn nftables_thread( } } let socket = mnl::Socket::new(mnl::Bus::Netfilter).unwrap(); - let all_sets = crate::nftables::get_sets(&socket).unwrap(); + let all_sets = get_sets(&socket).unwrap(); for set in all_sets { for ruleset in &mut rulesets { if set.table_name_str() == Some("global") && set.family() == libc::NFPROTO_INET as u32 { @@ -531,9 +531,7 @@ mod test { use ipnet::{Ipv4Net, Ipv6Net}; use iptrie::RTrieSet; - use crate::nftables::{iter_ip_trie, should_add}; - - use super::get_sets; + use super::{get_sets, iter_ip_trie, should_add}; #[test] fn test_nftables() { diff --git a/src/lib.rs b/src/lib.rs index f1f8713..b90da85 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,11 +15,9 @@ use unbound::ModuleExtState; )] mod bindings; mod combine; -mod domain_tree; #[cfg(feature = "example")] mod example; mod exports; -mod nftables; mod unbound; pub trait UnboundMod: Send + Sync + Sized + RefUnwindSafe + UnwindSafe { diff --git a/src/nftables_lib.rs b/src/nftables_lib.rs deleted file mode 100644 index 0a08bda..0000000 --- a/src/nftables_lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -fn run( - family: &str, - table: &str, - set: &str, - flush: bool, - items: impl IntoIterator, -) { - let nft = libnftables1_sys::Nftables::new(); - let mut cmd = String::new(); - if flush { - cmd.push_str(&format!("flush set {family} {table} {set}")); - nft.run_cmd(c) - } - nft.set_numeric_time -}