]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
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>
11 years agoxtables: arp: inhibit -l option so only a fixed 6 bytes length arhln can be used
Tomasz Bursztyka [Thu, 7 Nov 2013 08:14:37 +0000 (10:14 +0200)] 
xtables: arp: inhibit -l option so only a fixed 6 bytes length arhln can be used

This is a temporary workaround mechanism until variable interface
hardware address length can be handled through nftables. This
defaults on the length of EUI-64 mac address, which should be the
most common usage until this is appropriately fixed for all type
of layer 2 addresses.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: arp: Fix a compilation warning
Tomasz Bursztyka [Wed, 6 Nov 2013 11:51:18 +0000 (13:51 +0200)] 
xtables: arp: Fix a compilation warning

This fixes such warning:
xtables-arp.c: In function ‘check_inverse’:
xtables-arp.c:561:54: attention : declaration of ‘optind’ shadows a
global declaration [-Wshadow]

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: arp: fix possible string overflow
Giuseppe Longo [Sat, 12 Oct 2013 09:21:52 +0000 (11:21 +0200)] 
nft: arp: fix possible string overflow

This patch replaces strcat with strncat and strcpy with strncpy
fixing possible string overflow.

Based on the original patch:

http://patchwork.ozlabs.org/patch/279672/

from Jaromír Končický via Jiri Popelka.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix interface wildcard matching
Pablo Neira Ayuso [Fri, 11 Oct 2013 09:42:36 +0000 (11:42 +0200)] 
nft: fix interface wildcard matching

In (73ea1cc nft: convert rule into a command state structure), the
interface wildcard matching got broken. The previous handling was
flawed by the use of ifnametoindex in scenario where the interface
may vanished after a rule was added.

This approach relies on the trailing '\0' to identify if this is
an exact or wildcard matching, based on discussion with Florian.

Based on initial patch from Anand Raj Manickam.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix bad length when comparing extension data area
Pablo Neira Ayuso [Tue, 8 Oct 2013 10:13:57 +0000 (12:13 +0200)] 
nft: fix bad length when comparing extension data area

Use ->userspacesize to compare the extension data area, otherwise
we also compare the internal private pointers which are only
meaningful to the kernelspace.

This fixes:

xtables -4 -D INPUT -m connlimit \
--connlimit-above 10 --connlimit-mask 32 --connlimit-daddr

But it also fixes many other matches/targets which use internal
private data.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: pass ipt_entry to ->save_firewall hook
Pablo Neira Ayuso [Tue, 8 Oct 2013 08:44:20 +0000 (10:44 +0200)] 
nft: pass ipt_entry to ->save_firewall hook

The extension needs the ipt_entry not to crash. Since cs->fw
actually points to an union that also contains cs->fw6, just
pass cs->fw to make it work.

This fixes:

-A INPUT -p tcp -m multiport --ports 1,2,3,4,6,7,8,9,10,11,12,13,14,15

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: fix missing ipt_entry for MASQUERADE target
Pablo Neira Ayuso [Tue, 8 Oct 2013 08:50:39 +0000 (10:50 +0200)] 
xtables: fix missing ipt_entry for MASQUERADE target

The MASQUERADE target relies on the ipt_entry information that is
set in ->post_parse, which is too late.

Add a new hook called ->pre_parse, that sets the protocol
information accordingly.

Thus:

xtables -4 -A POSTROUTING -t nat -p tcp \
-j MASQUERADE --to-ports 1024

works again.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: arp: add parse_target to nft_family_ops_arp
Giuseppe Longo [Sun, 6 Oct 2013 12:36:47 +0000 (14:36 +0200)] 
nft: arp: add parse_target to nft_family_ops_arp

This patch adds parse_target for arp family, fixing segfaults
for xtables-arp -L after rules like:

xtables-arp -A OUTPUT -o eth0 -j CLASSIFY --set-class 0:7
xtables-arp -A OUTPUT -o eth1 --h-length 6 \
-j mangle --mangle-mac-s 01:00:5e:00:01:01

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: arp: initialize flags in nft_arp_parse_meta
Giuseppe Longo [Thu, 3 Oct 2013 14:31:39 +0000 (16:31 +0200)] 
nft: arp: initialize flags in nft_arp_parse_meta

This small patch initialize the flags in nft_arp_parse_meta,
now the nft_arp_rule_find is working properly.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix wrong target size
Tomasz Bursztyka [Thu, 3 Oct 2013 13:00:59 +0000 (16:00 +0300)] 
nft: fix wrong target size

The allocated area was not aligned.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: arp: Parse properly target options
Tomasz Bursztyka [Thu, 3 Oct 2013 13:00:47 +0000 (16:00 +0300)] 
xtables: arp: Parse properly target options

