126 Commits

Author SHA1 Message Date
Jan Palus
2e3c68f26d build: fix ./configure with non-bash shell
CONFIG_SHELL=/bin/dash ./configure

breaks with:

 ./config.status: 2044: Syntax error: Bad for loop variable

Fixes: 64c07e38f049 ("table: Embed creating nft version into userdata")
Signed-off-by: Jan Palus <jpalus@fastmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-12-06 17:27:01 +01:00
Pablo Neira Ayuso
95f82543dc build: Bump version to 1.1.6
This requires libnftnl 1.3.1 which includes new tunnel API.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-12-05 12:56:11 +01:00
Florian Westphal
f2813fb53b support for afl++ (american fuzzy lop++) fuzzer
afl comes with a compiler frontend that can add instrumentation suitable
for running nftables via the "afl-fuzz" fuzzer.

This change adds a "--with-fuzzer" option to configure script and enables
specific handling in nftables and libnftables to speed up the fuzzing process.
It also adds the "--fuzzer" command line option.

afl-fuzz initialisation gets delayed until after the netlink context is set up
and symbol tables such as (e.g. route marks) have been parsed.

When afl-fuzz restarts the process with a new input round, it will
resume *after* this point (see __AFL_INIT macro in main.c).

With --fuzzer <stage>, nft will perform multiple fuzzing rounds per
invocation: this increases processing rate by an order of magnitude.
The argument to '--fuzzer' specifies the last stage to run:

1: 'parser':
    Only run / exercise the flex/bison parser.

2: 'eval': stop after the evaluation phase.
    This attempts to build a complete ruleset in memory, does
    symbol resolution, adds needed shift/masks to payload instructions
    etc.

3: 'netlink-ro':
    'netlink-ro' builds the netlink buffer to send to the kernel,
    without actually doing so.

4: 'netlink-rw':
    Pass generated command/ruleset will be passed to the kernel.
    You can combine it with the '--check' option to send data to the kernel
    but without actually committing any changes.
    This could still end up triggering a kernel crash if there are bugs
    in the valiation / transaction / abort phases.

Use 'netlink-ro' if you want to prevent nft from ever submitting any
changes to the kernel or if you are only interested in fuzzing nftables
and its libraries.

In case a kernel splat is detected, the fuzzing process stops and all further
fuzzer attemps are blocked until reboot.

Signed-off-by: Florian Westphal <fw@strlen.de>
2025-11-11 13:00:29 +01:00
Jeremy Sowden
31007975cc build: don't install ancillary files without systemd service file
If the systemd service file is not installed, currently the related man-page
and example nft file are still installed.  Instead only install them when the
service file is installed.

Fixes: 107580cfa85c ("build: disable --with-unitdir by default")
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
2025-10-31 12:37:40 +01:00
Phil Sutter
df19bf51d4 Makefile: Enable support for 'make check'
With all test suites running all variants by default, add the various
testsuite runners to TESTS variable so 'make check' will execute them.

Introduce --enable-distcheck configure flag for internal use during
builds triggered by 'make distcheck'. This flag will force TESTS
variable to remain empty, so 'make check' run as part of distcheck will
not call any test suite: Most of the test suites require privileged
execution, 'make distcheck' usually doesn't and probably shouldn't.
Assuming the latter is used during the release process, it may even not
run on a machine which is up to date enough to generate meaningful test
suite results. Hence spare the release process from the likely pointless
delay imposed by 'make check'.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2025-09-11 18:11:53 +02:00
Phil Sutter
229fa8b440 Makefile: Fix for 'make CFLAGS=...'
Appending to CFLAGS from configure.ac like this was too naive, passing
custom CFLAGS in make arguments overwrites it. Extend AM_CFLAGS instead.

Fixes: 64c07e38f0494 ("table: Embed creating nft version into userdata")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-09-09 12:18:03 +02:00
Phil Sutter
64c07e38f0 table: Embed creating nft version into userdata
Upon listing a table which was created by a newer version of nftables,
warn about the potentially incomplete content.

