]> git.ipfire.org Git - thirdparty/iptables.git/log
thirdparty/iptables.git
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>
11 years agoxtables: remove bogus comment regarding rule replacement
Pablo Neira Ayuso [Fri, 19 Jul 2013 16:47:20 +0000 (18:47 +0200)] 
xtables: remove bogus comment regarding rule replacement

We support rule replacement since quite some time, remove it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: add -I chain rulenum
Pablo Neira Ayuso [Fri, 19 Jul 2013 16:42:30 +0000 (18:42 +0200)] 
xtables: add -I chain rulenum

This patch adds the nft_rule_insert function, which allows
us to insert rules at a given position.

The function nft_rule_add has been renamed to nft_rule_append.

This is possible thanks to Eric Leblond's (netfilter: nf_tables:
add insert operation) kernel patch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix selective chain display via -S
Pablo Neira Ayuso [Wed, 17 Jul 2013 13:04:19 +0000 (15:04 +0200)] 
nft: fix selective chain display via -S

Before:

% xtables -S INPUT
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -p tcp -j ACCEPT

After:

$ xtables -S INPUT
-P INPUT ACCEPT
-A INPUT -p tcp -j ACCEPT

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: break chain listing if only one if looked for
Pablo Neira Ayuso [Wed, 17 Jul 2013 12:55:01 +0000 (14:55 +0200)] 
nft: break chain listing if only one if looked for

Break looping on the chain list if it finds the chain
that the user requested.

Based on patch from Tomasz Bursztyka.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: use nft_*_list_add_tail
Pablo Neira Ayuso [Tue, 16 Jul 2013 20:43:06 +0000 (22:43 +0200)] 
src: use nft_*_list_add_tail

Adapt it to the semantic fix that has been applied to libnftable
nft_*_list_add now inserts nodes, instead of appending them.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix built-in chain ordering of the nat table
Pablo Neira Ayuso [Tue, 16 Jul 2013 20:18:47 +0000 (22:18 +0200)] 
nft: fix built-in chain ordering of the nat table

Should be:

% iptables -L -n -t nat
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

instead of:

% xtables -L -n -t nat
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

Reported-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@soleta.eu>
11 years agoxtables-events: fix missing newline in table and chain events
Pablo Neira Ayuso [Tue, 16 Jul 2013 20:01:04 +0000 (22:01 +0200)] 
xtables-events: fix missing newline in table and chain events

Add missing newline while printing table and chain events.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-events: print usage on wrong arguments
Pablo Neira Ayuso [Tue, 16 Jul 2013 19:55:15 +0000 (21:55 +0200)] 
xtables-events: print usage on wrong arguments

Set opterr to zero to skip getopt_long error reporting.

This also fixes the following compilation warning:

xtables-events.c:148:13: warning: ‘print_usage’ defined but not used [-Wunused-function]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Fix small memory leaks
Tomasz Bursztyka [Tue, 16 Jul 2013 12:38:53 +0000 (15:38 +0300)] 
nft: Fix small memory leaks

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: add function to test for a builtin chain
Tomasz Bursztyka [Tue, 16 Jul 2013 20:07:58 +0000 (22:07 +0200)] 
nft: add function to test for a builtin chain

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: Remove useless parameter to nft_chain_list_find
Tomasz Bursztyka [Tue, 16 Jul 2013 20:07:22 +0000 (22:07 +0200)] 
xtables: Remove useless parameter to nft_chain_list_find

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: Handle error on adding rule expressions
Tomasz Bursztyka [Tue, 16 Jul 2013 12:38:46 +0000 (15:38 +0300)] 
nft: Handle error on adding rule expressions

If adding one of match/target/jumpto/verdit/counters fails, adding a rule will
return an error.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@soleta.eu>
11 years agonft: Set the rule family when creating a new one
Tomasz Bursztyka [Tue, 16 Jul 2013 12:38:45 +0000 (15:38 +0300)] 
nft: Set the rule family when creating a new one

Fixes the debug output from (in case of ipv4 rule):
DEBUG: rule: arp filter INPUT 0
to:
DEBUG: rule: ip filter INPUT 0

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@soleta.eu>
11 years agoxtables: nft: display rule number via -S
Pablo Neira Ayuso [Mon, 15 Jul 2013 09:48:48 +0000 (11:48 +0200)] 
xtables: nft: display rule number via -S

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: nft: display rule by number via -L
Giuseppe Longo [Fri, 12 Jul 2013 11:27:33 +0000 (13:27 +0200)] 
xtables: nft: display rule by number via -L

This patch fixes the display of rule by number.

