]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
6 years agoxtables: avoid bogus 'is incompatible' warning
Florian Westphal [Tue, 24 Jul 2018 15:12:24 +0000 (17:12 +0200)] 
xtables: avoid bogus 'is incompatible' warning

when using custom nft tables + iptables-nft, iptables-nft -L
may fail with

iptables v1.8.0 (nf_tables): table `filter' is incompatible, use 'nft' tool.

even if filter table is compatible.

Problem is that the chain cache tracks ALL chains.

The "old" compat-check only walked chains in the table to checked
(filter in this case), now we will see all other
chains including base chains of another table.

It seems better to extend the chain cache long-term to track chains
per table instead, but for now skip the foreign ones.

Reported-by: Eric Garver <e@erig.me>
Fixes: 01e25e264a4c4 ("xtables: add chain cache")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agonft: decode meta l4proto
Florian Westphal [Thu, 19 Jul 2018 21:20:20 +0000 (23:20 +0200)] 
nft: decode meta l4proto

Allow to show '-p tcp' in case rule was added by nft (which prefers
use of meta l4proto).

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: implement ebtables-{save,restore}
Phil Sutter [Thu, 19 Jul 2018 16:32:09 +0000 (18:32 +0200)] 
xtables: implement ebtables-{save,restore}

The code for ebtables-restore was derived from legacy code,
ebtables-save is actually a new implementation using the existing
infrastructure and trying to adhere to legacy perl script output
formatting as much as possible.

This introduces a new format flag (FMT_EBT_SAVE) to allow
nft_bridge_save_rule() to distinguish between ruleset listing (i.e.,
ebtables -L) and saving via ebtables-save - the two differ in how
counters are being formatted. Odd, but that's how it is.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: introduce nft_init_eb()
Phil Sutter [Thu, 19 Jul 2018 16:32:08 +0000 (18:32 +0200)] 
xtables: introduce nft_init_eb()

This wraps nft_init(), adding required things needed for ebtables.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: parameter to add_argv() may be const
Phil Sutter [Thu, 19 Jul 2018 16:32:07 +0000 (18:32 +0200)] 
xtables: parameter to add_argv() may be const

Since the function doesn't alter the passed buffer, make it const.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: pass format to nft_rule_save()
Phil Sutter [Thu, 19 Jul 2018 16:32:06 +0000 (18:32 +0200)] 
xtables: pass format to nft_rule_save()

Preparing ebtables-save implementation, allow for callers to pass format
bits to nft_rule_save() instead of just the 'counters' boolean.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: introduce save_chain callback
Phil Sutter [Thu, 19 Jul 2018 16:32:05 +0000 (18:32 +0200)] 
xtables: introduce save_chain callback

In preparation for ebtables-save implementation, introduce a callback
for convenient per-family formatting of chains in save output.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: rename {print,save}_rule functions
Phil Sutter [Thu, 19 Jul 2018 16:32:04 +0000 (18:32 +0200)] 
xtables: rename {print,save}_rule functions

The name is quite misleading, since these functions/callbacks are not
about the whole ruleset but just a single rule. So rename them to
reflect this.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: get rid of nft_ipv{4,6}_save_counters()
Phil Sutter [Thu, 19 Jul 2018 16:32:03 +0000 (18:32 +0200)] 
xtables: get rid of nft_ipv{4,6}_save_counters()

Just replace them by the shared save_counters() function after adjusting
it's signature to meet callback requirements.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: eliminate nft_ipv{4,6}_rule_find()
Phil Sutter [Thu, 19 Jul 2018 16:32:02 +0000 (18:32 +0200)] 
xtables: eliminate nft_ipv{4,6}_rule_find()

Both functions just pass their parameters 1:1 to nft_ipv46_rule_find, so
replace them by the latter after minor adjustment to match expected
callback signature.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: merge nft_ipv{4,6}_parse_target()
Phil Sutter [Thu, 19 Jul 2018 16:32:01 +0000 (18:32 +0200)] 
xtables: merge nft_ipv{4,6}_parse_target()

Both functions are identical, replace them by a common one in
nft-shared.c.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: get rid of nft_ipv{4,6}_print_header()
Phil Sutter [Thu, 19 Jul 2018 16:32:00 +0000 (18:32 +0200)] 
xtables: get rid of nft_ipv{4,6}_print_header()

Both functions are identical, just passing all their parameters 1:1 to
print_header() shared function. So just replace them by the latter.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: arp: make rule_to_cs callback private
Phil Sutter [Thu, 19 Jul 2018 16:31:59 +0000 (18:31 +0200)] 
xtables: arp: make rule_to_cs callback private

Since it is not directly called from outside of nft-arp.c anymore, make
it private and reduce the overlong name it had.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Use new callbacks in nft_rule_print_save()
Phil Sutter [Thu, 19 Jul 2018 16:31:58 +0000 (18:31 +0200)] 
xtables: Use new callbacks in nft_rule_print_save()

This relieves callers from having to prepare iptables_command_state,
which often happens just for the sake of passing it to this function.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: introduce rule_to_cs/clear_cs callbacks
Phil Sutter [Thu, 19 Jul 2018 16:31:57 +0000 (18:31 +0200)] 
xtables: introduce rule_to_cs/clear_cs callbacks

This introduces callbacks in nft_family_ops for parsing an nftnl rule
into iptables_command_state and clearing it afterwards.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: simplify struct nft_xt_ctx
Phil Sutter [Thu, 19 Jul 2018 16:31:56 +0000 (18:31 +0200)] 
xtables: simplify struct nft_xt_ctx

Replace union 'state' by its sole member.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: merge {ip,arp}tables_command_state structs
Phil Sutter [Thu, 19 Jul 2018 16:31:55 +0000 (18:31 +0200)] 
xtables: merge {ip,arp}tables_command_state structs

Differences between both structs are marginal (apart from
arptables_command_state being much smaller), so merge them into one.
Struct iptables_command_state is already shared between iptables,
ip6tables and ebtables.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables: replace memset by c99-style initializers
Phil Sutter [Thu, 19 Jul 2018 16:31:54 +0000 (18:31 +0200)] 
iptables: replace memset by c99-style initializers

This cleans up a few obvious cases identified by grepping the source
code for 'memset'.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: fix crash if nft_rule_list_get() fails
Phil Sutter [Thu, 19 Jul 2018 16:31:53 +0000 (18:31 +0200)] 
xtables: fix crash if nft_rule_list_get() fails

Without this, trying to add a rule using ebtables without proper
permissions crashes the program.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxtables: Support nft suffix for arptables and ebtables
Phil Sutter [Wed, 11 Jul 2018 10:09:05 +0000 (12:09 +0200)] 
xtables: Support nft suffix for arptables and ebtables

Since the names without suffix clash with legacy tools, support the
suffixed versions as well to help distributions packaging for parallel
installation of both nft and legacy variants.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: check iptables retval, not echo
Florian Westphal [Tue, 10 Jul 2018 10:58:24 +0000 (12:58 +0200)] 
tests: check iptables retval, not echo

Pablo reports that tests that should return nozero now fail.
Reason is that $? is checking return value of "echo" and not the script.

Fixes: 17c66a50608 ("iptables: tests: shell: Add README")
Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoiptables: tests: add test for iptables-save and iptables-restore
Arushi Singhal [Mon, 9 Jul 2018 07:37:59 +0000 (13:07 +0530)] 
iptables: tests: add test for iptables-save and iptables-restore

Add test for testing if iptables configuration is restored and saved.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoextensions: don't bother to build libebt/libarp extensions if nft backend was disabled
Florian Westphal [Mon, 9 Jul 2018 14:24:14 +0000 (16:24 +0200)] 
extensions: don't bother to build libebt/libarp extensions if nft backend was disabled

Reported-by: Thomas Deutschmann <whissi@gentoo.org>
Tested-by: Thomas Deutschmann <whissi@gentoo.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoiptables: tests: shell: Add README
Arushi Singhal [Sat, 7 Jul 2018 08:38:38 +0000 (14:08 +0530)] 
iptables: tests: shell: Add README

1) README is added to run test suite.
2) Rename two test-case scripts to follow proper numerical order.
3) "echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line" command
should only used when verbose("-v") option is not there else instead of
clearing "[EXECUTING]" prompt it is clearing last prompt of the test file.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoconfigure: bump version and libnftnl dependency v1.8.0
Florian Westphal [Thu, 5 Jul 2018 18:54:11 +0000 (20:54 +0200)] 
configure: bump version and libnftnl dependency

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoman: clarify translate tools do not modify any state
Florian Westphal [Thu, 5 Jul 2018 18:53:17 +0000 (20:53 +0200)] 
man: clarify translate tools do not modify any state

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-monitor: add --version option
Florian Westphal [Wed, 4 Jul 2018 10:35:22 +0000 (12:35 +0200)] 
xtables-monitor: add --version option

... for consistency with other commands.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-legacy: fix argv0 name for ip6tables-legacy
Florian Westphal [Wed, 4 Jul 2018 10:21:40 +0000 (12:21 +0200)] 
xtables-legacy: fix argv0 name for ip6tables-legacy

xtables-legacy currently cannot be invoked as ip6tables-legacy.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: display legacy/nf_tables flavor in error messages, too
Florian Westphal [Fri, 29 Jun 2018 14:14:31 +0000 (16:14 +0200)] 
xtables: display legacy/nf_tables flavor in error messages, too

Also, in nf_tables backend case, only show more than one error
if we're iptables-restore, else we get very long concatenated errorline.

old:
iptables v1.6.2: can't initialize iptables table `security': Table does not exist (do you need to insmod?)
iptables v1.6.2: iptables: CHAIN_ADD failed (Device or resource busy): chain PREROUTINGCHAIN_ADD failed (Device or resource busy): chain INPUTCHAIN_ADD failed (Device or resource busy): chain POSTROUTINGCHAIN_ADD failed (Device or resource busy): chain OUTPUT
iptables-restore v1.6.2: iptables-restore:
line 1: CHAIN_ADD failed (Device or resource busy): chain PREROUTING
line 1: CHAIN_ADD failed (Device or resource busy): chain INPUT
line 1: CHAIN_ADD failed (Device or resource busy): chain POSTROUTING
line 1: CHAIN_ADD failed (Device or resource busy): chain OUTPUT
line 6: RULE_INSERT failed (No such file or directory): rule in chain PREROUTING

