]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
2 years agolibiptc: Fix for segfault when renaming a chain
Phil Sutter [Fri, 7 Oct 2022 16:29:07 +0000 (18:29 +0200)] 
libiptc: Fix for segfault when renaming a chain

This is an odd bug: If the number of chains is right and one renames the
last one in the list, libiptc dereferences a NULL pointer. Add fix and
test case for it.

Fixes: 64ff47cde38e4 ("libiptc: fix chain rename bug in libiptc")
Reported-by: Julien Castets <castets.j@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: shell: Fix expected ebtables log target output
Phil Sutter [Thu, 6 Oct 2022 00:10:44 +0000 (02:10 +0200)] 
tests: shell: Fix expected ebtables log target output

Forgot to update shell testsuite when removing empty --log-prefix
options.

Fixes: 9cdb52d655608 ("extensions: libebt_log: Avoid empty log-prefix in output")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: shell: Fix expected output for ip6tables dst match
Phil Sutter [Thu, 6 Oct 2022 00:08:10 +0000 (02:08 +0200)] 
tests: shell: Fix expected output for ip6tables dst match

Forgot to update the shell testsuites when fixing for duplicate
whitespace in output.

Fixes: 11e06cbb3a877 ("extensions: libip6t_dst: Fix output for empty options")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: libebt_stp.t: Drop duplicate whitespace
Phil Sutter [Wed, 5 Oct 2022 18:29:36 +0000 (20:29 +0200)] 
tests: libebt_stp.t: Drop duplicate whitespace

Code was fixed but the testcase adjustment slipped through.

Fixes: 262dff31a998e ("extensions: libebt_stp: Eliminate duplicate space in output")
2 years agotests: IDLETIMER.t: Fix syntax, support for restore input
Phil Sutter [Fri, 30 Sep 2022 16:06:10 +0000 (18:06 +0200)] 
tests: IDLETIMER.t: Fix syntax, support for restore input

Expected output was wrong in the last OK test, probably defeating rule
search check. Also use a different label, otherwise the kernel will
reject the second idletimer with same label but different type if both
rules are added at once.

Fixes: 85b9ec8615428 ("extensions: IDLETIMER: Add alarm timer option")
2 years agoextensions: libebt_log: Avoid empty log-prefix in output
Phil Sutter [Fri, 30 Sep 2022 22:10:34 +0000 (00:10 +0200)] 
extensions: libebt_log: Avoid empty log-prefix in output

Just like iptables LOG target, omit --log-prefix from output if the
string is empty.

2 years agoextensions: TCPOPTSTRIP: Do not print empty options
Phil Sutter [Fri, 30 Sep 2022 22:36:50 +0000 (00:36 +0200)] 
extensions: TCPOPTSTRIP: Do not print empty options

No point in printing anything if none of the bits are set.

Fixes: aef4c1e727563 ("libxt_TCPOPTSTRIP")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libip6t_dst: Fix output for empty options
Phil Sutter [Fri, 30 Sep 2022 22:17:50 +0000 (00:17 +0200)] 
extensions: libip6t_dst: Fix output for empty options

If no --dst-opts were given, print_options() would print just a
whitespace.

Fixes: 73866357e4a7a ("iptables: do not print trailing whitespaces")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libebt_stp: Eliminate duplicate space in output
Phil Sutter [Fri, 30 Sep 2022 22:15:35 +0000 (00:15 +0200)] 
extensions: libebt_stp: Eliminate duplicate space in output

No need for print_range() to print a trailing whitespace, caller does
this already.

Fixes: fd8d7d7e5d911 ("ebtables-nft: add stp match")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: among: Fix for use with ebtables-restore
Phil Sutter [Fri, 30 Sep 2022 15:51:55 +0000 (17:51 +0200)] 
extensions: among: Fix for use with ebtables-restore

When restoring multiple rules which use among match, new size may be
smaller than the old one which caused invalid writes by the memcpy()
call. Expect this and realloc the match only if it needs to grow. Also
use realloc instead of freeing and allocating from scratch.

