]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
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>
7 years agoxtables-compat: ebtables: support concurrent option
Florian Westphal [Mon, 7 May 2018 11:35:49 +0000 (13:35 +0200)] 
xtables-compat: ebtables: support concurrent option

We don't need extra locking as we don't go though rmw cycle
when adding a rule, but accept the option for compatibility with
legacy ebtables.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoiptables-test: fix bug with rateest
Florian Westphal [Sun, 6 May 2018 22:05:11 +0000 (00:05 +0200)] 
iptables-test: fix bug with rateest

rateest test needs to insert rateest targets with
@progname syntax.

However, this used the system-installed binary rather than the one
from git.

Morever, it did not respect --nftables switch, i.e. add occurs with
iptables so iptables-compat won't find it.

Fixes: d7ac61b58e78 ("add nft switch and test binaries from git")
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: fix ipv4 frag (-f)
Florian Westphal [Sat, 5 May 2018 08:38:38 +0000 (10:38 +0200)] 
xtables-compat: fix ipv4 frag (-f)

iptables-translate -A I -f
nft add rule ip filter I ip frag-off != 0 counter

iptables however checks:
frag_off = ntohs(iph->frag_off) & IP_OFFSET;

if (NF_INVF(ipinfo, IPT_INV_FRAG,
    (ipinfo->flags & IPT_F_FRAG) && !frag_off))
       return false;

So we need to mask off non-offset bits.

Second issue is that we negated the meaning in ipt-restore.

-f should match if (frag_off & IP_OFFSET) NE 0
  ! -f matches non-fragmented packets, i.e.
  frag_off & IP_OFFSET == 0.

So we cannot use nft_invflags2cmp(), as that will use
NEQ for negation, but we need EQ instead here.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: also check tg2->userspacesize
Florian Westphal [Sat, 5 May 2018 17:52:55 +0000 (19:52 +0200)] 
xtables-compat: also check tg2->userspacesize

memcmp uses tg1->userspacesize, make sure its same as tg2 first.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: avoid unneeded bitwise ops
Florian Westphal [Sat, 5 May 2018 17:34:57 +0000 (19:34 +0200)] 
xtables-compat: avoid unneeded bitwise ops

no need to and with all-ones mask.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: restore: sync options with iptables-restore
Florian Westphal [Sat, 5 May 2018 17:17:45 +0000 (19:17 +0200)] 
xtables-compat: restore: sync options with iptables-restore

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: add xlate test for ipables -f
Florian Westphal [Sat, 5 May 2018 09:21:48 +0000 (11:21 +0200)] 
extensions: add xlate test for ipables -f

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: output -s,d first during save, just like iptables
Florian Westphal [Sat, 5 May 2018 07:59:43 +0000 (09:59 +0200)] 
xtables-compat: output -s,d first during save, just like iptables

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoiptables-compat: chains are purge out already from table flush
Pablo Neira Ayuso [Fri, 4 May 2018 09:41:10 +0000 (11:41 +0200)] 
iptables-compat: chains are purge out already from table flush

Remove dead code that uses the ancient non-batch netlink API. Chains
are already purged out from table flush.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables-compat: do not fail on restore if user chain exists
Pablo Neira Ayuso [Fri, 4 May 2018 09:25:00 +0000 (11:25 +0200)] 
iptables-compat: do not fail on restore if user chain exists

The following snippet fails if user chain FOO exists, but it should not fail:

iptables-compat -F
iptables-compat -N FOO
iptables-compat-save > foo
iptables-compat-restore < foo

Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables-compat: remove non-batching routines
Pablo Neira Ayuso [Thu, 3 May 2018 14:38:20 +0000 (16:38 +0200)] 
iptables-compat: remove non-batching routines

This is only needed by 3.16, which was released 8 months after nftables was
merged upstream. That kernel version supports a reduced featureset.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables.conf: fix hook skeletons
Florian Westphal [Wed, 2 May 2018 16:29:51 +0000 (18:29 +0200)] 
xtables.conf: fix hook skeletons

nat prio for in/out were inverted.
arp no longer has a forward chain.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: fall back to comment match in case name is too long
Florian Westphal [Thu, 3 May 2018 19:45:59 +0000 (21:45 +0200)] 
xtables-compat: fall back to comment match in case name is too long

... or when using multiple --comment lines.
This is more of a 'cosmetic' fix to handle the test suite case.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxlate-test: use locally installed xlate tools
Florian Westphal [Fri, 27 Apr 2018 22:26:27 +0000 (00:26 +0200)] 
xlate-test: use locally installed xlate tools

same as iptables-test: use the translate tools in the current working
directory, not the system-wide ones.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: ebtables: handle mac masks properly
Florian Westphal [Fri, 4 May 2018 20:33:35 +0000 (22:33 +0200)] 
xtables-compat: ebtables: handle mac masks properly

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: nft-arp: fix warning wrt. sprintf-out-of-bounds
Florian Westphal [Thu, 3 May 2018 20:27:03 +0000 (22:27 +0200)] 
xtables-compat: nft-arp: fix warning wrt. sprintf-out-of-bounds