now:

iptables v1.6.2 (legacy): can't initialize iptables table `security': Table does not exist (do you need to insmod?)
iptables v1.6.2 (nf_tables):  CHAIN_ADD failed (Device or resource busy): chain PREROUTING
iptables-restore v1.6.2 (nf_tables):
line 1: CHAIN_ADD failed (Device or resource busy): chain PREROUTING
line 1: CHAIN_ADD failed (Device or resource busy): chain INPUT
line 1: CHAIN_ADD failed (Device or resource busy): chain POSTROUTING
line 1: CHAIN_ADD failed (Device or resource busy): chain OUTPUT
line 6: RULE_INSERT failed (No such file or directory): rule in chain PREROUTING

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-nft: add stp match
Florian Westphal [Sun, 1 Jul 2018 18:45:04 +0000 (20:45 +0200)] 
ebtables-nft: add stp match

Unfortunately no nft translation available so far.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: add script that mimics firewalld startup
Florian Westphal [Fri, 29 Jun 2018 17:14:18 +0000 (19:14 +0200)] 
tests: add script that mimics firewalld startup

Mimic firewalld startup, i.e. "iptables-restore -n" use.
First script is normal startup,
second script restores ruleset, then re-runs first one (i.e., with
existing rules rather than non-existent tables).

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: fix variable name to multi-binary
Florian Westphal [Fri, 29 Jun 2018 11:51:28 +0000 (13:51 +0200)] 
tests: fix variable name to multi-binary

