]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
20 months agonft-bridge: nft_bridge_add() uses wrong flags
Phil Sutter [Wed, 15 Nov 2023 16:41:50 +0000 (17:41 +0100)] 
nft-bridge: nft_bridge_add() uses wrong flags

When checking whether -s or -d was given, invflags were used by
accident. This change has no functional effect since the values remain
the same, but this way it's clear where the previously assigned flags
are used.

Signed-off-by: Phil Sutter <phil@nwl.cc>
20 months agoMakefile: Install arptables-translate link and man page
Phil Sutter [Sun, 19 Nov 2023 10:20:55 +0000 (11:20 +0100)] 
Makefile: Install arptables-translate link and man page

While at it, introduce a variable to hold the various semantic links to
xtables-translate.8 man page.

Fixes: 5b7324e0675e3 ("nft-arp: add arptables-translate")
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: more backslash-encoding of characters
Jan Engelhardt [Mon, 13 Nov 2023 10:17:35 +0000 (11:17 +0100)] 
man: more backslash-encoding of characters

"-" is the dash, "\-" is minus as we know, but groff lists some more
characters: "^" is "modifier circumflex" and "~" is "modifier tilde",
which, too, need to be escaped for our use.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
21 months agoman: limit targets for -P option synopsis
Jan Engelhardt [Mon, 13 Nov 2023 10:09:32 +0000 (11:09 +0100)] 
man: limit targets for -P option synopsis

Do not suggest that -P could be used with arbitrary targets.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
21 months agoman: copy synopsis markup from iptables.8 to arptables-nft.8
Jan Engelhardt [Mon, 13 Nov 2023 09:45:06 +0000 (10:45 +0100)] 
man: copy synopsis markup from iptables.8 to arptables-nft.8

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
21 months agoman: stop putting non-terminals in italic
Jan Engelhardt [Mon, 13 Nov 2023 10:08:28 +0000 (11:08 +0100)] 
man: stop putting non-terminals in italic

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
21 months agoman: repeal manual hyphenation
Jan Engelhardt [Mon, 13 Nov 2023 10:27:50 +0000 (11:27 +0100)] 
man: repeal manual hyphenation

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
21 months agoman: remove lone .nh command
Jan Engelhardt [Mon, 13 Nov 2023 09:20:50 +0000 (10:20 +0100)] 
man: remove lone .nh command