nft-arp.c:112:3: note: 'sprintf' output between 2 and 21 bytes into a destination of size 20
sprintf(buf, "/%s", addr_to_dotted(mask));

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: truncate comments to 254 bytes
Florian Westphal [Sat, 28 Apr 2018 09:43:09 +0000 (11:43 +0200)] 
xtables-compat: truncate comments to 254 bytes

Kernel clamps udata size at 256 bytes, udata size however also includes
internal bookkeeping which brings us over this limit.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: libipt_DNAT: support shifted portmap ranges
Thierry Du Tre [Tue, 3 Apr 2018 16:39:22 +0000 (18:39 +0200)] 
extensions: libipt_DNAT: support shifted portmap ranges

This is a proposal patch for iptables DNAT extension to support shifted portmap
ranges. It is related to the kernel patch proposed in earlier message '[PATCH
v5] netfilter : add NAT support for shifted portmap ranges'.

A new struct nf_nat_range2 was added as extension for existing struct
nf_nat_range and is used by new revisions (2) for the DNAT target. Current DNAT
revisions for Ipv4 (rev 0) and IPv6 (rev 1) are kept so functionality with
older kernels is not impacted.

The syntax for shifted portmaps uses an extra value in '--to-destination' for
setting the base port which determines the offset in the redirect port range
for incoming connections.  i.e. : iptables -t nat -A zone_wan_prerouting -p tcp
-m tcp --dport 5000:5100 -j DNAT --to-destination '192.168.1.2:2000-2100/5000'

The base port value is totally optional, so current behavior is not impacted in
any way.  The use of slash '/' as separator is an arbitrary choice, all other
suggestions are valid of course (original proposal used semicolon but this was
not practical for commandline use) Another approach using an additional option
seems also possible (i.e. '--base-port 5000'). However, that would mean more
parsing logic with extra lines of code and thus increased risk for regression.

Signed-off-by: Thierry Du Tre <thierry@dtsystems.be>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables-test: add nft switch and test binaries from git
Florian Westphal [Fri, 27 Apr 2018 14:50:13 +0000 (16:50 +0200)] 
iptables-test: add nft switch and test binaries from git

instead of testing the system-wide installed iptables, test the
version from git instead.

Also add a --nftables switch to feed the test cases to xt-compat.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: only fetch revisions for ip/ip6
Florian Westphal [Fri, 27 Apr 2018 10:37:53 +0000 (12:37 +0200)] 
xtables-compat: only fetch revisions for ip/ip6

Only ip and ip6tables have revision retrieval support; pretend
ebtables and arptables are always ok.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: Fix rules print/save after iptables update
Serhey Popovych [Wed, 7 Mar 2018 09:10:43 +0000 (11:10 +0200)] 
xtables: Fix rules print/save after iptables update

Updating iptables from 1.4.x to 1.6.x brokes rules print/save output
and causes rules load after reboot to fail. Here is example from
iptables-save(8) output after update:

  -A CHAIN1 -m set [unsupported revision] -j DROP
  -A CHAIN1 -m set [unsupported revision] -j DROP

Similar output could be obtained via iptables -L CHAIN1. While issue
reproduced with xt_set match it is not specific to any match or
target module: it is related on how xtables handles revisions.

In this particular case we have following situation:

  1) Kernel supports revisions from 1 to 4.

  2) Rules configured with iptables 1.4.x supporting only
     revisions from 1 to 3. Choosen highest possible revision 3.

  3) Rules printed/saved with iptables 1.6.x supporting revisions
     from 1 to 4.

  4) Xtables registers matches/targets with highest supported
     revision by the kernel. This is 4 in our case after update to
     iptables 1.6.x.

  5) When printing/saving kernel submits match/target with revision
     it is configured (3), while iptables thinks that rules configured
     with highest supported (4). That's causes revision mismatch in
     during print and "[unsupported revision]" output.

To fix this issue we now store all supported by kernel and xtables
revisions in xt_matches/xt_targets list sorted in descending order.

Introduce helper routines to find match/target with given revision
and use them to find right revision to print submitted by kernel
entry.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: Register all match/target revisions supported by us and kernel
Serhey Popovych [Wed, 7 Mar 2018 09:10:42 +0000 (11:10 +0200)] 
xtables: Register all match/target revisions supported by us and kernel

Keep the order of matches by appending them; keep order between
revisions of same match from most to least recent. All of this
keeps xtables_find_match() happy to find most recent supported
by kernel revision in the given order.

Apply the same for targets, except prepend targets; order between
revisions preserved too.

All this needed to fix nasty bug related to iptables package update
and broken print/save output.

After this change all supported revisions of match/target stored
in corresponding list with following pattern:

         xt_matches                 xt_targets
         ==========                 ==========

     m1  m2  m3     mN             tN     t1  t2  t3
  +-----+--+---+---~~~---+    +---~~~---+---+----+--+
  |43210|10|210|revisions|    |revisions|210|3210|10|
  +-----+--+---+---~~~---+    +---~~~---+---+----+--+

Where new [m]atches added to the list tail and new [t]argets added
to the list head to preserve previous behaviour. Multiple revisions
of single match/target type are grouped together and sorted in
descending order. Both this ensures xtables_find_match() and
xtables_find_target() behaviour remains the same after change: find
highest supported match/target revision given by it's name.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: Check match/target size vs XT_ALIGN(size) at register time
Serhey Popovych [Wed, 7 Mar 2018 09:10:41 +0000 (11:10 +0200)] 
xtables: Check match/target size vs XT_ALIGN(size) at register time

