]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
6 years agoarptables-nft-save: Fix position of -j option
Phil Sutter [Thu, 31 Jan 2019 15:12:54 +0000 (16:12 +0100)] 
arptables-nft-save: Fix position of -j option

Legacy arptables-save (just like arptables itself) prints verdict as
first option, then matches and finally any target options.

To achieve this without introducing double/trailing spaces everywhere,
integrate target ('-j') option printing into
nft_arp_print_rule_details() and make it print separating whitespace
before each option.

In nft_arp_save_rule(), replace the call to save_matches_and_target() by
by a direct call to cs->target->save() since the former prints '-j'
option itself. Since there are no match extensions in arptables, any
other code from that function is not needed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables-nft: Remove space between *cnt= and value
Phil Sutter [Thu, 31 Jan 2019 15:12:53 +0000 (16:12 +0100)] 
arptables-nft: Remove space between *cnt= and value

When printing rule counters, call xtables_print_num() with FMT_NOTABLE
bit set to avoid spaces between equal sign and value.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables-nft: Fix CLASSIFY target printing
Phil Sutter [Thu, 31 Jan 2019 15:12:52 +0000 (16:12 +0100)] 
arptables-nft: Fix CLASSIFY target printing

In legacy arptables, CLASSIFY target is not printed with fixed hex
number lengths. Counter this by introducing a dedicated target
definition for NFPROTO_ARP only having own print/save callbacks.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables-nft: Fix MARK target parsing and printing
Phil Sutter [Thu, 31 Jan 2019 15:12:51 +0000 (16:12 +0100)] 
arptables-nft: Fix MARK target parsing and printing

Legacy arptables parses mark values in hex no matter if prefixed with
'0x' or not. Sadly, this is not easily achievable with guided option
parser. Hence fall back to the old 'parse' callback. The introduced
target definition is valid only for revision 2, but that's consistent
with legacy arptables.

When printing, use --set-mark option instead of --set-xmark.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables-nft: Fix listing rules without target
Phil Sutter [Thu, 31 Jan 2019 15:12:50 +0000 (16:12 +0100)] 
arptables-nft: Fix listing rules without target

Don't try to print cs.jumpto if it is an empty string, otherwise listing
(and verbose output) contains '-j' flag without argument.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Speed up chain deletion in large rulesets
Phil Sutter [Wed, 12 Dec 2018 19:04:12 +0000 (20:04 +0100)] 
xtables: Speed up chain deletion in large rulesets

Kernel prefers to identify chain by handle if it was given which causes
manual traversal of the chain list. In contrast, chain lookup by name in
kernel makes use of a hash table so is considerably faster. Force this
code path by removing the cached chain's handle when removing it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Fix for inserting rule at wrong position
Phil Sutter [Tue, 15 Jan 2019 22:23:05 +0000 (23:23 +0100)] 
xtables: Fix for inserting rule at wrong position

iptables-restore allows to insert rules at a certain position which is
problematic for iptables-nft to realize since rule position is not
determined by number but handle of previous or following rule and in
case the rules surrounding the new one are new as well, they don't have
a handle to refer to yet.

Fix this by making use of NFTNL_RULE_POSITION_ID attribute: When
inserting before a rule which does not have a handle, refer to it using
its NFTNL_RULE_ID value. If the latter doesn't exist either, assign a
new one to it.

The last used rule ID value is tracked in a new field of struct
nft_handle which is incremented before each use.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoutils: Add a manpage for nfbpf_compile
Phil Sutter [Wed, 16 Jan 2019 21:47:59 +0000 (22:47 +0100)] 
utils: Add a manpage for nfbpf_compile

Content is rather sparse, but still better than no manpage at all.

Cc: Willem de Bruijn <willemb@google.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Fix position of replaced rules in cache
Phil Sutter [Tue, 15 Jan 2019 22:23:04 +0000 (23:23 +0100)] 
xtables: Fix position of replaced rules in cache

When replacing a rule, the replacement was simply appended to the
chain's rule list. Instead, insert it where the rule it replaces was.

This also fixes for zero counters command to remove the old rule from
cache.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Add new builtin chains to cache immediately
Phil Sutter [Tue, 15 Jan 2019 22:23:03 +0000 (23:23 +0100)] 
nft: Add new builtin chains to cache immediately

Newly created builtin chains missing from cache was the sole reason for
the immediate calls to nft_commit(). With nft_chain_builtin_add()
inserting the new chain into the table's chain list, this is not needed
anymore. Just make sure batch_obj_del() doesn't free the payload of
NFT_COMPAT_CHAIN_ADD jobs since it contains the new chain which has
been added to cache.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Set errno in nft_rule_check() if chain not found
Phil Sutter [Sun, 30 Dec 2018 19:06:10 +0000 (20:06 +0100)] 
xtables: Set errno in nft_rule_check() if chain not found

With this, the explicit check for chain existence can be removed from
xtables.c since all related commands do this now.

Note that this effectively changes the error message printed by
iptables-nft when given a non-existing chain, but the new error
message(s) conform with those printed by legacy iptables.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Simplify flush_chain_cache()
Phil Sutter [Sun, 30 Dec 2018 19:06:09 +0000 (20:06 +0100)] 
nft: Simplify flush_chain_cache()

With all the checks for 'tablename' being non-NULL, this code was rather
stupid and really hard to read. And the fix is indeed quite simple: If a
table name was given, use nft_table_builtin_find() and just flush its
chain cache. Otherwise iterate over all builtin tables without any
conditionals for 'tablename'.