No other manpage files use .nh, and I cannot see a reason
iptables-apply would exceptionally need it.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
21 months agoman: consistent use of \(em in Name sections
Jan Engelhardt [Mon, 13 Nov 2023 09:19:03 +0000 (10:19 +0100)] 
man: consistent use of \(em in Name sections

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
21 months agoextensions: libarpt_standard.t: Add a rule with builtin option masks
Phil Sutter [Wed, 8 Nov 2023 03:26:42 +0000 (04:26 +0100)] 
extensions: libarpt_standard.t: Add a rule with builtin option masks

Just some random values in hope this starts failing if masks support
changes or breaks.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
21 months agoarptables: Fix --proto-type mask formatting
Phil Sutter [Wed, 8 Nov 2023 03:08:44 +0000 (04:08 +0100)] 
arptables: Fix --proto-type mask formatting

Arptables accepts numeric --proto-type values and masks in any numeral
system identified by (absence of) prefix. Yet it prints the mask value
in hex without '0x'-prefix, breaking save and restore the same way
numeric --h-type output did.

In theory, this could be fixed either by adding the missing prefix or
printing the mask in decimal (like most other builtin matches do), but
since the value is printed in hex with prefix already, align mask output
with that.

Also a day 1 bug and consistent with legacy, so no Fixes: tag here as
well.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
21 months agoarptables: Fix formatting of numeric --h-type output
Phil Sutter [Wed, 8 Nov 2023 02:58:42 +0000 (03:58 +0100)] 
arptables: Fix formatting of numeric --h-type output

Arptables expects numeric arguments to --h-type option in hexadecimal
form, even if no '0x'-prefix is present. In contrast, it prints such
values in decimal. This is not just inconsistent, but makes it
impossible to save and later restore a ruleset without fixing up the
values in between.

Assuming that the parser side can't be changed for compatibility
reasons, fix the output side instead.

This is a day 1 bug and present in legacy arptables as well, so treat
this as a "feature" of arptables-nft and omit a Fixes: tag.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
21 months agoextensions: MARK: fix arptables support
Florian Westphal [Tue, 7 Nov 2023 11:15:40 +0000 (12:15 +0100)] 
extensions: MARK: fix arptables support

arptables "--set-mark" is really just "--or-mark".
This bug is also in arptables-legacy.

Fix this and add test cases.
Note that the test for "16" vs. "0x16" is intentional,
arptables parser is buggy and always uses "%x".

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoarptables-txlate: add test cases
Florian Westphal [Tue, 7 Nov 2023 11:15:39 +0000 (12:15 +0100)] 
arptables-txlate: add test cases

Add test cases for libarpt_mangle and extend the generic
tests to cover basic arptables matches.

Note that there are several historic artefacts that could be revised.
For example, arptables-legacy and arptables-nft both ignore "-p"
instead of returning an error about an unsupported option.

The ptype could be hard-wired to 0x800 and set unconditionally.
OTOH, this should always match for ethernet arp packets anyway.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agonft-arp: add arptables-translate
Florian Westphal [Tue, 7 Nov 2023 11:15:38 +0000 (12:15 +0100)] 
nft-arp: add arptables-translate

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agonft-arp: add missing mask support
Florian Westphal [Tue, 7 Nov 2023 11:15:37 +0000 (12:15 +0100)] 
nft-arp: add missing mask support

arptables-legacy supports masks for --h-type, --opcode
and --proto-type, but arptables-nft did not.

Add this.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoebtables: Fix corner-case noflush restore bug
Phil Sutter [Tue, 7 Nov 2023 18:12:14 +0000 (19:12 +0100)] 
ebtables: Fix corner-case noflush restore bug

Report came from firwalld, but this is actually rather hard to trigger.
Since a regular chain line prevents it, typical dump/restore use-cases
are unaffected.

Fixes: 73611d5582e72 ("ebtables-nft: add broute table emulation")
Cc: Eric Garver <eric@garver.life>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoarptables-nft: remove ARPT_INV flags usage
Florian Westphal [Fri, 3 Nov 2023 16:33:22 +0000 (17:33 +0100)] 
arptables-nft: remove ARPT_INV flags usage

ARPT_ and IPT_INV flags are not interchangeable, e.g.:
define IPT_INV_SRCDEVADDR 0x0080
define ARPT_INV_SRCDEVADDR 0x0010

as these flags can be tested by libarp_foo.so such checks can yield
incorrect results.

Because arptables-nft uses existing code, e.g. xt_mark, it makes
sense to unify this completely by converting the last users of
ARPT_INV_ constants.

Note that arptables-legacy does not do run-time module loading via
dlopen(). Functionaliy implemented by "extensions" in the
arptables-legacy git tree are built-in, so this doesn't break
arptables-legacy binaries.

Fixes: 44457c080590 ("xtables-arp: Don't use ARPT_INV_*")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: reveal rateest's combination categories
Phil Sutter [Tue, 24 Oct 2023 15:52:01 +0000 (17:52 +0200)] 
man: reveal rateest's combination categories

The .\" prefix made these paragraphs invisible in at least regular
man page output. Turn them into tags instead.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: use .TP for lists in xt_osf man page
Phil Sutter [Tue, 24 Oct 2023 15:49:13 +0000 (17:49 +0200)] 
man: use .TP for lists in xt_osf man page

Value and description are more clearly set apart. Using .RS/.RE
pairs also adds proper indenting.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: use native bullet point markup
Jan Engelhardt [Tue, 24 Oct 2023 13:16:40 +0000 (15:16 +0200)] 
man: use native bullet point markup

Replace some "fake" bullet point by the official syntax/markup
for bulleted lists.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: grammar fixes to some manpages
Jan Engelhardt [Tue, 24 Oct 2023 13:06:37 +0000 (15:06 +0200)] 
man: grammar fixes to some manpages

English generally uses open compounds rather than closed ones;
fix the excess hyphens in words. Fix a missing dash for the
portnr option as well.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: consistent casing of "IPv[46]"
Jan Engelhardt [Tue, 24 Oct 2023 13:14:54 +0000 (15:14 +0200)] 
man: consistent casing of "IPv[46]"

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: encode hyphens the way groff/man requires it
Jan Engelhardt [Tue, 24 Oct 2023 13:04:03 +0000 (15:04 +0200)] 
man: encode hyphens the way groff/man requires it

Edit a few spots where indeed a hyphens (U+2010) rather than U+002D is desired.
("set-name" is not something you input, it is a placeholder in the context of
documentation. "out-of-flow" is part of the regular flowed text, so should not
use anything but hyphens.)

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: encode emdash the way groff/man requires it
Jan Engelhardt [Tue, 24 Oct 2023 13:00:42 +0000 (15:00 +0200)] 
man: encode emdash the way groff/man requires it

Unlike LaTeX, two/three U+002D in the source do not translate to an
en and em-dash in man. Using \(en and \(em, respectively, addresses
this.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: encode minushyphen the way groff/man requires it
Jan Engelhardt [Tue, 24 Oct 2023 12:58:06 +0000 (14:58 +0200)] 
man: encode minushyphen the way groff/man requires it

Sparked by a recent LWN article[1], sweeps over the iptables manpages
for incorrectly encoded dashes was made by Phil Sutter and myself.

An ASCII minushyphen in the source manpage translates to a hyphen in
output, so one has to use the sequence "\-" to get a minushyphen in
the output, as groff_char(7) explains.

[1] https://lwn.net/Articles/947941/ (paywalled until about 2023-11-06)

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoman: display number ranges with an en dash
Jan Engelhardt [Thu, 26 Oct 2023 08:34:26 +0000 (10:34 +0200)] 
man: display number ranges with an en dash

For ranges, en dashes should be used; cf. e.g.
https://en.wikipedia.org/wiki/Dash#En_dash .

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
21 months agoextensions: string: Adjust description of --to to recent kernel changes
Phil Sutter [Tue, 24 Oct 2023 09:57:31 +0000 (11:57 +0200)] 
extensions: string: Adjust description of --to to recent kernel changes

This reverts commit 920ece2b392fb83bd26416e0e6f8f6a847aacbaa.

Since kernel commit c4eee56e14fe ("net: skb_find_text: Ignore patterns
extending past 'to'"), pattern scanning no longer happens past --to
offset even if skb_seq_read() returned a larger block. Point this out in
the description and also drop the '-1' offset which is not true as
kernel's selftest in tools/testing/selftests/netfilter/xt_string.sh
shows.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1707
Signed-off-by: Phil Sutter <phil@nwl.cc>
22 months agoextensions: string: Clarify description of --to
Phil Sutter [Thu, 12 Oct 2023 15:54:53 +0000 (17:54 +0200)] 
extensions: string: Clarify description of --to

String match indeed returns a match as long as the given pattern starts
in the range of --from and --to, update the text accordingly.
Also add a note regarding fragment boundaries.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1707
22 months agolibiptc: Fix for another segfault due to chain index NULL pointer
Phil Sutter [Thu, 12 Oct 2023 15:27:42 +0000 (17:27 +0200)] 
libiptc: Fix for another segfault due to chain index NULL pointer

Chain rename code missed to adjust the num_chains value which is used to
calculate the number of chain index buckets to allocate during an index
rebuild. So with the right number of chains present, the last chain in a
middle bucket being renamed (and ending up in another bucket) triggers
an index rebuild based on false data. The resulting NULL pointer index
bucket then causes a segfault upon reinsertion.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1713
Fixes: 64ff47cde38e4 ("libiptc: fix chain rename bug in libiptc")
22 months agoconfigure: Bump version for 1.8.10 release v1.8.10
Pablo Neira Ayuso [Tue, 10 Oct 2023 09:20:12 +0000 (11:20 +0200)] 
configure: Bump version for 1.8.10 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
22 months agobuild: Bump dependency on libnftnl
Phil Sutter [Fri, 29 Sep 2023 23:35:48 +0000 (01:35 +0200)] 
build: Bump dependency on libnftnl

Recently added support for broute table emulation requires libnftnl
version 1.2.6.

Fixes: 73611d5582e72 ("ebtables-nft: add broute table emulation")
Signed-off-by: Phil Sutter <phil@nwl.cc>
22 months agoinclude: linux: Update kernel.h
Phil Sutter [Wed, 6 Sep 2023 17:02:52 +0000 (19:02 +0200)] 
include: linux: Update kernel.h

Its contents were moved into const.h and sysinfo.h, apply these changes
to the cached copies. Fixes for the following warning when compiling
xtables-monitor.c with new kernel headers in /usr/include:

| In file included from ../include/linux/netfilter/x_tables.h:3,
|                  from ../include/xtables.h:19,
|                  from xtables-monitor.c:36:
| ../include/linux/kernel.h:7: warning: "__ALIGN_KERNEL" redefined
|     7 | #define __ALIGN_KERNEL(x, a)            __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
|       |
| In file included from /usr/include/linux/netlink.h:5,
|                  from /home/n0-1/git/libmnl/install/include/libmnl/libmnl.h:9,
|                  from xtables-monitor.c:30:
| /usr/include/linux/const.h:31: note: this is the location of the previous definition
|    31 | #define __ALIGN_KERNEL(x, a)            __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
|       |

Signed-off-by: Phil Sutter <phil@nwl.cc>
22 months agonft: Fix for useless meta expressions in rule
Phil Sutter [Wed, 6 Sep 2023 14:32:47 +0000 (16:32 +0200)] 
nft: Fix for useless meta expressions in rule

A relict of legacy iptables' mandatory matching on interfaces and IP
addresses is support for the '-i +' notation, basically a "match any
input interface". Trying to make things better than its predecessor,
iptables-nft boldly optimizes that nop away - not entirely though, the
meta expression loading the interface name was left in place. While not
a problem (apart from pointless overhead) in current HEAD, v1.8.7 would
trip over this as a following cmp expression (for another match) was
incorrectly linked to that stale meta expression, loading strange values
into the respective interface name field.

While being at it, merge and generalize the functions into a common one
for use with ebtables' NFT_META_BRI_(I|O)IFNAME matches, too.

Fixes: 0a8635183edd0 ("xtables-compat: ignore '+' interface name")
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1702
Signed-off-by: Phil Sutter <phil@nwl.cc>
22 months agotests: shell: Fix for ineffective 0007-mid-restore-flush_0
Phil Sutter [Fri, 1 Sep 2023 11:16:56 +0000 (13:16 +0200)] 
tests: shell: Fix for ineffective 0007-mid-restore-flush_0

The test did not catch non-zero exit status of the spawned coprocess. To
make it happen, Drop the line killing it (it will exit anyway) and pass
its PID to 'wait'.

While being at it, put the sleep into the correct spot (otherwise the
check for chain 'foo' existence fails as it runs too early) and make
said chain existence check effective.

Fixes: 4e3c11a6f5a94 ("nft: Fix for ruleset flush while restoring")
Signed-off-by: Phil Sutter <phil@nwl.cc>
22 months agoextensions: Fix checking of conntrack --ctproto 0
Quentin Armitage [Sat, 23 Nov 2013 08:41:58 +0000 (08:41 +0000)] 
extensions: Fix checking of conntrack --ctproto 0

There are three issues in the code:
1) the check (sinfo->invflags & XT_INV_PROTO) is using the wrong mask
2) in conntrack_mt_parse it is testing (info->invert_flags &
   XT_INV_PROTO) before the invert bit has been set.
3) the sense of the error message is the wrong way round

1) To get the error, ! -ctstatus XXX has to be specified, since
   XT_INV_PROTO == XT_CONNTRACK_STATUS e.g.
   | iptables -I CHAIN -m conntrack ! --ctstatus ASSURED --ctproto 0 ...

3) Unlike --proto 0 (where 0 means all protocols), in the conntrack
   match --ctproto 0 appears to mean protocol 0, which can never be.
   Therefore --ctproto 0 could never match and ! --ctproto 0 will always
   match. Both of these should be rejected, since the user clearly
   cannot be intending what was specified.