Need to prepend XT_MULTI, not XTABLES_MULTI.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: add a few simple tests for list/new/delete
Florian Westphal [Thu, 28 Jun 2018 22:15:28 +0000 (00:15 +0200)] 
tests: add a few simple tests for list/new/delete

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-nft: make -L, -X CHAINNAME work
Florian Westphal [Thu, 28 Jun 2018 22:15:27 +0000 (00:15 +0200)] 
ebtables-nft: make -L, -X CHAINNAME work

In both cases the argument is optional, in both cases
the argument wasn't evaluated.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-nft: remove exec_style
Florian Westphal [Thu, 28 Jun 2018 22:15:26 +0000 (00:15 +0200)] 
ebtables-nft: remove exec_style

no plans to support daemon mode, so remove this.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-nft: don't crash on ebtables -X
Florian Westphal [Thu, 28 Jun 2018 22:15:25 +0000 (00:15 +0200)] 
ebtables-nft: don't crash on ebtables -X

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: fix some spellos and the dash escape
Jan Engelhardt [Wed, 27 Jun 2018 23:02:48 +0000 (01:02 +0200)] 
doc: fix some spellos and the dash escape

Commands, options, filenames, and possibly references to other
manpages, should always use the minus. (Important for copy-n-paste
and e.g. following manpage links.) Everything else can do with the
dash.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: add firewalld default ruleset from fedora 27
Florian Westphal [Wed, 27 Jun 2018 21:35:21 +0000 (23:35 +0200)] 
tests: add firewalld default ruleset from fedora 27

The ipv4 version has bogus counters so this can also check
save/restore -c option.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: add another ipv4 only ruleset
Florian Westphal [Wed, 27 Jun 2018 13:37:47 +0000 (15:37 +0200)] 
tests: add another ipv4 only ruleset

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: add initial save/restore test cases
Florian Westphal [Tue, 26 Jun 2018 21:16:22 +0000 (23:16 +0200)] 
tests: add initial save/restore test cases

Add script to restore ipt-save files and compare it with save output.
This should be extended to cover as many rulesets as possible, so this
is only a start.

The test script is changed to pass XT_MULTI instead of
iptables/ip6tables.

This allows ip(6)tables/ebt/arp only test scripts and avoids running all scripts
multiple times for ip/ip6tables.

Current expected output:

I: [OK]          ./iptables/tests/shell/testcases/chain/0001duplicate_1
I: [OK]          ./iptables/tests/shell/testcases/chain/000newchain_0
I: [OK]          ./iptables/tests/shell/testcases/chain/0005rename_1
I: [OK]          ./iptables/tests/shell/testcases/ipt-save/0001load-dumps_0
I: legacy results: [OK] 10 [FAILED] 0 [TOTAL] 10
I: [OK]          ./iptables/tests/shell/testcases/chain/0001duplicate_1
I: [OK]          ./iptables/tests/shell/testcases/chain/0004newchain_0
I: [OK]          ./iptables/tests/shell/testcases/chain/0005rename_1
I: [OK]          ./iptables/tests/shell/testcases/ipt-save/0001load-dumps_0
I: nft results: [OK] 10 [FAILED] 0 [TOTAL] 10
I: combined results: [OK] 20 [FAILED] 0 [TOTAL] 20

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: adapt test suite to run with legacy+nftables based binaries
Florian Westphal [Tue, 26 Jun 2018 19:36:10 +0000 (21:36 +0200)] 
tests: adapt test suite to run with legacy+nftables based binaries

While at it, make following changes/fixes:
 1. run each test in a fresh net namespace
 2. remove rmmod use, its very distuptive and not needed after 1.
 3. avoid -e use if possible
 4. make sure we exit 0 when test is expected to fail
 5. set XT_LIBDIR so we point at the correct extensions to be used

