Skip to main content

nftnl_sys/
lib.rs

1// Copyright 2025 Mullvad VPN AB.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9//! Low level FFI bindings to [`libnftnl`], a userspace library providing a low-level netlink
10//! programming interface (API) to the in-kernel nf_tables subsystem.
11//!
12//! See [`nftnl`] for a higher level safe abstraction.
13//!
14//! # Linking to libmnl and libnftnl
15//!
16//! By default this crate uses pkg-config to find and link to its C dependencies, [`libmnl`] and
17//! [`libnftnl`]. To manually configure where to look for these libraries, set the environment
18//! variables `LIBMNL_LIB_DIR` and `LIBNFTNL_LIB_DIR` to point to the directories where `libmnl.so`
19//! (or `libmnl.a`) and `libnftnl.so` (or `libnftnl.a`) reside.
20//!
21//! # Selecting version of `libnftnl`
22//!
23//! This crate has bindings for most versions of [`libnftnl`]. All bindings are generated by
24//! [`bindgen`] via the `generate_bindings.sh` script in this repository.
25//!
26//! Only one version of `libnftnl` can be exposed via this crate. By default the crate exports the
27//! bindings for the oldest supported version (`libnftnl-1.0.6`). To get newer versions activate the
28//! corresponding features. See `Cargo.toml` for available features/versions.
29//!
30//! So for example, to get bindings to `libnftnl-1.0.9` depend on this crate like this:
31//! ```toml
32//! [dependencies]
33//! nftnl-sys = { version = "0.1", features = ["nftnl-1-0-9"] }
34//! ```
35//!
36//! [`libnftnl`]: https://netfilter.org/projects/libnftnl/
37//! [`libmnl`]: https://netfilter.org/projects/libmnl/
38//! [`nftnl`]: https://crates.io/crates/nftnl
39//! [`bindgen`]: https://crates.io/crates/bindgen
40
41#![no_std]
42#![cfg(target_os = "linux")]
43#![allow(non_camel_case_types)]
44
45pub use libc;
46
47cfg_if::cfg_if! {
48    if #[cfg(feature = "nftnl-1-3-0")] {
49        mod nftnl_1_3_0;
50        pub use self::nftnl_1_3_0::*;
51    } else if #[cfg(feature = "nftnl-1-2-9")] {
52        mod nftnl_1_2_9;
53        pub use self::nftnl_1_2_9::*;
54    } else if #[cfg(feature = "nftnl-1-2-8")] {
55        mod nftnl_1_2_8;
56        pub use self::nftnl_1_2_8::*;
57    } else if #[cfg(feature = "nftnl-1-2-7")] {
58        mod nftnl_1_2_7;
59        pub use self::nftnl_1_2_7::*;
60    } else if #[cfg(feature = "nftnl-1-2-6")] {
61        mod nftnl_1_2_6;
62        pub use self::nftnl_1_2_6::*;
63    } else if #[cfg(feature = "nftnl-1-2-5")] {
64        mod nftnl_1_2_5;
65        pub use self::nftnl_1_2_5::*;
66    } else if #[cfg(feature = "nftnl-1-2-4")] {
67        mod nftnl_1_2_4;
68        pub use self::nftnl_1_2_4::*;
69    } else if #[cfg(feature = "nftnl-1-2-3")] {
70        mod nftnl_1_2_3;
71        pub use self::nftnl_1_2_3::*;
72    } else if #[cfg(feature = "nftnl-1-2-2")] {
73        mod nftnl_1_2_2;
74        pub use self::nftnl_1_2_2::*;
75    } else if #[cfg(feature = "nftnl-1-2-1")] {
76        mod nftnl_1_2_1;
77        pub use self::nftnl_1_2_1::*;
78    } else if #[cfg(feature = "nftnl-1-2-0")] {
79        mod nftnl_1_2_0;
80        pub use self::nftnl_1_2_0::*;
81    } else if #[cfg(feature = "nftnl-1-1-9")] {
82        mod nftnl_1_1_9;
83        pub use self::nftnl_1_1_9::*;
84    } else if #[cfg(feature = "nftnl-1-1-8")] {
85        mod nftnl_1_1_8;
86        pub use self::nftnl_1_1_8::*;
87    } else if #[cfg(feature = "nftnl-1-1-7")] {
88        mod nftnl_1_1_7;
89        pub use self::nftnl_1_1_7::*;
90    } else if #[cfg(feature = "nftnl-1-1-6")] {
91        mod nftnl_1_1_6;
92        pub use self::nftnl_1_1_6::*;
93    } else if #[cfg(feature = "nftnl-1-1-5")] {
94        mod nftnl_1_1_5;
95        pub use self::nftnl_1_1_5::*;
96    } else if #[cfg(feature = "nftnl-1-1-4")] {
97        mod nftnl_1_1_4;
98        pub use self::nftnl_1_1_4::*;
99    } else if #[cfg(feature = "nftnl-1-1-3")] {
100        mod nftnl_1_1_3;
101        pub use self::nftnl_1_1_3::*;
102    } else if #[cfg(feature = "nftnl-1-1-2")] {
103        mod nftnl_1_1_2;
104        pub use self::nftnl_1_1_2::*;
105    } else if #[cfg(feature = "nftnl-1-1-1")] {
106        mod nftnl_1_1_1;
107        pub use self::nftnl_1_1_1::*;
108    } else if #[cfg(feature = "nftnl-1-1-0")] {
109        mod nftnl_1_1_0;
110        pub use self::nftnl_1_1_0::*;
111    } else if #[cfg(feature = "nftnl-1-0-9")] {
112        mod nftnl_1_0_9;
113        pub use self::nftnl_1_0_9::*;
114    } else if #[cfg(feature = "nftnl-1-0-8")] {
115        mod nftnl_1_0_8;
116        pub use self::nftnl_1_0_8::*;
117    } else if #[cfg(feature = "nftnl-1-0-7")] {
118        mod nftnl_1_0_7;
119        pub use self::nftnl_1_0_7::*;
120    } else {
121        mod nftnl_1_0_6;
122        pub use self::nftnl_1_0_6::*;
123    }
124}