The attached patch resolves the issue, and also produces an error
message if --ctproto 0 is specified (as well as ! --ctproto 0 ), since
--ctproto 0 will never match, and ! --ctproto 0 will always match.

[Phil: - Added Fixes: tag - it's a day 1 bug
       - Copied patch description from Bugzilla
       - Reorganized changes to reduce diff
       - Added test cases]

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=874
Fixes: 5054e85be3068 ("general conntrack match module userspace support files")
Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
Signed-off-by: Phil Sutter <phil@nwl.cc>
23 months agoRevert --compat option related commits
Phil Sutter [Tue, 15 Aug 2023 11:47:28 +0000 (13:47 +0200)] 
Revert --compat option related commits

This reverts the following commits:

b14c971db6db0 ("tests: Test compat mode")
11c464ed015b5 ("Add --compat option to *tables-nft and *-nft-restore commands")
ca709b5784c98 ("nft: Introduce and use bool nft_handle::compat")
402b9b3c07c81 ("nft: Pass nft_handle to add_{target,action}()")

This implementation of a compatibility mode implements rules using
xtables extensions if possible and thus relies upon existence of those
in kernel space. Assuming no viable replacement for the internal
mechanics of this mode will be found in foreseeable future, it will
effectively block attempts at deprecating and removing of these xtables
extensions in favor of nftables expressions and thus hinder upstream's
future plans for iptables.