Suggested-by: Florian Westphal <fw@strlen.de>
Cc: Dan Winship <danwinship@redhat.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-08-28 12:47:15 +02:00
Pablo Neira Ayuso
5fb7482435 build: Bump version to 1.1.5
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-08-27 16:56:14 +02:00
Pablo Neira Ayuso
107580cfa8 build: disable --with-unitdir by default
Same behaviour as in the original patch:

  --with-unitdir	auto-detects the systemd unit path.
  --with-unitdir=PATH	uses the PATH

no --with-unitdir means this does not install the systemd unit file.

INSTALL file description looks fine for what this does after this
patch.

While at this, extend tests/build/ to cover for this new option.

Fixes: c4b17cf830510 ("tools: add a systemd unit for static rulesets")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-08-27 16:56:04 +02:00
Jan Engelhardt
c4b17cf830 tools: add a systemd unit for static rulesets
There is a customer request (bugreport) for wanting to trivially load a ruleset
from a well-known location on boot, forwarded to me by M. Gerstner. A systemd
service unit is hereby added to provide that functionality. This is based on
various distributions attempting to do same, for example,

https://src.fedoraproject.org/rpms/nftables/tree/rawhide
https://gitlab.alpinelinux.org/alpine/aports/-/blob/master/main/nftables/nftables.initd
https://gitlab.archlinux.org/archlinux/packaging/packages/nftables
Acked-by: Eric Garver <eric@garver.life>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-08-20 14:52:31 +02:00
Pablo Neira Ayuso
a83dab190a build: Bump version to 1.1.4
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-08-06 12:52:51 +02:00
Pablo Neira Ayuso
4431c70ca9 build: Bump version to 1.1.3
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-04-22 11:47:38 +02:00
Pablo Neira Ayuso
3def289a06 build: Bump version to 1.1.2
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-04-14 18:55:15 +02:00
Jan Engelhardt
baeb2c200f build: add hint for a2x error message
Display:

  a2x not found, please install asciidoc, or pass --disable-man-doc

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2025-03-05 22:42:10 +01:00
Pablo Neira Ayuso
3271d78e70 build: Bump version to 1.1.1
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2024-10-03 00:23:56 +02:00
Pablo Neira Ayuso
d946842f57 build: Bump version to 1.1.0
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2024-07-16 22:20:35 +02:00
Thomas Haller
e6f21c85f2 build: no recursive make for "doc/Makefile.am"
Merge the Makefile.am under "doc/" into the toplevel Makefile.am. This
is a step in the effort of dropping recursive make.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2023-11-02 11:48:30 +01:00
Thomas Haller
c96e0a17f3 build: no recursive make for "examples/Makefile.am"
Merge the Makefile.am under "examples/" into the toplevel Makefile.am.
This is a step in the effort of dropping recursive make.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2023-11-02 11:48:30 +01:00
Thomas Haller
11e6213842 build: no recursive make for "src/Makefile.am"
Merge the Makefile.am under "src/" into the toplevel Makefile.am. This
is a step in the effort of dropping recursive make.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2023-11-02 11:48:30 +01:00
Thomas Haller
83512d6c22 build: no recursive make for "files/**/Makefile.am"
Merge the Makefile.am under "files/" into the toplevel Makefile.am. This
is a step in the effort of dropping recursive make.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2023-11-02 11:48:30 +01:00
Thomas Haller
89554fe9ef build: no recursive make for "py/Makefile.am"
Merge the Makefile.am under "py/" into the toplevel Makefile.am. This is
a step in the effort of dropping recursive make.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2023-11-02 11:48:30 +01:00
Thomas Haller
686d987706 build: no recursive-make for "include/**/Makefile.am"
Switch from recursive-make to a single top-level Makefile. This is the
first step, the following patches will continue this.

