]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
2 years agonft: Increase rule parser strictness
Phil Sutter [Thu, 15 Dec 2022 14:08:01 +0000 (15:08 +0100)] 
nft: Increase rule parser strictness

Catch more unexpected conditions.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoarptables: Check the mandatory ar_pln match
Phil Sutter [Thu, 15 Dec 2022 15:06:11 +0000 (16:06 +0100)] 
arptables: Check the mandatory ar_pln match

This match is added by nft_arp_add() to every rule with same value, so
when parsing just check it is as expected and otherwise ignore it. This
allows to treat matches on all other offsets/lengths as error.

Fixes: 84909d171585d ("xtables: bootstrap ARP compatibility layer for nftables")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Parse icmp header matches
Phil Sutter [Thu, 15 Dec 2022 12:20:21 +0000 (13:20 +0100)] 
nft: Parse icmp header matches

These were previously ignored.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoMakefile.am: Integrate testsuites
Phil Sutter [Sat, 15 Oct 2022 10:25:28 +0000 (12:25 +0200)] 
Makefile.am: Integrate testsuites

Support calling 'make check' in topdir to run all three testsuites.
While updating .gitignore, also add 'configure~' my autotools create and
the tags file.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: Adjust testsuite return codes to automake guidelines
Phil Sutter [Sat, 15 Oct 2022 09:43:01 +0000 (11:43 +0200)] 
tests: Adjust testsuite return codes to automake guidelines

As per the manual[1]:

"When no test protocol is in use, an exit status of 0 from a test script
will denote a success, an exit status of 77 a skipped test, an exit
status of 99 a hard error, and any other exit status will denote a
failure."

[1] https://www.gnu.org/software/automake/manual/html_node/Scripts_002dbased-Testsuites.html

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoinclude/Makefile: xtables-version.h is generated
Phil Sutter [Wed, 7 Dec 2022 16:23:12 +0000 (17:23 +0100)] 
include/Makefile: xtables-version.h is generated

List it in nodist_include_HEADERS so it is installed but not
distributed - configure generates it from xtables-version.h.in.

While being at it, list xtables.h in plain include_HEADERS. It doesn't
sit in a sub-dir, so the nobase prefix does not make a difference.

Fixes: df60a301bf24c ("build: separate AC variable replacements from xtables.h")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoMakefile: Generate .tar.xz archive with 'make dist'
Phil Sutter [Tue, 6 Dec 2022 20:05:04 +0000 (21:05 +0100)] 
Makefile: Generate .tar.xz archive with 'make dist'

Instead of the default .tar.gz one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoMakefile: Fix for 'make distcheck'
Phil Sutter [Tue, 6 Dec 2022 19:35:42 +0000 (20:35 +0100)] 
Makefile: Fix for 'make distcheck'

Since extensions/ directory does not use automake, some targets have to
be added manually. Apart from that, several Makefiles either missed to
specify relevant files or did not specify them correctly for 'make dist'
to add them to the tarball.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables/Makefile: Split nft-variant man page list
Phil Sutter [Mon, 5 Dec 2022 17:56:09 +0000 (18:56 +0100)] 
iptables/Makefile: Split nft-variant man page list

Some of them are not generated and must therefore be distributed. Hence
add them to a 'dist_man_MANS' variable. This leaves only generated
entries in the non-dist one, so use that to reduce the CLEANFILES list.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables/Makefile: Reorg variable assignments
Phil Sutter [Mon, 5 Dec 2022 16:29:30 +0000 (17:29 +0100)] 
iptables/Makefile: Reorg variable assignments

Introduce helper variables holding SOURCES, LDADD and CFLAGS used by
both legacy and nft builds. Specify also internal header files, builds
should depend on them. Doing that, reorder lists for clarity.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: Makefile: Merge initext targets
Phil Sutter [Mon, 5 Dec 2022 13:25:43 +0000 (14:25 +0100)] 
extensions: Makefile: Merge initext targets

Abstract initext*.c and .initext*.dd stamp file recipes so a single one
serves for all variants.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoMakefile: Generate ip6tables man pages on the fly
Phil Sutter [Sat, 3 Dec 2022 22:20:58 +0000 (23:20 +0100)] 
Makefile: Generate ip6tables man pages on the fly

No need to drag them around, creating them is simple.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoDrop libiptc/linux_stddef.h
Phil Sutter [Sat, 3 Dec 2022 21:45:59 +0000 (22:45 +0100)] 
Drop libiptc/linux_stddef.h

This header was never included anywhere.

Fixes: aae69bed01982 ("complete libiptc rewrite. Time to load 10k rules goes down from 2.20 minutes to 1.255 seconds (!). Might still contain bugs, use with caution.")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoDrop INCOMPATIBILITIES file
Phil Sutter [Sat, 3 Dec 2022 21:44:40 +0000 (22:44 +0100)] 
Drop INCOMPATIBILITIES file