Target never gets its options parsed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Header inclusion missing
Tomasz Bursztyka [Thu, 3 Oct 2013 11:39:22 +0000 (14:39 +0300)] 
nft: Header inclusion missing

Fixes compilation issues.

nft-shared.c: In function ‘nft_ipv46_rule_find’:
nft-shared.c:725:2: warning: implicit declaration of function ‘nft_rule_print_save’ [-Wimplicit-function-declaration]
nft-shared.c:725:32: error: ‘NFT_RULE_APPEND’ undeclared (first use in this function)
nft-shared.c:725:32: note: each undeclared identifier is reported only once for each function it appears in

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoextensions: libxt_mangle: Fixes option issues
Tomasz Bursztyka [Thu, 3 Oct 2013 11:28:05 +0000 (14:28 +0300)] 
extensions: libxt_mangle: Fixes option issues

Fix option IDs and remove irrelevant flags on setting options
mandatory.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoextensions: add arptables' libxt_mangle.c for xtables-arp
Tomasz Bursztyka [Thu, 3 Oct 2013 09:52:56 +0000 (12:52 +0300)] 
extensions: add arptables' libxt_mangle.c for xtables-arp

This is a porting of the original mangle target in arptables. This
also adapts original code so functions fits with libxtables.

This is needed by the xtables-arp compatibility tool for nftables.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: arp: Store target entry properly and compare them relevantly
Tomasz Bursztyka [Thu, 3 Oct 2013 09:52:55 +0000 (12:52 +0300)] 
xtables: arp: Store target entry properly and compare them relevantly

Fixes a segfault issue when deleting a rule.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: batch rule-set updates into one single netlink message
Pablo Neira Ayuso [Wed, 18 Sep 2013 15:00:18 +0000 (17:00 +0200)] 
xtables: batch rule-set updates into one single netlink message

With this patch, all rule-set updates are put in one single batch
of netlink messages that is sent to user-space using the new
nfnetlink batch infrastructure.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: arp: zeroing chain counters
Giuseppe Longo [Sun, 22 Sep 2013 08:18:56 +0000 (10:18 +0200)] 
xtables: arp: zeroing chain counters

This small patch permit to reset the chain counters.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: arp: add delete operation
Giuseppe Longo [Sun, 22 Sep 2013 08:18:55 +0000 (10:18 +0200)] 
xtables: arp: add delete operation

The following patch permit to delete the rules specifying
an entry or a rule number.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: adapt nft_rule_expr_get to use uint32_t instead of size_t
Pablo Neira Ayuso [Thu, 19 Sep 2013 18:46:42 +0000 (20:46 +0200)] 
nft: adapt nft_rule_expr_get to use uint32_t instead of size_t

According to libnftables change 437d610, now the length obtained
via getter function is uint32_t, not size_t anymore.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoinclude: cache netfilter_arp kernel headers
Pablo Neira Ayuso [Wed, 18 Sep 2013 17:01:11 +0000 (19:01 +0200)] 
include: cache netfilter_arp kernel headers

To ensure that compilation does not break if Linux kernel
headers are not installed in the system.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: arp: add rule replacement support
Giuseppe Longo [Wed, 18 Sep 2013 10:34:15 +0000 (12:34 +0200)] 
xtables: arp: add rule replacement support

The following patch permit to replace rule in xtables-arp.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: consolidate nft_rule_* functions to support ARP
Pablo Neira Ayuso [Wed, 18 Sep 2013 14:54:15 +0000 (16:54 +0200)] 
nft: consolidate nft_rule_* functions to support ARP

This should help to avoid code duplication to support ARP.
As a result, we have a common generic infrastructure for
IPv4, IPv6 and ARP.

This patch removes nft_arp_rule_append and nft_arp_rule_insert,
which were very similar to their original nft_rule_append and
nft_rule_insert.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: consolidate nft_rule_new to support ARP
Pablo Neira Ayuso [Wed, 18 Sep 2013 12:57:38 +0000 (14:57 +0200)] 
nft: consolidate nft_rule_new to support ARP

This patch removes nft_arp_rule_new, which almost a copy and paste
of the original nft_rule_new. This patch generalizes the
infrastructure to support ARP.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: consolidate nft_rule_find for ARP, IPv4 and IPv6
Pablo Neira Ayuso [Wed, 18 Sep 2013 12:13:47 +0000 (14:13 +0200)] 
nft: consolidate nft_rule_find for ARP, IPv4 and IPv6

This patch kills nft_arp_rule_find, which is almost a copy and paste
of the original nft_rule_find function. Refactor this function to
move specific protocol parts to the corresponding nft-{ipv4,ipv6,arp}.c
files.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: nft-arp: implements is_same op for ARP family
Giuseppe Longo [Mon, 16 Sep 2013 08:58:16 +0000 (10:58 +0200)] 
xtables: nft-arp: implements is_same op for ARP family