Unlike meson's subdir() or C's #include, automake's SUBDIRS= does not
include a Makefile. Instead, it calls `make -C $dir`.

  https://www.gnu.org/software/make/manual/html_node/Recursion.html
  https://www.gnu.org/software/automake/manual/html_node/Subdirectories.html

See also, "Recursive Make Considered Harmful".

  https://accu.org/journals/overload/14/71/miller_2004/

This has several problems, which we an avoid with a single Makefile:

- recursive-make is harder to maintain and understand as a whole.
  Recursive-make makes sense, when there are truly independent
  sub-projects. Which is not the case here. The project needs to be
  considered as a whole and not one directory at a time. When
  we add unit tests (which we should), those would reside in separate
  directories but have dependencies between directories. With a single
  Makefile, we see all at once. The build setup has an inherent complexity,
  and that complexity is not necessarily reduced by splitting it into more files.
  On the contrary it helps to have it all in once place, provided that it's
  sensibly structured, named and organized.

- typing `make` prints irrelevant "Entering directory" messages. So much
  so, that at the end of the build, the terminal is filled with such
  messages and we have to scroll to see what even happened.

- with recursive-make, during build we see:

    make[3]: Entering directory '.../nftables/src'
      CC       meta.lo
    meta.c:13:2: error: #warning hello test [-Werror=cpp]
       13 | #warning hello test
          |  ^~~~~~~

  With a single Makefile we get

      CC       src/meta.lo
    src/meta.c:13:2: error: #warning hello test [-Werror=cpp]
       13 | #warning hello test
          |  ^~~~~~~

  This shows the full filename -- assuming that the developer works from
  the top level directory. The full name is useful, for example to
  copy+paste into the terminal.

- single Makefile is also faster:

    $ make && perf stat -r 200 -B make -j

  I measure 35msec vs. 80msec.

- recursive-make limits parallel make. You have to craft the SUBDIRS= in
  the correct order. The dependencies between directories are limited,
  as make only sees "LDADD = $(top_builddir)/src/libnftables.la" and
  not the deeper dependencies for the library.

- I presume, some people like recursive-make because of `make -C $subdir`
  to only rebuild one directory. Rebuilding the entire tree is already very
  fast, so this feature seems not relevant. Also, as dependency handling
  is limited, we might wrongly not rebuild a target. For example,

        make check
        touch src/meta.c
        make -C examples check

  does not rebuild "examples/nft-json-file".
  What we now can do with single Makefile (and better than before), is
  `make examples/nft-json-file`, which works as desired and rebuilds all
  dependencies.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2023-11-02 11:48:30 +01:00
Pablo Neira Ayuso
49151cd070 build: Bump version to 1.0.9
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2023-10-19 12:17:08 +02:00
Thomas Haller
c9091421f0 configure: drop AM_PROG_CC_C_O autoconf check
This macro is obsolete since automake 1.14 (2013). It might have been
unnecessary even before, in practice only gcc/clang are supported
compilers.

[1] https://www.gnu.org/software/automake/manual/html_node/Public-Macros.html#index-AM_005fPROG_005fCC_005fC_005fO
[2] https://lists.gnu.org/archive/html/info-gnu/2013-06/msg00009.html

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2023-08-25 14:59:19 +02:00
Thomas Haller
6a90f33a6f configure: use AC_USE_SYSTEM_EXTENSIONS to get _GNU_SOURCE
Let "configure" detect which features are available. Also, nftables is a
Linux project, so portability beyond gcc/clang and glibc/musl is less
relevant. And even if it were, then feature detection by "configure"
would still be preferable.

Use AC_USE_SYSTEM_EXTENSIONS ([1]).

Available since autoconf 2.60, from 2006 ([2]).