The problems described in there were relevant 17 years ago.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoMakefile: Create LZMA-compressed dist-files
Phil Sutter [Thu, 8 Dec 2022 00:29:48 +0000 (01:29 +0100)] 
Makefile: Create LZMA-compressed dist-files

Use a more modern alternative to bzip2.

Suggested-by: Jan Engelhardt <jengelh@inai.de>
Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoebtables: Fix MAC address match translation
Phil Sutter [Thu, 1 Dec 2022 12:03:49 +0000 (13:03 +0100)] 
ebtables: Fix MAC address match translation

If a mask was present, ebtables-translate would emit illegal syntax.

Fixes: 5e2b473a64bc7 ("xtables-compat: extend generic tests for masks and wildcards")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxtables-translate: Fix for interfaces with asterisk mid-string
Phil Sutter [Thu, 1 Dec 2022 14:16:43 +0000 (15:16 +0100)] 
xtables-translate: Fix for interfaces with asterisk mid-string

For nft, asterisk is special at end of the interface name only. Escaping
it mid-string makes the escape char part of the interface name, so avoid
this.

In the test case, also drop the ticks around interface names in
*-translate command - since there's no shell involved which would eat
them, they become part of the interface name.

Fixes: e179e87a1179e ("xtables-translate: Fix for interface name corner-cases")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Recognize INVAL/D interface name
Phil Sutter [Sat, 22 Oct 2022 13:26:56 +0000 (15:26 +0200)] 
nft: Recognize INVAL/D interface name

It is just a hack to translate '! -i +' into a never matching nft rule,
but recognize it anyway for completeness' sake and to make xlate replay
test pass.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Fix match generator for '! -i +'
Phil Sutter [Thu, 1 Dec 2022 14:08:01 +0000 (15:08 +0100)] 
nft: Fix match generator for '! -i +'

It's actually nonsense since it will never match, but iptables accepts
it and the resulting nftables rule must behave identically. Reuse the
solution implemented into xtables-translate (by commit e179e87a1179e)
and turn the above match into 'iifname INVAL/D'.

The commit this fixes merely ignored the fact that "any interface" match
might be inverted.

Fixes: 0a8635183edd0 ("xtables-compat: ignore '+' interface name")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Fix for comparing ifname matches against nft-generated ones
Phil Sutter [Thu, 1 Dec 2022 12:09:48 +0000 (13:09 +0100)] 
nft: Fix for comparing ifname matches against nft-generated ones

Since nft adds the interface name as fixed-size string of 16 bytes,
filling a mask based on the length value will not match the mask nft
set.

Fixes: 652b98e793711 ("xtables-compat: fix wildcard detection")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: xlate: Use --check to verify replay
Phil Sutter [Thu, 1 Dec 2022 00:38:26 +0000 (01:38 +0100)] 
tests: xlate: Use --check to verify replay

After applying the translated rule using nft, pass the untranslated rule
to --check instead of dumping the ruleset and performing a string
search. This fixes for mandatory match reordering (e.g. addresses before
interfaces) and minor differences like /32 netmasks or even just
whitespace changes.

Fixes: 223e34b057b95 ("tests: xlate-test: Replay results for reverse direction testing")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoebtables: Implement --check command
Phil Sutter [Thu, 1 Dec 2022 12:06:25 +0000 (13:06 +0100)] 
ebtables: Implement --check command

Sadly, '-C' is in use already for --change-counters (even though
ebtables-nft does not implement this), so add a long-option only. It is
needed for xlate testsuite in replay mode, which will use '--check'
instead of '-C'.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agolibiptc: Eliminate garbage access
Phil Sutter [Wed, 30 Nov 2022 19:03:30 +0000 (20:03 +0100)] 
libiptc: Eliminate garbage access

When adding a rule, valgrind prints:

Syscall param socketcall.setsockopt(optval) points to uninitialised byte(s)
   at 0x4A8165A: setsockopt (in /lib64/libc.so.6)
   by 0x4857A48: iptc_commit (libiptc.c:2676)
   by 0x10E4BB: iptables_main (iptables-standalone.c:61)
   by 0x49A3349: (below main) (in /lib64/libc.so.6)
 Address 0x4b63788 is 40 bytes inside a block of size 1,448 alloc'd
   at 0x484659F: calloc (vg_replace_malloc.c:1328)
   by 0x4857654: iptc_commit (libiptc.c:2564)
   by 0x10E4BB: iptables_main (iptables-standalone.c:61)
   by 0x49A3349: (below main) (in /lib64/libc.so.6)

This is because repl->counters is not initialized upon allocation. Since
the field is an array, make use of calloc() which implicitly does the
initialization.

Fixes: e37c0dc100c51 ("Revert the recent addition of memset()'s to TC_COMMIT. One of them is bogus and the other one needs more investigation to why valgrind is complaining.")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxshared: Free data after printing help
Phil Sutter [Fri, 25 Nov 2022 20:47:52 +0000 (21:47 +0100)] 
xshared: Free data after printing help