Fixes: 26753888720d8 ("nft: bridge: Rudimental among extension support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: among: Remove pointless fall through
Phil Sutter [Thu, 29 Sep 2022 17:11:55 +0000 (19:11 +0200)] 
extensions: among: Remove pointless fall through

This seems to be a leftover from an earlier version of the switch().
This fall through is never effective as the next case's code will never
apply. So just break instead.

Fixes: 26753888720d8 ("nft: bridge: Rudimental among extension support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: iptables-test: Test both variants by default
Phil Sutter [Thu, 29 Sep 2022 14:00:09 +0000 (16:00 +0200)] 
tests: iptables-test: Test both variants by default

Via '--legacy' and '--nftables' flags one may choose the variant to
test. Change the default (none of them given) from legacy to both,
by effectively running twice. Prefix the summary line with the tested
variant for clarity and print a total count line as well.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: iptables-test: Pass netns to execute_cmd()
Phil Sutter [Thu, 29 Sep 2022 13:52:40 +0000 (15:52 +0200)] 
tests: iptables-test: Pass netns to execute_cmd()

The command to run might have to be prefixed. Once if the command is
'iptables' (or related) to define the variant, once if '-N' was given to
run the command inside the netns. Doing both prefixing inside
execute_cmd() avoids a potential conflict and thus simplifies things:
The "external command" and "external iptables call" lines become
identical in handling, there is no need for a separate prefix char
anymore.

As a side-effect, this commit also fixes for delete_rule() calls in
error case ignoring the netns value.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: iptables-test: Simplify execute_cmd() calling
Phil Sutter [Thu, 29 Sep 2022 12:48:29 +0000 (14:48 +0200)] 
tests: iptables-test: Simplify execute_cmd() calling

Default 'lineno' parameter to zero,

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: iptables-test: Simplify '-N' option a bit
Phil Sutter [Thu, 29 Sep 2022 12:46:26 +0000 (14:46 +0200)] 
tests: iptables-test: Simplify '-N' option a bit

Instead of hard-coding, store the netns name in args.netns if the flag
was given. The value defaults to None, so existing 'if netns' checks are
still valid.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft-bridge: Drop 'sreg_count' variable
Phil Sutter [Wed, 28 Sep 2022 16:42:02 +0000 (18:42 +0200)] 
nft-bridge: Drop 'sreg_count' variable

It is not needed, one can just use 'reg' function parameter in its
place.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
2 years agonft: Fix meta statement parsing
Phil Sutter [Wed, 28 Sep 2022 16:08:43 +0000 (18:08 +0200)] 
nft: Fix meta statement parsing

The function nft_meta_set_to_target() would always bail since nothing
sets 'sreg->meta_sreg.set' to true. This is obvious, as the immediate
expression "filling" the source register does not indicate its purpose.

The whole source register purpose storing in meta_sreg seems to be
pointless, so drop it altogether.

Fixes: f315af1cf8871 ("nft: track each register individually")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoebtables: Fix among match
Phil Sutter [Thu, 4 Aug 2022 15:01:26 +0000 (17:01 +0200)] 
ebtables: Fix among match

Fixed commit broke among match in two ways:

1) The two lookup sizes are 12 and 6, not 12 and 4 - among supports
   either ether+IP or ether only, not IP only.

2) Adding two to sreg_count to get the second register is too simple: It
   works only for four byte regs, not the 16 byte ones. The first
   register is always a 16 byte one, though.

Fixing (1) is trivial, fix (2) by introduction of nft_get_next_reg()
doing the right thing. For consistency, use it for among match creation,
too.

Fixes: f315af1cf8871 ("nft: track each register individually")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoebtables: Support '-p Length'
Phil Sutter [Tue, 27 Sep 2022 21:19:34 +0000 (23:19 +0200)] 
ebtables: Support '-p Length'

To match on Ethernet frames using the etherproto field as length value,
ebtables accepts the special protocol name "LENGTH". Implement this in
ebtables-nft using a native match for 'ether type < 0x0600'.

Since extension 802_3 matches are valid only with such Ethernet frames,
add a local add_match() wrapper which complains if the extension is used
without '-p Length' parameter. Legacy ebtables does this within the
extension's final_check callback, but it's not possible here due for lack of
fw->bitmask field access.

While being at it, add xlate support, adjust tests and make ebtables-nft
print the case-insensitive argument with capital 'L' like legacy
ebtables does.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft-shared: Introduce __get_cmp_data()
Phil Sutter [Tue, 27 Sep 2022 21:15:37 +0000 (23:15 +0200)] 
nft-shared: Introduce __get_cmp_data()

This is an inner function to get_cmp_data() returning the op value as-is
for caller examination.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoebtables: Merge OPT_* flags with xshared ones
Phil Sutter [Tue, 27 Sep 2022 17:46:47 +0000 (19:46 +0200)] 
ebtables: Merge OPT_* flags with xshared ones

Despite also including xshared.h, xtables-eb.c defined its own OPT_*
flags with clashing values. Albeit ugly, this wasn't a problem in
practice until commit 51d9d9e081344 ("ebtables: Support verbose mode")
which introduced use of OPT_VERBOSE from xshared - with same value as
the local OPT_PROTOCOL define.

Eliminate the clash by appending ebtables-specific flags to the xshared
enum and adjust for the different names of some others.

Fixes: 51d9d9e081344 ("ebtables: Support verbose mode")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoebtables: Eliminate OPT_TABLE
Phil Sutter [Tue, 27 Sep 2022 17:03:47 +0000 (19:03 +0200)] 
ebtables: Eliminate OPT_TABLE

The flag is used for duplicate option checking only and there is a
boolean indicating the same already. So copy the error message from
EBT_CHECK_OPTION() in situ and just take care not to disturb restore
mode handling.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoebtables: Drop unused OPT_* defines
Phil Sutter [Tue, 27 Sep 2022 16:53:50 +0000 (18:53 +0200)] 
ebtables: Drop unused OPT_* defines

Obviously copied from legacy ebtables, not needed by ebtables-nft.
OPT_CNT_* ones seem not even used in legacy anymore.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: extend native delinearize script
Florian Westphal [Fri, 23 Sep 2022 12:17:25 +0000 (14:17 +0200)] 
tests: extend native delinearize script

Feed nft-generated ruleset to iptables-nft.
At this time, this will NOT pass. because dissector can handle

  meta l4proto tcp ip saddr 1.2.3.4
but not
  ip saddr 1.2.3.4 meta l4proto tcp

In the latter case, iptables-nft picks up the immediate value (6) as the ip
address, because the first one (1.2.3.4) gets moved as PAYLOAD_PREV due to
missing 'removal' of the CTX_PAYLOAD flag.

This is error prone, so lets rewrite the dissector to track each
register separately and auto-clear state on writes.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Phil Sutter <phil@nwl.cc>
2 years agonft: track each register individually
Florian Westphal [Fri, 23 Sep 2022 12:17:08 +0000 (14:17 +0200)] 
nft: track each register individually

Instead of assuming only one register is used, track all 16 regs
individually.

This avoids need for the 'PREV_PAYLOAD' hack and also avoids the need to
clear out old flags:

When we see that register 'x' will be written to, that register state is
reset automatically.