Size is known at xtables_register_match()/xtables_register_target()
calls: no need to defer it to final registration steps.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: Do not register matches/targets with incompatible revision
Serhey Popovych [Wed, 7 Mar 2018 09:10:40 +0000 (11:10 +0200)] 
xtables: Do not register matches/targets with incompatible revision

If kernel tells revision isn't found/supported at the moment we should
keep entity in pending list, not register or bail to do so later.

Kernel might still load module for entity we asking it for and this
could be slow on some embedded devices.

Catch double registration attempts by checking me->next being non-NULL
in xtables_register_match() and xtables_register_target().

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: Introduce and use common function to print val[/mask] arguments
Serhey Popovych [Thu, 1 Mar 2018 11:03:12 +0000 (13:03 +0200)] 
xtables: Introduce and use common function to print val[/mask] arguments

There are number of places where argument is in val[/mask] format
printed in extensions and some of them may print corresponding symbolic
name.

By introducing common function for this task we eliminate custom code
parts in extensions to perform printing of arguments in required
formats.

Use xtables_print_mark_mask() helper for extensions without
symbolic name for val[/mask].

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables: Introduce and use common function to parse val[/mask] arguments
Serhey Popovych [Thu, 1 Mar 2018 11:03:11 +0000 (13:03 +0200)] 
xtables: Introduce and use common function to parse val[/mask] arguments

There are a couple of places in both core and extensions where arguments
in the form of val[/mask] is parsed (see XTTYPE_MARKMASK32).

In some cases symbolic name might be used which is mapped in code to
numeric value.

Introduce common function to handle both cases where value given is
either val[/mask] or symbolic name.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: Initialize linear mapping of symbols in _init() of extension
Serhey Popovych [Thu, 1 Mar 2018 11:03:10 +0000 (13:03 +0200)] 
extensions: Initialize linear mapping of symbols in _init() of extension

libxt_devgroup and libipt_realm currently unable to display symbolic
names in save/print commands because linear mapping is not initialized.

It looks bit confusing as linear mapping initialization is done in init()
of extension, which is expected to be called before any other function of
extension.

However init is called only when '-m' option specified on command line,
that is true only for insert, append, replace and destroy iptables
commands.

Move initialization to extension _init() function before calling
any function in extension.

Before:
-------
... src-group 0x1 dst-group 0x2
... src-group 0x2 dst-group 0x1

After:
------
... src-group grp1 dst-group grp2
... src-group grp2 dst-group grp1

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: ULOG: remove test
Florian Westphal [Fri, 27 Apr 2018 13:52:59 +0000 (15:52 +0200)] 
extensions: ULOG: remove test

ULOG target was removed in 3.17, so this always fails now.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-translate: turn off useless compat queries
Florian Westphal [Fri, 27 Apr 2018 05:45:41 +0000 (07:45 +0200)] 
ebtables-translate: turn off useless compat queries

not needed as we won't be installing any rules.
So just assume kernel supports everything.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft: arptables: remove obsolete forward hook definition
Florian Westphal [Fri, 27 Apr 2018 10:53:48 +0000 (12:53 +0200)] 
nft: arptables: remove obsolete forward hook definition

Its not supported anymore as of 4.13, and it did not work
before this either (arp packets cannot be routed).
This unbreaks arptables-compat -- without this fix kernel rejects the
incoming ruleset skeleton.

filtering forwarded arp packets on a bridge can be done either via
'netdev' or 'bridge' families.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoiptables-compat: statify nft_restart()
Pablo Neira Ayuso [Tue, 24 Apr 2018 14:42:42 +0000 (16:42 +0200)] 
iptables-compat: statify nft_restart()

This function is only used from iptables/nft.c.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables-compat: handle netlink dump EINTR errors
Pablo Neira Ayuso [Tue, 24 Apr 2018 14:03:33 +0000 (16:03 +0200)] 
iptables-compat: handle netlink dump EINTR errors

Release existing list and restart in case that netlink dump hits EINTR.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoebtables-compat: add 'vlan' match extension
Florian Westphal [Tue, 10 Apr 2018 09:54:57 +0000 (11:54 +0200)] 
ebtables-compat: add 'vlan' match extension

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

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-translate: update table name on -t
Florian Westphal [Thu, 19 Apr 2018 09:44:39 +0000 (11:44 +0200)] 
ebtables-translate: update table name on -t

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-compat: add 'ip6' match extension
Florian Westphal [Thu, 19 Apr 2018 09:19:52 +0000 (11:19 +0200)] 
ebtables-compat: add 'ip6' match extension

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agolibebt_ip: fix translations for tos and icmp
Florian Westphal [Thu, 19 Apr 2018 09:00:28 +0000 (11:00 +0200)] 
libebt_ip: fix translations for tos and icmp

tos translation to dscp yielded incorrect value.
icmp inserted extra "ip" keyword, remove it.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agolibebt_ip: add icmp support
Florian Westphal [Tue, 17 Apr 2018 22:09:06 +0000 (00:09 +0200)] 
libebt_ip: add icmp support