This is merely to make valgrind happy, but less noise means less real
issues missed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables: Properly clear iptables_command_state object
Phil Sutter [Fri, 25 Nov 2022 20:44:39 +0000 (21:44 +0100)] 
iptables: Properly clear iptables_command_state object

When adding a rule with a target which defines a udata_size, valgrind
prints:

8 bytes in 1 blocks are definitely lost in loss record 1 of 1
   at 0x484659F: calloc (vg_replace_malloc.c:1328)
   by 0x486B128: xtables_calloc (xtables.c:434)
   by 0x1128B4: xs_init_target (xshared.c:238)
   by 0x113CD3: command_jump (xshared.c:877)
   by 0x114969: do_parse (xshared.c:1644)
   by 0x10EEB9: do_command4 (iptables.c:691)
   by 0x10E45B: iptables_main (iptables-standalone.c:59)
   by 0x49A2349: (below main) (in /lib64/libc.so.6)

It is not sufficient to free cs.target->t, so call
xtables_clear_iptables_command_state() which takes care of all the
details.

Fixes: 2dba676b68ef8 ("extensions: support for per-extension instance "global" variable space")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxtables: Introduce xtables_clear_iptables_command_state()
Phil Sutter [Fri, 25 Nov 2022 20:42:20 +0000 (21:42 +0100)] 
xtables: Introduce xtables_clear_iptables_command_state()

This is nft_clear_iptables_command_state() but in a location reachable
by legacy iptables, too.

Changes callers in non-family-specific code to use clear_cs callback
instead of directly calling it - ebtables still has a custom variant.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables: Plug memleaks in print_firewall()
Phil Sutter [Fri, 25 Nov 2022 20:35:28 +0000 (21:35 +0100)] 
iptables: Plug memleaks in print_firewall()

When adding a rule in verbose mode, valgrind prints:

192 bytes in 1 blocks are definitely lost in loss record 1 of 2
   at 0x48417E5: malloc (vg_replace_malloc.c:381)
   by 0x486B158: xtables_malloc (xtables.c:446)
   by 0x486C1F6: xtables_find_match (xtables.c:826)
   by 0x10E684: print_match (iptables.c:115)
   by 0x10E684: print_firewall (iptables.c:169)
   by 0x10FC0C: print_firewall_line (iptables.c:196)
   by 0x10FC0C: append_entry (iptables.c:221)
   by 0x10FC0C: do_command4 (iptables.c:776)
   by 0x10E45B: iptables_main (iptables-standalone.c:59)
   by 0x49A2349: (below main) (in /lib64/libc.so.6)

200 bytes in 1 blocks are definitely lost in loss record 2 of 2
   at 0x48417E5: malloc (vg_replace_malloc.c:381)
   by 0x486B158: xtables_malloc (xtables.c:446)
   by 0x486BBD6: xtables_find_target (xtables.c:956)
   by 0x10E579: print_firewall (iptables.c:145)
   by 0x10FC0C: print_firewall_line (iptables.c:196)
   by 0x10FC0C: append_entry (iptables.c:221)
   by 0x10FC0C: do_command4 (iptables.c:776)
   by 0x10E45B: iptables_main (iptables-standalone.c:59)
   by 0x49A2349: (below main) (in /lib64/libc.so.6)

If the match/target was cloned, it needs to be freed. Basically a bug since
day 1.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Plug memleak in nft_rule_zero_counters()
Phil Sutter [Fri, 25 Nov 2022 20:21:22 +0000 (21:21 +0100)] 
nft: Plug memleak in nft_rule_zero_counters()

When zeroing a specific rule, valgrind reports:

40 bytes in 1 blocks are definitely lost in loss record 1 of 1
   at 0x484659F: calloc (vg_replace_malloc.c:1328)
   by 0x48DE128: xtables_calloc (xtables.c:434)
   by 0x11C7C6: nft_parse_immediate (nft-shared.c:1071)
   by 0x11C7C6: nft_rule_to_iptables_command_state (nft-shared.c:1236)
   by 0x119AF5: nft_rule_zero_counters (nft.c:2877)
   by 0x11A3CA: nft_prepare (nft.c:3445)
   by 0x11A7A8: nft_commit (nft.c:3479)
   by 0x114258: xtables_main.isra.0 (xtables-standalone.c:94)
   by 0x1142D9: xtables_ip6_main (xtables-standalone.c:118)
   by 0x49F2349: (below main) (in /lib64/libc.so.6)

Have to free the matches/target in populated iptables_command_state object
again. While being at it, call the proper family_ops callbacks since this is
family-agnostic code.

Fixes: a69cc575295ee ("xtables: allow to reset the counters of an existing rule")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables-xml: Free allocated chain strings
Phil Sutter [Fri, 25 Nov 2022 18:30:09 +0000 (19:30 +0100)] 
iptables-xml: Free allocated chain strings

Freeing only if 'created' is non-zero is wrong - the data was still
allocated. In fact, the field is supposed to prevent only the call to
openChain().