Existing dissector decodes
ip saddr 1.2.3.4 meta l4proto tcp
... as
-s 6.0.0.0 -p tcp

iptables-nft -s 1.2.3.4 -p tcp is decoded correctly because the expressions
are ordered like:

meta l4proto tcp ip saddr 1.2.3.4
                                                                                                                                                                                                                   |
... and 'meta l4proto' did clear the PAYLOAD flag.

The simpler fix is:
ctx->flags &= ~NFT_XT_CTX_PAYLOAD;

in nft_parse_cmp(), but that breaks dissection of '1-42', because
the second compare ('cmp lte 42') will not find the
payload expression anymore.

Link: https://lore.kernel.org/netfilter-devel/20220922143544.GA22541@breakpoint.cc/T/#t
Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Phil Sutter <phil@nwl.cc>
2 years agotests: shell: Test delinearization of native nftables expressions
Phil Sutter [Thu, 22 Sep 2022 17:04:32 +0000 (19:04 +0200)] 
tests: shell: Test delinearization of native nftables expressions

Even if iptables-nft doesn't generate them anymore, it should continue
to correctly parse them. Make sure this is tested for.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agoRevert "nft: prefer payload to ttl/hl module"/'meta pkttype' match.
Florian Westphal [Thu, 22 Sep 2022 14:14:51 +0000 (16:14 +0200)] 
Revert "nft: prefer payload to ttl/hl module"/'meta pkttype' match.

This reverts commit 8acaccf69c22fb195a0b88e28489792304728245.
This reverts commit 793caef9076cceb24336b6cbb8f55107de49f269.

As per ongoing discussion, keep the dissection side but keep using
nft_compat mode for now until we've figured out how to handle
backwards compatibility with older iptables-nft binaries dumping
the ruleset.

Furthermore, "nft: prefer native 'meta pkttype' instead of xt match"
broke ebtables: it has its own, incompatible pkttype match and needs
special handling.

Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agonft: un-break among match with concatenation
Florian Westphal [Thu, 22 Sep 2022 11:33:50 +0000 (13:33 +0200)] 
nft: un-break among match with concatenation

The kernel commit 88cccd908d51 ("netfilter: nf_tables: NFTA_SET_ELEM_KEY_END requires concat and interval flags")
breaks ebtables-nft 'among' emulation, it sets NFTA_SET_ELEM_KEY_END but
doesn't set the CONCAT flag.

Update uapi header and also set CONCAT.

Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agonft: prefer payload to ttl/hl module
Florian Westphal [Mon, 12 Sep 2022 08:58:46 +0000 (10:58 +0200)] 
nft: prefer payload to ttl/hl module

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Phil Sutter <phil@nwl.cc>
2 years agonft: support ttl/hoplimit dissection
Florian Westphal [Mon, 12 Sep 2022 08:58:44 +0000 (10:58 +0200)] 
nft: support ttl/hoplimit dissection

xlate raw "nft ... ttl eq 1" and so on to the ttl/hl matches.

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libxt_pkttype: support otherhost
Florian Westphal [Thu, 8 Sep 2022 15:12:42 +0000 (17:12 +0200)] 
extensions: libxt_pkttype: support otherhost

Makes no sense for iptables/ip6tables but it does make sense for ebtables.
Classic ebtables uses libebt_pkttype which isn't compatible, but
iptables-nft can use the libxt_pkttype version when printing native
'meta pkttype'.

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Phil Sutter <phil@nwl.cc>
2 years agonft: prefer native 'meta pkttype' instead of xt match
Florian Westphal [Thu, 8 Sep 2022 15:12:41 +0000 (17:12 +0200)] 
nft: prefer native 'meta pkttype' instead of xt match

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Phil Sutter <phil@nwl.cc>
2 years agonft: support dissection of meta pkktype mode
Florian Westphal [Thu, 8 Sep 2022 15:12:40 +0000 (17:12 +0200)] 
nft: support dissection of meta pkktype mode

Makes iptables-nft-save dump 'nft meta pkttype' rules.

Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Expand extended error reporting to nft_cmd, too
Phil Sutter [Fri, 26 Aug 2022 14:53:52 +0000 (16:53 +0200)] 
nft: Expand extended error reporting to nft_cmd, too

Introduce the same embedded 'error' struct in nft_cmd and initialize it
with the current value from nft_handle. Then in preparation phase,
update nft_handle's error.lineno with the value from the current
nft_cmd.

This serves two purposes:

* Allocated batch objects (obj_update) get the right lineno value
  instead of the COMMIT one.

* Any error during preparation may be reported with line number. Do this
  and change the relevant fprintf() call to use nft_handle's lineno
  instead of the global 'line' variable.

With this change, cryptic iptables-nft-restore error messages should
finally be gone:

| # iptables-nft-restore <<EOF
| *filter
| -A nonexist
| COMMIT
| EOF
| iptables-nft-restore: line 2 failed: No chain/target/match by that name.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxtables-restore: Extend failure error message
Phil Sutter [Thu, 25 Aug 2022 09:53:04 +0000 (11:53 +0200)] 
xtables-restore: Extend failure error message

If a line causes zero 'ret' value and errno is set, call nft_strerror()
for a more detailed error message. While not perfect, it helps with
debugging ominous "line NN failed" messages pointing at COMMIT:

| # iptables-nft-restore <<EOF
| *filter
| -A nonexist
| COMMIT
| EOF
| iptables-nft-restore: line 3 failed: No chain/target/match by that name.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: add ebtables among testcase
Yi Chen [Wed, 3 Aug 2022 07:14:55 +0000 (09:14 +0200)] 
tests: add ebtables among testcase

