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

feat(nftnl-sys): update libnftnl all the way to 1.2.6 #62

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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: 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
6 changes: 5 additions & 1 deletion nftnl-sys/libnftnl.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// for missing `iovec`
#include <sys/uio.h>

#include <libnftnl/batch.h>
#include <libnftnl/chain.h>
#include <libnftnl/common.h>
#include <libnftnl/expr.h>
#include <libnftnl/flowtable.h> // >= 1.1.0
#include <libnftnl/gen.h>
#include <libnftnl/object.h>
#include <libnftnl/object.h> // >= 1.0.7
#include <libnftnl/rule.h>
#include <libnftnl/ruleset.h>
#include <libnftnl/set.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
38 changes: 19 additions & 19 deletions nftnl-sys/src/nftnl_1_0_6.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// automatically generated by rust-bindgen 0.39.0
/* automatically generated by rust-bindgen 0.69.4 */

use core::option::Option;
use libc::{c_char, c_int, c_void, iovec, nlmsghdr, FILE};
use libc::{c_char, c_int, c_uint, c_void, iovec, nlmsghdr, FILE};

#[repr(C)]
pub struct nftnl_batch(c_void);
Expand Down Expand Up @@ -29,24 +29,24 @@ pub const NFTNL_PARSE_EOPNOTSUPP: u32 = 3;
pub const NFTNL_OUTPUT_DEFAULT: nftnl_output_type = 0;
pub const NFTNL_OUTPUT_XML: nftnl_output_type = 1;
pub const NFTNL_OUTPUT_JSON: nftnl_output_type = 2;
pub type nftnl_output_type = u32;
pub type nftnl_output_type = c_uint;
pub const NFTNL_OF_EVENT_NEW: nftnl_output_flags = 1;
pub const NFTNL_OF_EVENT_DEL: nftnl_output_flags = 2;
pub const NFTNL_OF_EVENT_ANY: nftnl_output_flags = 3;
pub type nftnl_output_flags = u32;
pub type nftnl_output_flags = c_uint;
pub const NFTNL_CMD_UNSPEC: nftnl_cmd_type = 0;
pub const NFTNL_CMD_ADD: nftnl_cmd_type = 1;
pub const NFTNL_CMD_INSERT: nftnl_cmd_type = 2;
pub const NFTNL_CMD_DELETE: nftnl_cmd_type = 3;
pub const NFTNL_CMD_REPLACE: nftnl_cmd_type = 4;
pub const NFTNL_CMD_FLUSH: nftnl_cmd_type = 5;
pub const NFTNL_CMD_MAX: nftnl_cmd_type = 6;
pub type nftnl_cmd_type = u32;
pub type nftnl_cmd_type = c_uint;
pub const NFTNL_PARSE_NONE: nftnl_parse_type = 0;
pub const NFTNL_PARSE_XML: nftnl_parse_type = 1;
pub const NFTNL_PARSE_JSON: nftnl_parse_type = 2;
pub const NFTNL_PARSE_MAX: nftnl_parse_type = 3;
pub type nftnl_parse_type = u32;
pub type nftnl_parse_type = c_uint;
#[repr(C)]
pub struct nftnl_parse_err(c_void);