[1] https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Posix-Variants.html#index-AC_005fUSE_005fSYSTEM_005fEXTENSIONS-1046
[2] https://lists.gnu.org/archive/html/autoconf/2006-06/msg00111.html

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2023-08-25 14:59:19 +02:00
Thomas Haller
7076523e48 nftutils: add and use wrappers for getprotoby{name,number}_r(), getservbyport_r()
We should aim to use the thread-safe variants of getprotoby{name,number}
and getservbyport(). However, they may not be available with other libc,
so it requires a configure check. As that is cumbersome, add wrappers
that do that at one place.

These wrappers are thread-safe, if libc provides the reentrant versions.
Use them.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2023-08-20 23:48:26 +02:00
Pablo Neira Ayuso
b3def33efe py: remove setup.py integration with autotools
With Python distutils and setuptools going deprecated, remove
integration with autotools. This integration is causing issues
in modern environments.

Note that setup.py is still left in place under the py/ folder.

Update INSTALL file to refer to Python support and setup.py.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2023-07-31 09:06:22 +02:00
Pablo Neira Ayuso
6493bf4abe build: Bump version to 1.0.8
Update dependency on libnftnl >= 1.2.6 which contains support for
meta broute.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2023-07-14 11:35:13 +02:00
Pablo Neira Ayuso
63b3efd9b4 build: Bump version to 1.0.7
Update dependency on libnftnl >= 1.2.5 which contains support for inner
header matching.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2023-03-13 15:12:17 +01:00
Pablo Neira Ayuso
a01fe3e488 build: Bump version to 1.0.6
Update dependency on libnftnl >= 1.2.4 which contains fixes.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-12-21 18:16:08 +01:00
Phil Sutter
fa8f10b19d Makefile: Create LZMA-compressed dist-files
Use a more modern alternative to bzip2.

Suggested-by: Jan Engelhardt <jengelh@inai.de>
Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2022-12-09 02:15:59 +01:00
Pablo Neira Ayuso
132486709b build: Bump version to 1.0.5
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-08-09 20:45:38 +02:00
Pablo Neira Ayuso
3eb0da9f47 build: Bump version to 1.0.4
Bump libnftnl dependency to fix --debug with new TCP reset support.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-06-07 16:14:25 +02:00
Pablo Neira Ayuso
87fdf683fb build: Bump version to 1.0.3
Still requires libnftnl 1.2.1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-05-31 10:21:44 +02:00
Pablo Neira Ayuso
964e097c4f build: Bump version to 1.0.2
Still requires libnftnl 1.2.1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-02-21 12:38:10 +01:00
Pablo Neira Ayuso
caf2a6ad2d examples: add libnftables example program
Create an example folder to add example source code files to show how to
use libnftables. Add first example program using the buffer API.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2022-02-17 18:23:05 +01:00
Jeremy Sowden
9d115ecaa6 build: fix autoconf warnings
autoconf complains about three obsolete macros.

`AC_CONFIG_HEADER` has been superseded by `AC_CONFIG_HEADERS`, so
replace it.

`AM_PROG_LEX` calls `AC_PROG_LEX` with no arguments, but this usage is
deprecated.  The only difference between `AM_PROG_LEX` and `AC_PROG_LEX`
is that the former defines `$LEX` as "./build-aux/missing lex" if no lex
is found to ensure a useful error is reported when make is run.  How-
ever, the configure script checks that we have a working lex and exits
with an error if none is available, so `$LEX` will never be called and
we can replace `AM_PROG_LEX` with `AC_PROG_LEX`.

`AM_PROG_LIBTOOL` has been superseded by `LT_INIT`, which is already in
configure.ac, so remove it.