Fixes: d4b0d248cc057 ("nft: Reduce indenting level in flush_chain_cache()")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Simplify nft_is_chain_compatible()
Phil Sutter [Sun, 30 Dec 2018 19:06:08 +0000 (20:06 +0100)] 
nft: Simplify nft_is_chain_compatible()

Make use of nft_{table,chain}_builtin_find() instead of open-coding the
list traversal. Since code is pretty obvious now, drop the comments
added earlier.

Fixes: e774b15299c27 ("nft: Review is_*_compatible() routines")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Make use of nftnl_rule_lookup_byindex()
Phil Sutter [Thu, 20 Dec 2018 15:09:20 +0000 (16:09 +0100)] 
nft: Make use of nftnl_rule_lookup_byindex()

Use the function where suitable to potentially speedup rule cache lookup
by rule number.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Optimize list rules command with given chain
Phil Sutter [Thu, 20 Dec 2018 15:09:19 +0000 (16:09 +0100)] 
xtables: Optimize list rules command with given chain

If a chain name was given, make use of nftnl_chain_list_lookup_byname().

Likewise in nftnl_rule_list_chain_save(), but introduce
__nftnl_rule_list_chain_save() suitable for passing to
nftnl_chain_list_foreach().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Optimize list command with given chain
Phil Sutter [Thu, 20 Dec 2018 15:09:18 +0000 (16:09 +0100)] 
xtables: Optimize list command with given chain

Make use of nftnl_chain_list_lookup_byname() even if not listing a
specific rule. Introduce __nft_print_header() to consolidate chain value
extraction for printing with ops->print_header().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Optimize user-defined chain deletion
Phil Sutter [Thu, 20 Dec 2018 15:09:17 +0000 (16:09 +0100)] 
xtables: Optimize user-defined chain deletion

Make use of nftnl_chain_list_lookup_byname() if a chain name was given.
Move the actual chain deleting code into a callback suitable for passing
to nftnl_chain_list_foreach().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: Extend verbose output and return code tests
Phil Sutter [Thu, 20 Dec 2018 15:09:16 +0000 (16:09 +0100)] 
tests: Extend verbose output and return code tests

Recent changes to chain flush and zero routines incorporate proper error
propagation so trying to flush or zero a non-existent chain results in
an error. This is consistent with iptables-legacy, extend tests to make
sure it stays this way.

Also extend verbose output test to make these recent changes didn't mess
it up.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Optimize nft_chain_zero_counters()
Phil Sutter [Thu, 20 Dec 2018 15:09:15 +0000 (16:09 +0100)] 
xtables: Optimize nft_chain_zero_counters()

If a chain name was given, make use of nftnl_chain_list_lookup_byname().
Streamline nft_chain_zero_rule_counters() to be suitable for calling
from nftnl_chain_list_foreach().

There is an unrelated optimization in here, too: Add batch job
NFT_COMPAT_CHAIN_ZERO only if it is a base chain. Since user-defined
chains don't have counters, there is no need to do anything for them.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Optimize flushing a specific chain
Phil Sutter [Thu, 20 Dec 2018 15:09:14 +0000 (16:09 +0100)] 
xtables: Optimize flushing a specific chain

If a chain name is given to nft_rule_flush(), make use of
nftnl_chain_list_lookup_byname().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Drop nft_chain_list_find()
Phil Sutter [Thu, 20 Dec 2018 15:09:13 +0000 (16:09 +0100)] 
nft: Drop nft_chain_list_find()

Replace the function by nftnl_chain_list_lookup_byname() as provided by
libnftnl.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Implement per chain rule cache
Phil Sutter [Thu, 20 Dec 2018 15:09:12 +0000 (16:09 +0100)] 
xtables: Implement per chain rule cache

Use recently introduced support for rules inside chains in libnftnl to
introduce a rule cache per chain instead of a global one.

A tricky bit is to decide if cache should be updated or not. Previously,
the global rule cache was populated just once and then reused unless
being flushed completely (via call to flush_rule_cache() with
NULL-pointer table argument). Resemble this behaviour by introducing a
boolean indicating cache status and fetch rules for all chains when
updating the chain cache in nft_chain_list_get().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Move nft_rule_list_get() above nft_chain_list_get()
Phil Sutter [Thu, 20 Dec 2018 15:09:11 +0000 (16:09 +0100)] 
nft: Move nft_rule_list_get() above nft_chain_list_get()

Later when introducing per chain rule caches, nft_rule_list_get() will
be removed. But nftnl_rule_list_cb() which it uses will be reused to
update each chain's rule cache from inside nftnl_chain_list_get(), so
move both into position.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Introduce fetch_chain_cache()
Phil Sutter [Thu, 20 Dec 2018 15:09:10 +0000 (16:09 +0100)] 
nft: Introduce fetch_chain_cache()

Move chain cache population from nft_chain_list_get() into a dedicated
function.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Simplify nft_rule_insert() a bit
Phil Sutter [Thu, 20 Dec 2018 15:09:09 +0000 (16:09 +0100)] 
nft: Simplify nft_rule_insert() a bit

Fetch rule list right on top instead of in each branch separately.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Simplify per table chain cache update
Phil Sutter [Thu, 20 Dec 2018 15:09:08 +0000 (16:09 +0100)] 
nft: Simplify per table chain cache update

Previously, each table's chain cache was potentially unallocated until
nftnl_chain_list_cb() saw a chain for it. This means such callback had to
check the chain_cache pointer for each chain belonging to that table.