Validate that matching works as expected.

Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agonft: fix ebtables among match when mac+ip addresses are used
Florian Westphal [Tue, 2 Aug 2022 12:52:30 +0000 (14:52 +0200)] 
nft: fix ebtables among match when mac+ip addresses are used

When matching mac and ip addresses, the ip address needs to be placed
into then 2nd 32bit register, the switch to dynamic register allocation
instead re-uses reg1, this partially clobbers the mac address, so
set lookup comes up empty even though it should find a match.

Fixes: 7e38890c6b4fb ("nft: prepare for dynamic register allocation")
Reported-by: Yi Chen <yiche@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoxshared: Print protocol numbers if --numeric was given
Phil Sutter [Thu, 28 Jul 2022 10:31:36 +0000 (12:31 +0200)] 
xshared: Print protocol numbers if --numeric was given

This is much trickier than expected: On one hand, proto_to_name() is
used to lookup protocol extensions so must resolve despite FMT_NUMERIC
being set. On the other, --verbose implies --numeric but changing the
output there is probably a bad idea. Luckily the latter situation is
identified by FMT_NOTABLE bit.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoxshared: Fix for missing space after 'prot' column
Phil Sutter [Wed, 27 Jul 2022 12:14:23 +0000 (14:14 +0200)] 
xshared: Fix for missing space after 'prot' column

Format string ensured a minimum field width of five characters, but
allowed for longer strings to eat the column delimiting white space.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agotests: shell: Fix testcases for changed ip6tables opts output
Phil Sutter [Thu, 28 Jul 2022 11:02:50 +0000 (13:02 +0200)] 
tests: shell: Fix testcases for changed ip6tables opts output

Adjust captured output, ip6tables prints '--' instead of spaces since
the commit in Fixes: tag.

Fixes: 6e41c2d8747b2 ("iptables: xshared: Ouptut '--' in the opt field in ipv6's fake mode")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoiptables: xshared: Ouptut '--' in the opt field in ipv6's fake mode
Erik Skultety [Wed, 20 Jul 2022 13:06:50 +0000 (15:06 +0200)] 
iptables: xshared: Ouptut '--' in the opt field in ipv6's fake mode

The fact that the 'opt' table field reports spaces instead of '--' for
IPv6 as it would have been the case with IPv4 has a bit of an
unfortunate side effect that it completely confuses the 'jc' JSON
formatter tool (which has an iptables formatter module).
Consider:
    # ip6tables -L test
    Chain test (0 references)
    target     prot opt source   destination
    ACCEPT     all      a:b:c::  anywhere    MAC01:02:03:04:05:06

Then:
    # ip6tables -L test | jc --iptables
    [{"chain":"test",
      "rules":[
          {"target":"ACCEPT",
           "prot":"all",
           "opt":"a:b:c::",
           "source":"anywhere",
           "destination":"MAC01:02:03:04:05:06"
          }]
    }]

which as you can see is wrong simply because whitespaces are considered
as a column delimiter.

[ Florian: added 'Link' for more background info.
  The '--' difference exists for > 20 years, but changing it
  appears to be least intrusive option. ]

Link: https://lore.kernel.org/netfilter-devel/bb391c763171f0c5511f73e383e1b2e6a53e2014.1658322396.git.eskultet@redhat.com/t/#u
Signed-off-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoextensions: libxt_conntrack: remove always-false conditionals
Florian Westphal [Sat, 23 Jul 2022 18:25:49 +0000 (20:25 +0200)] 
extensions: libxt_conntrack: remove always-false conditionals

libxt_conntrack.c:1292: warning: the comparison will always evaluate as
false for the address of origsrc_addr will never be NULL [-Waddress]

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoxt_sctp: support a couple of new chunk types
Yuxuan Luo [Mon, 11 Jul 2022 16:12:38 +0000 (12:12 -0400)] 
xt_sctp: support a couple of new chunk types

There are new chunks added in Linux SCTP not being traced by iptables.

This patch introduces the following chunks for tracing:
I_DATA, I_FORWARD_TSN (RFC8260), RE_CONFIG(RFC6525) and PAD(RFC4820)

Signed-off-by: Yuxuan Luo <luoyuxuan.carl@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agolibxtables: Fix unsupported extension warning corner case
Phil Sutter [Thu, 30 Jun 2022 16:04:39 +0000 (18:04 +0200)] 
libxtables: Fix unsupported extension warning corner case

Some extensions are not supported in revision 0 by user space anymore,
for those the warning in xtables_compatible_revision() does not print as
no revision 0 is tried.

To fix this, one has to track if none of the user space supported
revisions were accepted by the kernel. Therefore add respective logic to
xtables_find_{target,match}().

Note that this does not lead to duplicated warnings for unsupported
extensions that have a revision 0 because xtables_compatible_revision()
returns true for them to allow for extension's help output.

For the record, these ip6tables extensions are affected: set/SET,
socket, tos/TOS, TPROXY and SNAT. In addition to that, TEE is affected
for both families.

Fixes: 17534cb18ed0a ("Improve error messages for unsupported extensions")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agonetfilter: add nf_log.h
Markus Mayer [Thu, 16 Jun 2022 22:48:18 +0000 (15:48 -0700)] 
netfilter: add nf_log.h

Since libxt_NFLOG is now using the UAPI version of nf_log.h, it should
be bundled alongside the other netfilter kernel headers.

This copy of nf_log.h was taken from Linux 5.18.

Signed-off-by: Markus Mayer <mmayer@broadcom.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agolibxtables: Define XT_OPTION_OFFSET_SCALE in xtables.h
Phil Sutter [Thu, 2 Jun 2022 09:16:38 +0000 (11:16 +0200)] 
libxtables: Define XT_OPTION_OFFSET_SCALE in xtables.h

