]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
10 years agoebtables-compat: fix segfault in rules w/o target
Arturo Borrero [Mon, 5 Jan 2015 14:28:46 +0000 (15:28 +0100)] 
ebtables-compat: fix segfault in rules w/o target

This patch fixes a segfault in rules without target.

Now, these two rules are allowed:

% ebtables-compat -A FORWARD -p 0x0600 -j CONTINUE
% ebtables-compat -A FORWARD -p 0x0600

And both are printed:

Bridge chain: FORWARD, entries: 1, policy: ACCEPT
-p 0x600 -j CONTINUE

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoebtables-compat: fix printing of extension
Arturo Borrero [Fri, 26 Dec 2014 12:49:52 +0000 (13:49 +0100)] 
ebtables-compat: fix printing of extension

This patch fix printing of ebt extensions:

% sudo ebtables-compat -L
[...]
Bridge chain: FORWARD, entries: 1, policy: ACCEPT
--802_3-type 0x0012 -j ACCEPT
[...]

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoebtables-compat: fix counter listing
Arturo Borrero [Tue, 23 Dec 2014 12:24:26 +0000 (13:24 +0100)] 
ebtables-compat: fix counter listing

With this patch:

% sudo ebtables-compat -L --Lc
Bridge table: filter

Bridge chain: INPUT, entries: 0, policy: ACCEPT
-j ACCEPT , pcnt = 123 -- bcnt = 123

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoextensions: add ebt 802_3 extension
Arturo Borrero [Wed, 17 Dec 2014 11:06:56 +0000 (12:06 +0100)] 
extensions: add ebt 802_3 extension

This patch adds the first ebtables extension to ebtables-compat.
The original 802_3 code is adapted to the xtables environment.

I tried to mimic as much as possible the original ebtables code paths.

With this patch, ebtables-compat is able to send the 802_3 match to the kernel,
but the kernel-to-userspace path is not tested and should be adjusted
in follow-up patches.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables: xtables-eb: fix renaming of chains
Arturo Borrero [Mon, 24 Nov 2014 18:43:05 +0000 (19:43 +0100)] 
iptables: xtables-eb: fix renaming of chains

Renaming of chains is not working. and ebtables-compat gets:
 libnftnl: attribute 0 assertion failed in chain.c:159

This patch brings back the parser code of the original ebtables tool:
 http://git.netfilter.org/ebtables.old-history/tree/userspace/ebtables2/ebtables.c#n652

I adapted the original parser code to fit in the new environment. Also tried to
keep original error messages as much as possible.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables: xtables-eb: user-defined chains default policy is always RETURN
Arturo Borrero [Mon, 24 Nov 2014 09:52:04 +0000 (10:52 +0100)] 
iptables: xtables-eb: user-defined chains default policy is always RETURN

The RETURN default policy is mandatory in user-defined chains.
Builtin chains must have one of ACCEPT or DROP.

So, with this patch, ebtables-compat ends with:

Command:                             Result:

-L                                   Always RETURN for user-defined chains
-P builtin RETURN                    Policy RETURN only allowed for user defined chains
-P builtin ACCEPT|DROP               ok
-P userdefined RETURN|ACCEPT|DROP    Policy XYZ not allowed for user defined chains
-N userdefined                       ok
-N userdefined -P RETURN|ACCEPT|DROP Policy XYZ not allowed for user defined chains

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoebtables-compat: build ebtables extensions
Giuseppe Longo [Mon, 10 Nov 2014 19:03:08 +0000 (20:03 +0100)] 
ebtables-compat: build ebtables extensions

This permits to build extensions for ebtables-compat layer.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables: xtables-eb: delete extra 'policy' printf
Arturo Borrero [Mon, 17 Nov 2014 11:09:33 +0000 (12:09 +0100)] 
iptables: xtables-eb: delete extra 'policy' printf

This message doesn't exist in the original ebtables tool.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonft-bridge: fix inversion of builtin matches
Arturo Borrero [Wed, 12 Nov 2014 16:10:25 +0000 (17:10 +0100)] 
nft-bridge: fix inversion of builtin matches

This patch fixes inversion of builtin matches by updating the use of add_*()
functions and using nft_invflags2cmp() as well.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonft-bridge: fix printing of inverted protocols, addresses
Arturo Borrero [Sat, 8 Nov 2014 21:40:37 +0000 (22:40 +0100)] 
nft-bridge: fix printing of inverted protocols, addresses

Previous to this patch, no '!' is printed in payload comparisions.
This patch solves it, so we can print for example inverted protocols:

 % ebtables-compat -L
[...]
-p ! 0x800 -j ACCEPT

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoebtables-compat: fix print_header
Giuseppe Longo [Thu, 16 Oct 2014 14:29:51 +0000 (16:29 +0200)] 
ebtables-compat: fix print_header

This prints the header like ebtables.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoebtables-compat: use ebtables_command_state in bootstrap code
Pablo Neira Ayuso [Thu, 9 Oct 2014 18:11:16 +0000 (20:11 +0200)] 
ebtables-compat: use ebtables_command_state in bootstrap code

And introduce fake ebt_entry.

This gets the code in sync in other existing compat tools. This
will likely allow to consolidate common infrastructure.

This code is still quite experimental.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonft: bootstrap ebtables-compat
Pablo Neira Ayuso [Thu, 9 Oct 2014 13:02:02 +0000 (15:02 +0200)] 
nft: bootstrap ebtables-compat

This patch bootstraps ebtables-compat, the ebtables compatibility
software upon nf_tables.

[ Original patches:

  http://patchwork.ozlabs.org/patch/395544/
  http://patchwork.ozlabs.org/patch/395545/
  http://patchwork.ozlabs.org/patch/395546/

I have also forward port them on top of the current git HEAD, otherwise
compilation breaks.

This bootstrap is experimental, this still needs more work. --Pablo ]

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonft-compat: create a separated object update type to rename chains
Arturo Borrero [Mon, 24 Nov 2014 10:12:15 +0000 (11:12 +0100)] 
nft-compat: create a separated object update type to rename chains