Signed-off-by: Phil Sutter <phil@nwl.cc>
23 months agodoc: fix example of xt_cpu
Victor Julien [Tue, 29 Aug 2023 12:59:32 +0000 (14:59 +0200)] 
doc: fix example of xt_cpu

REDIRECT uses --to-ports instead of --to-port.

Fixes: 2d59208943a3 ("extension: add xt_cpu match")
Signed-off-by: Victor Julien <victor@inliniac.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agotests: Test compat mode
Phil Sutter [Fri, 5 May 2023 18:18:38 +0000 (20:18 +0200)] 
tests: Test compat mode

Extend iptables-test.py by a third mode, which is using
xtables-nft-multi and passing --compat to all calls creating rules.

Also add a shell testcase asserting the effectiveness of --compat by
comparing debug (-vv) output.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoAdd --compat option to *tables-nft and *-nft-restore commands
Phil Sutter [Fri, 5 May 2023 18:04:41 +0000 (20:04 +0200)] 
Add --compat option to *tables-nft and *-nft-restore commands

The flag sets nft_handle::compat boolean, indicating a compatible rule
implementation is wanted. Users expecting their created rules to be
fetched from kernel by an older version of *tables-nft may use this to
avoid potential compatibility issues.

Changes since v1:
- Expect short option '-C' in {ip,ip6,eb}tables-nft-restore command line
  parser
- Support -C/--compat in arptables-nft-restore, too
- Update man pages with the new flag

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Introduce and use bool nft_handle::compat
Phil Sutter [Fri, 5 May 2023 15:39:08 +0000 (17:39 +0200)] 
nft: Introduce and use bool nft_handle::compat