This is the last symbol in xshared.h used by libxtables, move it over.
Again, treat this as "implementation detail" and hence put it behind
XTABLES_INTERNAL-curtains.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agolibxtables: Move struct xtables_afinfo into xtables.h
Phil Sutter [Thu, 2 Jun 2022 08:53:31 +0000 (10:53 +0200)] 
libxtables: Move struct xtables_afinfo into xtables.h

The library "owns" this structure and maintains 'afinfo' pointer to
instances of it. With libxt_set, there's even an extension making use of
the data.

To avoid impact on library users, guard it by XTABLES_INTERNAL.

To eliminate the xshared.h include by libxt_set, DEBUGP has to be
redefined. Other extensions have similar defines, fix this later.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoxtables-monitor: add missing spaces in printed str
Anton Luka Šijanec [Wed, 22 Jun 2022 19:56:47 +0000 (21:56 +0200)] 
xtables-monitor: add missing spaces in printed str

when printing the ID and OPTs in iptables/xtables-monitor.c, a space is
missing after the string, thereby concatenating the number with the next
item in the printed PACKET line.

Fixes: d26c538b9a549 ("xtables: add xtables-monitor")
Signed-off-by: Anton Luka Šijanec <anton@sijanec.eu>
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agonft: Exit if nftnl_alloc_expr fails
Phil Sutter [Tue, 14 Jun 2022 15:44:47 +0000 (17:44 +0200)] 
nft: Exit if nftnl_alloc_expr fails

In some code-paths, 'reg' pointer remaining uninitialized is used later
so at least minimal error checking is necessary. Given that a call to
nftnl_alloc_expr() with sane argument should never fail, complain and
exit if it happens.

Fixes: 7e38890c6b4fb ("nft: prepare for dynamic register allocation")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoiptables.8: mention that iptables exits when setuid
Florian Westphal [Fri, 17 Jun 2022 21:34:52 +0000 (23:34 +0200)] 
iptables.8: mention that iptables exits when setuid

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoextensions: string: Fix and enable tests
Phil Sutter [Wed, 8 Jun 2022 12:36:20 +0000 (14:36 +0200)] 
extensions: string: Fix and enable tests

Some minor fixes were necessary:

* --algo is printed after the pattern
* Second long string test must fail, that string is 129 chars long
* --from 0 and --to 65535 are not printed (default values)

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: string: Review parse_string() function
Phil Sutter [Wed, 8 Jun 2022 11:45:13 +0000 (13:45 +0200)] 
extensions: string: Review parse_string() function

* Compare against sizeof(info->pattern) which is more clear than having
  to know that this buffer is of size XT_STRING_MAX_PATTERN_SIZE

* Invert the check and error early to reduce indenting

* Pass info->patlen to memcpy() to avoid reading past end of 's'

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: string: Do not print default --to value
Phil Sutter [Wed, 8 Jun 2022 11:28:10 +0000 (13:28 +0200)] 
extensions: string: Do not print default --to value

Default value is UINT16_MAX, not 0. Fix the conditional printing.

Fixes: c6fbf41cdd157 ("update string match to reflect new kernel implementation (Pablo Neira)")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoebtables-restore: Deny --init-table
Phil Sutter [Wed, 2 Jun 2021 08:13:26 +0000 (10:13 +0200)] 
ebtables-restore: Deny --init-table

Allowing this segfaults the program. The deny is in line with legacy
ebtables, so no point in implementing support for that.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: libebt_standard.t: Test logical-{in,out} as well
Phil Sutter [Thu, 20 May 2021 10:25:57 +0000 (12:25 +0200)] 
extensions: libebt_standard.t: Test logical-{in,out} as well

These weren't used anywhere before. At least ensure they are only
allowed where claimed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agotests: shell: Extend zero counters test a bit further
Phil Sutter [Wed, 8 Jun 2022 16:15:20 +0000 (18:15 +0200)] 
tests: shell: Extend zero counters test a bit further

Test zeroing a single rule's counters as well.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agotests: shell: Extend iptables-xml test a bit
Phil Sutter [Thu, 20 May 2021 09:58:09 +0000 (11:58 +0200)] 
tests: shell: Extend iptables-xml test a bit

Call with --combine as well, even though output doesn't differ. Also
there's no need to skip for xtables-nft-multi, it provides the same
functionality.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agotests: shell: Add some more rules to 0002-verbose-output_0
Phil Sutter [Thu, 20 May 2021 09:40:18 +0000 (11:40 +0200)] 
tests: shell: Add some more rules to 0002-verbose-output_0

This increases coverage of function print_match() from 0 to 86.6%.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoMakefile: Add --enable-profiling configure option
Phil Sutter [Thu, 20 May 2021 09:59:23 +0000 (11:59 +0200)] 
Makefile: Add --enable-profiling configure option

A little convenience to prepare a build for analysis with gcov/gprof.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoxshared: Make some functions static
Phil Sutter [Wed, 1 Jun 2022 17:24:41 +0000 (19:24 +0200)] 
xshared: Make some functions static

With all ip(6)tables variants using the same do_parse() function, quite
a bunch of functions are not used outside of xshared.c anymore. Make them
static.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoiptables-legacy: Drop redundant include of xtables-multi.h
Phil Sutter [Wed, 1 Jun 2022 17:29:28 +0000 (19:29 +0200)] 
iptables-legacy: Drop redundant include of xtables-multi.h

The header is included unconditionally first, so no point in doing it a
second time of ENABLE_NFTABLES is defined.

Fixes: be70918eab26e ("xtables: rename xt-multi binaries to -nft, -legacy")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoarptables: Support -x/--exact flag
Phil Sutter [Tue, 7 Jun 2022 16:07:00 +0000 (18:07 +0200)] 
arptables: Support -x/--exact flag