This patch adds an explicit object update type to rename chains, so we avoid
calling the nf_tables API with NLM_F_EXCL.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: kill add_*() invflags parameter
Arturo Borrero [Wed, 12 Nov 2014 12:00:12 +0000 (13:00 +0100)] 
iptables-compat: kill add_*() invflags parameter

Let's kill the invflags parameter and use directly NFT_CMP_[N]EQ.
The caller must calculate which kind of cmp operation requires.

BTW, this patch solves absence of inversion in some arptables-compat
builtin matches. Thus, translating arptables inv flags is no longer needed.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoextensions: libxt_TEE: Trim kernel struct to allow deletion
Loganaden Velvindron [Sun, 9 Nov 2014 14:15:05 +0000 (06:15 -0800)] 
extensions: libxt_TEE: Trim kernel struct to allow deletion

Correct trimming of userspacesize to fix deletions.

Fixes: Bugzilla #884.
The rule having TEE target with '--oif' option cannot be deleted by iptables command.

  $ iptables -I INPUT -i foo -j TEE --gateway x.x.x.x --oif bar
  $ iptables -D INPUT -i foo -j TEE --gateway x.x.x.x --oif bar
  iptables: No chain/target/match by that name.

Signed-off-by: Loganaden Velvindron <logan@elandsys.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: homogenize error messages with 'R' option
Ana Rey [Wed, 5 Nov 2014 15:46:34 +0000 (16:46 +0100)] 
iptables-compat: homogenize error messages with 'R' option

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

 # iptables -R INPUT 23 -s 192.168.2.140 -j ACCEPT
iptables: Index of replacement too big.
 # iptables-compat -R INPUT 23 -s 192.168.2.140 -j ACCEPT
iptables: No chain/target/match by that name.

Now, iptables-compat shows the same error message than iptables in
this case.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoMerge branch 'ipset'
Pablo Neira Ayuso [Tue, 4 Nov 2014 23:57:12 +0000 (00:57 +0100)] 
Merge branch 'ipset'

This provides the ipset skbinfo extension.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoextensions: devgroup: fix showing and saving of dst-group
Ana Rey [Thu, 30 Oct 2014 16:26:26 +0000 (17:26 +0100)] 
extensions: devgroup: fix showing and saving of dst-group

Closes bugzilla: https://bugzilla.netfilter.org/show_bug.cgi?id=985

The --dst-group parameter in devgroup extensions lists and saves
incorrectly its value. --dst-group always shows "0x0/0x0".

This is an example:

 # iptables -I FORWARD -m devgroup --dst-group 200 -j ACCEPT

 # iptables -L FORWARD
 Chain FORWARD (policy ACCEPT)
 target     prot opt source               destination
 ACCEPT     all  --  anywhere             anywhere     src-group 0x64 dst-group 0x0/0x0

 # iptables -S FORWARD
 -P FORWARD ACCEPT
 -A FORWARD -m devgroup --dst-group 0x0/0x0 -j ACCEPT

Reporte-by: Axinchan <axinchan@cnrouter.com>
Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: homogenize error messages
Ana Rey [Thu, 30 Oct 2014 08:31:56 +0000 (09:31 +0100)] 
iptables-compat: homogenize error messages

There are some differences between error messages in iptables and
iptables-compat:

 # iptables -C INPUT -s 192.168.2.102 -j ACCEPT
iptables: Bad rule (does a matching rule exist in that chain?).
 # iptables-compat -C INPUT -s 192.168.2.102 -j ACCEPT
iptables: No chain/target/match by that name.

 # iptables -N new_chain
 # iptables -N new_chain
iptables: Chain already exists.
 # iptables-compat -N new_chain
 # iptables-compat -N new_chain
iptables: File exists.

Now, iptables-compat shows the same error messages than iptables in
those cases.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agolibxtables: move some code to avoid cautions in vfork man page
Dan Wilder [Fri, 24 Oct 2014 22:51:59 +0000 (00:51 +0200)] 
libxtables: move some code to avoid cautions in vfork man page