Also delete 0003duplicate_1, its same test as 0001duplicate_1.

NB: I don't think its good to have this 'encode retval in name' scheme.

These are scripts, so they should always return 0, i.e. do

  iptables --this-command-should-fail || exit 0
  echo "succeess, should fail"
  exit 1

Much simpler, imo.  This was inherited from nft shell tests
though and changing it there is rather intrusive so use same scheme for
now.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: rename xt-multi binaries to -nft, -legacy
Florian Westphal [Mon, 18 Jun 2018 07:18:28 +0000 (09:18 +0200)] 
xtables: rename xt-multi binaries to -nft, -legacy

This adds a clear distinction between old iptables (formerly
xtables-multi, now xtables-legacy-multi) and new iptables
(formerly xtables-compat-multi, now xtables-nft-multi).

Users will get the ip/ip6tables names via symbolic links, having
a distinct name postfix for the legacy/nft variants helps to
make a clear distinction, as iptables-nft will always use
nf_tables and iptables-legacy always uses get/setsockopt wheres
"iptables" could be symlinked to either -nft or -legacy.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-restore: init table before processing policies
Florian Westphal [Wed, 27 Jun 2018 08:21:15 +0000 (10:21 +0200)] 
xtables-restore: init table before processing policies

*filter
 :INPUT DROP [32:4052]
 :FORWARD DROP [0:0]
 :OUTPUT ACCEPT [0:0]
 -A OUTPUT
 COMMIT

will be restored with ACCEPT policies.  When
-A OUTPUT is processed, the OUTPUT chain isn't found in the chain cache,
so the table is re-created with ACCEPT policies, which overrides the
earlier DROP policies.

A better fix would be to add the policy setting to the chain cache
but it seems we'll need a chain abstraction with refcounting first.

Fixes: 01e25e264a4c4 ("xtables: add chain cache")
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: Fix spelling error in hashlimit section
Major Hayden [Mon, 25 Jun 2018 15:37:33 +0000 (10:37 -0500)] 
doc: Fix spelling error in hashlimit section

Signed-off-by: Major Hayden <major@mhtx.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: make duplicate test work
Florian Westphal [Mon, 25 Jun 2018 14:49:05 +0000 (16:49 +0200)] 
tests: make duplicate test work

set -e causes 2nd command (which is expected to fail)
to terminate the script as well.

So, don't set -e and let the error check invert the return
value to 0.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: add xtables-monitor
Florian Westphal [Tue, 8 May 2018 23:15:10 +0000 (01:15 +0200)] 
xtables: add xtables-monitor

This is a partial revert of commit 7462e4aa757dc28e74b4a731b3ee13079b04ef23
("iptables-compat: Keep xtables-config and xtables-events out from tree")
and re-adds xtables-events under a new name, with a few enhancements,
this is --trace mode, which replaces printk-based tracing, and an
imroved event mode which will now also display pid/name and new generation id
at the end of a batch.

Example output of xtables-monitor --event --trace

PACKET: 10 fa6b77e1 IN=wlan0 MACSRC=51:14:31:51:XX:XX MACDST=1c:b6:b0:ac:XX:XX MACPROTO=86dd SRC=2a00:3a0:2::1 DST=2b00:bf0:c001::1 LEN=1440 TC=18 HOPLIMIT=61 FLOWLBL=1921 SPORT=22 DPORT=13024 ACK PSH
 TRACE: 10 fa6b77e1 raw:PREROUTING:return:
 TRACE: 10 fa6b77e1 raw:PREROUTING:policy:DROP
 EVENT: -6 -t mangle -A PREROUTING -j DNPT --src-pfx dead::/64 --dst-pfx 1c3::/64
NEWGEN: GENID=6581 PID=15601 NAME=xtables-multi

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: translate nft meta trace set 1 to -j TRACE
Florian Westphal [Thu, 10 May 2018 21:25:27 +0000 (23:25 +0200)] 
xtables: translate nft meta trace set 1 to -j TRACE

nft meta expr enables the nfnetlink based trace infrastruvture, so
prefer to use that rather than xt_TRACE.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: warn in case old-style (set/getsockopt) tables exist
Florian Westphal [Tue, 19 Jun 2018 10:02:24 +0000 (12:02 +0200)] 
xtables: warn in case old-style (set/getsockopt) tables exist

Provide a hint that iptables isn't showing all rules because
its using nfnetlink rather than old set/getsockopt.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: add nf_tables vs. legacy postfix to version strings
Florian Westphal [Mon, 18 Jun 2018 11:27:59 +0000 (13:27 +0200)] 
xtables: add nf_tables vs. legacy postfix to version strings

-V now yields:
arptables vlibxtables.so.12 (nf_tables)
ebtables 1.6.2 (nf_tables)
ip6tables v1.6.2 (legacy)
ip6tables v1.6.2 (nf_tables)
ip6tables-restore v1.6.2 (nf_tables)
ip6tables-save v1.6.2 (nf_tables)
ip6tables-restore v1.6.2 (legacy)
ip6tables-restore-translate v1.6.2
ip6tables-save v1.6.2 (legacy)
ip6tables-translate v1.6.2 (nf_tables)
iptables v1.6.2 (legacy)
iptables v1.6.2 (nf_tables)
iptables-restore v1.6.2 (nf_tables)
iptables-save v1.6.2 (nf_tables)
iptables-restore v1.6.2 (legacy)
iptables-restore-translate v1.6.2
iptables-save v1.6.2 (legacy)
iptables-translate v1.6.2 (nf_tables)