Was added to ebtables recently, so backport this to ebt-compat.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxt-translate: quote interface names in translated output
Florian Westphal [Tue, 17 Apr 2018 22:09:05 +0000 (00:09 +0200)] 
xt-translate: quote interface names in translated output

it its good practice as interface names can be virtually any
identifier and could clash with nft keywords.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoicmp: split icmp type printing to header file
Florian Westphal [Tue, 17 Apr 2018 22:09:04 +0000 (00:09 +0200)] 
icmp: split icmp type printing to header file

libebt_ip will get icmp support soon, unify icmp name
mapping a bit so we can re-use this code from libebt_ip.c.

It doesn't seem to be too useful to move to libxtables
(as its icmp specific), so add a hedaer file for this to reduce
copy & paste needs.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-translate: add initial test cases
Florian Westphal [Fri, 13 Apr 2018 15:40:56 +0000 (17:40 +0200)] 
ebtables-translate: add initial test cases

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxt-compat: add ebtables-translate
Florian Westphal [Thu, 12 Apr 2018 09:31:31 +0000 (11:31 +0200)] 
xt-compat: add ebtables-translate

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxlate-translate: split common parts into helper
Florian Westphal [Thu, 12 Apr 2018 09:46:02 +0000 (11:46 +0200)] 
xlate-translate: split common parts into helper

7 years agoxtables-eb: export 3 functions
Florian Westphal [Fri, 13 Apr 2018 12:53:43 +0000 (14:53 +0200)] 
xtables-eb: export 3 functions

Will be used from eb-translate parser.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft-bridge: add eb-translate backend functions
Florian Westphal [Fri, 13 Apr 2018 12:49:17 +0000 (14:49 +0200)] 
nft-bridge: add eb-translate backend functions

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft-bridge: fix mac address printing
Florian Westphal [Fri, 13 Apr 2018 12:43:28 +0000 (14:43 +0200)] 
nft-bridge: fix mac address printing

Mask needs to be all-ones, else we print
<macaddr>/ff:ff:ff:ff:ff:ff

but such a mask is redundant, we can omit the mask.
ebtables does this correctly.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft: fix crash when getprotobynumber() returns 0
Florian Westphal [Fri, 13 Apr 2018 17:19:57 +0000 (19:19 +0200)] 
nft: fix crash when getprotobynumber() returns 0

This needs to first check if pent is NULL.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-compat: support intra-positioned negations
Florian Westphal [Fri, 13 Apr 2018 15:41:47 +0000 (17:41 +0200)] 
ebtables-compat: support intra-positioned negations

ebtables sitll allows intra-postitioned negations, e.g.

--ip-src ! 1.2.3.4

support this.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft-bridge: add forward declaration for struct nftnl_rule
Florian Westphal [Fri, 13 Apr 2018 13:10:27 +0000 (15:10 +0200)] 
nft-bridge: add forward declaration for struct nftnl_rule

nft-bridge.h:121:48: warning: 'struct nftnl_rule' declared inside parameter list will not be visible outside ..

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agolibebt_limit: print 'minute' and 'seconds', not 'min' and 'secs'
Florian Westphal [Fri, 13 Apr 2018 15:46:27 +0000 (17:46 +0200)] 
libebt_limit: print 'minute' and 'seconds', not 'min' and 'secs'

nft xlate needs the full name, for ebtables it makes no difference,
'minute' would work too.

Also fixup ' ' placement in xlate.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft: make nft_init self-contained
Florian Westphal [Thu, 12 Apr 2018 09:51:38 +0000 (11:51 +0200)] 
nft: make nft_init self-contained

nft_init() should rollback all changes it made during init
when something goes wrong, callers should NOT call nft_fini()
on error.

Note that this change is irrelevant at the moment, all users
call exit() on failure.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-translate: rm duplicate includes
Florian Westphal [Thu, 12 Apr 2018 09:26:59 +0000 (11:26 +0200)] 
xtables-translate: rm duplicate includes

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxt-compat: constify a few struct members
Florian Westphal [Fri, 13 Apr 2018 11:43:33 +0000 (13:43 +0200)] 
xt-compat: constify a few struct members

avoids a compiler warning in a followup patch.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoebtables-compat: add initial translations
Florian Westphal [Wed, 11 Apr 2018 08:24:37 +0000 (10:24 +0200)] 
ebtables-compat: add initial translations

add translations for ip, limit, log, mark, mark_m, nflog.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoiptables: constify option struct
Arushi Singhal [Wed, 21 Mar 2018 09:50:28 +0000 (15:20 +0530)] 
iptables: constify option struct

The struct of type option is only used to initialise a field and
is not modified anywhere.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoebtables-compat: load mark target
Florian Westphal [Tue, 10 Apr 2018 10:53:38 +0000 (12:53 +0200)] 
ebtables-compat: load mark target

Its already there but it did not work because it wasn't loaded.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoebtables-compat: don't make failing extension load fatal
Florian Westphal [Tue, 10 Apr 2018 10:54:16 +0000 (12:54 +0200)] 
ebtables-compat: don't make failing extension load fatal

We will fail later when we can't parse the option, but that
failure only happens if the is actually used.

So in some cases things will work fine even if an extension
doesn't exist.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agolibxt_comment: silence truncation warning
Florian Westphal [Fri, 30 Mar 2018 20:11:58 +0000 (22:11 +0200)] 
libxt_comment: silence truncation warning