Fixes: 8d3eccb19a9c6 ("Add iptables-xml tool (Amin Azez <azez@ufomechanic.net>)")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables-restore: Free handle with --test also
Phil Sutter [Fri, 25 Nov 2022 18:24:38 +0000 (19:24 +0100)] 
iptables-restore: Free handle with --test also

When running 'iptables-restore -t', valgrind reports:

1,496 (160 direct, 1,336 indirect) bytes in 1 blocks are definitely lost in loss record 4 of 4
   at 0x48417E5: malloc (vg_replace_malloc.c:381)
   by 0x4857A46: alloc_handle (libiptc.c:1279)
   by 0x4857A46: iptc_init (libiptc.c:1342)
   by 0x1167CE: create_handle (iptables-restore.c:72)
   by 0x1167CE: ip46tables_restore_main (iptables-restore.c:229)
   by 0x116DAE: iptables_restore_main (iptables-restore.c:388)
   by 0x49A2349: (below main) (in /lib64/libc.so.6)

Free the handle pointer before parsing the next table.

Fixes: 1c9015b2cb483 ("libiptc: remove indirections")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: shell: Fix valgrind mode for 0008-unprivileged_0
Phil Sutter [Wed, 30 Nov 2022 16:58:13 +0000 (17:58 +0100)] 
tests: shell: Fix valgrind mode for 0008-unprivileged_0

Valgrind is run as user nobody, let everyone write into the temporary
directory.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: add xt_statistics random mode translation
Florian Westphal [Thu, 1 Dec 2022 10:13:17 +0000 (11:13 +0100)] 
extensions: add xt_statistics random mode translation

Use meta random and bitops to replicate what xt_statistics
is doing.

Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agonft-bridge: work around recent "among" decode breakage
Florian Westphal [Wed, 30 Nov 2022 10:38:12 +0000 (11:38 +0100)] 
nft-bridge: work around recent "among" decode breakage

ebtables-nft-save will fail with
"unknown meta key" when decoding "among" emulation with ipv4 or ipv6
addresses included.

This is because "meta protocol ip" is used as a dependency, but
its never decoded anywhere.

Skip this for now to restore the "ebtables/0006-flush_0"
test case.

Fixes: 25883ce88bfb ("nft: check for unknown meta keys")
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Phil Sutter <phil@nwl.cc>
2 years agoxlate-test: avoid shell entanglements
Florian Westphal [Wed, 30 Nov 2022 09:31:54 +0000 (10:31 +0100)] 
xlate-test: avoid shell entanglements

Feed the nft expected output found in the .txlate test files to
nft -f via pipe/stdin directly without the shell mangling it.

The shell step isn't needed anymore because xtables-translate no longer
escapes quotes.

We only need to remove the "nft '" and trailing "'" because nft doesn't
expect those.

v3: handle multi-line expectations such as libxt_connlimmit.txlate (Phil Sutter)

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: change expected output for new format
Florian Westphal [Wed, 30 Nov 2022 09:31:53 +0000 (10:31 +0100)] 
extensions: change expected output for new format

Now that xtables-translate encloses the entire command line in ', update
the test cases accordingly.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxlate: get rid of escape_quotes
Florian Westphal [Wed, 30 Nov 2022 09:31:52 +0000 (10:31 +0100)] 
xlate: get rid of escape_quotes

