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-1-2")] {
49 mod nftnl_1_1_2;
50 pub use self::nftnl_1_1_2::*;
51 } else if #[cfg(feature = "nftnl-1-1-1")] {
52 mod nftnl_1_1_1;
53 pub use self::nftnl_1_1_1::*;
54 } else if #[cfg(feature = "nftnl-1-1-0")] {
55 mod nftnl_1_1_0;
56 pub use self::nftnl_1_1_0::*;
57 } else if #[cfg(feature = "nftnl-1-0-9")] {
58 mod nftnl_1_0_9;
59 pub use self::nftnl_1_0_9::*;
60 } else if #[cfg(feature = "nftnl-1-0-8")] {
61 mod nftnl_1_0_8;
62 pub use self::nftnl_1_0_8::*;
63 } else if #[cfg(feature = "nftnl-1-0-7")] {
64 mod nftnl_1_0_7;
65 pub use self::nftnl_1_0_7::*;
66 } else {
67 mod nftnl_1_0_6;
68 pub use self::nftnl_1_0_6::*;
69 }
70}