gcc warned here:
libxt_comment.c:62 output may be truncated before the last format character [-Wformat-truncation=]
snprintf(comment, XT_MAX_COMMENT_LEN, "\"%s\"" ...

It tells us that the '"' might not fit anymore, so increase output
buffer size to make room for "" escapes too.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: only validate the xtables builtin tables
Florian Westphal [Sat, 7 Apr 2018 21:16:04 +0000 (23:16 +0200)] 
xtables-compat: only validate the xtables builtin tables

This allows xtables-compat to list all builtin tables unless one
contains nft specific expressions.

Tables that do not exist in xtables world are not printed anymore
(but a small hint is shown that such non-printable table(s) exist).

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: skip unsupported tables
Florian Westphal [Fri, 6 Apr 2018 22:44:49 +0000 (00:44 +0200)] 
xtables-compat: skip unsupported tables

Instead of not listing anything at all if an unknown table name
exists, just skip them.  Output a small comment that the listing
doesn't include the (unrecognized, nft-created) tables.

Next patch will restrict 'is this table printable in
xtables syntax' check to the "builtin" tables.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: also validate priorities and hook points match expected values
Florian Westphal [Fri, 6 Apr 2018 22:42:28 +0000 (00:42 +0200)] 
xtables-compat: also validate priorities and hook points match expected values

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat: fix snprintf truncation warnings
Florian Westphal [Sat, 7 Apr 2018 21:21:23 +0000 (23:21 +0200)] 
xtables-compat: fix snprintf truncation warnings

proto is u16 in the data structure, so this gave:
nft-ipv6.c:422:44: warning: '__builtin___snprintf_chk' output may be truncated before the last format character [-Wformat-truncation=]

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: CLUSTERIP: do not allow --local-node 0
Pablo Neira Ayuso [Fri, 30 Mar 2018 10:32:38 +0000 (12:32 +0200)] 
extensions: CLUSTERIP: do not allow --local-node 0

Makes no sense, fail in such a case.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: CLUSTERIP: add tests
Pablo Neira Ayuso [Wed, 28 Mar 2018 14:19:27 +0000 (16:19 +0200)] 
extensions: CLUSTERIP: add tests

Add a few tests to catch regressions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables: add xtables-translate.8 manpage
Arturo Borrero Gonzalez [Fri, 16 Mar 2018 18:24:36 +0000 (19:24 +0100)] 
iptables: add xtables-translate.8 manpage

This new manpage describes how to operate the translation tools for nftables.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: libxt_bpf: Fix build with old kernel versions
Hauke Mehrtens [Tue, 27 Feb 2018 15:56:55 +0000 (16:56 +0100)] 
extensions: libxt_bpf: Fix build with old kernel versions

In kernel 3.18 the union bpf_attr does not have a pathname attribute and
BPF_OBJ_GET is also not defined in these versions.
This was added in Linux commit b2197755b263 ("bpf: add support for
persistent maps/progs"). Check for the BPF_FS_MAGIC define which was
also added in this Linux commit and only activate this code in case we
find that define.

This fixes a build problem with Linux 3.18.
Netfilter bug: #1231

Fixes: f17f9ace8a8 ("extensions: libxt_bpf: support ebpf pinned objects")
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextenstions: ecn: add tcp ecn/cwr translation
Florian Westphal [Sun, 18 Feb 2018 08:49:16 +0000 (09:49 +0100)] 
extenstions: ecn: add tcp ecn/cwr translation

nft can match tcp flags, so add ece/cwr translation.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: add tests for comp match options
Harsha Sharma [Tue, 6 Feb 2018 18:03:30 +0000 (23:33 +0530)] 
extensions: add tests for comp match options

This patch adds test for ipcomp flow match specified by its SPI value
and move tests for ipcomp protocol to libxt_policy.t

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoxtables-compat-multi.c: Allow symlink of ebtables
Duncan Roe [Sun, 25 Feb 2018 07:14:00 +0000 (18:14 +1100)] 
xtables-compat-multi.c: Allow symlink of ebtables

This patch allows one to force a subsystem that one does not wish to modify
(e.g. libvirt) to use the ebtables compatibility layer.

ebtables-compat was already a symlink to xtables-compat-multi but ebtables was a
stand-alone program. So one could move it out of the way before making the
symlink as below:

 lrwxrwxrwx 1 root root       20 Feb 24 11:03 ebtables -> xtables-compat-multi
 -rwxr-xr-x 1 root root    75176 Feb 24 11:03 ebtables.orig

With this patch, kernel modules ebtable_filter & ebtables are no longer loaded.

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables: add xtables-compat.8 manpage
Arturo Borrero Gonzalez [Sun, 25 Feb 2018 18:07:41 +0000 (19:07 +0100)] 
iptables: add xtables-compat.8 manpage

Copied back from the downstream Debian package.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: connmark: remove non-working translation
Florian Westphal [Mon, 19 Feb 2018 11:30:45 +0000 (12:30 +0100)] 
extensions: connmark: remove non-working translation

... and return 0 so output reflects that no translation was performed.

iptables-translate -A I -j CONNMARK --save-mark --mask 0xff
nft # -A I -j CONNMARK --save-mark --mask 0xff

The translation that was performed:
nft add rule ip mangle PREROUTING counter meta mark set ct mark and 0xff

will clear (zero) most bits:
  [ meta load mark => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0x000000ff ) ^ 0x00000000 ]
  [ ct set mark with reg 1 ]

The xtables module however does this:

newmark = (ct->mark & ~info->ctmask) ^
           (skb->mark & info->nfmask);

I.e., for ctmark mask defines what to clear,
for nfmark what to keep, i.e. we're supposed to only alter the lower
bits of the ctmark.

nftables can't do this at the moment because bitwise operator RHS
requires immediate values.

same is true for 'restore'.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoextensions: prefer plain 'set' over 'set mark and'
Florian Westphal [Mon, 19 Feb 2018 09:57:18 +0000 (10:57 +0100)] 
extensions: prefer plain 'set' over 'set mark and'

adding a test case for MARK --set-mark 0 fails with
exp: nft add rule ip mangle OUTPUT counter meta mark set 0x0
res: nft add rule ip mangle OUTPUT counter meta mark set mark and 0x0

This translation isn't wrong, but unneccessarily complex, so
change order to first check if mask bits are all ones.

In that case we can simply use an immediate value without
need for logical operators.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoxtables-compat-restore: use correct hook priorities
Florian Westphal [Sat, 17 Feb 2018 10:46:54 +0000 (11:46 +0100)] 
xtables-compat-restore: use correct hook priorities

Currently defaulted to 0, it should reflect the one from xtables
to get the right ordering.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoiptables 1.6.2 release v1.6.2
Pablo Neira Ayuso [Fri, 2 Feb 2018 15:37:25 +0000 (16:37 +0100)] 
iptables 1.6.2 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agopolicy: add nft translation for simple policy none/strict use case
Florian Westphal [Sat, 27 Jan 2018 10:09:46 +0000 (11:09 +0100)] 
policy: add nft translation for simple policy none/strict use case

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: xlate-test: no need to require superuser privileges
Florian Westphal [Fri, 26 Jan 2018 22:31:48 +0000 (23:31 +0100)] 
tests: xlate-test: no need to require superuser privileges

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: hashlimit: remove space before burst in translation to nft
Pablo Neira Ayuso [Mon, 29 Jan 2018 14:22:02 +0000 (15:22 +0100)] 
extensions: hashlimit: remove space before burst in translation to nft

Fixes the following test:

 # python xlate-test.py extensions/libxt_hashlimit.txlate
 extensions/libxt_hashlimit.txlate: Fail
 src: iptables-translate -A OUTPUT -m tcp -p tcp --dport 443 -m hashlimit --hashlimit-upto 300 --hashlimit-burst 15 --hashlimit-mode srcip,dstip --hashlimit-name https --hashlimit-htable-expire 300000 -m state --state NEW -j DROP
 exp: nft add rule ip filter OUTPUT tcp dport 443 meter https { ip daddr . ip saddr timeout 300s limit rate 300/second burst 15 packets} ct state new  counter drop
 res: nft add rule ip filter OUTPUT tcp dport 443 meter https { ip daddr . ip saddr timeout 300s limit rate 300/second  burst 15 packets} ct state new  counter drop

1 test file, 2 tests, 1 tests passed, 1 tests failed, 0 errors

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: hashlimit: Rename 'flow table' keyword to meter
shyam saini [Fri, 26 Jan 2018 18:41:16 +0000 (00:11 +0530)] 
extensions: hashlimit: Rename 'flow table' keyword to meter

After nft v0.8.1 "flow table" is renamed as meter.
This should reflect in iptables to nftables translation.

Before this patch:
$ iptables-translate -A INPUT -m tcp -p tcp --dport 80 -m hashlimit
--hashlimit-above 200/sec --hashlimit-mode srcip,dstport
--hashlimit-name http1 -j DROP

nft add rule ip filter INPUT tcp dport 80 flow table http1 { tcp dport .
ip saddr limit rate over 200/second } counter drop

After this patch:
$ iptables-translate -A INPUT -m tcp -p tcp --dport 80 -m hashlimit
--hashlimit-upto 200 --hashlimit-mode srcip --hashlimit-name http3
--hashlimit-srcmask 24 -j DROP

nft add rule ip filter INPUT tcp dport 80 meter http3 { ip saddr and
255.255.255.0 limit rate 200/second } counter drop

Signed-off-by: shyam saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: Add test for cluster nft translation
Shyam Saini [Tue, 16 Jan 2018 16:20:13 +0000 (21:50 +0530)] 
extensions: Add test for cluster nft translation

This patch adds test cases for iptables to nft translation of cluster match
This adds all test cases including corner cases.

Run these test cases like:

$ ./xlate-test.py extensions/libxt_cluster.txlate

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: ip6t_{S,D}NAT: add more tests
Thierry Du Tre [Tue, 16 Jan 2018 15:40:32 +0000 (16:40 +0100)] 
extensions: ip6t_{S,D}NAT: add more tests

Signed-off-by: Thierry Du Tre <thierry@dtsystems.be>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: ip6t_{S,D}NAT: multiple to-dst/to-src arguments not reported
Thierry Du Tre [Tue, 16 Jan 2018 12:44:37 +0000 (13:44 +0100)] 
extensions: ip6t_{S,D}NAT: multiple to-dst/to-src arguments not reported

This patch is fixing the detection of multiple '--to-destination' in a
DNAT rule and '--to-source' in SNAT rule for IPv6.  Currently, when
defining multiple values for these, only the last will be used and
others ignored silently.

The checks for (cb->xflags & F_X_TO_[DEST/SRC]) always fails because the
flags are never set before.  It seems to be a copy-paste artefact since
introduction of the IPv6 DNAT/SNAT extensions based on IPv4 code.

I also removed the kernel_version checks because they seem useless.
Extensions for IPv6 DNAT/SNAT are using xt_target with revision 1.  That
seems only added since kernel version 3.7-rc1 and therefore the check
for > v2.6.10 will always return true.  The check is probably also
coming from the IPv4 copy-paste.

Add tests to cover this too, including the IPv4 side.

Signed-off-by: Thierry Du Tre <thierry@dtsystems.be>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: libxt_cluster: Add translation to nft
Shyam Saini [Mon, 15 Jan 2018 05:59:28 +0000 (11:29 +0530)] 
extensions: libxt_cluster: Add translation to nft

Add translation for cluster to nft

$ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster
--cluster-total-nodes 7 --cluster-local-node 5 --cluster-hash-seed
0xdeadbeef -j MARK --set-mark 0xffff

nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr
mod 7 seed 0xdeadbeef eq 5 meta pkttype set host counter meta mark set
0xffff

$ sudo iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster
--cluster-total-nodes 7 --cluster-local-nodemask 5 --cluster-hash-seed
0xdeadbeef -j MARK --set-mark 0xffff

nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr
mod 7 seed 0xdeadbeef { 0, 2 } meta pkttype set host counter meta
mark set 0xffff

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: add support for 'srh' match
Ahmed Abdelsalam [Thu, 11 Jan 2018 17:12:41 +0000 (18:12 +0100)] 
extensions: add support for 'srh' match

This patch adds a new exetension to iptables to supprt 'srh' match
The implementation considers revision 7 of the SRH draft.
https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-07

Signed-off-by: Ahmed Abdelsalam <amsalam20@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: hashlimit: fix incorrect burst in translations
Pablo Neira Ayuso [Wed, 3 Jan 2018 14:36:14 +0000 (15:36 +0100)] 
extensions: hashlimit: fix incorrect burst in translations

iptables-translate -A INPUT -m tcp -p tcp --dport 80 -m hashlimit --hashlimit-above 200kb/s --hashlimit-burst 1mb --hashlimit-mode srcip,dstport --hashlimit-name http2 --hashlimit-htable-expire 3000 -j DROP

shows:

nft add rule ip filter INPUT tcp dport 80 flow table http2 { tcp dport . ip saddr timeout 3s limit rate over 200 kbytes/second burst 1 mbytes burst 6 packets} counter drop

which prints burst twice, this is not correct.

Reported-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: libxt_hashlimit: Do not print default timeout and burst
Harsha Sharma [Thu, 28 Dec 2017 07:28:33 +0000 (12:58 +0530)] 
extensions: libxt_hashlimit: Do not print default timeout and burst

Do not print timeout and burst in case default values are used.
For e.g.
iptables-translate -A INPUT -m tcp -p tcp --dport 80 -m hashlimit
--hashlimit-above 200/sec --hashlimit-mode srcip,dstport
--hashlimit-name http1 -j DROP

nft add rule ip filter INPUT tcp dport 80 flow table http1 { tcp dport .
ip saddr limit rate over 200/second } counter drop

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: Add macro _DEFAULT_SOURCE.
Varsha Rao [Thu, 21 Dec 2017 03:35:45 +0000 (09:05 +0530)] 
extensions: Add macro _DEFAULT_SOURCE.

Define _DEFAULT_SOURCE as _BSD_SOURCE is deprecated.
https://sourceware.org/glibc/wiki/Release/2.20#Packaging_Changes

This patch fixes the following warning:

warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use
_DEFAULT_SOURCE" [-Wcpp]
 # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use
 # _DEFAULT_SOURCE"

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables: Remove const qualifier from struct option.
Varsha Rao [Thu, 21 Dec 2017 03:35:45 +0000 (09:05 +0530)] 
iptables: Remove const qualifier from struct option.

As opts is reassigned multiple times, it cannot be made constant.
So remove const qualifier from structure option. This patch fixes the
following warning:

warning: initialization discards ‘const’ qualifier from pointer target
type [-Wdiscarded-qualifiers]
  .orig_opts = original_opts,

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables: masquerade: add randomize-full support
Max Laverse [Sun, 3 Dec 2017 21:29:51 +0000 (22:29 +0100)] 
iptables: masquerade: add randomize-full support

Signed-off-by: Max Laverse <max@laverse.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables: patch to correct linker flag sequence
Yogesh Prasad [Wed, 29 Nov 2017 06:10:54 +0000 (00:10 -0600)] 
iptables: patch to correct linker flag sequence

Description
This patch will correct the sequence of -pie and -shared options.
 When used together, -pie should be provided to the linker before
 -shared. If -pie is provided after -shared, the linker throws an
 error shown below as example.

-------------------------------------------------------------------------
/host/lib/gcc/powerpc-buildroot-linux-gnu/6.4.0/../../../..
/powerpc-buildroot-linux-gnu/bin/ld: BFD (GNU Binutils) 2.28.1
 assertion fail elf32-ppc.c:8923
collect2: error: ld returned 1 exit status
        + ./libxt_SYNPROXY.man
make[4]: *** [libxt_TCPOPTSTRIP.so] Error 1
        + ./libip6t_mh.man
/host/powerpc-buildroot-linux-gnu/sysroot/usr/lib/Scrt1.o:(.data+0x4):
 undefined reference to `main'
/host/lib/gcc/powerpc-buildroot-linux-gnu      + ./libxt_TCPMSS.man
/6.4.0/../../../../powerpc-buildroot-linux-gnu/bin/ld:
 BFD (GNU Binutils) 2.28.1 assertion fail elf32-ppc.c:8923
collect2: error: ld returned 1 exit status
-------------------------------------------------------------------------

Signed-off-by: Yogesh Prasad <yogesh.prasad@rockwellcollins.com>
Signed-off-by: Matt Weber <matthew.weber@rockwellcollins.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: libxt_tcpmss: Add test case for invalid ranges.
Varsha Rao [Thu, 30 Nov 2017 13:48:06 +0000 (19:18 +0530)] 
extensions: libxt_tcpmss: Add test case for invalid ranges.

This patch adds test case for invalid MSS range.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables: xtables-eb: Remove const qualifier from struct option
Varsha Rao [Thu, 30 Nov 2017 13:48:05 +0000 (19:18 +0530)] 
iptables: xtables-eb: Remove const qualifier from struct option

As opts is reassigned multiple times, it cannot be made constant.
So remove const qualifier from structure option. This patch fixes the
following warning.

xtables-eb.c: In function ‘ebt_load_match_extensions’:
xtables-eb.c:653:7: warning: assignment discards ‘const’ qualifier
from pointer target type
  opts = ebt_original_options;

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoiptables: extensions: Fix MARK target help
Mart Frauenlob [Mon, 27 Nov 2017 15:18:43 +0000 (16:18 +0100)] 
iptables: extensions: Fix MARK target help

A typo in the help output of: iptables -j MARK -h.

Signed-off-by: Mart Frauenlob <mart.frauenlob@chello.at>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agolibxt_sctp: fix array out of range in print_chunk
huaibin Wang [Mon, 13 Nov 2017 13:27:54 +0000 (14:27 +0100)] 
libxt_sctp: fix array out of range in print_chunk

For chunk type ASCONF, ASCONF_ACK and FORWARD_TSN, sctp_chunk_names[].chunk_type
is not equal to the corresponding index in sctp_chunk_names[]. Using this field
leads to a segmentation fault (index out of range).

Example
$ iptables -A INPUT -p sctp --chunk-type all ASCONF,ASCONF_ACK,FORWARD_TSN -j ACCEPT
$ iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
Segmentation fault

Signed-off-by: huaibin Wang <huaibin.wang@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoextensions: add tests for ipcomp protocol
Harsha Sharma [Mon, 23 Oct 2017 04:23:16 +0000 (09:53 +0530)] 
extensions: add tests for ipcomp protocol

This patch adds test for ipcomp protocol.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: xlate: print output in same way as nft-test.py
Harsha Sharma [Sun, 22 Oct 2017 12:49:09 +0000 (18:19 +0530)] 
tests: xlate: print output in same way as nft-test.py

Print errors and total no. of tests, tests passed, failed and errors for
testfile argument
Remove option "--all"
Print file names for which all tests are passed with OK
For e.g -
sudo ./xlate-test.py
generic.txlate: OK
libip6t_DNAT.txlate: OK
...
libxt_TCPMSS.txlate: Fail
src: iptables-translate -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j
TCPMSS --clamp-mss-to-pmtu
exp: nft add rule ip filter FORWARD tcp flags & (syn|rst) == syn counter
tcp option maxseg size set rt mtu
res: nft # -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS
--clamp-mss-to-pmtu
...
libxt_connlabel.txlate: Error: iptables-translate failure
iptables-translate v1.6.1: Couldn't load match `connlabel':No such file
or directory
...
64 test files, 246 tests, 242 tests passed, 2 tests failed, 2 errors

sudo ./xlate-test.py extensions/libxt_iprange.txlate
1 test file, 5 tests, 5 tests passed, 0 tests failed, 0 errors

sudo ./xlate-test.py extensions/libxt_connlabel.txlate
extensions/libxt_connlabel.txlate: Error: iptables-translate failure
iptables-translate v1.6.1: Couldn't load match `connlabel':No such file
or directory
...
1 test file, 2 tests, 0 tests passed, 0 tests failed, 2 errors

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agolibxt_recent: Remove ineffective checks for info->name
Phil Sutter [Fri, 20 Oct 2017 11:24:36 +0000 (13:24 +0200)] 
libxt_recent: Remove ineffective checks for info->name

In struct xt_recent_mtinfo{,_v1}, field 'name' is an array, not a
pointer. So there is no point in comparing it against NULL. Changing the
check to make sure it's content is not an empty string is pointless
either, since a non-empty default string is used and the argument parser
will refuse empty strings as --name argument. So simply get rid of the
checks altogether.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>