make building the example optional

This commit is contained in:
chayleaf 2024-08-13 11:16:38 +07:00
parent dcfce58525
commit 4f43475c76
Signed by: chayleaf
GPG key ID: 78171AD46227E68E
6 changed files with 39 additions and 41 deletions

View file

@ -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"]

View file

@ -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::<ExampleMod>();
}
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::<ExampleMod>();
}
#[cfg(test)]
mod test {
use std::{net::Ipv4Addr, os::unix::fs::MetadataExt, path::PathBuf, str::FromStr, sync::mpsc};

View file

@ -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() {

View file

@ -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 {

View file

@ -1,15 +0,0 @@
fn run<T: ToString>(
family: &str,
table: &str,
set: &str,
flush: bool,
items: impl IntoIterator<T>,
) {
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
}