The following patch implements the is_same operation
for ARP family needed for searching arp rule.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: nft-arp: fix endianess in nft_arp_parse_payload
Pablo Neira Ayuso [Sat, 14 Sep 2013 18:48:39 +0000 (20:48 +0200)] 
xtables: nft-arp: fix endianess in nft_arp_parse_payload

nft_arp_print_firewall already handles endianess appropriately.
This fixes the output of the option that allows you to match
ARP header fields.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: bootstrap ARP compatibility layer for nftables
Giuseppe Longo [Mon, 9 Sep 2013 10:54:04 +0000 (12:54 +0200)] 
xtables: bootstrap ARP compatibility layer for nftables

This patch bootstraps ARP support for the compatibility layer:

1) copy original arptables code into xtables-arp.c
2) adapt it to fit into the existing nft infrastructure.
3) add the builtin table/chains for ARP.
4) add necessary parts so xtables-multi can provide xtables-arp.
5) add basic support for rule addition (-A), insertion (-I) and
   listing (-L).

[ This was originally posted in a series of patches with interdependencies
  that I have collapsed to leave the repository in consistent state. This
  patch includes the following changes I made:

* Rename from xtables-arptables to xtables-arp, previous name too long.
* Remove nft-arptables.c, now we have one single nft-arp.c file. Moved
  specific ARP functions to nft.c. Those should go away at some point as
  some refactorization should allow to accomodate those functions to the
  existing infrastructure.
* Fix --opcode Request/Reply, so we can do something useful with this
  like dropping ARP request/replies.

--pablo ]

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: skip unset tables on table configuration emulation
Tomasz Bursztyka [Fri, 13 Sep 2013 16:25:57 +0000 (18:25 +0200)] 
nft: skip unset tables on table configuration emulation

The ARP family has less tables, so skip iteration once we find
a null one.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: generalize rule addition family hook
Pablo Neira Ayuso [Sun, 8 Sep 2013 21:53:05 +0000 (23:53 +0200)] 
nft: generalize rule addition family hook

This should help Giuseppe with his ARP support works, this change
was missing in (618309c nft: refactoring parse operations for more
genericity).

Based on patch from Giuseppe.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Fix a minor compilation warning
Tomasz Bursztyka [Fri, 6 Sep 2013 07:51:48 +0000 (10:51 +0300)] 
nft: Fix a minor compilation warning

nft-shared.c: In function ‘nft_rule_to_iptables_command_state’:
nft-shared.c:454:22: warning: ‘jumpto’ may be used uninitialized in this function [-Wmaybe-uninitialized]
nft-shared.c:432:14: note: ‘jumpto’ was declared here

All verdicts are managed and jumpto has to get a value, but since
the compiler complains, let's fix it.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: refactoring parse operations for more genericity
Giuseppe Longo [Wed, 4 Sep 2013 12:36:41 +0000 (14:36 +0200)] 
nft: refactoring parse operations for more genericity

This allows to reuse the nft_parse_* function for the bridge and
arp family (not yet supported).

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: allow to reset the counters of an existing rule
Tomasz Bursztyka [Mon, 19 Aug 2013 12:04:06 +0000 (15:04 +0300)] 
xtables: allow to reset the counters of an existing rule

Now that we convert nft rules to native xt command structure, it's
easier to reset the counters by replacing the existing rule by a
new one with all counters set to zero.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: use xtables_print_num
Pablo Neira Ayuso [Tue, 20 Aug 2013 18:42:50 +0000 (20:42 +0200)] 
nft: use xtables_print_num

So we can kill our own implementation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix wrong flags handling in print_firewall_details
Pablo Neira Ayuso [Tue, 20 Aug 2013 18:24:26 +0000 (20:24 +0200)] 
nft: fix wrong flags handling in print_firewall_details

Unfortunately, IPT_F_* and IP6T_F_* don't overlap, therefore, we have
to add an specific function to print the fragment flag, otherwise
xtables -6 misinterprets the protocol flag, ie.

Chain INPUT (policy ACCEPT)
           tcp  -f  ::/0                 ::/0

Note that -f should not show up. This problem was likely added with
the IPv6 support for the compatibility layer.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: convert rule into a command state structure
Tomasz Bursztyka [Mon, 19 Aug 2013 12:04:02 +0000 (15:04 +0300)] 
nft: convert rule into a command state structure

This helps to reduce the code complexity to have one single common path
for printing, saving and looking up for the rule.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: use xtables_rule_matches_free
Pablo Neira Ayuso [Fri, 9 Aug 2013 15:51:31 +0000 (17:51 +0200)] 
xtables: use xtables_rule_matches_free