Legacy arptables accepts but ignores the flag. Yet there are remains of
the functionality in sources, like OPT_EXPANDED define and a print_num()
function which acts on FMT_KILOMEGAGIGA flag being set or not. So
instead of mimicking legacy behaviour by explicitly ignoring -x flag for
arptables, just enable the feature for it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agolibxtables: Unexport init_extensions*() declarations
Phil Sutter [Wed, 1 Jun 2022 17:15:06 +0000 (19:15 +0200)] 
libxtables: Unexport init_extensions*() declarations

The functions are used for static builds to initialize extensions after
libxtables init. Regular library users should not need them, but the
empty declarations introduced in #else case (and therefore present in
user's env) may clash with existing symbol names.

Avoid problems and guard the whole block declaring the function
prototypes and mangling extensions' _init functions by XTABLES_INTERNAL.

Reported-by: Nick Hainke <vincent@systemli.org>
Fixes: 6c689b639cf8e ("Simplify static build extension loading")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agotests: shell: Check overhead in iptables-save and -restore
Phil Sutter [Thu, 2 Jun 2022 11:44:45 +0000 (13:44 +0200)] 
tests: shell: Check overhead in iptables-save and -restore

Some repeated calls have been reduced recently, assert this in a test
evaluating strace output.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agobuild: Fix error during out of tree build
Ben Brown [Wed, 25 May 2022 15:26:13 +0000 (16:26 +0100)] 
build: Fix error during out of tree build

Fixes the following error:

    ../../libxtables/xtables.c:52:10: fatal error: libiptc/linux_list.h: No such file or directory
       52 | #include <libiptc/linux_list.h>

Fixes: f58b0d7406451 ("libxtables: Implement notargets hash table")
Signed-off-by: Ben Brown <ben@demerara.io>
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoRevert "fix build for missing ETH_ALEN definition"
Phil Sutter [Wed, 18 May 2022 14:04:09 +0000 (16:04 +0200)] 
Revert "fix build for missing ETH_ALEN definition"

This reverts commit c5d9a723b5159a28f547b577711787295a14fd84 as it broke
compiling against musl libc. Might be a bug in the latter, but for the
time being try to please both by avoiding the include and instead
defining ETH_ALEN if unset.

While being at it, move netinet/ether.h include up.