This allows to see wheter "iptables" is using
old set/getsockopt or new nf_tables infrastructure.

Suggested-by: Harald Welte <laforge@gnumonks.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoiptables8.in: Update coreteam names
Florian Westphal [Mon, 18 Jun 2018 11:21:46 +0000 (13:21 +0200)] 
iptables8.in: Update coreteam names

Refresh this to match reality again.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoinclude: update kernel netfilter header files
Florian Westphal [Tue, 15 May 2018 20:44:24 +0000 (22:44 +0200)] 
include: update kernel netfilter header files

needed to get the TRACE definition.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: silence two compiler warnings
Florian Westphal [Sun, 17 Jun 2018 20:35:30 +0000 (22:35 +0200)] 
xtables: silence two compiler warnings

inlined from ‘do_commandarp’ at xtables-arp.c:1198:16:
xtables-arp.c:844:2: warning: ‘strncpy’ specified bound 29 equals destination size [-Wstringop-truncation]
  strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name));
xtables-eb-translate.c: In function ‘do_commandeb_xlate’:
xtables-eb-translate.c:285:6: warning: unused variable ‘chcounter’ [-Wunused-variable]
  int chcounter = 0; /* Needed for -C */
      ^~~~~~~~~
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: remove dead code inherited from ebtables
Florian Westphal [Fri, 15 Jun 2018 09:08:27 +0000 (11:08 +0200)] 
xtables: remove dead code inherited from ebtables

previous patch shows this problem:

 xtables-eb.c: In function ‘parse_change_counters_rule’:
 xtables-eb.c:534:65: warning: logical ‘and’ of mutually exclusive tests is always false [-Wlogical-op]
 (argv[optind + 1][0] == '-' && (argv[optind + 1][1] < '0'  && argv[optind + 1][1] > '9')))

... so this never worked.  Just remove it, the arg will be fed to
strtol() -- No need to do this check.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1149
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoconfigure: add -Wlogical-op warning to cflags
Florian Westphal [Fri, 15 Jun 2018 09:04:39 +0000 (11:04 +0200)] 
configure: add -Wlogical-op warning to cflags

It finds dead code in ebtables.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-translate: remove --change-counters code
Florian Westphal [Fri, 15 Jun 2018 08:56:24 +0000 (10:56 +0200)] 
ebtables-translate: remove --change-counters code

Not used in the translator, so zap it.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoiptables: tests: shell: add shell test-suite
Arushi Singhal [Sat, 9 Jun 2018 17:34:27 +0000 (23:04 +0530)] 
iptables: tests: shell: add shell test-suite

To run the test suite (as root):
 % cd iptables/tests/shell
 % ./run-tests.sh

Test files are executables files with the pattern <<name_N>> , where
N is the expected return code of the executable. Since they are
located with `find', test-files can be spreaded in any sub-directories.

You can turn on a verbose execution by calling:
 % ./run-tests.sh -v

Before each call to the test-files, `kernel_cleanup' will be called.
Also, test-files will receive the environment variable $IPTABLES which
contains the path to the iptables binary being tested.

You can pass an arbitrary $IPTABLES value as well:
 % IPTABLES=/../../xtables-multi iptables ./run-tests.sh

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables-compat: skip invalid tables
Florian Westphal [Tue, 29 May 2018 20:29:50 +0000 (22:29 +0200)] 
xtables-compat: skip invalid tables

in bridge and arp families, some tables such as security do not exist,
so name is NULL. skip them, else we segfault in strcmp.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: more error printing fixes
Pablo Neira Ayuso [Tue, 29 May 2018 08:20:47 +0000 (10:20 +0200)] 
xtables: more error printing fixes

Check for nft_insert_rule, since nft_add_rule is never set via nft_fn.
Moreover, generalize ELOOP error since there is only one single location
in the kernel code where we can hit this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables: homogenize error message
Arushi Singhal [Sun, 27 May 2018 13:09:01 +0000 (18:39 +0530)] 
xtables: homogenize error message

There is a difference between error messages in iptables and
iptables-compat:

 # iptables-compat -D INPUT 4
 iptables: No chain/target/match by that name.

 # iptables -D INPUT 4
 iptables: Index of deletion too big.

Now, will show same error message.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables: initialize basechains for rule flush command too
Pablo Neira Ayuso [Mon, 28 May 2018 18:21:10 +0000 (20:21 +0200)] 
xtables: initialize basechains for rule flush command too

Otherwise, flush commands on not-yet-initialized basechains hit ENOENT.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables: rework rule cache logic
Pablo Neira Ayuso [Mon, 28 May 2018 17:10:56 +0000 (19:10 +0200)] 
xtables: rework rule cache logic

Perform incremental tracking on rule cache updates, instead of flushing
and resynchronizing with the kernel over and over again.