Thus, we can kill clear_rule_matches. Not required since we are based
upon 1.4.19.1.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Print unknown target data only when relevant
Tomasz Bursztyka [Wed, 7 Aug 2013 08:31:37 +0000 (11:31 +0300)] 
nft: Print unknown target data only when relevant

Bug is:
xtables -N test
xtables -A FORWARD -j test
xtables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
test       all  --  anywhere             anywhere            [0 bytes of unknown target data]

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain test (1 references)
target     prot opt source               destination

"[0 bytes of unknown target data]" should not be printed in this case.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Generalize nft_rule_list() against current family
Tomasz Bursztyka [Wed, 7 Aug 2013 08:31:36 +0000 (11:31 +0300)] 
nft: Generalize nft_rule_list() against current family

Now, firewall rule printing is done through nft_family_ops
.print_firewall function. This moves generic part for ipv4 and ipv6 into
nft-shared.c, and enables reusing nft_rule_list() for other family such
as ARP which will be useful for arptables compatibility tool.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Remove useless test on rulenum in nft_rule_list()
Tomasz Bursztyka [Wed, 7 Aug 2013 08:31:35 +0000 (11:31 +0300)] 
nft: Remove useless test on rulenum in nft_rule_list()

Rulenum is already handled before the loop, making this test useless.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Make internal rule listing callback more generic
Tomasz Bursztyka [Thu, 1 Aug 2013 17:44:35 +0000 (20:44 +0300)] 
nft: Make internal rule listing callback more generic

This will be useful for reusing nft_rule_list in other tools such as
xtables-arptables.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Optimize rule listing when chain and rulenum are provided
Tomasz Bursztyka [Thu, 1 Aug 2013 17:44:34 +0000 (20:44 +0300)] 
nft: Optimize rule listing when chain and rulenum are provided

Thus, we can save some cycles by not dumping the entire chain list
and looping on 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 function
Tomasz Bursztyka [Thu, 25 Jul 2013 17:16:21 +0000 (20:16 +0300)] 
nft: Remove useless function

Likely to be a leftover from the initial bootstrap.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: Do not dump before command parsing has been finished
Tomasz Bursztyka [Wed, 31 Jul 2013 12:18:52 +0000 (15:18 +0300)] 
xtables: Do not dump before command parsing has been finished

On xtables-save.c, -d will not output right away but after the full
command line hase been parsed.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: load only the tables of the current family
Giuseppe Longo [Tue, 30 Jul 2013 11:03:46 +0000 (14:03 +0300)] 
nft: load only the tables of the current family

This changes nft_xtables_config_load() permit to load only
the tables of the current family.

[ This patch includes a fix for the configuration parser
  that I detected while testing this patch --pablo ]

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoetc: add default IPv6 table and chain definitions
Pablo Neira Ayuso [Tue, 30 Jul 2013 18:17:44 +0000 (20:17 +0200)] 
etc: add default IPv6 table and chain definitions

Add definition of table and chains to the optional xtables.conf file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix family operation lookup
Giuseppe Longo [Fri, 26 Jul 2013 11:05:19 +0000 (13:05 +0200)] 
nft: fix family operation lookup

xtables-restore -6 was using the IPv4 family, instead of IPv6
as it should be.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix match revision lookup for IPv6
Pablo Neira Ayuso [Tue, 30 Jul 2013 09:39:59 +0000 (11:39 +0200)] 
nft: fix match revision lookup for IPv6

IPT_SO_GET_REVISION_MATCH != IP6T_SO_GET_REVISION_MATCH, thus,
the revision infrastructure was looking for targets instead
matches.

11 years agoxtables: fix typo in add_entry for the IPv6 case
Pablo Neira Ayuso [Tue, 30 Jul 2013 09:28:45 +0000 (11:28 +0200)] 
xtables: fix typo in add_entry for the IPv6 case

It should pass zero, instead of the 'append' boolean.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: associate table configuration to handle via nft_init
Giuseppe Longo [Fri, 26 Jul 2013 11:05:15 +0000 (13:05 +0200)] 
nft: associate table configuration to handle via nft_init

We need family dependent built-in table/chain configuration. This
patch is a step forward making nft family independent in
order to support arptables and ebtables compatibility layers.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: no need for rule lookup if no position specified via -I
Pablo Neira Ayuso [Wed, 24 Jul 2013 18:11:52 +0000 (20:11 +0200)] 
nft: no need for rule lookup if no position specified via -I

Improve (dc3d8a6 xtables: add -I chain rulenum) to avoid a look
up for the rule if no rule number is specified via -I.

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