[ Mangled this patch not to display the header, to mimic iptables
  --pablo ]

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: fix missing afinfo configuration
Pablo Neira Ayuso [Sun, 30 Jun 2013 10:34:36 +0000 (12:34 +0200)] 
xtables: fix missing afinfo configuration

I noticed that the iprange match in IPv6 was broken, fix it
by overriding the default family (IPv4) if -6 is passed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: do not proceed if nft_init fails
Pablo Neira Ayuso [Tue, 25 Jun 2013 09:56:55 +0000 (11:56 +0200)] 
xtables: do not proceed if nft_init fails

Fix a crash if nft_init fails, it happens if nfnetlink support
is not available in your Linux kernel.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix another memleak in nft_rule_list_cb
Giuseppe Longo [Tue, 25 Jun 2013 07:46:17 +0000 (09:46 +0200)] 
nft: fix another memleak in nft_rule_list_cb

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: print counter issues
Giuseppe Longo [Tue, 25 Jun 2013 07:46:06 +0000 (09:46 +0200)] 
nft: print counter issues

The patch fixes the counter print, missing line,
and delete warnings.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: break loop after found matching chain
Giuseppe Longo [Wed, 19 Jun 2013 11:14:23 +0000 (13:14 +0200)] 
nft: break loop after found matching chain

This patch breaks looping in nft_chain_user_del, nft_chain_zero_counters
and nft_rule_flush after the chain is found.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: nft: remove lots of useless debugging messages
Pablo Neira Ayuso [Tue, 18 Jun 2013 00:50:48 +0000 (02:50 +0200)] 
xtables: nft: remove lots of useless debugging messages

While at it, fix several memleaks of list objects.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: remove bogus comment on chain rename
Pablo Neira Ayuso [Tue, 18 Jun 2013 00:41:34 +0000 (02:41 +0200)] 
xtables: remove bogus comment on chain rename

No longer true since Patrick added the chain rename approach back in
September 2012.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: allow to zero chains via -Z
Giuseppe Longo [Tue, 18 Jun 2013 00:29:11 +0000 (02:29 +0200)] 
xtables: allow to zero chains via -Z

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix leaks in nft_xtables_config_load
Pablo Neira Ayuso [Wed, 12 Jun 2013 09:49:52 +0000 (11:49 +0200)] 
nft: fix leaks in nft_xtables_config_load

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix leak of chain iterator in nft_rule_list
Giuseppe Longo [Sat, 8 Jun 2013 03:40:04 +0000 (03:40 +0000)] 
nft: fix leak of chain iterator in nft_rule_list

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: fix leak of rule and chain iterators
Giuseppe Longo [Sat, 8 Jun 2013 02:24:35 +0000 (02:24 +0000)] 
nft: fix leak of rule and chain iterators

This patch fixes the leak of chain and rule iterators.

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: fix -p protocol
Pablo Neira Ayuso [Sat, 1 Jun 2013 19:14:47 +0000 (21:14 +0200)] 
xtables: fix -p protocol

The protocol field in both IPv4 and IPv6 headers are 8 bits long,
so we have to compare 8 bits.

Reported-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-restore: output the same error message that iptables-restore uses
Pablo Neira Ayuso [Fri, 31 May 2013 14:21:04 +0000 (16:21 +0200)] 
xtables-restore: output the same error message that iptables-restore uses

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: don't call nft_init in nft_xtables_config_load
Pablo Neira Ayuso [Fri, 31 May 2013 12:54:33 +0000 (14:54 +0200)] 
nft: don't call nft_init in nft_xtables_config_load

Otherwise we keep initializing the handle over and over again.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: fix compilation due to missing autogenerated header
Pablo Neira Ayuso [Tue, 21 May 2013 22:39:36 +0000 (00:39 +0200)] 
xtables: fix compilation due to missing autogenerated header

Fix compilation:

nft.c:51:35: fatal error: xtables-config-parser.h: File or directory doesn't exist

xtables-config-parser.h was generated after compiling nft.c.

Reported-by: Giuseppe Longo <giuseppelng@gmail.com>
Tested-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: policy can be changed only on builtin chain
Tomasz Bursztyka [Tue, 14 May 2013 00:52:04 +0000 (00:52 +0000)] 
xtables: policy can be changed only on builtin chain

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: initialize xtables defaults even on listing rules
Tomasz Bursztyka [Tue, 14 May 2013 00:52:02 +0000 (00:52 +0000)] 
xtables: initialize xtables defaults even on listing rules