Note that there is no need to call flush_rule_cache() from
nft_rule_delete() and nft_rule_delete_num(), since __nft_rule_del()
already deletes the rule from the list.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables: add chain cache
Pablo Neira Ayuso [Mon, 28 May 2018 16:48:19 +0000 (18:48 +0200)] 
xtables: add chain cache

So we don't have to dump the chain cache content over and over again.
Moreover, perform incremental updates on the chain cache to add and to
delete non-base chains.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables: initialize basechains only once on ruleset restore
Pablo Neira Ayuso [Mon, 28 May 2018 15:33:02 +0000 (17:33 +0200)] 
xtables: initialize basechains only once on ruleset restore

We cannot assume iptables-restore files always come with explicit
basechain definition, eg.

:PREROUTING ACCEPT

incremental ruleset updates may deliberately skip this.

But loading basechains over and over again can take time, so do it just
once per batch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables-compat: ignore '+' interface name
Florian Westphal [Mon, 28 May 2018 20:17:50 +0000 (22:17 +0200)] 
xtables-compat: ignore '+' interface name

its same as omitting it, so instead of generating
invalid compare-with-0-sized-register, just ignore it.

Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: append all errors into single line
Florian Westphal [Mon, 28 May 2018 20:17:39 +0000 (22:17 +0200)] 
xtables-compat: append all errors into single line

iptables-restore < /tmp/bogus
iptables-restore v1.6.2: iptables-restore:
line 49: RULE_APPEND failed (No such file or directory): rule in chain FOOBAR
line 2023: RULE_APPEND failed (Invalid argument): rule in chain TESTSNAT

This is a followup commit to 437746c7b528f ("xtables: extended error reporting").

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: extended error reporting
Florian Westphal [Sat, 26 May 2018 17:20:16 +0000 (19:20 +0200)] 
xtables: extended error reporting

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables: allocate struct xt_comment_info for comments
Pablo Neira Ayuso [Sat, 26 May 2018 17:04:08 +0000 (19:04 +0200)] 
xtables: allocate struct xt_comment_info for comments

When mapping it to the comment match, otherwise, crash happens when
trying to save the ruleset listing.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables: use libnftnl batch API
Pablo Neira Ayuso [Sat, 26 May 2018 09:34:34 +0000 (11:34 +0200)] 
xtables: use libnftnl batch API

Use existing batching API from library, the existing code relies on an
earlier implementation of it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables-compat: remove nft_is_ruleset_compatible
Florian Westphal [Thu, 24 May 2018 15:57:34 +0000 (17:57 +0200)] 
xtables-compat: remove nft_is_ruleset_compatible

Use nft_is_table_compatible instead as only helper to a 'skip' decision.

Custom tables, tables that have extra base chains that iptables
syntax doesn't allow or rules that have special constructs line nftables
set lookups or verdict maps are not listed, but a message is provided
to show that such table exists.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: allow dumping of chains in specific table
Florian Westphal [Thu, 24 May 2018 15:50:25 +0000 (17:50 +0200)] 
xtables: allow dumping of chains in specific table

This is used by a followup patch to avoid continuing the 'dump everything
and then ignore what we don't need' model.

Places that know they only need a particular table
'iptables-save -t filter' can ask the kernel to limit this for us.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: inconsistent error reporting for -X and no empty chain
Pablo Neira Ayuso [Wed, 23 May 2018 09:55:24 +0000 (11:55 +0200)] 
xtables: inconsistent error reporting for -X and no empty chain

 # iptables-compat -N coffee
 # iptables-compat -I coffee
 # iptables-compat -X coffee
 iptables: Device or resource busy.

While it should say:

 iptables: Directory not empty.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoebtables-compat: add arp match extension
Florian Westphal [Fri, 4 May 2018 15:32:42 +0000 (17:32 +0200)] 
ebtables-compat: add arp match extension

no translation yet, might be doable with raw payload expressions though.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-compat: add redirect match extension
Florian Westphal [Tue, 10 Apr 2018 09:15:26 +0000 (11:15 +0200)] 
ebtables-compat: add redirect match extension

No translation.  The kernel match will alter packet type
(meta set pkttype), but also replace dst mac with the bridges' mac address,
however nft currently doesn't allow to retrieve this at runtime.

So just add this without the xlate part for now.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-compat: add nat match extensions
Florian Westphal [Tue, 10 Apr 2018 08:55:30 +0000 (10:55 +0200)] 
ebtables-compat: add nat match extensions

adds snat and dnat.

Translation for snat isn't complete, the --snat-arp switch isn't supported so far.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ebtables: prefer snprintf to strncpy
Florian Westphal [Sun, 20 May 2018 21:56:32 +0000 (23:56 +0200)] 
xtables-compat: ebtables: prefer snprintf to strncpy

gcc emits these warnings:
xtables-eb-translate.c:185:2: warning: ‘strncpy’ specified bound 29 equals destination size [-Wstringop-truncation]
  strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: extend generic tests for masks and wildcards
Florian Westphal [Mon, 14 May 2018 22:48:01 +0000 (00:48 +0200)] 
xtables-compat: extend generic tests for masks and wildcards

This uncovered broken translation of ethernet + mask.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agolibxtables: store all requested match types
Florian Westphal [Fri, 11 May 2018 21:17:15 +0000 (23:17 +0200)] 
libxtables: store all requested match types