Expand All @@ -63,7 +63,7 @@ extern "C" {

pub fn nftnl_parse_err_free(arg1: *mut nftnl_parse_err);

pub fn nftnl_parse_perror(str: *const c_char, err: *mut nftnl_parse_err) -> c_int;
pub fn nftnl_parse_perror(str_: *const c_char, err: *mut nftnl_parse_err) -> c_int;

pub fn nftnl_batch_is_supported() -> c_int;

Expand Down Expand Up @@ -92,7 +92,7 @@ pub const NFTNL_CHAIN_HANDLE: nftnl_chain_attr = 9;
pub const NFTNL_CHAIN_TYPE: nftnl_chain_attr = 10;
pub const NFTNL_CHAIN_DEV: nftnl_chain_attr = 11;
pub const __NFTNL_CHAIN_MAX: nftnl_chain_attr = 12;
pub type nftnl_chain_attr = u32;
pub type nftnl_chain_attr = c_uint;
extern "C" {
pub fn nftnl_chain_is_set(c: *const nftnl_chain, attr: u16) -> bool;

Expand All @@ -110,7 +110,7 @@ extern "C" {

pub fn nftnl_chain_set_u64(t: *mut nftnl_chain, attr: u16, data: u64);

pub fn nftnl_chain_set_str(t: *mut nftnl_chain, attr: u16, str: *const c_char);
pub fn nftnl_chain_set_str(t: *mut nftnl_chain, attr: u16, str_: *const c_char);

pub fn nftnl_chain_get(c: *const nftnl_chain, attr: u16) -> *const c_void;

Expand Down Expand Up @@ -218,7 +218,7 @@ extern "C" {

pub fn nftnl_expr_set_u64(expr: *mut nftnl_expr, type_: u16, data: u64);

pub fn nftnl_expr_set_str(expr: *mut nftnl_expr, type_: u16, str: *const c_char);
pub fn nftnl_expr_set_str(expr: *mut nftnl_expr, type_: u16, str_: *const c_char);

pub fn nftnl_expr_get(expr: *const nftnl_expr, type_: u16, data_len: *mut u32)
-> *const c_void;
Expand Down Expand Up @@ -411,7 +411,7 @@ pub const NFTNL_RULE_COMPAT_FLAGS: nftnl_rule_attr = 5;
pub const NFTNL_RULE_POSITION: nftnl_rule_attr = 6;
pub const NFTNL_RULE_USERDATA: nftnl_rule_attr = 7;
pub const __NFTNL_RULE_MAX: nftnl_rule_attr = 8;
pub type nftnl_rule_attr = u32;
pub type nftnl_rule_attr = c_uint;
extern "C" {
pub fn nftnl_rule_unset(r: *mut nftnl_rule, attr: u16);

Expand All @@ -425,7 +425,7 @@ extern "C" {

pub fn nftnl_rule_set_u64(r: *mut nftnl_rule, attr: u16, val: u64);

pub fn nftnl_rule_set_str(r: *mut nftnl_rule, attr: u16, str: *const c_char);
pub fn nftnl_rule_set_str(r: *mut nftnl_rule, attr: u16, str_: *const c_char);

pub fn nftnl_rule_get(r: *const nftnl_rule, attr: u16) -> *const c_void;

Expand Down Expand Up @@ -544,7 +544,7 @@ pub const NFTNL_RULESET_CHAIN: nftnl_ruleset_type = 3;
pub const NFTNL_RULESET_RULE: nftnl_ruleset_type = 4;
pub const NFTNL_RULESET_SET: nftnl_ruleset_type = 5;
pub const NFTNL_RULESET_SET_ELEMS: nftnl_ruleset_type = 6;
pub type nftnl_ruleset_type = u32;
pub type nftnl_ruleset_type = c_uint;
extern "C" {
pub fn nftnl_ruleset_is_set(r: *const nftnl_ruleset, attr: u16) -> bool;

Expand Down Expand Up @@ -633,7 +633,7 @@ pub const NFTNL_SET_DESC_SIZE: nftnl_set_attr = 10;
pub const NFTNL_SET_TIMEOUT: nftnl_set_attr = 11;
pub const NFTNL_SET_GC_INTERVAL: nftnl_set_attr = 12;
pub const __NFTNL_SET_MAX: nftnl_set_attr = 13;
pub type nftnl_set_attr = u32;
pub type nftnl_set_attr = c_uint;
#[repr(C)]
pub struct nftnl_set(c_void);

Expand All @@ -656,7 +656,7 @@ extern "C" {

pub fn nftnl_set_set_u64(s: *mut nftnl_set, attr: u16, val: u64);

pub fn nftnl_set_set_str(s: *mut nftnl_set, attr: u16, str: *const c_char);
pub fn nftnl_set_set_str(s: *mut nftnl_set, attr: u16, str_: *const c_char);

pub fn nftnl_set_get(s: *const nftnl_set, attr: u16) -> *const c_void;

Expand Down Expand Up @@ -767,7 +767,7 @@ extern "C" {

pub fn nftnl_set_elem_set_u64(s: *mut nftnl_set_elem, attr: u16, val: u64);

pub fn nftnl_set_elem_set_str(s: *mut nftnl_set_elem, attr: u16, str: *const c_char);
pub fn nftnl_set_elem_set_str(s: *mut nftnl_set_elem, attr: u16, str_: *const c_char);

pub fn nftnl_set_elem_get(
s: *mut nftnl_set_elem,
Expand Down Expand Up @@ -852,7 +852,7 @@ pub const NFTNL_TABLE_FAMILY: nftnl_table_attr = 1;
pub const NFTNL_TABLE_FLAGS: nftnl_table_attr = 2;
pub const NFTNL_TABLE_USE: nftnl_table_attr = 3;
pub const __NFTNL_TABLE_MAX: nftnl_table_attr = 4;
pub type nftnl_table_attr = u32;
pub type nftnl_table_attr = c_uint;
extern "C" {
pub fn nftnl_table_is_set(t: *const nftnl_table, attr: u16) -> bool;

Expand All @@ -874,7 +874,7 @@ extern "C" {

pub fn nftnl_table_set_u32(t: *mut nftnl_table, attr: u16, data: u32);

pub fn nftnl_table_set_str(t: *mut nftnl_table, attr: u16, str: *const c_char);
pub fn nftnl_table_set_str(t: *mut nftnl_table, attr: u16, str_: *const c_char);

pub fn nftnl_table_get_u8(t: *const nftnl_table, attr: u16) -> u8;

Expand Down Expand Up @@ -966,7 +966,7 @@ pub const NFTNL_TRACE_VERDICT: nftnl_trace_attr = 15;
pub const NFTNL_TRACE_NFPROTO: nftnl_trace_attr = 16;
pub const NFTNL_TRACE_POLICY: nftnl_trace_attr = 17;
pub const __NFTNL_TRACE_MAX: nftnl_trace_attr = 18;
pub type nftnl_trace_attr = u32;
pub type nftnl_trace_attr = c_uint;
#[repr(C)]
pub struct nftnl_trace(c_void);

Expand Down
Loading