Output of the tool should be the same as for iptables.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: remove unused leftover definitions
Pablo Neira Ayuso [Sun, 12 May 2013 14:50:31 +0000 (16:50 +0200)] 
xtables: remove unused leftover definitions

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: add new nft_ops->post_parse hook
Pablo Neira Ayuso [Sun, 12 May 2013 14:47:11 +0000 (16:47 +0200)] 
xtables: add new nft_ops->post_parse hook

Move specific layer 3 protocol post argument parsing code
to the respective nft-ipv[4|6].c files.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: add new container xtables_args structure
Pablo Neira Ayuso [Sun, 12 May 2013 13:33:54 +0000 (15:33 +0200)] 
xtables: add new container xtables_args structure

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: update .gitignore
Pablo Neira Ayuso [Mon, 22 Apr 2013 11:48:00 +0000 (13:48 +0200)] 
iptables: update .gitignore

Ignore xtables-config-* generated by flex and bison.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-config-parser: fix compilation warning
Pablo Neira Ayuso [Mon, 22 Apr 2013 11:43:07 +0000 (13:43 +0200)] 
xtables-config-parser: fix compilation warning

xtables-config-parser.y: In function ‘xtables_config_parse’:
xtables-config-parser.y:216:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: fix missing protocol and invflags
Pablo Neira Ayuso [Sun, 24 Mar 2013 12:15:23 +0000 (13:15 +0100)] 
xtables: fix missing protocol and invflags

xtables -I INPUT -p tcp --dport 22 -j ACCEPT
iptables: Target problem. Run `dmesg' for more information
x_tables: ip_tables: tcp match: only valid for protocol

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoiptables: fix compilation when lib[mnl|nftables] are not in standard path
Nicolas Dichtel [Wed, 6 Mar 2013 05:00:31 +0000 (05:00 +0000)] 
iptables: fix compilation when lib[mnl|nftables] are not in standard path

There was several problems:
 a typo in the configure option
 a typo in CFLAGS addon for libmnl and libnftables
 paths to lib were missing on link

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-config: fix off by one in parsed strings from /etc/xtables.conf
Pablo Neira Ayuso [Sun, 10 Mar 2013 15:56:20 +0000 (16:56 +0100)] 
xtables-config: fix off by one in parsed strings from /etc/xtables.conf

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: support family in /etc/xtables.conf file
Pablo Neira Ayuso [Sun, 10 Mar 2013 15:20:27 +0000 (16:20 +0100)] 
xtables: support family in /etc/xtables.conf file

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: load tables and chains based on /etc/xtables.conf
Pablo Neira Ayuso [Sun, 10 Mar 2013 15:04:39 +0000 (16:04 +0100)] 
nft: load tables and chains based on /etc/xtables.conf

If /etc/xtables.conf is available, use the configuration there to
autoload the xtables built-in table and chain so you can define custom
configurations. Otherwise, rely on default common table/chain
configuration.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-config: priority has to be per-chain to support
Pablo Neira Ayuso [Sun, 10 Mar 2013 10:43:32 +0000 (11:43 +0100)] 
xtables-config: priority has to be per-chain to support

To support NAT table chain configuration appropriately. Modify example
configuration file as well.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-standalone: fix error message
Pablo Neira Ayuso [Sat, 9 Mar 2013 00:04:29 +0000 (01:04 +0100)] 
xtables-standalone: fix error message

xtables -m tcp -h
(nil) v1.4.15: ...
^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables: fix missing xtables_exit_error definition
Pablo Neira Ayuso [Sat, 9 Mar 2013 00:01:11 +0000 (01:01 +0100)] 
xtables: fix missing xtables_exit_error definition

iptables_exit_error is defined in iptables/iptables.c, that
symbol cannot be used by iptables/xtables.c

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: remove license for header file
Pablo Neira Ayuso [Sat, 23 Feb 2013 18:36:46 +0000 (19:36 +0100)] 
nft: remove license for header file

No tradition in the project to include the header file in .h file.
This one is also internal - not exported.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-save: add -4 and -6 support
Pablo Neira Ayuso [Sat, 23 Feb 2013 17:30:36 +0000 (18:30 +0100)] 
xtables-save: add -4 and -6 support

Now you can specify:

 xtables-save -6 > my-ip6tables-ruleset

to dump the IPv6 rule-set.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxtables-restore: add -4 and -6 support
Pablo Neira Ayuso [Sat, 23 Feb 2013 17:27:08 +0000 (18:27 +0100)] 
xtables-restore: add -4 and -6 support

Now you can specify:

 xtables-restore -6 < my-ip6tables-ruleset

to restore the IPv6 rule-set.

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