iptables and ip6tables don't need this because iptables is AF_INET,
ip6tables AF_INET6, etc.

But tools that can change af in-between such as nftables will then
may then find to find such module.

One example is conntrack, it offsers NFPROTO_IPV4 and NFPROTO_IPV6.
When first loading with NFPROTO_IPV6, the IPV4 would be discarded.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ip6table-save: fix save of ip6 address masks
Florian Westphal [Thu, 10 May 2018 19:47:30 +0000 (21:47 +0200)] 
xtables-compat: ip6table-save: fix save of ip6 address masks

ip6tables-save didn't include the masks.
Furhermore, mask decoding used the ipv4 struct which caused it to write
into parts of ipv6 saddr.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-translate: suppress redundant protocols
Florian Westphal [Tue, 8 May 2018 08:15:11 +0000 (10:15 +0200)] 
ebtables-translate: suppress redundant protocols

kernel would reject ip, ip6 etc. without -p ip, -p ip6.
So add it.  On reverse, search the match list to decide if -p
has to be translated or not.

Also, icmp and icmpv6 also imply l3 protocol, so no need to translate
that either.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ebtables: allow checking for zero-mac
Florian Westphal [Tue, 8 May 2018 14:31:29 +0000 (16:31 +0200)] 
xtables-compat: ebtables: allow checking for zero-mac

Allow checking for an all-zero mac address by replacing checks on the
address with a check on the option flag.

Its set when '-d' or '-s' appears on the command line and when seeing
a linklayer payload request for ether s/daddr.

Same for -p: s this flag gets removed during getopt when 'p' is encountered.

So, if its set, no need to check protocol type.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ebtables: add helpers to print interface and mac addresses
Florian Westphal [Tue, 8 May 2018 10:03:46 +0000 (12:03 +0200)] 
xtables-compat: ebtables: add helpers to print interface and mac addresses

Reduces repetition, follow patch adds back suppression of
src/dst mac when it was not given.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ebtables: remove interface masks from ebt_entry struct
Florian Westphal [Tue, 8 May 2018 09:37:46 +0000 (11:37 +0200)] 
xtables-compat: ebtables: remove interface masks from ebt_entry struct

They don't exist in the legacy ABI, so don't pretend otherwise.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ebtables: fix logical interface negation
Florian Westphal [Tue, 8 May 2018 11:48:44 +0000 (13:48 +0200)] 
xtables-compat: ebtables: fix logical interface negation

before:
Bridge chain: OUTPUT, entries: 4, policy: ACCEPT
-o ! noout -j CONTINUE
-o out -j CONTINUE
--logical-out notlogout -j CONTINUE
--logical-out logout -j CONTINUE

after:
Bridge chain: OUTPUT, entries: 5, policy: ACCEPT
-o ! noout -j CONTINUE
-o out -j CONTINUE
--logical-out ! notlogout -j CONTINUE
--logical-out logout -j CONTINUE

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ebtables: add and use helper to parse all interface names
Florian Westphal [Tue, 8 May 2018 09:33:02 +0000 (11:33 +0200)] 
xtables-compat: ebtables: add and use helper to parse all interface names

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ebtables: split match/target print from nft_bridge_print_firewall
Florian Westphal [Tue, 8 May 2018 08:43:45 +0000 (10:43 +0200)] 
xtables-compat: ebtables: split match/target print from nft_bridge_print_firewall

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ebtables: kill ebtables_command_state
Florian Westphal [Tue, 8 May 2018 07:41:47 +0000 (09:41 +0200)] 
xtables-compat: ebtables: kill ebtables_command_state

Use iptables_command_state instead.
This allows to re-use code from the ip(6)tables layer and
reduces cop&pasted code.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: pass correct table skeleton
Florian Westphal [Thu, 12 Apr 2018 09:31:42 +0000 (11:31 +0200)] 
xtables-compat: pass correct table skeleton

This always uses xtables_ipv4 (which is same as _ipv6).
Pass the correct skeleton instead, this is needed to handle ebtables
correctly from xt-translate, as it doesn't use ip/ip6 tables.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: fix wildcard detection
Florian Westphal [Tue, 8 May 2018 10:45:25 +0000 (12:45 +0200)] 
xtables-compat: fix wildcard detection

if (outiface[len] == '\0')

is always true. 'eth+' is stored as 'eth' with length 3, so
   "eth"[3] == 0.

'eth' is stored as 'eth\0' with length 4, so "eth\0"[4] is also true.
Add a helper for this, then use it.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: libip6t_srh.t: Add test cases for psid, nsid, and lsid
Ahmed Abdelsalam [Wed, 9 May 2018 08:12:54 +0000 (03:12 -0500)] 
extensions: libip6t_srh.t: Add test cases for psid, nsid, and lsid

This patch add some testcases for psid, nsid, and lsid matches
into libip6t_srh.t

Signed-off-by: Ahmed Abdelsalam <amsalam20@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: libxt_CONNMARK: incorrect translation after v2
Pablo Neira Ayuso [Tue, 8 May 2018 13:06:33 +0000 (15:06 +0200)] 
extensions: libxt_CONNMARK: incorrect translation after v2