In addition to the above, nft_chain_list_get() had to cover for the
possibility that a given table didn't have any chains at all in kernel,
so check requested table's chain cache once more and allocate it if
NULL.

Instead, simply iterate over all tables and preallocate their chain
caches prior to requesting the chain list from kernel. The only caveat
is to flush the chain cache completely before retrying in case of EINTR.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Reduce indenting level in flush_chain_cache()
Phil Sutter [Thu, 20 Dec 2018 15:09:07 +0000 (16:09 +0100)] 
nft: Reduce indenting level in flush_chain_cache()

Instead of doing all in one go, make two separate decisions:

1) If table has no chain cache, either continue or return depending on
   whether we're flushing for a specific table.

2) With chain cache present, flushing strategy once more depends on
   whether we're flushing for a specific table: If given, just remove
   all rules and return. If not, free the cache and set to NULL (so that
   it will be repopulated later), then continue the loop.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Reduce __nft_rule_del() signature
Phil Sutter [Thu, 20 Dec 2018 15:09:06 +0000 (16:09 +0100)] 
nft: Reduce __nft_rule_del() signature

The function does not use passed struct nftnl_rule_list, so remove it
from its parameters.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Review is_*_compatible() routines
Phil Sutter [Thu, 20 Dec 2018 15:09:05 +0000 (16:09 +0100)] 
nft: Review is_*_compatible() routines

- Call to nft_table_builtin_find() in nft_is_table_compatible() is not
  needed, as it is repeated in the latter call to nft_chain_list_get()
  by nft_are_chains_compatible().

- Turn nft_is_chain_compatible(), nft_is_rule_compatible() and
  nft_is_expr_compatible() into callbacks for use with respective
  foreach functions.

- nft_are_chains_compatible() is not needed anymore due to foreach
  function use.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables-restore: Review chain handling
Phil Sutter [Thu, 20 Dec 2018 15:09:04 +0000 (16:09 +0100)] 
xtables-restore: Review chain handling

There is no need to "delete" (actually, remove from cache) a chain if
noflush wasn't given: While handling the corresponding table line,
'table_flush' callback has already taken care of that.

This .chain_del indirection is not required since d1eb4d587297
("iptables-compat: chains are purge out already from table flush").

Streamlining the code further, move syntax checks to the top. If these
concede, there are three cases to distinguish:

A) Given chain name matches a builtin one in current table, so assume it
   exists already and just set policy and counters.

B) Noflush was given and the (custom) chain exists already, flush it.

C) Custom chain was either flushed (noflush not given) or didn't exist
   before, create it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Review unclear return points
Phil Sutter [Thu, 20 Dec 2018 15:09:03 +0000 (16:09 +0100)] 
nft: Review unclear return points

When converting to per table chain caches, these two error returns were
marked for review but apparently forgotten. Make sure error condition is
propagated when returning at those points.

Fixes: c58ecf9f8bcb7 ("xtables: Introduce per table chain caches")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: Simplify nftnl_rule_list_chain_save()
Phil Sutter [Thu, 20 Dec 2018 15:09:02 +0000 (16:09 +0100)] 
nft: Simplify nftnl_rule_list_chain_save()

Since there are per table chain caches, The chain list passed to that
function is comprised of chains belonging to the right table only.
Therefore the table name check can safely be skipped.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoextensions: TRACE: Point at xtables-monitor in documentation
Phil Sutter [Tue, 18 Dec 2018 11:16:30 +0000 (12:16 +0100)] 
extensions: TRACE: Point at xtables-monitor in documentation

With iptables-nft, logging of trace events is different from legacy.
Explain why and hint at how to receive events in this case.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoinclude: extend the headers conflict workaround to in6.h
Baruch Siach [Sun, 2 Dec 2018 16:56:34 +0000 (18:56 +0200)] 
include: extend the headers conflict workaround to in6.h

Commit 8d9d7e4b9ef ("include: fix build with kernel headers before 4.2")
introduced a kernel/user headers conflict workaround that allows build
of iptables with kernel headers older than 4.2. This minor extension
allows build with kernel headers older than 3.12, which is the version
that introduced explicit IP headers synchronization.

Fixes: 8d9d7e4b9ef4 ("include: fix build with kernel headers before 4.2")
Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoextensions: libipt_realm: Document allowed realm values
Phil Sutter [Mon, 3 Dec 2018 13:52:28 +0000 (14:52 +0100)] 
extensions: libipt_realm: Document allowed realm values

Older versions of iptables allowed for negative realm values by accident
(they would be cast to unsigned). While this was clearly a bug, document
the fixed behaviour.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Don't use native nftables comments
Phil Sutter [Tue, 27 Nov 2018 19:07:11 +0000 (20:07 +0100)] 
xtables: Don't use native nftables comments

The problem with converting libxt_comment into nftables comment is that
rules change when parsing from kernel due to comment match being moved
to the end of the match list. And since match ordering matters, the rule
may not be found anymore when checking or deleting. Apart from that,
iptables-nft didn't support multiple comments per rule anymore. This is
a compatibility issue without technical reason.

Leave conversion from nftables comment to libxt_comment in place so we
don't break running systems during an update.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoebtables: Use xtables_exit_err()
Phil Sutter [Fri, 23 Nov 2018 14:32:53 +0000 (15:32 +0100)] 
ebtables: Use xtables_exit_err()

When e.g. ebtables-nft detects an incompatible table, a stray '.' was
printed as last line of output:

| # ebtables-nft -L
| table `filter' is incompatible, use 'nft' tool.
| .

This comes from ebtables' own exit_err callback. Instead use the common
one which also provides useful version information.

While being at it, align the final error message in xtables_eb_main()
with how the others print it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoarptables: Support --set-counters option
Phil Sutter [Thu, 22 Nov 2018 19:50:13 +0000 (20:50 +0100)] 
arptables: Support --set-counters option

Relevant code for this was already present (short option '-c'), just the
long option definition was missing.

While being at it, add '-c' to help text.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: libip6t_mh: fix bogus translation error
Pablo Neira Ayuso [Mon, 19 Nov 2018 13:09:20 +0000 (14:09 +0100)] 
extensions: libip6t_mh: fix bogus translation error

 libip6t_mh.txlate: Fail
 src: ip6tables-translate -A INPUT -p mh --mh-type 1 -j ACCEPT
 exp: nft add rule ip6 filter INPUT meta l4proto 135 mh type 1 counter accept
 res: nft add rule ip6 filter INPUT meta l4proto mobility-header mh type 1 counter accept

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: make all nft_parse_ helpers static
Florian Westphal [Sun, 18 Nov 2018 18:26:51 +0000 (19:26 +0100)] 
xtables: make all nft_parse_ helpers static

no more external callers.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: rename opcodes to arp_opcodes
Florian Westphal [Fri, 8 Jun 2018 13:19:18 +0000 (15:19 +0200)] 
xtables: rename opcodes to arp_opcodes

way too generic name.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: constify struct builtin_table and struct builtin_chain
Pablo Neira Ayuso [Sat, 17 Nov 2018 17:25:58 +0000 (18:25 +0100)] 
xtables: constify struct builtin_table and struct builtin_chain

These definitions should be const, propagate this to all existing users.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: move initialize to struct nft_handle
Pablo Neira Ayuso [Sat, 17 Nov 2018 17:38:30 +0000 (18:38 +0100)] 
nft: move initialize to struct nft_handle

Move this to the structure that stores, stateful information. Introduce
nft_table_initialized() and use it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: move chain_cache back to struct nft_handle
Pablo Neira Ayuso [Sat, 17 Nov 2018 17:16:45 +0000 (18:16 +0100)] 
nft: move chain_cache back to struct nft_handle

Place this back into the structure that stores the state information.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: add type field to builtin_table
Pablo Neira Ayuso [Sat, 17 Nov 2018 17:10:15 +0000 (18:10 +0100)] 
nft: add type field to builtin_table

Use enum nft_table_type to set the new type field in the structure that
define tables.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoarptables-nft: use generic expression parsing function
Florian Westphal [Sun, 18 Nov 2018 11:31:33 +0000 (12:31 +0100)] 
arptables-nft: use generic expression parsing function

since commit d9c6a5d0977a6d8bbe772dbc31a2c4f58eec1708
("xtables: merge {ip,arp}tables_command_state structs") arptables
uses the shared representation.

With only minor changes (e.g., use generic counters in command_state),
in print/save functions we can use the shared nftnl expression parser
too.

arptables-legacy prints (-L) the jump target first, i.e.:
-j MARK -d 0.0.0.0/8 --h-length 6 ...

... so keep that here too.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables-monitor: fix build with musl libc
Baruch Siach [Sat, 17 Nov 2018 20:20:08 +0000 (22:20 +0200)] 
xtables-monitor: fix build with musl libc

Commit 7c8791edac3 ("xtables-monitor: fix build with older glibc")
changed the code to use GNU style tcphdr fields. Unfortunately, musl
libc requires _GNU_SOURCE definition to expose these fields.

Fix the following build failure:

xtables-monitor.c: In function â€˜trace_print_packet’:
xtables-monitor.c:406:43: error: â€˜const struct tcphdr’ has no member named â€˜source’
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->source), ntohs(tcph->dest));
                                           ^~
xtables-monitor.c:406:64: error: â€˜const struct tcphdr’ has no member named â€˜dest’
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->source), ntohs(tcph->dest));
                                                                ^~
...

Cc: Florian Westphal <fw@strlen.de>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoinclude: fix build with kernel headers before 4.2
Baruch Siach [Fri, 16 Nov 2018 07:30:33 +0000 (09:30 +0200)] 
include: fix build with kernel headers before 4.2

Commit 672accf1530 (include: update kernel netfilter header files)
updated linux/netfilter.h and brought with it the update from kernel
commit a263653ed798 (netfilter: don't pull include/linux/netfilter.h
from netns headers). This triggers conflict of headers that is fixed in
kernel commit 279c6c7fa64f (api: fix compatibility of linux/in.h with
netinet/in.h) included in kernel version 4.2. For earlier kernel headers
we need a workaround that prevents the headers conflict.

Fixes the following build failure:

In file included from .../sysroot/usr/include/netinet/ip.h:25:0,
                 from ../include/libiptc/ipt_kernel_headers.h:8,
                 from ../include/libiptc/libiptc.h:6,
                 from libip4tc.c:29:
.../sysroot/usr/include/linux/in.h:26:3: error: redeclaration of enumerator â€˜IPPROTO_IP’
   IPPROTO_IP = 0,  /* Dummy protocol for TCP  */
   ^
.../sysroot/usr/include/netinet/in.h:33:5: note: previous definition of â€˜IPPROTO_IP’ was here
     IPPROTO_IP = 0,    /* Dummy protocol for TCP.  */
     ^~~~~~~~~~

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Introduce per table chain caches
Phil Sutter [Thu, 15 Nov 2018 13:53:02 +0000 (14:53 +0100)] 
xtables: Introduce per table chain caches

Being able to omit the previously obligatory table name check when
iterating over the chain cache might help restore performance with large
rulesets in xtables-save and -restore.

There is one subtle quirk in the code: flush_chain_cache() did free the
global chain cache if not called with a table name but didn't if a table
name was given even if it emptied the chain cache. In other places,
chain_cache being non-NULL prevented a cache update from happening, so
this patch establishes the same behaviour (for each individual chain
cache) since otherwise unexpected cache updates lead to weird problems.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables-monitor: fix build with older glibc
Baruch Siach [Fri, 16 Nov 2018 05:23:32 +0000 (07:23 +0200)] 
xtables-monitor: fix build with older glibc

glibc older than 2.19 only expose BSD style fields of struct tcphdr when
_BSD_SOURCE is define. Current glibc however, warn that _BSD_SOURCE is
deprecated. Migrate to the GNU style of tcphdr fields to make the code
compatible with any glibc version.

Fix the following build failure:

xtables-monitor.c: In function 'trace_print_packet':
xtables-monitor.c:406:43: error: 'const struct tcphdr' has no member named 'th_sport'
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
                                           ^
xtables-monitor.c:406:66: error: 'const struct tcphdr' has no member named 'th_dport'
    printf("SPORT=%d DPORT=%d ", ntohs(tcph->th_sport), ntohs(tcph->th_dport));
                                                                  ^
...

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: format-security fixes in libip[6]t_icmp
Adam Gołębiowski [Wed, 14 Nov 2018 06:35:28 +0000 (07:35 +0100)] 
extensions: format-security fixes in libip[6]t_icmp

commit 61d6c3834de3 ("xtables: add 'printf' attribute to xlate_add")
introduced support for gcc feature to check format string against passed
argument.  This commit adds missing bits to extenstions's libipt_icmp.c
and libip6t_icmp6.c that were causing build to fail.

Fixes: 61d6c3834de3 ("xtables: add 'printf' attribute to xlate_add")
Signed-off-by: Adam Gołębiowski <adamg@pld-linux.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoebtables: vlan: fix userspace/kernel headers collision
Baruch Siach [Tue, 13 Nov 2018 17:22:08 +0000 (19:22 +0200)] 
ebtables: vlan: fix userspace/kernel headers collision

Build with musl libc fails because of conflicting struct ethhdr
definitions:

In file included from .../sysroot/usr/include/net/ethernet.h:10:0,
                 from ../iptables/nft-bridge.h:8,
                 from libebt_vlan.c:18:
.../sysroot/usr/include/netinet/if_ether.h:107:8: error: redefinition of â€˜struct ethhdr’
 struct ethhdr {
        ^~~~~~
In file included from libebt_vlan.c:16:0:
.../sysroot/usr/include/linux/if_ether.h:160:8: note: originally defined here
 struct ethhdr {
        ^~~~~~

Include the userspace header first for the definition suppression logic
to do the right thing.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoip6tables-save: Merge into iptables-save.c
Phil Sutter [Wed, 19 Sep 2018 14:25:58 +0000 (16:25 +0200)] 
ip6tables-save: Merge into iptables-save.c

Both implementations were very similar already. Differences were mostly
in which libiptc functions were called. Therefore introduce struct
iptables_save_cb to point to the right functions for each variant.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoip6tables-restore: Merge into iptables-restore.c
Phil Sutter [Wed, 19 Sep 2018 14:25:57 +0000 (16:25 +0200)] 
ip6tables-restore: Merge into iptables-restore.c

Introduce struct iptables_restore_cb and merge ip6tables-restore with
iptables-restore.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibiptc: Extend struct xtc_ops
Phil Sutter [Wed, 19 Sep 2018 14:25:56 +0000 (16:25 +0200)] 
libiptc: Extend struct xtc_ops

Add a few more callbacks used by iptables-save.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoconfigure: bump versions for 1.8.2 release v1.8.2
Florian Westphal [Tue, 13 Nov 2018 05:45:21 +0000 (06:45 +0100)] 
configure: bump versions for 1.8.2 release

this release also adds xtables_print_mac* functions to libxtables, so
current and age are incremented again.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: add 'printf' attribute to xlate_add
Florian Westphal [Mon, 12 Nov 2018 13:40:41 +0000 (14:40 +0100)] 
xtables: add 'printf' attribute to xlate_add

This allows gcc to check format string vs. passed arguments.
Fix the fallout from this as well, typical warning produced is:

libebt_mark_m.c:112:28: warning: format '%x' expects argument of type 'unsigned int', but argument 3 has type 'long unsigned int' [-Wformat=]
   xt_xlate_add(xl, "and 0x%x %s0 ", info->mask, ...
                           ~^        ~~~~~~~~~~

so add the required casts or fixup format strings as needed.
libxt_conntrack also passed an unneeded argument (port), so remove that.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxtables: xlate: init buffer to zero
Florian Westphal [Mon, 12 Nov 2018 17:04:45 +0000 (18:04 +0100)] 
libxtables: xlate: init buffer to zero

Doesn't affect iptables-xlate, but nft (when built w. xtables support).

Without this, nft can print random content if an extension doesn't
add anything to the output xlate buffer, e.g.

-p mh -m mh

can cause nft to print random data after "meta l4proto mobility",
as mh ->xlate doesn't do anything in this case.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: shell: fix expected arptables-save output
Florian Westphal [Mon, 5 Nov 2018 16:51:18 +0000 (17:51 +0100)] 
tests: shell: fix expected arptables-save output

forgot to squash this before pushing arptables fixes.

Fixes: 5aecb2d8bfd ("arptables: pre-init hlen and ethertype")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix --version info
Florian Westphal [Wed, 7 Nov 2018 09:32:42 +0000 (10:32 +0100)] 
arptables: fix --version info

old: arptables vlibxtables.so.12 (nf_tables)
now: arptables 1.8.1 (nf_tables)

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: ignore --table argument.
Florian Westphal [Wed, 7 Nov 2018 09:16:24 +0000 (10:16 +0100)] 
arptables: ignore --table argument.

You can run 'arptables-legacy -t foobar' and commands work fine,
as it still operates on filter table (the only table that exists).

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: make uni/multicast mac masks static
Florian Westphal [Tue, 6 Nov 2018 17:39:16 +0000 (18:39 +0100)] 
arptables: make uni/multicast mac masks static

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: add test cases
Florian Westphal [Mon, 5 Nov 2018 16:51:37 +0000 (17:51 +0100)] 
arptables: add test cases

Unicast being shown as '00:00:00:00:00:00/01:00:00:00:00:00' looks like
broken output, however, arptables classic did not pretty-print either.

Also add test cases for all targets supported by the original
arptables tool:

-j CLASSIFY
-j MARK
-j mangle

[ yes, mangle target is lower-case 8-( ]

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: pre-init hlen and ethertype
Florian Westphal [Mon, 5 Nov 2018 16:51:18 +0000 (17:51 +0100)] 
arptables: pre-init hlen and ethertype

to check -s 1.2.3.4, we need to add the size of the hardware address
to the arp header to obtain the offset where the ipv4 address begins:

base_arphdr
HW_ADDR
IP_ADDR (src)
IP_ADDR (target)

In arptables-classic, the kernel will add dev->addr_len to the
arp header base address to obtain the correct location, but we cannot
do this in nf_tables, at least not at this time (we need a fixed offset
value).

code does:

  op = nft_invflags2cmp(fw->arp.invflags, ARPT_INV_TGTIP);
  add_addr(r, sizeof(struct arphdr) + fw->arp.arhln + ...

but if user did not provide "--h-length 6" argument, then this won't
work even for ethernet, as the payload expression will be told to load
the first 4 bytes of arp header source mac address (sender hw address).

Fix this by pre-initialising arhlen to 6.
We also need to set up arhrd.  Otherwise, src/dst mac can't be used:

arptables -A INPUT -i lo --destination-mac 11:22:33:44:55:66
arptables v1.8.1 (nf_tables):  RULE_APPEND failed (Invalid argument): rule in chain INPUT

This means that matching won't work for AX25, NETROM etc, however,
arptables "classic" can't  parse non-ethernet addresses, and makes
ETH_ALEN assumptions in several spots, so this should be fine from
compatibility point of view.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix src/dst mac handling
Florian Westphal [Tue, 6 Nov 2018 16:52:10 +0000 (17:52 +0100)] 
arptables: fix src/dst mac handling

1. check both address and mask, not just first byte of mac
2. use add_addr() for this so mask is also handled via bitwise expr.
3. use the correct offsets.
4. add dissector so we can reverse translate the payload expressions
   generated for this.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix target ip offset
Florian Westphal [Tue, 6 Nov 2018 16:48:24 +0000 (17:48 +0100)] 
arptables: fix target ip offset

--dst-ip checks the first four octets of the target mac.

Format of ipv4 arp is:
arphdr (htype, ptype...)
src mac
src ip
target mac
target ip

So we need to add hlen (6 bytes) a second time
(arphdr + 6 + 4 + 6) to get correct offset.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix -s/-d handling for negation and mask
Florian Westphal [Mon, 5 Nov 2018 16:05:12 +0000 (17:05 +0100)] 
arptables: fix -s/-d handling for negation and mask

also handle negations in other cases.
Still to be resolved: mask handling for other options such as hlen.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: add basic test infra for arptables-nft
Florian Westphal [Mon, 5 Nov 2018 16:03:07 +0000 (17:03 +0100)] 
arptables: add basic test infra for arptables-nft

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: fix rule deletion/compare
Florian Westphal [Mon, 5 Nov 2018 16:01:36 +0000 (17:01 +0100)] 
arptables: fix rule deletion/compare

arptables -D fails most of the time, as we compared
source mask with target mask.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: remove code that is also commented-out in original arptables
Florian Westphal [Mon, 5 Nov 2018 22:53:31 +0000 (23:53 +0100)] 
arptables: remove code that is also commented-out in original arptables

This isn't a missing feature in the -nft version,
neither plen and -m were ever implemented in arptables-legacy.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables-save: add -c option, like xtables-save
Florian Westphal [Mon, 5 Nov 2018 12:38:08 +0000 (13:38 +0100)] 
arptables-save: add -c option, like xtables-save

arptables classic doesn't have arptables-save, it only has a perl
script that attempts to emulate iptables-save.  It supports no options,
and thus has no way to dump counters.  Add -c option, like iptables to
enable this.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoarptables: use ->save for arptables-save, like xtables
Florian Westphal [Wed, 7 Nov 2018 12:57:16 +0000 (13:57 +0100)] 
arptables: use ->save for arptables-save, like xtables

arptables-save will show
-A OUTPUT --h-length 6 --h-type 1 -j MARK --set-xmark 0x1/0xffffffff
as
--h-length 6 --h-type Ethernet -j MARK MARK set 0x1

Because it uses ->print() instead of ->save().
Switch it to use ->save, we can then also drop special handling of
CLASSIFY target.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: test protocol and interface negation
Florian Westphal [Mon, 5 Nov 2018 17:58:42 +0000 (18:58 +0100)] 
extensions: test protocol and interface negation

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Fix error return code in nft_chain_user_rename()
Phil Sutter [Mon, 12 Nov 2018 13:29:47 +0000 (14:29 +0100)] 
xtables: Fix error return code in nft_chain_user_rename()

If the chain to rename wasn't found, the function would return -1 which
got interpreted as success.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoxtables: Clarify error message when deleting by index
Phil Sutter [Mon, 12 Nov 2018 13:29:46 +0000 (14:29 +0100)] 
xtables: Clarify error message when deleting by index

Trying to delete a rule by index from a non-existent chain leads to a
somewhat confusing error message:

| # iptables-nft -D foobar 1
| iptables: Index of deletion too big.

Fix this by performing chain existence checks for CMD_DELETE_NUM, too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoxtables: Fix typo in do_command() error message
Phil Sutter [Mon, 12 Nov 2018 13:29:45 +0000 (14:29 +0100)] 
xtables: Fix typo in do_command() error message

This checks p->chain for existence, not cs->jumpto. Fixes this bogus
error message:

| # iptables-nft -t nat -A FORWARD -j ACCEPT
| iptables v1.8.1 (nf_tables): Chain 'ACCEPT' does not exist

Fixes: b6a06c1a215f8 ("xtables: Align return codes with legacy iptables")
Signed-off-by: Phil Sutter <phil@nwl.cc>
6 years agoebtables: use extrapositioned negation consistently
Florian Westphal [Mon, 12 Nov 2018 11:49:11 +0000 (12:49 +0100)] 
ebtables: use extrapositioned negation consistently

in the iptables universe, we enforce extrapositioned negation:

! -i foo

"-i ! foo" is not even supported anymore.

At least make sure that ebtables prints the former syntax everywhere as
well so we don't have a mix of both ways.
Parsing of --option ! 42 will still work for backwards compat reasons.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables-save: add -c option, using xtables-style counters
Florian Westphal [Mon, 12 Nov 2018 11:49:10 +0000 (12:49 +0100)] 
ebtables-save: add -c option, using xtables-style counters

The 'original' ebtables-save was a perl script that supported no option.
Add minimal options, like ip(6)tables save.

Retain the old way of formatiing counters via environment variable,
but allow overriding this using the -c option.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agonft: add NFT_TABLE_* enumeration
Pablo Neira Ayuso [Mon, 12 Nov 2018 11:44:56 +0000 (12:44 +0100)] 
nft: add NFT_TABLE_* enumeration

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft: replace nft_chain_dump() by nft_chain_list_get()
Pablo Neira Ayuso [Mon, 12 Nov 2018 11:03:57 +0000 (12:03 +0100)] 
nft: replace nft_chain_dump() by nft_chain_list_get()

So we can remove nft_chain_dump() and replace nftnl_chain_get_list().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoiptables-nft: fix -f fragment option
Florian Westphal [Sun, 11 Nov 2018 21:02:39 +0000 (22:02 +0100)] 
iptables-nft: fix -f fragment option

This needs to be passed in network byte order.

Reported-by: Arno van Amersfoort <arnova@rocky.eld.leidenuniv.nl>
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1292
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agolibxtables: add and use mac print helpers
Florian Westphal [Sat, 3 Nov 2018 22:43:49 +0000 (23:43 +0100)] 
libxtables: add and use mac print helpers

This changes ebtables-nft to consistently print mac
address with two characters, i.e.
00:01:02:03:04:0a, not 0:1:2:3:4:a.

Will require another bump of vcurrent/vage.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: libebt_ip: fix tos negation
Florian Westphal [Mon, 5 Nov 2018 10:46:02 +0000 (11:46 +0100)] 
extensions: libebt_ip: fix tos negation

passing ->tos as uintmax_t will clear adjacent fields in the structure,
including invflags.

Fixes: 49479aa12a15 ("ebtables-compat: add 'ip' match extension")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoextensions: libebt_ip6: fix ip6-dport negation
Florian Westphal [Mon, 5 Nov 2018 10:30:57 +0000 (11:30 +0100)] 
extensions: libebt_ip6: fix ip6-dport negation

Fixes: 5c8ce9c6aede0 ("ebtables-compat: add 'ip6' match extension")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables-nft: make -Z option work
Florian Westphal [Mon, 5 Nov 2018 09:44:20 +0000 (10:44 +0100)] 
xtables-nft: make -Z option work

-Z doesn't just zero base counters, it zeroes out all rule
counters, or, optionally, all counters of a chain (-Z FOO).

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1286
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agonft: add missing error string
Florian Westphal [Sat, 3 Nov 2018 22:45:13 +0000 (23:45 +0100)] 
nft: add missing error string

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables-tests: add % to run iptables commands
Pablo Neira Ayuso [Sat, 3 Nov 2018 13:40:26 +0000 (14:40 +0100)] 
iptables-tests: add % to run iptables commands

Lines starting by % allows you to run iptables commands, use it for
rateest test.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoiptables-tests: do not append xtables-multi to external commands
Pablo Neira Ayuso [Sat, 3 Nov 2018 13:40:26 +0000 (14:40 +0100)] 
iptables-tests: do not append xtables-multi to external commands

Lines starting by @ can be used to invoke an external command of any
kind. Do not add xtables-multi here since we may want to execute a
non-iptables command.

Fixes: 9ff99156b63e ("iptables-test: fix netns test")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoebtables-nft: add arpreply target
Florian Westphal [Tue, 9 Oct 2018 15:21:37 +0000 (17:21 +0200)] 
ebtables-nft: add arpreply target

Unfortunately no nft translation available so far.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables: add redirect test case
Florian Westphal [Fri, 2 Nov 2018 15:19:42 +0000 (16:19 +0100)] 
ebtables: add redirect test case

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables: add test cases
Florian Westphal [Fri, 2 Nov 2018 15:19:20 +0000 (16:19 +0100)] 
ebtables: add test cases

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables: relax -t table restriction, add snat/dnat test cases
Florian Westphal [Fri, 2 Nov 2018 15:24:24 +0000 (16:24 +0100)] 
ebtables: relax -t table restriction, add snat/dnat test cases

Its artificial and prevents test cases that need to add rules
to a different table from working.

The test script generates:
-A PREROUTING -t nat

... which works fine for iptables and ip6tables.
Just accept it for ebtables too and add test cases
for snat and dnat.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoebtables: fix -j CONTINUE handling for add/delete
Florian Westphal [Fri, 2 Nov 2018 13:36:54 +0000 (14:36 +0100)] 
ebtables: fix -j CONTINUE handling for add/delete

-j CONTINUE can be added, but it can't be removed:
extensions/libebt_standard.t: ERROR: line 5 (cannot find: ebtables -I INPUT -d de:ad:be:ef:00:00 -j CONTINUE)

This problem stems from silly ambiguity in ebtables-nft vs. iptables.

In iptables, you can do
iptables -A INPUT
(no -j)
in ebtables, you can do either
ebtables -A INPUT
or
ebtables -A INPUT -j CONTINUE

both are *supposed* to be the same (and they do the same even
in ebtables-nft on netlink side).

However, the temprary binary representation within ebtables-nft is not
the same: when parsing -j CONTINUE, we add a standard target, then omit
it later in _add_target().

When translating netlink representation to ebt binary one,
we do not add a standard target and instead just print '-j CONTINUE'
when listing rules.

So when doing
-I INPUT -j CONTINUE
-D INPUT -j CONTINUE

the -D operation fails because it has a standard target in the binary
representation, whereas the rule we obtained from translating
nftables netlink back to ebtables' binary represenation doesn't.

Fix it by ignoring 'CONTINUE' on parser side.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: add basic ebtables test support
Florian Westphal [Fri, 2 Nov 2018 11:06:30 +0000 (12:06 +0100)] 
tests: add basic ebtables test support

now that we have ebtables-save, lets add test cases for ebtables-nft
as well.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables-nft: fix bogus handling of zero saddr/daddr
Florian Westphal [Fri, 2 Nov 2018 09:47:25 +0000 (10:47 +0100)] 
iptables-nft: fix bogus handling of zero saddr/daddr

rule for 0.0.0.0/8 is added as 0.0.0.0/0, because we did not check
mask (or negation, for that matter).

Fix this and add test cases too.

This also revealed an ip6tables-nft-save bug, it would print
' !-d', not '! -d'.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1287
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables-test: fix netns test
Taehee Yoo [Thu, 1 Nov 2018 14:32:50 +0000 (23:32 +0900)] 
iptables-test: fix netns test

The libxt_rateest test always fails because dependent command is not
executed in netns.

(@iptables -I INPUT -j RATEEST --rateest-name RE1 --rateest-interval \
 250.0ms --rateest-ewmalog 500.0ms)

After this path, adding netns command is executed first.
Then test commands are executed.

Fixes: 0123183f43a9 ("iptables-test: add -N option to exercise netns removal path")
Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxtables: Fix for matching rules with wildcard interfaces
Phil Sutter [Wed, 31 Oct 2018 19:13:34 +0000 (20:13 +0100)] 
xtables: Fix for matching rules with wildcard interfaces

Due to xtables_parse_interface() and parse_ifname() being misaligned
regarding interface mask setting, rules containing a wildcard interface
added with iptables-nft could neither be checked nor deleted.

As suggested, introduce extensions/iptables.t to hold checks for
built-in selectors. This file is picked up by iptables-test.py as-is.
The only limitation is that iptables is being used for it, so no
ip6tables-specific things can be tested with it (for now).

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoextensions: limit: unbreak build without libnftnl
Florian Westphal [Wed, 24 Oct 2018 10:00:11 +0000 (12:00 +0200)] 
extensions: limit: unbreak build without libnftnl

Lars Wendler reported 1.8.1 build failure when trying to build without nft backend:

  In file included from ../iptables/nft.h:5, from libxt_limit.c:18: libnftnl/rule.h: No such file or directory

Reported-by: Lars Wendler <polynomial-c@gentoo.org>
Fixes: 02b80972c43 ("ebtables: Merge libebt_limit.c into libxt_limit.c")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Fix for spurious errors from iptables-translate
Phil Sutter [Tue, 23 Oct 2018 14:59:14 +0000 (16:59 +0200)] 
xtables: Fix for spurious errors from iptables-translate

When aligning iptables-nft error messages with legacy ones, I missed
that translate tools shouldn't check for missing or duplicated chains.

Introduce a boolean in struct nft_xt_cmd_parse indicating we're "just"
translating and do_parse() should skip the checks.

Fixes: b6a06c1a215f8 ("xtables: Align return codes with legacy iptables")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoconfigure: bump versions for 1.8.1 release v1.8.1
Florian Westphal [Mon, 22 Oct 2018 16:48:53 +0000 (18:48 +0200)] 
configure: bump versions for 1.8.1 release

this release also adds xtables_getether* functions to libxtables, so
current and age are incremented as well.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>