small changes

This commit is contained in:
chayleaf 2024-08-11 01:29:09 +07:00
parent 3df012a6df
commit 0b6b49ddee
Signed by: chayleaf
GPG key ID: 78171AD46227E68E
2 changed files with 9 additions and 7 deletions

View file

@ -24,6 +24,7 @@
pkgs = import nixpkgs { system = "x86_64-linux"; };
in pkgs.mkShell rec {
name = "unbound-rust-mod-shell";
nativeBuildInputs = [ pkgs.rustc pkgs.cargo pkgs.nftables ];
LIBMNL_LIB_DIR = "${nixpkgs.lib.getLib pkgs.libmnl}/lib";
LIBNFTNL_LIB_DIR = "${nixpkgs.lib.getLib (pkgs.libnftnl.overrideAttrs (old: {
patches = (old.patches or []) ++ [ ./libnftnl-fix.patch ];

View file

@ -11,8 +11,8 @@ use std::{
};
use ipnet::{IpNet, Ipv4Net, Ipv6Net};
use nftnl::{nftnl_sys, set::SetKey, Batch, FinalizedBatch, MsgType, NlMsg};
use mnl::mnl_sys;
use nftnl::{nftnl_sys, set::SetKey, Batch, FinalizedBatch, MsgType, NlMsg};
fn cidr_bound_ipv4(net: Ipv4Net) -> Option<Ipv4Addr> {
let data = u32::from(net.network());
@ -224,7 +224,12 @@ impl Set1 {
nftnl_sys::nftnl_set_elem_add(self.as_mut_ptr(), elem);
}
}
pub fn add_cidrs(&self, socket: &mnl::Socket, flush: bool, cidrs: impl IntoIterator<Item = IpNet>) -> io::Result<()> {
pub fn add_cidrs(
&self,
socket: &mnl::Socket,
flush: bool,
cidrs: impl IntoIterator<Item = IpNet>,
) -> io::Result<()> {
let mut batch = Batch::new();
// FIXME: why 2048?
let max_batch_size = 2048;
@ -321,7 +326,7 @@ pub fn get_sets(socket: &mnl::Socket) -> io::Result<Vec<Set1>> {
#[cfg(test)]
mod test {
use std::{ffi::CString, net::Ipv6Addr};
use std::net::Ipv6Addr;
use ipnet::Ipv6Net;
@ -329,10 +334,6 @@ mod test {
#[test]
fn test_nftables() {
let table = nftnl::Table::new(
&CString::from_vec_with_nul(b"test\0".to_vec()).unwrap(),
nftnl::ProtoFamily::Inet,
);
let socket = mnl::Socket::new(mnl::Bus::Netfilter).unwrap();
let sets = get_sets(&socket).unwrap();
assert!(!sets.is_empty());