If set, create rules using compat expressions where possible and disable
the bitwise expression avoidance introduced in 323259001d617 ("nft:
Optimize class-based IP prefix matches").

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Pass nft_handle to add_{target,action}()
Phil Sutter [Fri, 5 May 2023 14:01:29 +0000 (16:01 +0200)] 
nft: Pass nft_handle to add_{target,action}()

Prepare for varying rule content based on a global flag.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoUse SOCK_CLOEXEC/O_CLOEXEC where available
Phil Sutter [Tue, 8 Aug 2023 14:33:44 +0000 (16:33 +0200)] 
Use SOCK_CLOEXEC/O_CLOEXEC where available

No need for the explicit fcntl() call, request the behaviour when
opening the descriptor.

One fcntl() call setting FD_CLOEXEC remains in extensions/libxt_bpf.c,
the indirect syscall seems not to support passing the flag directly.

Reported-by: Gaurav Gupta <g.gupta@samsung.com>
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1104
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: shell: Test chain policy counter behaviour
Phil Sutter [Thu, 10 Aug 2023 10:51:13 +0000 (12:51 +0200)] 
tests: shell: Test chain policy counter behaviour

Test the last two fixes in that area.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoRevert "libiptc: fix wrong maptype of base chain counters on restore"
Phil Sutter [Thu, 3 Aug 2023 15:59:03 +0000 (17:59 +0200)] 
Revert "libiptc: fix wrong maptype of base chain counters on restore"

This reverts commit 7c4d668c9c2ee007c82063b7fc784cbbf46b2ec4.

The change can't be right: A simple rule append call will reset all
built-in chains' counters. The old code works fine even given the
mentioned "empty restore" use-case, at least if counters don't change on
the fly in-kernel.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=912
Fixes: 7c4d668c9c2ee ("libiptc: fix wrong maptype of base chain counters on restore")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Create builtin chains with counters enabled
Phil Sutter [Thu, 10 Aug 2023 09:30:59 +0000 (11:30 +0200)] 
nft: Create builtin chains with counters enabled

The kernel enables policy counters for nftables chains only if
NFTA_CHAIN_COUNTERS attribute is present. For this to be generated, one
has to set NFTNL_CHAIN_PACKETS and NFTNL_CHAIN_BYTES attributes in the
allocated nftnl_chain object.

The above happened for base chains only with iptables-nft-restore if
called with --counters flag. Since this is very unintuitive to users,
fix the situation by adding counters to base chains in any case.

Fixes: 384958620abab ("use nf_tables and nf_tables compatibility interface")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: iptables-test: Fix command segfault reports
Phil Sutter [Wed, 26 Jul 2023 17:43:20 +0000 (19:43 +0200)] 
tests: iptables-test: Fix command segfault reports

Logging produced a stack trace due to undefined variable 'cmd'.

Fixes: 0e80cfea3762b ("tests: iptables-test: Implement fast test mode")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft-ruleparse: parse meta mark set as MARK target
Florian Westphal [Thu, 3 Aug 2023 19:39:13 +0000 (21:39 +0200)] 
nft-ruleparse: parse meta mark set as MARK target

Mixing nftables and iptables-nft in the same table doesn't work,
but some people do this.

v1.8.8 ignored rules it could not represent in iptables syntax,
v1.8.9 bails in this case.

Add parsing of meta mark expressions so iptables-nft can render them
as -j MARK rules.

This is flawed, nft has features that have no corresponding
syntax in iptables, but we can't undo this.

Link: https://bugzilla.netfilter.org/show_bug.cgi?id=1659
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft-ruleparse: Introduce nft_create_target()
Phil Sutter [Tue, 31 Jan 2023 18:55:57 +0000 (19:55 +0100)] 
nft-ruleparse: Introduce nft_create_target()

Like nft_create_match(), this is a small wrapper around the typical
target extension lookup and (standard) init code.

To use it from nft_parse_target() and nft_parse_log(), introduce an
inner variant which accepts the target payload size as parameter.

The call to rule_parse_ops::target callback was problematic with
standard target, because the callbacks initialized
iptables_command_state::jumpto with the target name, "standard" in that
case. Perform its tasks in nft_create_target(), keep it only for bridge
family's special handling of watcher "targets".

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libip6t_icmp: Add names for mld-listener types
Phil Sutter [Wed, 2 Aug 2023 09:31:56 +0000 (11:31 +0200)] 
extensions: libip6t_icmp: Add names for mld-listener types

Add the three names (plus one alias) just as in nftables.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1250
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: move processing logic out of asserts
Jan Palus [Mon, 28 Dec 2020 09:59:42 +0000 (10:59 +0100)] 
nft: move processing logic out of asserts

[Phil: Introduce assert_nft_restart() to keep things clean, also add
       fallback returns to nft_action() and nft_prepare(), sanitizing
       things at least a bit.]

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1487
Signed-off-by: Jan Palus <atler@pld-linux.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables-save.8: Start paragraphs in upper-case
Phil Sutter [Wed, 2 Aug 2023 00:06:00 +0000 (02:06 +0200)] 
man: iptables-save.8: Start paragraphs in upper-case

Also add a missing full stop.

Fixes: 117341ada43dd ("Added iptbles-restore and iptables-save manpages")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables-save.8: Fix --modprobe description
Phil Sutter [Wed, 2 Aug 2023 00:01:59 +0000 (02:01 +0200)] 
man: iptables-save.8: Fix --modprobe description

- Consistently use 'modprobe' as option argument name
- Add a reference to modprobe man page
- Put the path in italics and the command in bold

Fixes: fbb5639c02218 ("iptables-save: module loading corrections")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables-save.8: Clarify 'available tables'
Phil Sutter [Tue, 1 Aug 2023 23:55:08 +0000 (01:55 +0200)] 
man: iptables-save.8: Clarify 'available tables'

This appears to be confusing. Since a missing table is also not flushed
("restored") when feeding the dump into iptables-restore, such a restore
call may be considered incomplete.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: Trivial: Missing space after comma
Phil Sutter [Tue, 1 Aug 2023 23:48:14 +0000 (01:48 +0200)] 
man: Trivial: Missing space after comma

Fixes: 6a79d78986c02 ("iptables: mention iptables-apply(8) in manpages")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables-restore.8: Start paragraphs in upper-case
Phil Sutter [Tue, 1 Aug 2023 23:40:17 +0000 (01:40 +0200)] 
man: iptables-restore.8: Start paragraphs in upper-case

Also add a missing full stop in one spot.

Fixes: 117341ada43dd ("Added iptbles-restore and iptables-save manpages")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables-restore.8: Put 'file' in italics in synopsis
Phil Sutter [Tue, 1 Aug 2023 23:37:09 +0000 (01:37 +0200)] 
man: iptables-restore.8: Put 'file' in italics in synopsis

The text has it this way already, be consistent.

Fixes: 081d57839e91e ("iptables-restore.8: file to read from can be specified as argument")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables-restore.8: Drop -W option from synopsis
Phil Sutter [Tue, 1 Aug 2023 23:34:51 +0000 (01:34 +0200)] 
man: iptables-restore.8: Drop -W option from synopsis

The description was dropped already, there is no benefit in still
listing it.

Fixes: 07e2107ef0cbc ("xshared: Implement xtables lock timeout using signals")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables-restore.8: Consistently document -w option
Phil Sutter [Tue, 1 Aug 2023 23:33:26 +0000 (01:33 +0200)] 
man: iptables-restore.8: Consistently document -w option

Use the same name for the option's argument.

Fixes: 65801d02a482b ("iptables-restore.8: document -w/-W options")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables-restore.8: Fix --modprobe description
Phil Sutter [Tue, 1 Aug 2023 23:27:11 +0000 (01:27 +0200)] 
man: iptables-restore.8: Fix --modprobe description

- Consistently use 'modprobe' as option argument name
- Add a reference to modprobe man page
- Put the path in italics, and the command in bold

Fixes: 8c46901ff5785 ("doc: document iptables-restore's -M option")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables.8: Trivial font fixes
Phil Sutter [Tue, 1 Aug 2023 22:49:03 +0000 (00:49 +0200)] 
man: iptables.8: Trivial font fixes

No content changes intended, just type commands in bold and the single
path reference in italics.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: Use HTTPS for links to netfilter.org
Phil Sutter [Tue, 1 Aug 2023 22:41:38 +0000 (00:41 +0200)] 
man: Use HTTPS for links to netfilter.org

The browser is redirected there anyway, but who cares about such minor
details nowadays.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables.8: Clarify --goto description
Phil Sutter [Tue, 1 Aug 2023 22:28:03 +0000 (00:28 +0200)] 
man: iptables.8: Clarify --goto description

Text speaks about behaviour of RETURN target when used in chains
redirected to using --goto instead of --jump, not the difference between
--jump option and "return".

Fixes: 17fc163babc34 ("add 'goto' support (Henrik Nordstrom <hno@marasystems.com>)")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables.8: Fix intra page reference
Phil Sutter [Tue, 1 Aug 2023 22:23:37 +0000 (00:23 +0200)] 
man: iptables.8: Fix intra page reference

When sections MATCH EXTENSIONS and TARGET EXTENSIONS were combined, the
reference could have been updated to specify the exact title.

Fixes: 4496801821c01 ("doc: deduplicate extension descriptions into a new manpage")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables.8: Trivial spelling fixes
Phil Sutter [Tue, 1 Aug 2023 22:05:45 +0000 (00:05 +0200)] 
man: iptables.8: Trivial spelling fixes

- Missing "and" as well as full stop
- Missing comma in enumeration
- Duplicate "previous"
- Confusions are avoided rather than simplified
- Missing space after comma

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: iptables.8: Extend exit code description
Phil Sutter [Tue, 1 Aug 2023 19:24:15 +0000 (21:24 +0200)] 
man: iptables.8: Extend exit code description

Codes 3 and 4 were missing.

Reported-by: Steven Barre <steven.barre@dxcas.com>
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1353
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: libipt_icmp.t: Enable tests with numeric output
Phil Sutter [Tue, 1 Aug 2023 21:42:24 +0000 (23:42 +0200)] 
tests: libipt_icmp.t: Enable tests with numeric output

Unrelated to the question whether numeric (save) output is desired or
not, enable the tests and expect the known format.

Using --list without --numeric prints the names, BTW.

Fixes: 49d5b7277c7f2 ("extensions: libipt_icmp: add unit test")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libipt_icmp: Fix confusion between 255/255 and any
Phil Sutter [Tue, 1 Aug 2023 21:28:20 +0000 (23:28 +0200)] 
extensions: libipt_icmp: Fix confusion between 255/255 and any

Per definition, ICMP type "any" is type 255 and the full range of codes
(0-255). Save callback though ignored the actual code values, printing
"any" for every type 255 match. This at least confuses users as they
can't find their rule added as '--icmp-type 255/255' anymore.

It is not entirely clear what the fixed commit was trying to establish,
but the save output is certainly not correct (especially since print
callback gets things right).

Reported-by: Amelia Downs <adowns@vmware.com>
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1600
Fixes: fc9237da4e845 ("Fix '-p icmp -m icmp' issue (Closes: #37)")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables-apply: Eliminate shellcheck warnings
Phil Sutter [Tue, 1 Aug 2023 14:56:42 +0000 (16:56 +0200)] 
iptables-apply: Eliminate shellcheck warnings

Actual warnings were only about use of '-a' in bracket expressions
(replace by '&&' pipeline) and the immediate evaluation of the variable
in trap command.

The remaining changes silence info-level messages: missing quoting
around variables, pointless '$' in arithmetic expressions, backticks
instead of $(...), missing '-r' parameter when calling read and an
awkward negated '-z' check.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables-restore: Drop dead code
Phil Sutter [Thu, 13 Jul 2023 16:32:02 +0000 (18:32 +0200)] 
iptables-restore: Drop dead code

Handle initialization is guarded by 'in_table' boolean, so there can't
be a handle already (because the branch which unsets 'in_table' also
frees the handle).

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: shell: Fix and extend chain rename test
Phil Sutter [Fri, 28 Jul 2023 11:58:46 +0000 (13:58 +0200)] 
tests: shell: Fix and extend chain rename test

The old version exited unintentionally before testing ip6tables. Replace
it by a more complete variant testing for all tools, creating and
renaming of,chains with various illegal names instead of just renaming
to a clashing name.

Fixes: ed9cfe1b48526 ("tests: add initial save/restore test cases")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoebtables: Improve invalid chain name detection
Phil Sutter [Fri, 28 Jul 2023 11:50:11 +0000 (13:50 +0200)] 
ebtables: Improve invalid chain name detection

Fix several issues:

- Most importantly, --new-chain command accepted any name. Introduce
  ebt_assert_valid_chain_name() for use with both --new-chain and
  --rename-chain.
- Restrict maximum name length to what legacy ebtables allows - this is
  a bit more than iptables-nft, subject to be unified.
- Like iptables, legacy ebtables rejects names prefixed by '-' or '!'.
- Use xs_has_arg() for consistency, keep the check for extra args for
  now.

Fixes: da871de2a6efb ("nft: bootstrap ebtables-compat")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years ago*tables: Reject invalid chain names when renaming
Phil Sutter [Fri, 21 Jul 2023 18:14:09 +0000 (20:14 +0200)] 
*tables: Reject invalid chain names when renaming

While given chain name was sanity checked with --new-chain command,
--rename-chain command allowed to choose an invalid name. Keep things
consistent by adding the missing check.

Fixes: e6869a8f59d77 ("reorganized tree after kernel merge")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years ago*tables-restore: Enforce correct counters syntax if present
Phil Sutter [Fri, 21 Jul 2023 17:40:30 +0000 (19:40 +0200)] 
*tables-restore: Enforce correct counters syntax if present

If '--counters' option was not given, restore parsers would ignore
anything following the policy word. Make them more strict, rejecting
anything in that spot which does not look like counter values even if
not restoring counters.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Include sets in debug output
Phil Sutter [Sat, 15 Jul 2023 12:13:28 +0000 (14:13 +0200)] 
nft: Include sets in debug output

Rules referencing them are incomplete without, so add debug output on
the same level as for rules.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Do not pass nft_rule_ctx to add_nft_among()
Phil Sutter [Fri, 14 Jul 2023 23:35:39 +0000 (01:35 +0200)] 
nft: Do not pass nft_rule_ctx to add_nft_among()

It is not used, must be a left-over from an earlier version of the fixed
commit.

Fixes: 4e95200ded923 ("nft-bridge: pass context structure to ops->add() to improve anonymous set support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: More verbose extension comparison debugging
Phil Sutter [Fri, 21 Jul 2023 09:15:15 +0000 (11:15 +0200)] 
nft: More verbose extension comparison debugging

Dump extension data if it differs.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Special casing for among match in compare_matches()
Phil Sutter [Fri, 21 Jul 2023 11:14:36 +0000 (13:14 +0200)] 
nft: Special casing for among match in compare_matches()

When other extensions may have "garbage" appended to their data which
should not be considered for match comparison, among match is the
opposite in that it extends its data beyond the value in 'size' field.
Add special casing to cover for this, avoiding false-positive rule
comparison.

Fixes: 26753888720d8 ("nft: bridge: Rudimental among extension support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: shell: Sanitize nft-only/0009-needless-bitwise_0
Phil Sutter [Wed, 19 Jul 2023 12:58:11 +0000 (14:58 +0200)] 
tests: shell: Sanitize nft-only/0009-needless-bitwise_0

Some versions of awk (gawk-4.2.1-4.el8 in particular) also print the
non-debug ruleset listing's empty lines, causing the diff to fail. Catch
this by exiting upon seeing the first table heading. For the sake of
comparing bytecode, the actual ruleset listing is not interesting,
anyway.

Fixes: 0f7ea0390b336 ("tests/shell: Fix nft-only/0009-needless-bitwise_0")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft-bridge: pass context structure to ops->add() to improve anonymous set support
Pablo Neira Ayuso [Tue, 11 Jul 2023 20:06:44 +0000 (22:06 +0200)] 
nft-bridge: pass context structure to ops->add() to improve anonymous set support

Add context structure to improve bridge among support which creates an
anonymous set. This context structure specifies the command and it
allows to optionally store a anonymous set.

Use this context to generate native bytecode only if this is an
add/insert/replace command.

This fixes a dangling anonymous set that is created on rule removal.

Fixes: 26753888720d ("nft: bridge: Rudimental among extension support")
Reported-and-tested-by: Igor Raits <igor@gooddata.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agoiptables: Fix handling of non-existent chains
Jacek Tomasiak [Mon, 19 Jun 2023 11:46:36 +0000 (13:46 +0200)] 
iptables: Fix handling of non-existent chains

Since 694612adf87 the "compatibility" check considers non-existent
chains as "incompatible". This broke some scripts which used calls
like `iptables -L CHAIN404` to test for chain existence and expect
"No chain/target/match by that name." in the output.

This patch changes the logic of `nft_is_table_compatible()` to
report non-existent chains as "compatible" which restores the old
behavior.

Fixes: 694612adf87 ("nft: Fix selective chain compatibility checks")
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1648
Signed-off-by: Jacek Tomasiak <jtomasiak@arista.com>
Signed-off-by: Jacek Tomasiak <jacek.tomasiak@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables: Fix setting of ipv6 counters
Jacek Tomasiak [Mon, 19 Jun 2023 10:44:54 +0000 (12:44 +0200)] 
iptables: Fix setting of ipv6 counters

When setting counters using ip6tables-nft -c X Y the X and Y values were
not stored.

This is a fix based on 9baf3bf0e77dab6ca4b167554ec0e57b65d0af01 but
applied to the nft variant of ipv6 not the legacy.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1647
Fixes: 0391677c1a0b2 ("xtables: add IPv6 support")
Signed-off-by: Jacek Tomasiak <jtomasiak@arista.com>
Signed-off-by: Jacek Tomasiak <jacek.tomasiak@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxshared: dissolve should_load_proto
Jan Engelhardt [Tue, 30 May 2023 16:11:09 +0000 (18:11 +0200)] 
xshared: dissolve should_load_proto

cs->proto_used already tells whether -p foo was turned into an
implicit -m foo once, so I do not think should_load_proto() has a
reason to exist.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: use payload matching for layer 4 protocol
Pablo Neira Ayuso [Fri, 9 Jun 2023 10:30:30 +0000 (12:30 +0200)] 
nft: use payload matching for layer 4 protocol

This is an IPv4 header, which does not require the special handling
as in IPv6, use the payload matching instead of meta l4proto which
is slightly faster in this case.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoman: string: document BM false negatives
Jeremy Sowden [Sun, 11 Jun 2023 11:34:29 +0000 (12:34 +0100)] 
man: string: document BM false negatives

For non-linear skb's there's a possibility that the kernel's Boyer-Moore
text-search implementation may miss matches.  There's a warning about
this in the kernel source.  Include that warning in the man-page.

Link: https://bugzilla.netfilter.org/show_bug.cgi?id=1390
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: check for source and destination address in first place
Pablo Neira Ayuso [Thu, 1 Jun 2023 19:28:28 +0000 (21:28 +0200)] 
nft: check for source and destination address in first place

When generating bytecode, check for source and destination address in
first place, then, check for the input and output device. In general,
the first expression in the rule is the most evaluated during the
evaluation process. These selectors are likely to show more variability
in rulesets.

 # iptables-nft -vv -I INPUT -s 1.2.3.4 -p tcp
  tcp opt -- in * out *  1.2.3.4  -> 0.0.0.0/0
table filter ip flags 0 use 0 handle 0
ip filter INPUT use 0 type filter hook input prio 0 policy accept packets 0 bytes 0
ip filter INPUT
  [ payload load 4b @ network header + 12 => reg 1 ]
  [ cmp eq reg 1 0x04030201 ]
  [ meta load l4proto => reg 1 ]
  [ cmp eq reg 1 0x00000006 ]
  [ counter pkts 0 bytes 0 ]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: ruleparse: Create family-specific source files
Phil Sutter [Fri, 21 Apr 2023 13:52:14 +0000 (15:52 +0200)] 
nft: ruleparse: Create family-specific source files

Extract the remaining nftnl rule parsing code from
nft-<family>.c sources into dedicated ones to complete the separation.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Extract rule parsing callbacks from nft_family_ops
Phil Sutter [Wed, 29 Mar 2023 16:26:23 +0000 (18:26 +0200)] 
nft: Extract rule parsing callbacks from nft_family_ops

Introduce struct nft_ruleparse_ops holding the family-specific
expression parsers and integrate it into nft_family_ops for now.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Introduce nft-ruleparse.{c,h}
Phil Sutter [Wed, 29 Mar 2023 15:53:11 +0000 (17:53 +0200)] 
nft: Introduce nft-ruleparse.{c,h}

Extract all code dealing with parsing from struct nftnl_rule into struct
iptables_command_state from nft-shared.c into a separate source file.

Basically this is nft_rule_to_iptables_command_state() and the functions
it calls, plus family-independent parsers called from family-specific
callbacks.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxshared: Fix parsing of option arguments in same word
Phil Sutter [Fri, 28 Apr 2023 12:41:08 +0000 (14:41 +0200)] 
xshared: Fix parsing of option arguments in same word

When merging commandline parsers, a decision between 'argv[optind - 1]'
and 'optarg' had to be made in some spots. While the implementation of
check_inverse() required the former, use of the latter allows for the
common syntax of '--opt=arg' or even '-oarg' as 'optarg' will point at
the suffix while 'argv[optind - 1]' will just point at the following
option.

Fix the mess by making check_inverse() update optarg pointer if needed
so calling code may refer to and always correct 'optarg'.

Fixes: 0af80a91b0a98 ("nft: Merge xtables-arp-standalone.c into xtables-standalone.c")
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1677
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoarptables: Don't omit standard matches if inverted
Phil Sutter [Fri, 28 Apr 2023 12:37:47 +0000 (14:37 +0200)] 
arptables: Don't omit standard matches if inverted

Inverted --h-len and --h-type matches were omitted from output by
accident if they matched on their standard value.

Fixes: 84331e3ed3f8e ("arptables-nft: Don't print default h-len/h-type values")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoarptables: Fix parsing of inverted 'arp operation' match
Phil Sutter [Fri, 28 Apr 2023 12:33:43 +0000 (14:33 +0200)] 
arptables: Fix parsing of inverted 'arp operation' match

The wrong bit was set in 'invflags', probably due to copy'n'paste from
the previous case.

Fixes: 84909d171585d ("xtables: bootstrap ARP compatibility layer for nftables")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft-shared: Drop unused include
Phil Sutter [Wed, 29 Mar 2023 14:22:16 +0000 (16:22 +0200)] 
nft-shared: Drop unused include

Code does not refer to struct xt_comment_info anymore.

Fixes: 3bb497c61d743 ("xtables: Fix for deleting rules with comment")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoutils: nfbpf_compile: Replace pcap_compile_nopcap()
Phil Sutter [Fri, 21 Apr 2023 13:53:43 +0000 (15:53 +0200)] 
utils: nfbpf_compile: Replace pcap_compile_nopcap()

The function is deprecated. Eliminate the warning by use of
pcap_open_dead(), pcap_compile() and pcap_close() just how
pcap_compile_nopcap() is implemented internally in libpcap.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: shell: Test for false-positive rule check
Phil Sutter [Wed, 5 Apr 2023 11:18:24 +0000 (13:18 +0200)] 
tests: shell: Test for false-positive rule check

Rule comparison in legacy ip6tables was broken by commit eb2546a846776
("xshared: Share make_delete_mask() between ip{,6}tables"): A part of
the rules' data was masked out for comparison by accident.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoebtables-nft: add broute table emulation
Florian Westphal [Tue, 4 Apr 2023 09:45:44 +0000 (11:45 +0200)] 
ebtables-nft: add broute table emulation

Use new 'meta broute set 1' to emulate -t broute.  If '-t broute' is given,
automatically translate -j DROP to 'meta broute set 1 accept' internally.

Reverse translation zaps the broute and pretends verdict was DROP.

Note that BROUTING is internally handled via PREROUTING, i.e. 'redirect'
and 'nat' targets are not available, they will need to be emulated via
nft expressions.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoinclude: update nf_tables uapi header
Florian Westphal [Tue, 4 Apr 2023 09:45:43 +0000 (11:45 +0200)] 
include: update nf_tables uapi header

Taken from nf-next.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agobuild: use pkg-config for libpcap
Alyssa Ross [Sun, 2 Apr 2023 23:29:40 +0000 (23:29 +0000)] 
build: use pkg-config for libpcap

If building statically, with libpcap built with libnl support, linking
will fail, as the compiler won't be able to find the libnl symbols
since static libraries don't contain dependency information.  To fix
this, use pkg-config to find the flags for linking libpcap, since the
pkg-config files contain the neccesary dependency information.

autoconf will add code to the configure script for initializing
pkg-config the first time it seems PKG_CHECK_MODULES, so make the
libnfnetlink check the first one in the script, so the initialization
code is run unconditionally.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoip6tables: Fix checking existence of rule
Markus Boehme [Mon, 3 Apr 2023 21:13:47 +0000 (23:13 +0200)] 
ip6tables: Fix checking existence of rule

Pass the proper entry size when creating a match mask for checking the
existence of a rule. Failing to do so causes wrong results.

Reported-by: Jonathan Caicedo <jonathan@jcaicedo.com>
Fixes: eb2546a846776 ("xshared: Share make_delete_mask() between ip{,6}tables")
Signed-off-by: Markus Boehme <markubo@amazon.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables-test.py: make explicit use of python3
Arturo Borrero Gonzalez [Sat, 14 Jan 2023 20:59:47 +0000 (21:59 +0100)] 
iptables-test.py: make explicit use of python3

In most distros 'python' means python2, which is not available anywhere.
This is a problem when, for example, building the Debian package. This
script is called as part of the build but 'python' is not available.

Mention python3 explictly. The script runs just fine in python3.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>