We can also replace `AC_DISABLE_STATIC` with an argument to `LT_INIT`.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-12-15 22:50:24 +01:00
Pablo Neira Ayuso
168e4e29e3 build: Bump version to 1.0.1
Requires libnftnl 1.2.1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-11-18 11:56:12 +01:00
Pablo Neira Ayuso
b4dded0ca7 configure: default to libedit for cli
readline support only compiles for libreadline5, set libedit as default
library.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-10-25 23:36:33 +02:00
Pablo Neira Ayuso
8062079da0 build: Bump version to v1.0.0
Update libversion since new API has been added in 9edaa6a51eab ("src:
add --define key=value").

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-08-17 19:31:19 +02:00
Pablo Neira Ayuso
6fad96cde8 build: Bump version to v0.9.9
Update release name based on the Fearless Fosdick series: Prudence Pimpleton.

Bump dependencies on libnftnl.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-05-25 22:58:37 +02:00
Pablo Neira Ayuso
c487209984 build: Bump version to v0.9.8
Update release name based on the Fearless Fosdick series: E.D.S.

E.D.S. is the robotic "Electronic Detective Substitute" appearing in the
"Hole Story".

Bump dependencies on libnftnl.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-01-15 18:53:12 +01:00
Pablo Neira Ayuso
9420423900 cli: add libedit support
Extend cli to support for libedit readline shim code:

	./configure --with-cli=editline

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2021-01-05 18:36:19 +01:00
Pablo Neira Ayuso
ca7464bf51 build: search for python3
Eric Garver says: "It would probably be better to use the automake macro
AM_PATH_PYTHON. [...] The above is fine for now."

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-12-15 20:09:27 +01:00
Pablo Neira Ayuso
501ae116ed build: Bump version to v0.9.7
Update release name based on the Fearless Fosdick series: Anyface.

Bump dependencies on libnftnl.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-10-26 14:41:08 +01:00
Pablo Neira Ayuso
17ee0ff0af build: Bump version to v0.9.6
v0.9.5 broke 'vmap' support:

	https://bugzilla.kernel.org/show_bug.cgi?id=208093

Release new version to fix this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-06-15 21:13:39 +02:00
Pablo Neira Ayuso
515d3819dd build: Bump version to v0.9.5
Update release name based on Jazz series, Gene Krupa's "Capital Idea".

Bump dependencies on libmnl and libnftnl.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-06-06 11:58:40 +02:00
Stefano Brivio
6c824e781e build: Fix doc build, restore A2X assignment for doc/Makefile
Commit 4f2813a313ae ("build: Include generated man pages in dist
tarball") skips AC_CHECK_PROG for A2X altogether if doc/nft.8 is
already present.

Now, starting from a clean situation, we can have this sequence:
  ./configure	# doc/nft.8 not there, A2X set in doc/Makefile
  make		# builds doc/nft.8
  ./configure	# doc/nft.8 is there, A2X left empty in doc/Makefile
  make clean	# removes doc/nft.8
  make

resulting in:

  [...]
    GEN      nft.8
  /bin/sh: -L: command not found
  make[2]: *** [Makefile:639: nft.8] Error 127

and the only way to get out of this is to issue ./configure again
after make clean, which is rather unexpected.

Instead of skipping AC_CHECK_PROG when doc/nft.8 is present, keep
it and simply avoid returning failure if a2x(1) is not available but
doc/nft.8 was built, so that A2X is properly set in doc/Makefile
whenever needed.

Fixes: 4f2813a313ae ("build: Include generated man pages in dist tarball")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-05-25 21:53:16 +02:00
Matt Turner
2885cf2e65 build: Allow building from tarballs without yacc/lex
The generated files are included in the tarballs already, but
configure.ac was coded to fail if yacc/lex were not found regardless.

Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-04-19 18:41:35 +02:00
Matt Turner
4f2813a313 build: Include generated man pages in dist tarball
Most projects ship pre-generated man pages in the distribution tarball
so that builders don't need the documentation tools installed, similar
to how bison-generated sources are included.

To do this, we conditionalize the presence check of a2x on whether nft.8
already exists in the source directory, as it would exist if included in
the distribution tarball.

Secondly, we move the 'if BUILD_MAN' conditional to around the man page
generation rules. This ensures that the man pages are unconditionally
installed. Also only add the man pages to CLEANFILES if their generation
is enabled.

Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2020-04-19 18:40:59 +02:00