Running iptables-restore on an embedded platform containing no modprobe program, the following lines in xtables.c lead to corrupted stack frame:

 357     switch (vfork()) {
 358     case 0:
 359         argv[0] = (char *)modprobe;
 360         argv[1] = (char *)modname;
 361         if (quiet) {
 362             argv[2] = "-q";
 363             argv[3] = NULL;
 364         } else {
 365             argv[2] = NULL;
 366             argv[3] = NULL;
 367         }
 368         execv(argv[0], argv);
 369
 370         /* not usually reached */
 371         exit(1);

modprobe pointed to a non-existant program /sbin/modprobe, so execv()
always failed.  Not a problem in itself on our platform, as the kernel
modules are pre-loaded before iptables-restore is run, but it took a
bit of headscratching to track this down, as a stack frame was
corrupted, leading to failures quite a while after the function
containing this code had returned!

Relevant caution in man 2 vfork:

    "The vfork() function has the same effect as fork(2), except that
    the behavior is undefined if the process created by vfork() either
    modifies any data ... or calls any other function before
    successfully calling _exit(2) or one of the exec(3) family of
    functions."

Apparently this has not been a problem for us in earlier versions of
glibc, maybe because vfork was more like fork, maybe because the
stack corruption was innocuous.  Ours is a corner case anyway, as
it might not have been a problem had modprobe existed or had
modprobe been a symlink to /bin/true.  But it seems odd to disregard
man page cautions, and our problem goes away if they are heeded.

Signed-off-by: Florian Westphal <fw@strlen.de>
10 years agoiptables-compat: fix empty chains after first invocation of iptables-compat -L
Pablo Neira Ayuso [Thu, 23 Oct 2014 11:30:36 +0000 (13:30 +0200)] 
iptables-compat: fix empty chains after first invocation of iptables-compat -L

 # iptables-compat -L
 # iptables-compat -L
 Chain INPUT (policy ACCEPT)
 target     prot opt source               destination

 Chain FORWARD (policy ACCEPT)
 target     prot opt source               destination

 Chain OUTPUT (policy ACCEPT)
 target     prot opt source               destination

Note that the second (and follow up) invocations after the first one
display the chains.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: assume chain policy NF_ACCEPT when creating built-in chains
Pablo Neira Ayuso [Thu, 23 Oct 2014 11:21:27 +0000 (13:21 +0200)] 
iptables-compat: assume chain policy NF_ACCEPT when creating built-in chains

Newly created (emulated) xt built-in chain have to use NF_ACCEPT. Remove
extra unused chain parameter and rename nft_chain_builtin_init to
nft_xt_builtin_init too.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: statify unused built-in table/chain functions
Pablo Neira Ayuso [Thu, 23 Oct 2014 10:53:59 +0000 (12:53 +0200)] 
iptables-compat: statify unused built-in table/chain functions

The functions that allows you to create built-in table and chains are
required out of the scope of nft.c

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: fix chain policy reset with iptables -L -n
Pablo Neira Ayuso [Thu, 23 Oct 2014 10:42:11 +0000 (12:42 +0200)] 
iptables-compat: fix chain policy reset with iptables -L -n

Initialize built-in tables/chains if they don't exists, otherwise
simply skip.

This avoids the chain policy reset to NF_ACCEPT by when you call
iptables -L -n.

Reported-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Tested-by: Ana Rey <anarey@gmail.com>
10 years agonft-ipv46: replace offset var with ctx->payload.offset
Giuseppe Longo [Thu, 16 Oct 2014 14:29:53 +0000 (16:29 +0200)] 
nft-ipv46: replace offset var with ctx->payload.offset

The offset variable (undefined) is passed to DEBUGP function,
so you get a compilation error if you try to build iptables
with debug enabled

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonft: fix syntax error in nft_parse_cmp()
Giuseppe Longo [Thu, 16 Oct 2014 14:29:52 +0000 (16:29 +0200)] 
nft: fix syntax error in nft_parse_cmp()

This fixes a syntax error, remove ; in an if statement

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agorefresh nf_tables.h cached copy
Pablo Neira Ayuso [Wed, 1 Oct 2014 19:10:47 +0000 (21:10 +0200)] 
refresh nf_tables.h cached copy

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoarptables-compat: remove save code
Pablo Neira Ayuso [Thu, 9 Oct 2014 11:07:05 +0000 (13:07 +0200)] 
arptables-compat: remove save code

There is not native arptables-save. The original author provides
perl scripts to implement arptables-save and arptables-restore.
We should use them to mimic arptables behaviour.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoarptables-compat: get output in sync with arptables -L -n --line-numbers
Pablo Neira Ayuso [Thu, 9 Oct 2014 10:45:42 +0000 (12:45 +0200)] 
arptables-compat: get output in sync with arptables -L -n --line-numbers

 # arptables-compat -L -n --line-numbers
 Chain INPUT (policy ACCEPT)
 num  target     prot opt source               destination <--

This header is not shown by arptables.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoarptables-compat: allow to not specify a target
Pablo Neira Ayuso [Wed, 8 Oct 2014 20:17:51 +0000 (22:17 +0200)] 
arptables-compat: allow to not specify a target

arptables allows this:

 # arptables -I INPUT

however, arptables-compat says:

 arptables v1.4.21: No target provided or initalization failed
 Try `arptables -h' or 'arptables --help' for more information.

the compat utility must mimic the same behaviour.

Fix this by introducing the arptables_command_state abstraction that
is already available in ip{6}tables.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoarptables-compat: fix missing error reporting
Pablo Neira Ayuso [Wed, 8 Oct 2014 20:17:50 +0000 (22:17 +0200)] 
arptables-compat: fix missing error reporting

# arptables-compat -D INPUT -j ACCEPT
 arptables: Bad rule (does a matching rule exist in that chain?)

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: nft: fix error reporting
Pablo Neira Ayuso [Wed, 8 Oct 2014 20:17:49 +0000 (22:17 +0200)] 
iptables-compat: nft: fix error reporting

This fixes

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

 # iptables-compat -N test4345
 # iptables-compat -N test4345
 iptables: File exists.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: nft: fix user chain addition, deletion and rename
Pablo Neira Ayuso [Wed, 8 Oct 2014 20:17:48 +0000 (22:17 +0200)] 
iptables-compat: nft: fix user chain addition, deletion and rename

Add the glue code to use the chain batching for user chain commands.

Reported-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoMerge branch 'tests'
Pablo Neira Ayuso [Wed, 1 Oct 2014 08:44:49 +0000 (10:44 +0200)] 
Merge branch 'tests'

This merges the iptables-test.py script and the corresponding
test files.

10 years agoiptables-compat: get rid of error reporting via perror
Pablo Neira Ayuso [Tue, 30 Sep 2014 17:40:18 +0000 (19:40 +0200)] 
iptables-compat: get rid of error reporting via perror

The compat layer should report problems in the iptables way instead.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: fix use after free in the batch send path
Pablo Neira Ayuso [Tue, 30 Sep 2014 16:12:34 +0000 (18:12 +0200)] 
iptables-compat: fix use after free in the batch send path

Release the batch pages once they have been sent via sendmsg().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: nft: use nft_batch_begin and nft_batch_end from libnftnl
Pablo Neira Ayuso [Tue, 30 Sep 2014 15:52:15 +0000 (17:52 +0200)] 
iptables-compat: nft: use nft_batch_begin and nft_batch_end from libnftnl

Use the existing functions in libnftnl to begin and end a batch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoiptables-compat: fix address prefix
Pablo Neira Ayuso [Tue, 30 Sep 2014 11:07:18 +0000 (13:07 +0200)] 
iptables-compat: fix address prefix

This patch fixes:

 # iptables-compat -I INPUT -s 1.2.3.0/24

generates this bytecode:

ip filter INPUT 20
  [ payload load 4b @ network header + 12 => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0x00ffffff ) ^ 0x00000000 ]
  [ cmp eq reg 1 0x00030201 ]
  [ counter pkts 0 bytes 0 ]

and it displays:

 # iptables-compat-save
...
-A INPUT -s 1.2.3.0/24

ip6tables-compat and arptables-compat are also fixed.

This patch uses the new context structure to annotate payload, meta
and bitwise, so it interprets the cmp expression based on the context.
This provides a rudimentary way to delinearize the iptables-compat
rule-set, but it should be enough for the built-in xtables selectors
since we still use the xtables extensions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoextensions: libxt_devgroup: Fix the path of the group mappings file
Ana Rey [Thu, 18 Sep 2014 11:06:42 +0000 (13:06 +0200)] 
extensions: libxt_devgroup: Fix the path of the group mappings file

Use "/etc/iproute2/group" as the default path to the mapping file
instead of "/etc/iproute2/group_map".

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoxtables: SET target: Add mapping of meta informations (skbinfo ipset extension)
Anton Danilov [Tue, 2 Sep 2014 10:15:53 +0000 (14:15 +0400)] 
xtables: SET target: Add mapping of meta informations (skbinfo ipset extension)

This feature add support of mapping metainformation to packets like nftables maps or
ipfw tables. Currently we can map firewall mark, tc priority and hardware NIC queue.
Usage of this functionality allowed only from mangle table. We can map tc priority
only in OUTPUT/FORWARD/POSTROUTING chains because it rewrite by route decision.
If entry doesn't exist in the set nothing of fields changed.

Example of classify by destination address:
iptables -t mangle -A POSTROUTING -o eth0 -j SET --map-set DST2CLASS dst --map-prio

Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
10 years agoextensions: libxt_connlabel: do not open config file from _init hook
Florian Westphal [Fri, 5 Sep 2014 18:45:56 +0000 (20:45 +0200)] 
extensions: libxt_connlabel: do not open config file from _init hook

else, static builds will print this for every iptables invocation,
even 'iptables -L'.  Delay open until we need to translate a mapping.

Reported-by: Thomas De Schampheleire <patrickdepinguin@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
10 years agolibxtables: fix two off-by-one memory corruption bugs
Ronald Wahl [Thu, 4 Sep 2014 22:54:48 +0000 (00:54 +0200)] 
libxtables: fix two off-by-one memory corruption bugs

The LSB of xtables_pending_matches was overwritten with zero
that lead to segmentation fault. But simply adding an additional variable
in the code or changing compilation options modified the behaviour so that no
segmentation fault happens so it is rather subtle.

(1) memset(p + (bits / 8) + 1, 0, (128 - bits) / 8);
In case of bits % 8 == 0 we write the byte behind *p

(2) p[bits/8] = 0xff << (8 - (bits & 7));
In case of bits == 128 we write the byte behind *p

Closes bug 943.

Signed-off-by: Florian Westphal <fw@strlen.de>
10 years agonft: add nft_xt_ctx struct
Giuseppe Longo [Fri, 22 Aug 2014 09:16:29 +0000 (11:16 +0200)] 
nft: add nft_xt_ctx struct

This patch provides the context used to transfer
information between different nft_parse_* function calls.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonft: compare layer 4 protocol in first place
Giuseppe Longo [Fri, 22 Aug 2014 09:16:31 +0000 (11:16 +0200)] 
nft: compare layer 4 protocol in first place

Currently the protocol is tested after the ip address,
this fixes the order testing the protocol before the ip address.

Now the code generated is incorrect:

ip filter INPUT 16
  [ payload load 4b @ network header + 12 => reg 1 ]
  [ cmp eq reg 1 0x0100a8c0 ]
  [ payload load 1b @ network header + 9 => reg 1 ]
  [ cmp eq reg 1 0x00000006 ]
  [ match name tcp rev 0 ]
  [ match name conntrack rev 3 ]
  [ counter pkts 0 bytes 0 ]
  [ immediate reg 0 accept ]

With this patch, the code generated is:
ip filter INPUT 16
  [ payload load 1b @ network header + 9 => reg 1 ]
  [ cmp eq reg 1 0x00000006 ]
  [ payload load 4b @ network header + 12 => reg 1 ]
  [ cmp eq reg 1 0x0100a8c0 ]
  [ bitwise reg 1 = (reg=1 & 0xffffffff ) ^ 0x00000000 ]
  [ match name tcp rev 0 ]
  [ match name conntrack rev 3 ]
  [ counter pkts 0 bytes 0 ]
  [ immediate reg 0 accept ]

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonft-arp: remove wrong conditions
Giuseppe Longo [Fri, 8 Aug 2014 23:04:17 +0000 (01:04 +0200)] 
nft-arp: remove wrong conditions

Removes wrong conditions in flags translating functions
that doesn't permit to delete rule with inverse flags set.

For instance, the following command doesn't remove the rule:
arptables-compat -D INPUT -i ! eth1 -j ACCEPT

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoinclude: add linux/filter.h
Willem de Bruijn [Tue, 29 Jul 2014 22:19:02 +0000 (18:19 -0400)] 
include: add linux/filter.h

xt_bpf.h includes linux/filter.h for the definition of sock_filter.
add that file to the repository

Signed-off-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: add optional [seconds] argument to -w
Jiri Popelka [Fri, 4 Jul 2014 13:50:41 +0000 (15:50 +0200)] 
iptables: add optional [seconds] argument to -w

This patch adds an optional numeric argument
to -w option (added with 93587a0) so one can
specify how long to wait for an exclusive lock.

If the value isn't specified it works as before,
i.e. program waits indefinitely.

If user specifies it, program exits after
the given time interval passes.

This patch also adds the -w/--wait to nftables
compat code, so the parser doesn't complain.

[ In the original patch, iptables-compat -w X was not working,
  I have fixed by adding the dummy code not to break scripts
  using the new optional argument --pablo ]

Signed-off-by: Jiri Popelka <jpopelka@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoMakefile: fix static compilation iptables-compat without shared libraries
Pablo Neira Ayuso [Fri, 13 Jun 2014 09:40:41 +0000 (11:40 +0200)] 
Makefile: fix static compilation iptables-compat without shared libraries

Fix linking problems when this configuration is used:

 $ ./configure --prefix=/usr --enable-shared=no --enable-static=yes
 $ make
 ...
xtables_compat_multi-xtables-save.o: In function `xtables_save_main':
/home/pablo/devel/iptables/iptables/xtables-save.c:98: undefined reference to `init_extensions4'
xtables_compat_multi-xtables-restore.o: In function `xtables_restore_main':
/home/pablo/devel/iptables/iptables/xtables-restore.c:195: undefined reference to `init_extensions4'
xtables_compat_multi-xtables-standalone.o: In function `xtables_main':
/home/pablo/devel/iptables/iptables/xtables-standalone.c:61: undefined reference to `init_extensions4'
xtables_compat_multi-xtables-events.o: In function `xtables_events_main':
/home/pablo/devel/iptables/iptables/xtables-events.c:184: undefined reference to `init_extensions4'

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agolibxtables: fix getaddrinfo return value usage
Domen Puncer [Tue, 10 Jun 2014 13:29:49 +0000 (14:29 +0100)] 
libxtables: fix getaddrinfo return value usage

getaddrinfo return value on error can also be positive.

On Android they're positive, e.g.:

 android-ndk-r9d/platforms/android-19/arch-arm/usr/include/netdb.h
 147 #define EAI_NONAME       8      /* hostname nor servname provided, or not known */

And as a plus, it's not bad to conform to specs.

Signed-off-by: Domen Puncer Kugler <domen.puncer@samsung.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: save: fix the printing of the counters
Giuseppe Longo [Wed, 11 Jun 2014 08:53:12 +0000 (10:53 +0200)] 
nft: save: fix the printing of the counters

This patch prints the counters of a rule before the details,
like iptables-save syntax.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: nft: add tables and chains to the batch
Pablo Neira Ayuso [Mon, 9 Jun 2014 16:55:29 +0000 (18:55 +0200)] 
iptables: nft: add tables and chains to the batch

Since kernel changes:

55dd6f9 ("netfilter: nf_tables: use new transaction infrastructure
to handle table").
91c7b38 ("netfilter: nf_tables: use new transaction infrastructure
to handle chain").

it is possible to put tables and chains in the same batch (which was
already including rules). This patch probes the kernel to check if
if the new transaction is available, otherwise it falls back to the
previous non-transactional approach to handle these two objects.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: nft: remove unused code
Pablo Neira Ayuso [Mon, 9 Jun 2014 16:23:05 +0000 (18:23 +0200)] 
iptables: nft: remove unused code

Remove code to set table in dormant state, this is not required from
the iptables over nft compatibility layer.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: nft: generalize batch infrastructure
Pablo Neira Ayuso [Mon, 9 Jun 2014 16:18:26 +0000 (18:18 +0200)] 
iptables: nft: generalize batch infrastructure

Prepare inclusion of tables and chain objects in the batch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoMerge branch 'next-3.14'
Pablo Neira Ayuso [Fri, 16 May 2014 12:11:05 +0000 (14:11 +0200)] 
Merge branch 'next-3.14'

11 years agoiptables.8: --policy is either ACCEPT or DROP
Florian Westphal [Thu, 17 Apr 2014 11:03:00 +0000 (13:03 +0200)] 
iptables.8: --policy is either ACCEPT or DROP

its enforced by both by libiptc and kernel.

Signed-off-by: Florian Westphal <fw@strlen.de>
11 years agonft: replace nft_rule_attr_get_u8
Giuseppe Longo [Mon, 24 Mar 2014 10:59:46 +0000 (11:59 +0100)] 
nft: replace nft_rule_attr_get_u8

Since the family declaration has been modified in libnftnl,
from commit 3cd9cd06625f8181c713489cec2c1ce6722a7e16
the assertion is failed for {ip,ip6,arp}tables-compat
when printing rules.

iptables-compat -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
libnftnl: attribute 0 assertion failed in rule.c:273

ip6tables-compat -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
libnftnl: attribute 0 assertion failed in rule.c:273

arptables-compat -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
libnftnl: attribute 0 assertion failed in rule.c:273

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables-save: actually parse -M/--modprobe option
Jiri Popelka [Fri, 14 Mar 2014 11:52:48 +0000 (12:52 +0100)] 
iptables-save: actually parse -M/--modprobe option

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables-{save,restore}: warn that -b/--binary isn't implemented
Jiri Popelka [Fri, 14 Mar 2014 11:52:47 +0000 (12:52 +0100)] 
iptables-{save,restore}: warn that -b/--binary isn't implemented

see also 296dca39be

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables-restore.8: file to read from can be specified as argument
Jiri Popelka [Thu, 13 Mar 2014 16:01:20 +0000 (17:01 +0100)] 
iptables-restore.8: file to read from can be specified as argument

original bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=1022228

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables-restore.8: missing -T in synopsis
Jiri Popelka [Thu, 13 Mar 2014 16:01:19 +0000 (17:01 +0100)] 
iptables-restore.8: missing -T in synopsis

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: missing bracket in iptables-save(8)
Jiri Popelka [Thu, 13 Mar 2014 09:02:14 +0000 (10:02 +0100)] 
iptables: missing bracket in iptables-save(8)

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoupdate FSF address in license text
Jiri Popelka [Thu, 13 Mar 2014 09:02:13 +0000 (10:02 +0100)] 
update FSF address in license text

http://www.gnu.org/licenses/gpl-2.0.html
http://www.fsf.org/about/contact/

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables.8: update coreteam members from manpage
Pablo Neira Ayuso [Fri, 7 Mar 2014 17:40:41 +0000 (18:40 +0100)] 
iptables.8: update coreteam members from manpage

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: fix version in iptables(8)
Jiri Popelka [Fri, 7 Mar 2014 15:23:03 +0000 (16:23 +0100)] 
iptables: fix version in iptables(8)

Signed-off-by: Jiri Popelka <jpopelka@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft-arp: wrong condition in parse_payload
Giuseppe Longo [Fri, 7 Mar 2014 14:21:10 +0000 (15:21 +0100)] 
nft-arp: wrong condition in parse_payload

the current condition doesn't permit to parse ip addresses
when they should be. Obviously they are not printed.

arptables-compat -A INPUT -s 1.1.1.1 -i eth0 -j ACCEPT
arptables-compat -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
-j ACCEPT -i eth0

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft-arp: fix is_same_interfaces arguments
Giuseppe Longo [Fri, 7 Mar 2014 10:43:13 +0000 (11:43 +0100)] 
nft-arp: fix is_same_interfaces arguments

Wrong arguments are passed to is_same_interfaces
that causes sometimes to delete a wrong rule.
See the example below:

arptables-compat -A INPUT -i eth0 -j ACCEPT
arptables-compat -A INPUT -i eth1 -j ACCEPT
arptables-compat -A INPUT -i eth2 -j ACCEPT

arptables-compat -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
-j ACCEPT -i eth0
-j ACCEPT -i eth1
-j ACCEPT -i eth2

arptables-compat -D INPUT -i eth2 -j ACCEPT

arptables-compat -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
-j ACCEPT -i eth1
-j ACCEPT -i eth2

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-events: prints arp rules
Giuseppe Longo [Wed, 19 Feb 2014 12:10:29 +0000 (13:10 +0100)] 
xtables-events: prints arp rules

This patch permits to print arp rules, avoiding the segfault that
you got currently.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft-arp: adds nft_arp_save_firewall
Giuseppe Longo [Wed, 19 Feb 2014 12:10:28 +0000 (13:10 +0100)] 
nft-arp: adds nft_arp_save_firewall

Adds nft_arp_save_firewall to arp family. (Avoids the segfault in
xtables-events)

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoMerge branch 'nft-compat'
Pablo Neira Ayuso [Thu, 13 Feb 2014 10:39:48 +0000 (11:39 +0100)] 
Merge branch 'nft-compat'

This merges the branch that contains the iptables over nftables
compatibility layer into master.

11 years agonft: Pass a line after printing out a debug message
Tomasz Bursztyka [Tue, 11 Feb 2014 16:36:46 +0000 (18:36 +0200)] 
nft: Pass a line after printing out a debug message

In this specific places, libnftnl gives back a string on which iptables
should not assume any line break, thus it's up to iptables to add it.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Remove useless error message
Tomasz Bursztyka [Tue, 11 Feb 2014 16:36:45 +0000 (18:36 +0200)] 
nft: Remove useless error message

These are not helpful.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Initialize a table only once
Tomasz Bursztyka [Tue, 11 Feb 2014 16:36:44 +0000 (18:36 +0200)] 
nft: Initialize a table only once

This helps to remove some runtime overhead, especially when running
xtables-restore.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: A builtin chain might be created when restoring
Tomasz Bursztyka [Tue, 11 Feb 2014 16:36:43 +0000 (18:36 +0200)] 
nft: A builtin chain might be created when restoring

nft_chain_set() is directly used in xtables-restore.c, however at that
point no builtin chains have been created yet thus the need to request
to build it relevantly.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Add useful debug output when a builtin table is created
Tomasz Bursztyka [Tue, 11 Feb 2014 16:36:42 +0000 (18:36 +0200)] 
nft: Add useful debug output when a builtin table is created

This is useful to know if a builtin table is requested to be created.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft-compat: fix wrong protocol context in initialization
Pablo Neira Ayuso [Tue, 11 Feb 2014 13:24:06 +0000 (14:24 +0100)] 
nft-compat: fix wrong protocol context in initialization

This fixes matches/targets that are dependent on that IPv4/Ipv6
context, eg.

 # ip6tables-compat -I INPUT -j REJECT --reject-with icmp6-addr-unreachable
 # ip6tables-compat-save
 ...
 -A INPUT -j REJECT --reject-with icmp6-port-unreachable

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft-compat: fix IP6T_F_GOTO flag handling
Pablo Neira Ayuso [Tue, 11 Feb 2014 12:58:03 +0000 (13:58 +0100)] 
nft-compat: fix IP6T_F_GOTO flag handling

IPT_F_GOTO and IP6T_F_GOTO don't overlap, so this need special handling
to avoid misinterpretations.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: adds save_matches_and_target
Giuseppe Longo [Mon, 10 Feb 2014 15:49:33 +0000 (16:49 +0100)] 
nft: adds save_matches_and_target

This patch permits to save matches and target for ip/ip6/arp/eb
family, required for xtables-events.

Also, generalizes nft_rule_print_save to be reused for all protocol
families.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: Add backward compatibility with -w option
Tomasz Bursztyka [Tue, 11 Feb 2014 10:46:44 +0000 (12:46 +0200)] 
xtables: Add backward compatibility with -w option

Just to keep aligned with iptables legacy tool.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: add xtables-compat-multi for the nftables compatibility layer
Pablo Neira Ayuso [Tue, 4 Feb 2014 15:21:18 +0000 (16:21 +0100)] 
xtables: add xtables-compat-multi for the nftables compatibility layer

This patch should allow distributors to switch to the iptables over
nftables compatibility layer in a transparent way by updating
symbolic links from:

lrwxrwxrwx  1 root    root         13 feb  4 15:35 iptables -> xtables-multi

to:

lrwxrwxrwx  1 root    root         13 feb  4 15:35 iptables -> xtables-compat-multi

Same thing with iptables-save, iptables-restore, ip6tables, ip6tables-save,
ip6tables-restore and arptables.

Note that, after this patch, the following new symlinks are installed:

* iptables-compat
* iptables-compat-save
* iptables-compat-restore
* ip6tables-compat
* ip6tables-compat-save
* ip6tables-compat-restore
* arptables-compat

which point to the new binary xtables-compat-multi.

The idea is to keep both native and compatibility tools installed in the
system, which should also make it easier for testing purposes.

The iptables over nftables compatibility layer is enabled by default
and it requires the libmnl and libnftnl libraries. If you don't want to
compile the compatibility layer, you can still disable it through
--disable-nftables.

This patch also includes changes to adapt the existing code to this
approach.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-restore: remove dependency with libip4tc
Pablo Neira Ayuso [Tue, 4 Feb 2014 15:18:55 +0000 (16:18 +0100)] 
xtables-restore: remove dependency with libip4tc

Add a new operation structure, we don't actually need the libip4tc
definition.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoconfigure: conditional dependencies for nftables-compat
Pablo Neira Ayuso [Tue, 4 Feb 2014 12:32:58 +0000 (13:32 +0100)] 
configure: conditional dependencies for nftables-compat

Depend on libmnl, libnftnl, flex and bison if only if the nftables
compatibility is enabled.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoconfigure: rename --disable-xtables to --disable-nftables
Pablo Neira Ayuso [Tue, 4 Feb 2014 12:20:09 +0000 (13:20 +0100)] 
configure: rename --disable-xtables to --disable-nftables

The compat utility name is xtables, the name used for the
compatibility binary. Better explicitly refer to the compatibility
later as nftables-compat.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoconfigure: fix wrong reference to the conntrack-tools
Pablo Neira Ayuso [Tue, 4 Feb 2014 12:17:30 +0000 (13:17 +0100)] 
configure: fix wrong reference to the conntrack-tools

Reported-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agolibxtables: Print meaningful error message for an invalid MAC address string
Mart Frauenlob [Sun, 2 Feb 2014 18:39:01 +0000 (19:39 +0100)] 
libxtables: Print meaningful error message for an invalid MAC address string

If an invalid MAC address is used on the commmand line, the error message
`ether' was not really describing the problem.

Signed-off-by: Mart Frauenlob <mart.frauenlob@chello.at>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoextensions: libxt_SYNPROXY: initial manual page
Martin Topholm [Thu, 30 Jan 2014 13:47:26 +0000 (14:47 +0100)] 
extensions: libxt_SYNPROXY: initial manual page

Signed-off-by: Martin Topholm <mph@one.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
11 years agoiptables-xml: fix segfault if missing space after -A
Phil Oester [Fri, 24 Jan 2014 06:06:58 +0000 (22:06 -0800)] 
iptables-xml: fix segfault if missing space after -A

As pointed out by Bernhard Reutner-Fischer, a malformed line fed to
iptables-xml such as the below with a missing space after the -A:

-APOSTROUTING -d 1.1.1.1/32 -p tcp -j MASQUERADE

causes a segfault.  Patch attached.

This closes netfilter bugzilla #886.

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Use new libnftnl library name against former libnftables
Tomasz Bursztyka [Mon, 20 Jan 2014 15:56:41 +0000 (17:56 +0200)] 
nft: Use new libnftnl library name against former libnftables

Adapt the current code to use the new library name libnftnl.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix inconsistent data type in NFT_EXPR_CMP_OP and NFT_EXPR_META_KEY
Pablo Neira Ayuso [Fri, 10 Jan 2014 13:02:22 +0000 (14:02 +0100)] 
nft: fix inconsistent data type in NFT_EXPR_CMP_OP and NFT_EXPR_META_KEY

We have to use uint32_t instead uint8_t to adapt this to the libnftables
changes.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoextensions: libxt_set: Add missing hyphen to --bytes-eq synopsis in manpage
Mart Frauenlob [Sat, 4 Jan 2014 15:57:46 +0000 (16:57 +0100)] 
extensions: libxt_set: Add missing hyphen to --bytes-eq synopsis in manpage

Signed-off-by: Mart Frauenlob <mart.frauenlob@chello.at>
Signed-off-by: Florian Westphal <fw@strlen.de>
11 years agoiptables: add libxt_cgroup frontend
Daniel Borkmann [Mon, 23 Dec 2013 17:46:29 +0000 (18:46 +0100)] 
iptables: add libxt_cgroup frontend

This patch adds the user space extension/frontend for process matching
based on cgroups from the kernel patch entitled "netfilter: xtables:
lightweight process control group matching".

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: snat: add randomize-full support
Daniel Borkmann [Sun, 22 Dec 2013 03:15:38 +0000 (04:15 +0100)] 
iptables: snat: add randomize-full support

This patch provides the userspace part for snat in order to make
randomize-full support available in {ip,nf}tables. It allows for
enabling full port randomization that was motivated in [1] and
introduced to the kernel in [2].

Joint work between Hannes Frederic Sowa and Daniel Borkmann.

 [1] https://sites.google.com/site/hayashulman/files/NIC-derandomisation.pdf
 [2] http://patchwork.ozlabs.org/patch/304306/

Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoinclude: Update nftables API header in sync with kernel's one
Tomasz Bursztyka [Fri, 13 Dec 2013 07:43:25 +0000 (09:43 +0200)] 
include: Update nftables API header in sync with kernel's one

Many changes were missing.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix wrong function to release iterator
Pablo Neira Ayuso [Wed, 4 Dec 2013 11:27:37 +0000 (12:27 +0100)] 
nft: fix wrong function to release iterator

nft.c: In function ‘nft_xtables_config_load’:
nft.c:2522:3: warning: passing argument 1 of ‘nft_table_list_iter_destroy’ from incompatible pointer type [enabled by default]
In file included from nft.c:41:0:
/usr/include/libnftables/table.h:64:6: note: expected ‘struct nft_table_list_iter *’ but argument is of type ‘struct nft_chain_list_iter *’

Introduced in (12eb85b nft: fix memory leaks in
nft_xtables_config_load) but that was my fault indeed since Ana sent
a v2 patch that I have overlook.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: nft: fix memory leaks in nft_fini
Ana Rey [Mon, 2 Dec 2013 10:45:14 +0000 (11:45 +0100)] 
iptables: nft: fix memory leaks in nft_fini

Those errors are shown with valgrind tool:

valgrind --leak-check=full xtables -A INPUT -i eth0 -p tcp --dport 80

==12554== 40 bytes in 1 blocks are still reachable in loss record 1 of 10
==12554==    at 0x4C2935B: malloc (vg_replace_malloc.c:270)
==12554==    by 0x574D755: mnl_nlmsg_batch_start (nlmsg.c:447)
==12554==    by 0x416520: nft_action (nft.c:2281)
==12554==    by 0x41355E: xtables_main (xtables-standalone.c:75)
==12554==    by 0x5B87994: (below main) (libc-start.c:260)

==12554== 135,168 bytes in 1 blocks are still reachable in loss record 9 of 10
==12554==    at 0x4C2935B: malloc (vg_replace_malloc.c:270)
==12554==    by 0x415A24: mnl_nft_batch_alloc (nft.c:102)
==12554==    by 0x416520: nft_action (nft.c:2281)
==12554==    by 0x41355E: xtables_main (xtables-standalone.c:75)
==12554==    by 0x5B87994: (below main) (libc-start.c:260)

These objects are allocated from nft_init but they were not released
appropriately in the exit path.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix memory leaks in nft_xtables_config_load
Ana Rey [Mon, 2 Dec 2013 10:44:48 +0000 (11:44 +0100)] 
nft: fix memory leaks in nft_xtables_config_load

Those errors are shown with the valgrind tool:

valgrind --leak-check=full xtables -A INPUT -i eth0 -p tcp --dport 80

==7377==
==7377== 16 bytes in 1 blocks are definitely lost in loss record 2 of 14
==7377==    at 0x4C2B514: calloc (vg_replace_malloc.c:593)
==7377==    by 0x5955B02: nft_table_list_alloc (table.c:425)
==7377==    by 0x4186EB: nft_xtables_config_load (nft.c:2427)
==7377==    by 0x4189E6: nft_rule_append (nft.c:991)
==7377==    by 0x413A7D: add_entry.isra.6 (xtables.c:424)
==7377==    by 0x41524A: do_commandx (xtables.c:1176)
==7377==    by 0x4134DC: xtables_main (xtables-standalone.c:72)
==7377==    by 0x5B87994: (below main) (libc-start.c:260)
==7377==
==7377== 16 bytes in 1 blocks are definitely lost in loss record 3 of 14
==7377==    at 0x4C2B514: calloc (vg_replace_malloc.c:593)
==7377==    by 0x5956A32: nft_chain_list_alloc (chain.c:888)
==7377==    by 0x4186F3: nft_xtables_config_load (nft.c:2428)
==7377==    by 0x4189E6: nft_rule_append (nft.c:991)
==7377==    by 0x413A7D: add_entry.isra.6 (xtables.c:424)
==7377==    by 0x41524A: do_commandx (xtables.c:1176)
==7377==    by 0x4134DC: xtables_main (xtables-standalone.c:72)
==7377==    by 0x5B87994: (below main) (libc-start.c:260)

Fix these leaks and consolidate error handling in the exit path of
nft_xtables_config_load

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-standalone: call nft_fini in the error path
Ana Rey [Mon, 2 Dec 2013 10:43:25 +0000 (11:43 +0100)] 
xtables-standalone: call nft_fini in the error path

This error is shown with valgrind tools:

valgrind --leak-check=full xtables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT

==7377== 16 bytes in 1 blocks are still reachable in loss record 1 of 14
==7377==    at 0x4C2B514: calloc (vg_replace_malloc.c:593)
==7377==    by 0x574CC76: mnl_socket_open (socket.c:117)
==7377==    by 0x417495: nft_init (nft.c:598)
==7377==    by 0x4134C2: xtables_main (xtables-standalone.c:64)
==7377==    by 0x5B87994: (below main) (libc-start.c:260)

This patch calls nft_fini to release the objects that have been allocated in
nft_init. This function was not used so far.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix out of bound memory copy
Pablo Neira Ayuso [Tue, 26 Nov 2013 12:09:13 +0000 (13:09 +0100)] 
nft: fix out of bound memory copy

Valgrind reports an invalid read after a memory block:

==11114== Invalid read of size 8
==11114==    at 0x4C2DB02: memcpy@@GLIBC_2.14 (mc_replace_strmem.c:877)
==11114==    by 0x41788E: add_match (nft.c:781)
==11114==    by 0x41B54C: nft_ipv4_add (nft-ipv4.c:72)
==11114==    by 0x415DF2: nft_rule_new.isra.2 (nft.c:945)
==11114==    by 0x418ACE: nft_rule_append (nft.c:1000)
==11114==    by 0x413A92: add_entry.isra.6 (xtables.c:424)
==11114==    by 0x4152DE: do_commandx (xtables.c:1184)
==11114==    by 0x4134E8: xtables_main (xtables-standalone.c:72)
==11114==    by 0x5B87994: (below main) (libc-start.c:260)
==11114==  Address 0x61399e8 is 8 bytes after a block of size 48 alloc'd
==11114==    at 0x4C2B514: calloc (vg_replace_malloc.c:593)
==11114==    by 0x52448C8: xtables_calloc (xtables.c:272)
==11114==    by 0x410AC2: command_default (xshared.c:150)
==11114==    by 0x4149A2: do_commandx (xtables.c:1075)
==11114==    by 0x4134E8: xtables_main (xtables-standalone.c:72)
==11114==    by 0x5B87994: (below main) (libc-start.c:260)

m->u.match_size also contains the size of the xt_entry_match structure.
Fix also the target path which is very similar.

Reported-by: Ana Rey Botello <anarey@gmail.com>
Tested-by: Ana Rey Botello <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix inversion of built-in selectors
Pablo Neira Ayuso [Mon, 18 Nov 2013 12:50:21 +0000 (13:50 +0100)] 
nft: fix inversion of built-in selectors

(0ab045f xtables: fix missing ipt_entry for MASQUERADE target) broke
inversion of built-in selectors, such as -s, -d, etc.

We need to refresh the invflags if -p is used or set it for first
time if -p is not used, otherwise inversion is ignored.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-events: fix compilation due change in libnftables
Pablo Neira Ayuso [Wed, 13 Nov 2013 23:48:07 +0000 (00:48 +0100)] 
xtables-events: fix compilation due change in libnftables

The patch (989b793 src: unify parse and output types) changed
the table and chain type definitions, adapt this code to use
the new ones.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>