Its not necessary to escape " characters, we can let xtables-translate
print the entire translation/command enclosed in '' chracters, i.e. nft
'add rule ...', this also takes care of [, { and other special characters
that some shells might parse otherwise (when copy-pasting translated output).

The escape_quotes struct member is retained to avoid an ABI breakage.

This breaks all xlate test cases, fixup in followup patches.

v3: no need to escape ', replace strcmp(x, "") with x[0] (Phil Sutter)

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: shell: Test selective ebtables flushing
Phil Sutter [Tue, 29 Nov 2022 14:21:01 +0000 (15:21 +0100)] 
tests: shell: Test selective ebtables flushing

Found this on disk, maybe there was a problem with this and among match
at some point? Anyway, it is relevant again since it fails recently.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: xlate: Format sets consistently
Phil Sutter [Fri, 25 Nov 2022 13:05:28 +0000 (14:05 +0100)] 
extensions: xlate: Format sets consistently

Print a space after separating commas.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libxt_conntrack: Drop extra whitespace in xlate
Phil Sutter [Fri, 25 Nov 2022 03:35:35 +0000 (04:35 +0100)] 
extensions: libxt_conntrack: Drop extra whitespace in xlate

No point in having this. Interestingly, other test cases even made up
for it.

Fixes: 0afd957f6bc03 ("extensions: libxt_state: add translation to nft")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: Leverage xlate auto-spacing
Phil Sutter [Fri, 25 Nov 2022 03:27:21 +0000 (04:27 +0100)] 
extensions: Leverage xlate auto-spacing

Drop code which is used explicitly to deal with spacing.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agolibxtables: xt_xlate_add() to take care of spacing
Phil Sutter [Fri, 25 Nov 2022 02:13:14 +0000 (03:13 +0100)] 
libxtables: xt_xlate_add() to take care of spacing

Try to eliminate most of the whitespace issues by separating strings
from separate xt_xlate_add() calls by whitespace if needed.

Cover the common case of consecutive range, list or MAC/IP address
printing by inserting whitespace only if the string to be appended
starts with an alphanumeric character or a brace. The latter helps to
make spacing in anonymous sets consistent.

Provide *_nospc() variants which disable the auto-spacing for the
mandatory exception to the rule.

Make things round by dropping any trailing whitespace before returning
the buffer via xt_xlate_get().

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: ipcomp: Add comment to clarify xlate callback
Phil Sutter [Tue, 15 Mar 2022 10:58:37 +0000 (11:58 +0100)] 
extensions: ipcomp: Add comment to clarify xlate callback

Kernel ignores 'hdrres' field, this matching on reserved field value was
never effective.

While being at it, drop its description from man page. Continue to parse
and print it for compatibility reasons, but avoid attracting new users.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: frag: Add comment to clarify xlate callback
Phil Sutter [Thu, 17 Nov 2022 16:38:52 +0000 (17:38 +0100)] 
extensions: frag: Add comment to clarify xlate callback

Matching on fragmentation header length is ineffective in kernel, xlate
callback correctly ignores it. Add a comment as a hint for reviewers.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libebt_log: Add comment to clarify xlate callback
Phil Sutter [Thu, 17 Nov 2022 16:37:27 +0000 (17:37 +0100)] 
extensions: libebt_log: Add comment to clarify xlate callback

Several log flags are ignored by the function. Add a comment explaining
why this is correct.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: tcp: Translate TCP option match
Phil Sutter [Thu, 17 Nov 2022 15:39:40 +0000 (16:39 +0100)] 
extensions: tcp: Translate TCP option match

A simple task since 'tcp option' expression exists.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: ecn: Sanitize xlate callback
Phil Sutter [Thu, 17 Nov 2022 15:37:02 +0000 (16:37 +0100)] 
extensions: ecn: Sanitize xlate callback

Catch unexpected values in einfo->ip_ect.

Fixes: ca42442093d3d ("iptables: extensions: libxt_ecn: Add translation to nft")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: TOS: Fix v1 xlate callback
Phil Sutter [Thu, 17 Nov 2022 15:10:14 +0000 (16:10 +0100)] 
extensions: TOS: Fix v1 xlate callback

Translation entirely ignored tos_mask field.

Fixes: b669e18489709 ("extensions: libxt_TOS: Add translation to nft")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: TCPMSS: Use xlate callback for IPv6, too
Phil Sutter [Thu, 17 Nov 2022 15:06:46 +0000 (16:06 +0100)] 
extensions: TCPMSS: Use xlate callback for IPv6, too

Data structures are identical and the translation is layer3-agnostic.

Fixes: bebce197adb42 ("iptables: iptables-compat translation for TCPMSS")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: MARK: Sanitize MARK_xlate()
Phil Sutter [Thu, 17 Nov 2022 15:01:11 +0000 (16:01 +0100)] 
extensions: MARK: Sanitize MARK_xlate()

Since markinfo->mode might contain unexpected values, add a default case
returning zero.

Fixes: afefc7a134ca0 ("extensions: libxt_MARK: Add translation for revision 1 to nft")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: CONNMARK: Fix xlate callback
Phil Sutter [Thu, 17 Nov 2022 14:30:11 +0000 (15:30 +0100)] 
extensions: CONNMARK: Fix xlate callback

Bail out if nfmask != ctmask with XT_CONNMARK_SAVE and
XT_CONNMARK_RESTORE. Looks like this needs a similar implementation to
the one for XT_CONNMARK_SET.

Fix shift mark translation: xt_connmark_shift_ops does not contain
useful strings for nftables. Also add needed braces around the term
being shifted.

Fixes: db7b4e0de960c ("extensions: libxt_CONNMARK: Support bit-shifting for --restore,set and save-mark")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libipt_ttl: Sanitize xlate callback
Phil Sutter [Wed, 16 Nov 2022 12:09:16 +0000 (13:09 +0100)] 
extensions: libipt_ttl: Sanitize xlate callback

Catch unexpected values in info->mode, also fix indenting.

Fixes: 1b320a1a1dc1f ("extensions: libipt_ttl: Add translation to nft")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libebt_redirect: Fix xlate return code
Phil Sutter [Wed, 16 Nov 2022 12:03:05 +0000 (13:03 +0100)] 
extensions: libebt_redirect: Fix xlate return code

The callback is supposed to return 1 on success, not 0.

Fixes: 24ce7465056ae ("ebtables-compat: add redirect match extension")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libebt_mark: Fix xlate test case
Phil Sutter [Fri, 11 Mar 2022 17:28:49 +0000 (18:28 +0100)] 
extensions: libebt_mark: Fix xlate test case

The false suffix effectively disabled this test file, but it also has
problems: Apart from brmark_xlate() printing 'meta mark' instead of just
'mark', target is printed in the wrong position (like with any other
target-possessing extension.

Fixes: e67c08880961f ("ebtables-translate: add initial test cases")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libebt_mark: Fix mark target xlate
Phil Sutter [Wed, 23 Nov 2022 02:35:34 +0000 (03:35 +0100)] 
extensions: libebt_mark: Fix mark target xlate

Target value is constructed setting all non-target bits to one instead
of zero.

Fixes: 03ecffe6c2cc0 ("ebtables-compat: add initial translations")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoiptables-nft: exit nonzero when iptables-save cannot decode all expressions
Florian Westphal [Wed, 23 Nov 2022 13:44:22 +0000 (14:44 +0100)] 
iptables-nft: exit nonzero when iptables-save cannot decode all expressions

We always return 0, even if we printed some error message half-way.
Increment an error counter whenever an error message was printed so that
the chain-loop can exit with an error if this counter is nonzero.

Another effect is that iptables-save will no longer print the COMMIT line anmore.

Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Phil Sutter <phil@nwl.cc>
2 years agonft: check for unknown meta keys
Florian Westphal [Fri, 18 Nov 2022 14:20:32 +0000 (15:20 +0100)] 
nft: check for unknown meta keys

Set ->errmsg when the meta key isn't supported by iptables-nft instead
of pretending everything is fine.

The old code is good enough to handle rules added by iptables-nft, but
its not enough to handle rules added by native nft.

At least make sure that there is a an error message telling that
iptables-nft could not decode the entire ruleset.

Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agoextensions: mark: Test double bitwise in a rule
Phil Sutter [Wed, 16 Nov 2022 10:52:20 +0000 (11:52 +0100)] 
extensions: mark: Test double bitwise in a rule

In v1.8.8, the second bitwise changed the first one, messing
iptables-nft-save output.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft-shared: replace nftnl_expr_get_data() by nftnl_expr_get()
Pablo Neira Ayuso [Mon, 14 Nov 2022 16:57:15 +0000 (17:57 +0100)] 
nft-shared: replace nftnl_expr_get_data() by nftnl_expr_get()

Replace nftnl_expr_get_data() alias by real function call.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: replace nftnl_.*_nlmsg_build_hdr() by nftnl_nlmsg_build_hdr()
Pablo Neira Ayuso [Mon, 14 Nov 2022 16:54:42 +0000 (17:54 +0100)] 
nft: replace nftnl_.*_nlmsg_build_hdr() by nftnl_nlmsg_build_hdr()

Replace alias to real nftnl_nlmsg_build_hdr() function call.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoDrop extra newline from xtables_error() calls
Phil Sutter [Fri, 7 Jan 2022 15:26:30 +0000 (16:26 +0100)] 
Drop extra newline from xtables_error() calls

Since basic_exit_err() appends a newline to the message itself, drop
explicit ones.

While being at it, fix indentation and join texts split over multiple
lines.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: Unify ICMP parser into libxt_icmp.h
Phil Sutter [Wed, 12 Oct 2022 00:02:38 +0000 (02:02 +0200)] 
extensions: Unify ICMP parser into libxt_icmp.h

Merge all four copies of the ICMP/ICMPv6/IGMP parameter parsing code.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: Collate ICMP types/codes in libxt_icmp.h
Phil Sutter [Tue, 11 Oct 2022 15:07:33 +0000 (17:07 +0200)] 
extensions: Collate ICMP types/codes in libxt_icmp.h

Put the most extensive version of icmp_codes, icmpv6_codes and
igmp_codes into the header. Have to rename the function
xt_print_icmp_types's parameter to avoid a compiler warning.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libebt_arp, libebt_ip: Use xtables_ipparse_any()
Phil Sutter [Thu, 6 Oct 2022 12:54:48 +0000 (14:54 +0200)] 
extensions: libebt_arp, libebt_ip: Use xtables_ipparse_any()

The libxtables function covers all formerly supported inputs (and more).
The extended libebt_arp.t passes before and after this patch.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libebt_ip: Include kernel header
Phil Sutter [Thu, 6 Oct 2022 13:09:32 +0000 (15:09 +0200)] 
extensions: libebt_ip: Include kernel header

Update the local copy of linux/netfilter_bridge/ebt_ip.h and include it
instead of keeping the local copy of struct ebt_ip_info et al.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: libip*t_LOG: Merge extensions
Phil Sutter [Sat, 22 Oct 2022 13:16:59 +0000 (15:16 +0200)] 
extensions: libip*t_LOG: Merge extensions

Data structures were identical already, make use of the names in
xt_LOG.h and merge all code into a single extension of family
NFPROTO_UNSPEC.

While being at it, define SYSLOG_NAMES and use the array in syslog.h
instead of dragging along an own level->name mapping two times.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft-shared: Introduce port_match_single_to_range()
Phil Sutter [Thu, 6 Oct 2022 16:20:14 +0000 (18:20 +0200)] 
nft-shared: Introduce port_match_single_to_range()

The same algorithm was present four times, outsource it. Also use
max()/min() macros for a more readable boundary notation.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoxshared: Share make_delete_mask() between ip{,6}tables
Phil Sutter [Tue, 12 May 2020 16:46:39 +0000 (18:46 +0200)] 
xshared: Share make_delete_mask() between ip{,6}tables

Function bodies were mostly identical, the only difference being the use
of struct ipt_entry or ip6t_entry for size calculation. Pass this value
via parameter to make them fully identical.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: xlate-test: Replay results for reverse direction testing
Phil Sutter [Fri, 21 Oct 2022 10:15:21 +0000 (12:15 +0200)] 
tests: xlate-test: Replay results for reverse direction testing

Call nft with translation output as input, then check xtables-save
output to make sure iptables-nft can handle anything it suggests nft to
turn its ruleset into.

This extends the test case syntax to cover for expected asymmetries.
When the existing syntax was something like this:

| <xlate command>
| <nft output1>
| [<nft output2>

The new syntax then is:

| <xlate command>[;<replay rule part>]
| <nft output1>
| [<nft output2>]

To keep things terse, <replay rule part> may omit the obligatory '-A
<chain>' argument. If missing, <xlate command> is sanitized for how it
would appear in xtables-save output: '-I' is converted into '-A' and an
optional table spec is removed.

Since replay mode has to manipulate the ruleset in-kernel, abort if
called by unprivileged user. Also try to run in own net namespace to
reduce collateral damage.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: xlate-test.py: Introduce run_proc()
Phil Sutter [Fri, 28 Oct 2022 17:07:14 +0000 (19:07 +0200)] 
tests: xlate-test.py: Introduce run_proc()

It's just a convenience wrapper around Popen(), simplifying the call.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: xlate-test: Cleanup file reading loop
Phil Sutter [Fri, 21 Oct 2022 08:28:09 +0000 (10:28 +0200)] 
tests: xlate-test: Cleanup file reading loop

Put the actual translation test into a function to call from the loop
and clean it up a bit. Preparation work for running a second test on the
same data.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: Merge SNAT, DNAT, REDIRECT and MASQUERADE
Phil Sutter [Tue, 12 Apr 2022 19:19:39 +0000 (21:19 +0200)] 
extensions: Merge SNAT, DNAT, REDIRECT and MASQUERADE

REDIRECT was already merged into DNAT. Given the callback generator and
generalized inner parsing routines, merging the other "flavors" is
relatively simple. Rename the extension into "libxt_NAT.so" while doing
so and turn the old DSOs into symlinks.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: DNAT: Rename some symbols
Phil Sutter [Wed, 2 Nov 2022 22:21:29 +0000 (23:21 +0100)] 
extensions: DNAT: Rename some symbols

No functional change intended, just a more generic name for some symbols
which won't be DNAT-specific soon.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: DNAT: Generate print, save and xlate callbacks
Phil Sutter [Sat, 9 Jul 2022 09:01:35 +0000 (11:01 +0200)] 
extensions: DNAT: Generate print, save and xlate callbacks

Each extension's callbacks follow the same scheme so introduce a
generator which accepts the specifics as parameter - including the
method to transform from per-extension data into struct nf_nat_range2.

Also move the different parser frontends and fcheck callbacks in one
spot for clarity.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: DNAT: Use __DNAT_xlate for REDIRECT, too
Phil Sutter [Sat, 9 Jul 2022 14:40:15 +0000 (16:40 +0200)] 
extensions: DNAT: Use __DNAT_xlate for REDIRECT, too

Make the common function a bit more versatile and give it a more
generic name, then use it for REDIRECT target, too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: *NAT: Drop NF_NAT_RANGE_PROTO_RANDOM* flag checks
Phil Sutter [Wed, 2 Nov 2022 20:54:41 +0000 (21:54 +0100)] 
extensions: *NAT: Drop NF_NAT_RANGE_PROTO_RANDOM* flag checks

SNAT, DNAT and REDIRECT extensions tried to prevent
NF_NAT_RANGE_PROTO_RANDOM flag from being set if no port or address was
also given.

With SNAT and DNAT, this is not possible as the respective
--to-destination or --to-source parameters are mandatory anyway.

Looking at the kernel code, doing so with REDIRECT seems harmless.
Moreover, nftables supports 'redirect random' without specifying a
port-range.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: DNAT: Fix bad IP address error reporting
Phil Sutter [Sun, 3 Jul 2022 13:59:19 +0000 (15:59 +0200)] 
extensions: DNAT: Fix bad IP address error reporting

When introducing 'start' variable to cover for IPv6 addresses enclosed
in brackets, this single spot was missed.

Fixes: 14d77c8aa29a7 ("extensions: Merge IPv4 and IPv6 DNAT targets")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: *.t: Add missing all-one's netmasks to expected output
Phil Sutter [Wed, 12 Oct 2022 14:21:17 +0000 (16:21 +0200)] 
tests: *.t: Add missing all-one's netmasks to expected output

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: libxt_connlimit.t: Add missing default values
Phil Sutter [Wed, 5 Oct 2022 18:34:16 +0000 (20:34 +0200)] 
tests: libxt_connlimit.t: Add missing default values

This extension always prints --connlimit-mask and (the default)
--connlimit-saddr options.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: libebt_vlan.t: Drop trailing whitespace from rules
Phil Sutter [Wed, 5 Oct 2022 18:30:44 +0000 (20:30 +0200)] 
tests: libebt_vlan.t: Drop trailing whitespace from rules

Fast iptables-test.py mode is picky and it has to: Plain redirect target
prints a trailing whitespace, generally stripping the rules in test
cases won't work therefore.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: libxt_tos.t, libxt_TOS.t: Add missing masks in output
Phil Sutter [Fri, 30 Sep 2022 23:25:50 +0000 (01:25 +0200)] 
tests: libxt_tos.t, libxt_TOS.t: Add missing masks in output

Mask differs between numeric --set-tos values and symbolic ones, make
sure it is covered by the tests.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: libxt_recent.t: Add missing default values
Phil Sutter [Fri, 30 Sep 2022 23:13:54 +0000 (01:13 +0200)] 
tests: libxt_recent.t: Add missing default values

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: libxt_length.t: Fix odd use-case output
Phil Sutter [Fri, 30 Sep 2022 22:39:07 +0000 (00:39 +0200)] 
tests: libxt_length.t: Fix odd use-case output

Specifying the lower boundary suffixed by colon is an undocumented
feature. Explicitly printing the upper boundary in that case seems sane.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: libebt_redirect.t: Plain redirect prints with trailing whitespace
Phil Sutter [Fri, 30 Sep 2022 22:14:56 +0000 (00:14 +0200)] 
tests: libebt_redirect.t: Plain redirect prints with trailing whitespace

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: *.t: Fix for hexadecimal output
Phil Sutter [Fri, 30 Sep 2022 22:43:40 +0000 (00:43 +0200)] 
tests: *.t: Fix for hexadecimal output

Use hex input to avoid having to specify an expected output in trivial
cases.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: *.t: Fix expected output for simple calls
Phil Sutter [Fri, 30 Sep 2022 22:10:34 +0000 (00:10 +0200)] 
tests: *.t: Fix expected output for simple calls

These minimal extension uses print in more detailed form. Track this,
the output is desired.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: iptables-test: Cover for obligatory -j CONTINUE in ebtables
Phil Sutter [Wed, 5 Oct 2022 17:51:08 +0000 (19:51 +0200)] 
tests: iptables-test: Cover for obligatory -j CONTINUE in ebtables

Unlike iptables, ebtables includes the default rule target in output.
Instead of adding it to every rule in ebtables tests, add special casing
to the testscript checking if the expected rule output contains a target
already and adding the default one if not.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: iptables-test: Implement fast test mode
Phil Sutter [Fri, 30 Sep 2022 16:15:59 +0000 (18:15 +0200)] 
tests: iptables-test: Implement fast test mode

Implement a faster mode of operation for suitable test files:

1) Collect all rules to add and all expected output in lists
2) Any supposedly failing rules are checked immediately like in slow
   mode.
3) Create and load iptables-restore input from the list in (1)
5) Construct the expected iptables-save output from (1) and check it in
   a single search