Fixes: 1bdb5535f561a ("libxtables: Extend MAC address printing/parsing support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Maciej Żenczykowski <maze@google.com>
3 years agotreewide: use uint* instead of u_int*
Nick Hainke [Mon, 16 May 2022 16:16:41 +0000 (18:16 +0200)] 
treewide: use uint* instead of u_int*

Gcc complains about missing types. Some commits introduced u_int* instead
of uint*. Use uint treewide.

Fixes errors in the form of:
In file included from xtables-legacy-multi.c:5:
xshared.h:83:56: error: unknown type name 'u_int16_t'; did you mean 'uint16_t'?
    83 | set_option(unsigned int *options, unsigned int option, u_int16_t *invflg,
        |                                                        ^~~~~~~~~
        |                                                        uint16_t
make[6]: *** [Makefile:712: xtables_legacy_multi-xtables-legacy-multi.o] Error 1

Avoid libipq API breakage by adjusting libipq.h include accordingly. For
arpt_mangle.h kernel uAPI header, apply same change as in kernel commit
e91ded8db5747 ("uapi: netfilter_arp: use __u8 instead of u_int8_t").

Signed-off-by: Nick Hainke <vincent@systemli.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoxshared: Fix build for -Werror=format-security
Phil Sutter [Fri, 13 May 2022 14:51:58 +0000 (16:51 +0200)] 
xshared: Fix build for -Werror=format-security

Gcc complains about the omitted format string.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoconfigure: bump version for 1.8.8 release v1.8.8
Pablo Neira Ayuso [Fri, 13 May 2022 13:26:12 +0000 (15:26 +0200)] 
configure: bump version for 1.8.8 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agonft: Fix EPERM handling for extensions without rev 0
Phil Sutter [Wed, 4 May 2022 09:19:16 +0000 (11:19 +0200)] 
nft: Fix EPERM handling for extensions without rev 0

Treating revision 0 as compatible in EPERM case works fine as long as
there is a revision 0 of that extension defined in DSO. Fix the code for
others: Extend the EPERM handling to all revisions and keep the existing
warning for revision 0.

Fixes: 17534cb18ed0a ("Improve error messages for unsupported extensions")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: LOG: Document --log-macdecode in man page
Phil Sutter [Thu, 24 Mar 2022 10:06:24 +0000 (11:06 +0100)] 
extensions: LOG: Document --log-macdecode in man page

Help text already contains it, so no update needed there.

Fixes: 127647892c7ca ("extensions: libipt_LOG/libip6t_LOG: support macdecode option")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoman: *NAT: Review --random* option descriptions
Phil Sutter [Sat, 16 Apr 2022 12:21:51 +0000 (14:21 +0200)] 
man: *NAT: Review --random* option descriptions

Stating the option again in the first (single?) sentence is pointless.
Get rid of that initial half-sentence in MASQUERADE options and unify
the texts a bit.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: DNAT: Merge core printing functions
Phil Sutter [Thu, 14 Apr 2022 15:44:08 +0000 (17:44 +0200)] 
extensions: DNAT: Merge core printing functions

Have a versatile __NAT_print() function providing enough flexibility for
DNAT and REDIRECT, IPv4 and IPv6 and 'print' and 'save' output. Then
define macros to simplify calling it.

As a side effect, this fixes ip6tables DNAT revision 1 print output.

Fixes: 14d77c8aa29a7 ("extensions: Merge IPv4 and IPv6 DNAT targets")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agolibxtables: Revert change to struct xtables_pprot
Phil Sutter [Thu, 5 May 2022 22:11:47 +0000 (00:11 +0200)] 
libxtables: Revert change to struct xtables_pprot

While protocol values may exceed eight bits, the data structure is
indeed used only to store the static list of name/value pairs for faster
lookups. None of those has such a value and if one is added in future,
the compiler will complain about it.

So restore the old field type to retain binary compatibility.

Fixes: 556f704458cdb ("Use proto_to_name() from xshared in more places")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agolibxtables: Drop xtables_globals 'optstring' field
Phil Sutter [Thu, 5 May 2022 21:48:50 +0000 (23:48 +0200)] 
libxtables: Drop xtables_globals 'optstring' field

Define the different optstrings in xshared.h instead, they are not
relevant for other libxtables users.

This is a partial revert of commit 65b150ae382a8 ("xshared: Store
optstring in xtables_globals") to avoid breaking libxtables' ABI
compatibility.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoxshared: Extend xtables_printhelp() for arptables
Phil Sutter [Thu, 5 May 2022 16:13:12 +0000 (18:13 +0200)] 
xshared: Extend xtables_printhelp() for arptables

The function checks afinfo->family already to cover ip6tables specifics,
doing the same for arptables does not make things much worse.

This changes arptables-nft help output slightly:

* List possible negations extrapositioned, which is preferred anyway
  (arptables-nft supports both)
* List --out-interface option at lexically sorted position
* Print --wait option, it's ignored just like with iptables
* Restore default target option printing as with legacy arptables (not
  sure if arptables-nft ever did this) by explicitly loading them.

While being at it, add --set-counters short option '-c' to help output
for ip(6)tables.

This effectively removes the need for (and all users of)
xtables_global's 'print_help' callback, thus effectively reverts commit
fe83b12fc910e ("libxtables: Introduce xtables_globals print_help
callback") which broke libxtables' ABI compatibility.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoxshared: Move arp_opcodes into shared space
Phil Sutter [Thu, 5 May 2022 16:07:38 +0000 (18:07 +0200)] 
xshared: Move arp_opcodes into shared space

It will be referenced by xtables_printhelp() if printing for arptables
and therefore must be present in legacy as well even if unused.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: MARK: Drop extra newline at end of help
Phil Sutter [Thu, 5 May 2022 16:00:14 +0000 (18:00 +0200)] 
extensions: MARK: Drop extra newline at end of help

Fixes: f4b737fb0c52a ("libxt_MARK r2")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agonft: split gen_payload() to allocate register and initialize expression
Pablo Neira Ayuso [Sun, 24 Apr 2022 20:19:21 +0000 (22:19 +0200)] 
nft: split gen_payload() to allocate register and initialize expression

Add __gen_payload(), in preparation for the dynamic register allocation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agonft: prepare for dynamic register allocation
Pablo Neira Ayuso [Sun, 24 Apr 2022 20:19:20 +0000 (22:19 +0200)] 
nft: prepare for dynamic register allocation

Store the register that has been allocated and pass it on to the next
expression. NFT_REG_1 is still used.

No functional changes are expected.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agonft: pass handle to helper functions to build netlink payload
Pablo Neira Ayuso [Sun, 24 Apr 2022 20:19:18 +0000 (22:19 +0200)] 
nft: pass handle to helper functions to build netlink payload

Pass struct nft_handle to helper functions in preparation for the
dynamic register allocation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agonft: native mark matching support
Pablo Neira Ayuso [Sun, 24 Apr 2022 20:19:14 +0000 (22:19 +0200)] 
nft: native mark matching support

Use meta mark + bitwise + cmp instead of nft_compat mark match.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agonft: pass struct nft_xt_ctx to parse_meta()
Pablo Neira Ayuso [Sun, 24 Apr 2022 19:34:47 +0000 (21:34 +0200)] 
nft: pass struct nft_xt_ctx to parse_meta()

In preparation for native mark match support.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agonft-shared: update context register for bitwise expression
Pablo Neira Ayuso [Thu, 21 Apr 2022 14:53:33 +0000 (16:53 +0200)] 
nft-shared: update context register for bitwise expression

Update the destination register, otherwise nft_parse_cmp() gives up on
interpreting the cmp expression when bitwise sreg != dreg.

Fixes: 2c4a34c30cb4 ("iptables-compat: fix address prefix")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoextensions: man: Document service name support in DNAT and REDIRECT
Phil Sutter [Thu, 31 Mar 2022 00:22:08 +0000 (02:22 +0200)] 
extensions: man: Document service name support in DNAT and REDIRECT

Unless as part of a range, service names may be used. Point this out to
avoid confusion.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: Merge REDIRECT into DNAT
Phil Sutter [Thu, 17 Mar 2022 13:42:51 +0000 (14:42 +0100)] 
extensions: Merge REDIRECT into DNAT

Code is very similar, join them to reuse parsing code at least.

As a side-effect, this enables parsing of service names for ports in
DNAT as well as using port number 0 as that's what REDIRECT allows.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: Merge IPv4 and IPv6 DNAT targets
Phil Sutter [Wed, 19 Jan 2022 00:59:09 +0000 (01:59 +0100)] 
extensions: Merge IPv4 and IPv6 DNAT targets

Make parse_to() family-aware so it serves for both IPv4 and IPv6. Have a
core _DNAT_parse() function which parses into the most modern
(nf_nat_range2) data structure and a bunch of wrappers to copy into
legacy data structures if needed. Treat other callbacks analogous.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: DNAT: Rename from libipt to libxt
Phil Sutter [Fri, 25 Mar 2022 18:49:43 +0000 (19:49 +0100)] 
extensions: DNAT: Rename from libipt to libxt

Prepare for merge of libipt and libip6t DNAT extensions, allow for
better code review.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: ipt_DNAT: Combine xlate functions also
Phil Sutter [Tue, 29 Mar 2022 22:17:09 +0000 (00:17 +0200)] 
extensions: ipt_DNAT: Combine xlate functions also

Make use of the new sprint_range() to introduce a common inner function
for both v1 and v2 xlate functions.

Also abort translation with shifted port ranges to not hide the missing
feature in nftables.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: ipt_DNAT: Merge v1/v2 print/save code
Phil Sutter [Tue, 29 Mar 2022 22:11:14 +0000 (00:11 +0200)] 
extensions: ipt_DNAT: Merge v1/v2 print/save code

Turn print_range() function into sprint_range() so it becomes more
versatile. Make it accept the new nf_nat_range2 data structure and
make v1 callers convert their nf_nat_ipv4_multi_range_compat structs
to that.
This allows to introduce an inner __DNAT_print() which acts for v1 and
v2 and prints either 'print' or 'save' syntax.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoextensions: ipt_DNAT: Merge v1 and v2 parsers
Phil Sutter [Mon, 10 Jan 2022 15:39:53 +0000 (16:39 +0100)] 
extensions: ipt_DNAT: Merge v1 and v2 parsers

Use v2 parser for both and copy field values into v1 data structure if
needed.

While being at it:

* Introduce parse_ports() function similar to the one in
  libipt_REDIRECT.c.
* Use xtables_strtoui() in the above instead of atoi() for integrated
  range checking.
* Parse IP addresses using inet_pton(), writing directly into
  struct nf_nat_range2 fields.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoRevert "libipt_[SD]NAT: avoid false error about multiple destinations specified"
Phil Sutter [Thu, 17 Mar 2022 10:17:13 +0000 (11:17 +0100)] 
Revert "libipt_[SD]NAT: avoid false error about multiple destinations specified"

This reverts commit f25b2355e889290879c8cecad3dd24ec0c384fb8.

The workaround is not needed anymore since commit 30b178b9bf11e
("extensions: *NAT: Kill multiple IPv4 range support").

While being at it, drop the same hidden flag logic from
libip6t_[SD]NAT extensions as well and just don't set XTOPT_MULTI so
guided option parser will reject multiple parameters automatically.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoman: DNAT: Describe shifted port range feature
Phil Sutter [Wed, 12 Jan 2022 01:06:38 +0000 (02:06 +0100)] 
man: DNAT: Describe shifted port range feature

This wasn't mentioned anywhere.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoxlate-test: Fix for empty source line on failure
Phil Sutter [Wed, 30 Mar 2022 15:54:13 +0000 (17:54 +0200)] 
xlate-test: Fix for empty source line on failure

The code overwrites 'line' before checking expected output. Save it in a
temporary variable.

Fixes: 62828a6aff231 ("tests: xlate-test: support multiline expectation")
Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agolibxtables: Boost rule target checks by announcing chain names
Phil Sutter [Fri, 4 Mar 2022 11:50:01 +0000 (12:50 +0100)] 
libxtables: Boost rule target checks by announcing chain names

When restoring a ruleset, feed libxtables with chain names from
respective lines to avoid an extension search.

While the user's intention is clear, this effectively disables the
sanity check for clashes with target extensions. But:

* The check yielded only a warning and the clashing chain was finally
  accepted.

* Users crafting iptables dumps for feeding into iptables-restore likely
  know what they're doing.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
3 years agolibxtables: Implement notargets hash table
Phil Sutter [Tue, 15 Dec 2020 14:40:56 +0000 (15:40 +0100)] 
libxtables: Implement notargets hash table

Target lookup is relatively costly due to the filesystem access. Avoid
this overhead in huge rulesets which contain many chain jumps by caching
the failed lookups into a hashtable for later.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
3 years agonft: Reject standard targets as chain names when restoring
Phil Sutter [Wed, 16 Mar 2022 16:14:07 +0000 (17:14 +0100)] 
nft: Reject standard targets as chain names when restoring

Reuse parse_chain() called from do_parse() for '-N' and rename it for a
better description of what it does.

Note that by itself, this patch will likely kill iptables-restore
performance for big rulesets due to the extra extension lookup for chain
lines. A following patch announcing those chains to libxtables will
alleviate that.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Florian Westphal <fw@strlen.de>
3 years agotests: shell: Fix 0004-return-codes_0 for static builds
Phil Sutter [Tue, 15 Mar 2022 12:15:49 +0000 (13:15 +0100)] 
tests: shell: Fix 0004-return-codes_0 for static builds

In static builds, xtables_find_match() returns a slightly different
error message if not found - make grep accept both.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agonft: Review static extension loading
Phil Sutter [Tue, 15 Mar 2022 11:45:04 +0000 (12:45 +0100)] 
nft: Review static extension loading

Combine the init_extensions() call common to all families, do not load
IPv6 extensions for iptables and vice versa, drop the outdated comment
about "same table".

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoxtables: Call init_extensions{,a,b}() for static builds
Etienne Champetier [Mon, 14 Mar 2022 00:09:12 +0000 (20:09 -0400)] 
xtables: Call init_extensions{,a,b}() for static builds

Add calls to arp- and ebtables-specific extension loaders where missing.
Also consistently call init_extensions() for them, as some extensions
(ebtables 'limit' and arptables 'CLASSIFY' and 'MARK') live in libxt_*
files.

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>