Skip to content

Commit

Permalink
feat(nftnl-sys): update libnftnl all the way to 1.2.6
Browse files Browse the repository at this point in the history
Fix bash script bindgen options and version comment.

Add version features to `nftnl-sys` and `nftnl`.

Add `/lib/` to .gitignore to keep libnftnl directories.
  • Loading branch information
my4ng committed Jun 4, 2024
1 parent a37214b commit 244b28e
Show file tree
Hide file tree
Showing 21 changed files with 20,495 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/lib/
/target/
**/*.rs.bk
Cargo.lock
24 changes: 19 additions & 5 deletions nftnl-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,25 @@ edition = "2018"

[features]
nftnl-1-0-7 = []
nftnl-1-0-8 = ["nftnl-1-0-7"]
nftnl-1-0-9 = ["nftnl-1-0-8"]
nftnl-1-1-0 = ["nftnl-1-0-9"]
nftnl-1-1-1 = ["nftnl-1-1-0"]
nftnl-1-1-2 = ["nftnl-1-1-1"]
nftnl-1-0-8 = []
nftnl-1-0-9 = []
nftnl-1-1-0 = []
nftnl-1-1-1 = []
nftnl-1-1-2 = []
nftnl-1-1-3 = []
nftnl-1-1-4 = []
nftnl-1-1-5 = []
nftnl-1-1-6 = []
nftnl-1-1-7 = []
nftnl-1-1-8 = []
nftnl-1-1-9 = []
nftnl-1-2-0 = []
nftnl-1-2-1 = []
nftnl-1-2-2 = []
nftnl-1-2-3 = []
nftnl-1-2-4 = []
nftnl-1-2-5 = []
nftnl-1-2-6 = []

[dependencies]
cfg-if = "1.0"
Expand Down
30 changes: 29 additions & 1 deletion nftnl-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,35 @@ extern crate pkg_config;
use std::{env, path::PathBuf};

cfg_if::cfg_if! {
if #[cfg(feature = "nftnl-1-1-2")] {
if #[cfg(feature = "nftnl-1-2-6")] {
const MIN_VERSION: &str = "1.2.6";
} else if #[cfg(feature = "nftnl-1-2-5")] {
const MIN_VERSION: &str = "1.2.5";
} else if #[cfg(feature = "nftnl-1-2-4")] {
const MIN_VERSION: &str = "1.2.4";
} else if #[cfg(feature = "nftnl-1-2-3")] {
const MIN_VERSION: &str = "1.2.3";
} else if #[cfg(feature = "nftnl-1-2-2")] {
const MIN_VERSION: &str = "1.2.2";
} else if #[cfg(feature = "nftnl-1-2-1")] {
const MIN_VERSION: &str = "1.2.1";
} else if #[cfg(feature = "nftnl-1-2-0")] {
const MIN_VERSION: &str = "1.2.0";
} else if #[cfg(feature = "nftnl-1-1-9")] {
const MIN_VERSION: &str = "1.1.9";
} else if #[cfg(feature = "nftnl-1-1-8")] {
const MIN_VERSION: &str = "1.1.8";
} else if #[cfg(feature = "nftnl-1-1-7")] {
const MIN_VERSION: &str = "1.1.7";
} else if #[cfg(feature = "nftnl-1-1-6")] {
const MIN_VERSION: &str = "1.1.6";
} else if #[cfg(feature = "nftnl-1-1-5")] {
const MIN_VERSION: &str = "1.1.5";
} else if #[cfg(feature = "nftnl-1-1-4")] {
const MIN_VERSION: &str = "1.1.4";
} else if #[cfg(feature = "nftnl-1-1-3")] {
const MIN_VERSION: &str = "1.1.3";
} else if #[cfg(feature = "nftnl-1-1-2")] {
const MIN_VERSION: &str = "1.1.2";
} else if #[cfg(feature = "nftnl-1-1-1")] {
const MIN_VERSION: &str = "1.1.1";
Expand Down
31 changes: 13 additions & 18 deletions nftnl-sys/generate_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,25 @@ bindgen \
--no-doc-comments \
--use-core \
--no-prepend-enum-name \
--whitelist-function '^nftnl_.+$' \
--whitelist-type '^nftnl_.+$' \
--whitelist-var '^nftnl_.+$' \
--whitelist-var '^NFTNL_.+$' \
--blacklist-type '(FILE|iovec)' \
--blacklist-type '^_IO_.+$' \
--blacklist-type '^__.+$' \
--blacklist-type 'nlmsghdr' \
--raw-line 'use libc::{c_char, c_int, c_void, iovec, nlmsghdr, FILE};' \
--allowlist-function '^nftnl_.+$' \
--allowlist-type '^nftnl_.+$' \
--allowlist-var '^nftnl_.+$' \
--allowlist-var '^NFTNL_.+$' \
--blocklist-type '(FILE|iovec)' \
--blocklist-type '^_IO_.+$' \
--blocklist-type '^__.+$' \
--blocklist-type 'nlmsghdr' \
--raw-line 'use libc::{c_char, c_int, c_uint, c_void, iovec, nlmsghdr, FILE};' \
--raw-line 'use core::option::Option;' \
--ctypes-prefix 'libc' \
-o $BINDING_PATH \
libnftnl.h --\
-I$LIBNFTNL_PATH/include
libnftnl.h -- -I$LIBNFTNL_PATH/include

# Tidy up and correct things I could not manage to configure bindgen to do for me
sed -i 's/libc::\(c_[a-z]*\)/\1/g' $BINDING_PATH
sed -i 's/libc::\(c_[a-z]*\)/\1/g' $BINDING_PATH
sed -i 's/::core::option::Option/Option/g' $BINDING_PATH
sed -i 's/_bindgen_ty_[0-9]\+/u32/g' $BINDING_PATH
sed -i 's/pub type u32 = u32;//g' $BINDING_PATH
sed -i 's/pub type u32 = c_uint;//g' $BINDING_PATH
sed -i '/#\[derive(Debug, Copy, Clone)\]/d' $BINDING_PATH

# Change struct bodies to (c_void);
Expand All @@ -45,10 +44,9 @@ sed -i -e '/^pub struct .* {$/ {
s/ {\n *_unused: \[u8; 0\],\n}/(c_void);\n/
}' "$BINDING_PATH"


# Remove all }\nextern "C" { to condense code a bit
# Search regex: }\nextern "C" {
# Replace string:
# Replace string:
sed -i -e '/^extern "C" {$/ {
:loop
n
Expand All @@ -62,7 +60,4 @@ sed -i -e '/^extern "C" {$/ {
}
}' "$BINDING_PATH"

# Add bindgen version to comment at start of file
sed -i "1s/bindgen/$(bindgen --version)/" $BINDING_PATH

rustfmt $BINDING_PATH
3 changes: 3 additions & 0 deletions nftnl-sys/libnftnl.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// for missing `iovec`
#include <sys/uio.h>

#include <libnftnl/batch.h>
#include <libnftnl/chain.h>
#include <libnftnl/common.h>
Expand Down
44 changes: 43 additions & 1 deletion nftnl-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,49 @@
pub use libc;

cfg_if::cfg_if! {
if #[cfg(feature = "nftnl-1-1-2")] {
if #[cfg(feature = "nftnl-1-2-6")] {
mod nftnl_1_2_6;
pub use self::nftnl_1_2_6::*;
} else if #[cfg(feature = "nftnl-1-2-5")] {
mod nftnl_1_2_5;
pub use self::nftnl_1_2_5::*;
} else if #[cfg(feature = "nftnl-1-2-4")] {
mod nftnl_1_2_4;
pub use self::nftnl_1_2_4::*;
} else if #[cfg(feature = "nftnl-1-2-3")] {
mod nftnl_1_2_3;
pub use self::nftnl_1_2_3::*;
} else if #[cfg(feature = "nftnl-1-2-2")] {
mod nftnl_1_2_2;
pub use self::nftnl_1_2_2::*;
} else if #[cfg(feature = "nftnl-1-2-1")] {
mod nftnl_1_2_1;
pub use self::nftnl_1_2_1::*;
} else if #[cfg(feature = "nftnl-1-2-0")] {
mod nftnl_1_2_0;
pub use self::nftnl_1_2_0::*;
} else if #[cfg(feature = "nftnl-1-1-9")] {
mod nftnl_1_1_9;
pub use self::nftnl_1_1_9::*;
} else if #[cfg(feature = "nftnl-1-1-8")] {
mod nftnl_1_1_8;
pub use self::nftnl_1_1_8::*;
} else if #[cfg(feature = "nftnl-1-1-7")] {
mod nftnl_1_1_7;
pub use self::nftnl_1_1_7::*;
} else if #[cfg(feature = "nftnl-1-1-6")] {
mod nftnl_1_1_6;
pub use self::nftnl_1_1_6::*;
} else if #[cfg(feature = "nftnl-1-1-5")] {
mod nftnl_1_1_5;
pub use self::nftnl_1_1_5::*;
} else if #[cfg(feature = "nftnl-1-1-4")] {
mod nftnl_1_1_4;
pub use self::nftnl_1_1_4::*;
} else if #[cfg(feature = "nftnl-1-1-3")] {
mod nftnl_1_1_3;
pub use self::nftnl_1_1_3::*;
} else if #[cfg(feature = "nftnl-1-1-2")] {
mod nftnl_1_1_2;
pub use self::nftnl_1_1_2::*;
} else if #[cfg(feature = "nftnl-1-1-1")] {
Expand Down
Loading

0 comments on commit 244b28e

Please sign in to comment.