5) If any of the steps above fail, fall back to slow mode for
   verification and detailed error analysis. Fast mode failures are not
   fatal, merely warn about them.

To keep things simple (and feasible), avoid complicated test files
involving external commands, multiple tables or variant-specific
results.

Aside from speeding up testsuite run-time, rule searching has become
more strict since EOL char is practically part of the search string.
This revealed many false positives where the expected string was
actually a substring of the printed rule.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoextensions: NFQUEUE: Document queue-balance limitation
Phil Sutter [Wed, 12 Oct 2022 13:00:09 +0000 (15:00 +0200)] 
extensions: NFQUEUE: Document queue-balance limitation

The range is not communicated as "min and max queue number", but "first
queue number and count" instead. With 16bits for each value, it is not
possible to balance between all 65536 possible queues. Although probably
never used in practice, point this detail out in man page and make the
parser complain instead of the cryptic "xt_NFQUEUE: number of total
queues is 0" emitted by the kernel module.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agonft: Fix compile with -DDEBUG
Phil Sutter [Fri, 7 Oct 2022 20:16:43 +0000 (22:16 +0200)] 
nft: Fix compile with -DDEBUG

Conversion from 'ctx' to 'reg' missed some of the DEBUGP() calls.

Fixes: f315af1cf8871 ("nft: track each register individually")
Signed-off-by: Phil Sutter <phil@nwl.cc>
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>