src: iptables-translate -t mangle -A PREROUTING -j CONNMARK --set-mark 0
exp: nft add rule ip mangle PREROUTING counter ct mark set 0x0
res: nft add rule ip mangle PREROUTING counter ct mark set ct mark and 0x0

Fixes: db7b4e0de960 ("extensions: libxt_CONNMARK: Support bit-shifting for --restore,set and save-mark")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: libxt_CONNMARK: Support bit-shifting for --restore,set and save-mark
Jack Ma [Tue, 24 Apr 2018 02:58:57 +0000 (14:58 +1200)] 
extensions: libxt_CONNMARK: Support bit-shifting for --restore,set and save-mark

This patch adds a new feature to iptables that allow bitshifting for
--restore,set and save-mark operations. This allows existing logic
operators (and, or and xor) and mask to co-operate with new bitshift
operations.

The intention is to provide uses with more fexible uses of skb->mark
and ct->mark. For example, users can save extra bits in skb->mark:
        skb->mark = ct->mark << 8;

Reviewed-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Jack Ma <jack.ma@alliedtelesis.co.nz>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: libip6t_srh: support matching previous, next and last SID
Ahmed Abdelsalam [Wed, 25 Apr 2018 10:30:47 +0000 (05:30 -0500)] 
extensions: libip6t_srh: support matching previous, next and last SID

This patch extends the libip6t_srh shared library to support matching
previous SID, next SID, and last SID.

Signed-off-by: Ahmed Abdelsalam <amsalam20@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: libipt_DNAT: tests added for shifted portmap range
Thierry Du Tre [Mon, 7 May 2018 20:31:31 +0000 (22:31 +0200)] 
extensions: libipt_DNAT: tests added for shifted portmap range

I added and verified these tests after applying Florian's fixed wrt.
nf_nat_range2 size for rev2.

Signed-off-by: Thierry Du Tre <thierry@dtsystems.be>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables-compat-restore: flush table and its content with no -n
Pablo Neira Ayuso [Tue, 8 May 2018 09:45:59 +0000 (11:45 +0200)] 
xtables-compat-restore: flush table and its content with no -n

With no -n, semantics for *filter are to delete filter table and all its
content.

This restores the similar behaviour introduced in ca165845f7ec
("xtables-compat-restore: flush rules and delete user-defined chains").

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables-compat: fix bogus error with -X and no user-defined chains
Pablo Neira Ayuso [Mon, 7 May 2018 15:11:21 +0000 (17:11 +0200)] 
xtables-compat: fix bogus error with -X and no user-defined chains

 # iptables-compat -X
 iptables: No chain/target/match by that name.

While it should display no error message at all.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables-compat-restore: flush user-defined chains with -n
Pablo Neira Ayuso [Mon, 7 May 2018 13:32:33 +0000 (15:32 +0200)] 
xtables-compat-restore: flush user-defined chains with -n

-n still flushes user-defined chains and its content, the following snippet:

 iptables-compat -N FOO
 iptables-compat -I INPUT
 iptables-compat -I FOO
 iptables-compat -I FOO
 iptables-compat-save > A
 iptables-compat-restore < A
 iptables-compat -N BAR
 iptables-compat -A BAR
 iptables-compat-restore -n < A

results in:

 iptables-compat-save
 # Generated by xtables-save v1.6.2 on Mon May  7 17:18:44 2018
 *filter
 :INPUT ACCEPT [0:0]
 :FORWARD ACCEPT [0:0]
 :OUTPUT ACCEPT [0:0]
 :BAR - [0:0]
 :FOO - [0:0]
 -A INPUT
 -A INPUT
 -A BAR
 -A FOO
 -A FOO
 COMMIT
 # Completed on Mon May  7 17:18:44 2018

Still, user-defined chains that are not re-defined, such as BAR, are
left in place.

Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables-compat-restore: flush rules and delete user-defined chains
Pablo Neira Ayuso [Mon, 7 May 2018 13:05:15 +0000 (15:05 +0200)] 
xtables-compat-restore: flush rules and delete user-defined chains

Instead of deleting the table and base chains.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: libipt_DNAT: use size of nf_nat_range2 for rev2
Florian Westphal [Thu, 3 May 2018 19:40:52 +0000 (21:40 +0200)] 
extensions: libipt_DNAT: use size of nf_nat_range2 for rev2

DNAT tests fail on nf-next.git, kernel complains about target size
mismatch (40 vs 48), this fixes this for me.

Fixes: 36976c4b5406 ("extensions: libipt_DNAT: support shifted portmap ranges")
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: pass larger socket buffer
Florian Westphal [Mon, 7 May 2018 11:41:21 +0000 (13:41 +0200)] 
xtables-compat: pass larger socket buffer

needed to display rules that exceed 4k (MNL buffer size).
This can happen with many matches in a rule or when using
-m cgroup (4k per match).

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: xtables-save: don't return 1
Florian Westphal [Mon, 7 May 2018 11:37:45 +0000 (13:37 +0200)] 
xtables-compat: xtables-save: don't return 1

noticed that iptables-compat-save exits with 1 on success,
whereas iptables-compat-save -t filter returns 0 (as expected).

Caused by double-invert of return value, so ge rid of those.
do_output now returns a value suitable to pass to exit() or return from main.

Signed-off-by: Florian Westphal <fw@strlen.de>