]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
12 years agopayload: fix endianess of ARP operation code
Pablo Neira Ayuso [Sat, 14 Sep 2013 18:37:26 +0000 (20:37 +0200)] 
payload: fix endianess of ARP operation code

So it display compatibility command:

xtables-arp -A INPUT --opcode Reply -j DROP

accordinly:

arp plen 4 arp operation reply counter packets 0 bytes 0 drop

12 years agosrc: Better error reporting if chain type is invalid
Tomasz Bursztyka [Wed, 4 Sep 2013 09:50:20 +0000 (12:50 +0300)] 
src: Better error reporting if chain type is invalid

This patch verifies at command line parsing that given chain type
is valid. Possibilities are: filter, nat, and route.

nft add chain test test { type cheese hook input priority 0 };
<cmdline>:1:28-33: Error: unknown chain type cheese
add chain test test { type cheese hook input priority 0 };
                           ^^^^^^

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodatatype: fix mark parsing if string is used
Pablo Neira Ayuso [Wed, 4 Sep 2013 11:13:35 +0000 (13:13 +0200)] 
datatype: fix mark parsing if string is used

This fixes string mark parsing. Note that /etc/iproute2/rt_marks may
contain mapping between string and mark values.

This fixes here:

add rule filter output meta mark 0 counter

Assumming that:

cat /etc/iproute2/rt_marks

says:

0 test

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agometa: fix output display of meta length
Pablo Neira Ayuso [Wed, 4 Sep 2013 10:51:13 +0000 (12:51 +0200)] 
meta: fix output display of meta length

nft list table filter

Before:
meta len 1000 counter packets 0 bytes 0
After:
meta length 1000 counter packets 0 bytes 0

Now it doesn't break with nft -f.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: Update bate chain creation according to latest syntax changes
Tomasz Bursztyka [Wed, 4 Sep 2013 09:50:22 +0000 (12:50 +0300)] 
tests: Update bate chain creation according to latest syntax changes

Adding type, plain hook's name and priority keyword.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: Add priority keyword on base chain description
Tomasz Bursztyka [Wed, 4 Sep 2013 09:50:21 +0000 (12:50 +0300)] 
src: Add priority keyword on base chain description

Instead of:
add chain foo bar { type route hook input 0; }

it should be now:
add chain foo bar { type route hook input priority 0; }

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
12 years agosrc: Wrap netfilter hooks around human readable strings
Tomasz Bursztyka [Wed, 4 Sep 2013 09:50:19 +0000 (12:50 +0300)] 
src: Wrap netfilter hooks around human readable strings

This allows to use unique, human readable, hook names for the command
line and let the user being unaware of the complex netfilter's hook
names and there difference depending on the netfilter family.

So:
add chain foo bar { type route hook NF_INET_LOCAL_IN 0; }

becomes:
add chain foo bar { type route hook input 0; }

It also fixes then the difference in hook values between families.
I.e. ARP family has different values for input, forward and output
compared to IPv4, IPv6 or bridge.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoINSTALL: Update dependency list and repository URLs
Tomasz Bursztyka [Thu, 29 Aug 2013 06:18:39 +0000 (09:18 +0300)] 
INSTALL: Update dependency list and repository URLs

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: Fix base chain printing
Tomasz Bursztyka [Wed, 28 Aug 2013 08:33:07 +0000 (11:33 +0300)] 
src: Fix base chain printing

Relying on chain's hooknum to know whether the chain is a base one or
not is bogus: having 0 as hooknum is a valid number. Thus setting the
right flag and handling it is the way to go, as parser does already.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: allow to specify the base chain type
Pablo Neira Ayuso [Thu, 22 Aug 2013 15:26:31 +0000 (17:26 +0200)] 
src: allow to specify the base chain type

This patch allows you to specify the type of the base chain, eg.

add table mangle
add chain mangle OUTPUT { type route hook NF_INET_LOCAL_OUT 0; }

The chain type determines the semantics of the chain, we currently
have three types:

* filter, used for plain packet filtering.
* nat, it only sees the first packet of the flow.
* route, which is the equivalent of the iptables mangle table, that
  triggers a re-route if there is any change in some of the packet header
  fields, eg. IP TOS/DSCP, or the packet metainformation, eg. mark.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodatatype: fix wrong endianess in numeric ports
Pablo Neira Ayuso [Sat, 24 Aug 2013 10:27:57 +0000 (12:27 +0200)] 
datatype: fix wrong endianess in numeric ports

In (5075879 datatype: validate port number in inet_service_type_parse),
conversion to network byte order was missing.

Reported-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonftables: add additional --numeric level
Phil Oester [Thu, 15 Aug 2013 23:24:11 +0000 (16:24 -0700)] 
nftables: add additional --numeric level

Personally, I like seeing ports and IPs numerically, but prefer protocols
to be shown by name.  As such, add a third --numeric level which will
show protocols by number, splitting them out from ports.

  -n/--numeric                  When specified once, show network addresses numerically.
                                When specified twice, also show Internet services,
                                user IDs and group IDs numerically.
                                When specified thrice, also show protocols numerically.

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agolog: convert group and qthreshold to use u16
Pablo Neira Ayuso [Sat, 17 Aug 2013 10:41:49 +0000 (12:41 +0200)] 
log: convert group and qthreshold to use u16

Required since (netfilter: nft_log: group and qthreshold are 2^16)
kernel change.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodatatype: allow protocols by number in inet_protocol_type_parse
Phil Oester [Thu, 15 Aug 2013 23:09:07 +0000 (16:09 -0700)] 
datatype: allow protocols by number in inet_protocol_type_parse

nftables does not currently allow specifying protocols by number.  Below
patch adds this capability.

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodatatype: validate port number in inet_service_type_parse
Phil Oester [Thu, 15 Aug 2013 17:19:11 +0000 (10:19 -0700)] 
datatype: validate port number in inet_service_type_parse

At present, nft accepts out of range port values such as in this example:

    nft add rule ip filter input tcp dport 123456 accept

Attached patch adds checks for both integer overflow and 16 bit overflow,
and avoids getaddrinfo call in the (common) case of digit input. Example
above now produces this output:

    <cmdline>:1:36-41: Error: Service out of range
    add rule ip filter input tcp dport 123456 accept
                                       ^^^^^^
Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: Add icmpv6 support
Eric Leblond [Sun, 28 Jul 2013 22:30:56 +0000 (00:30 +0200)] 
src: Add icmpv6 support

This patch adds ICMPv6 support to nftables. It is now possible to
write rules such as:

  nft add rule ip6 filter input icmpv6 type nd-router-advert accept

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodatatype: fix crash if wrong integer type is passed
Pablo Neira Ayuso [Wed, 24 Jul 2013 13:14:22 +0000 (15:14 +0200)] 
datatype: fix crash if wrong integer type is passed

Eric Leblond reported that this command:

nft add rule ip6 filter input position 4 meta protocol icmpv6 accept

crashes nft. The problem is that 'icmpv6' is wrong there, as
meta protocol is expecting an ethernet protocol, that can be
expressed as an hexadecimal.

Now this command displays the following error:

<cmdline>:1:52-57: Error: This is not a valid Ethernet protocol
add rule ip6 filter input position 4 meta protocol icmpv6 accept
                                                   ^^^^^^

This closes bugzilla #834:
https://bugzilla.netfilter.org/show_bug.cgi?id=834

Reported-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: Add support for insertion inside rule list
Eric Leblond [Sat, 6 Jul 2013 15:33:57 +0000 (17:33 +0200)] 
src: Add support for insertion inside rule list

This patch adds support to insert and to add rule using a rule
handle as reference. The rule handle syntax has an new optional
position field which take a handle as argument.

Two examples:

  nft add rule filter output position 5 ip daddr 1.2.3.1 drop
  nft insert rule filter output position 5 ip daddr 1.2.3.1 drop

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agomnl: use nft_*_list_add_tail
Pablo Neira Ayuso [Tue, 16 Jul 2013 20:35:07 +0000 (22:35 +0200)] 
mnl: use nft_*_list_add_tail

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

Signed-off-by: Pablo Neira Ayuso <pablo@soleta.eu>
12 years agodatatype: fix table listing if name resolution is not available
Pablo Neira Ayuso [Sat, 6 Jul 2013 14:38:18 +0000 (16:38 +0200)] 
datatype: fix table listing if name resolution is not available

nft list table filter returns garbage here for IP and IPv6 addresses if
no name resolution is available. The output looks good if `-n' is used
in that case.

The problem is that getnameinfo() returns:

EAI_AGAIN   -3    /* Temporary failure in name resolution.  */

Without working name resolution. To fix this, force a fall back to
numeric resolution in that case.

While at it, fix also possible resolution of services in case of
that /etc/services is missing in the system.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonetlink: fix network address prefix
Pablo Neira Ayuso [Sat, 22 Jun 2013 17:12:24 +0000 (19:12 +0200)] 
netlink: fix network address prefix

eg. nft add rule filter output ip daddr 192.168.1.0/24 counter

so far, this operation was only possible using sets.

nft add rule filter output ip daddr \{ 192.168.1.0/24 \} counter

While at it, move all binop postprocess code to a new function that
contains this transformation and the existing bitmask to constant
(as used by eg. ct state new,established).

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: use libnftables
Pablo Neira Ayuso [Thu, 13 Jun 2013 14:38:33 +0000 (16:38 +0200)] 
src: use libnftables

This patch migrates nft to use the libnftables library, that is used
by the iptables over nftables compat utility as well. Most of the
conversion was pretty straight forward. Some small significant changes
happened in the handling of set element and immediate data abstraction
that libnl provides. libnftables is a bit more granular since it splits
the struct nfnl_nft_data into three attributes: verdict, chain and plain
data (used in maps).

I have added a new file src/mnl.c that contains the low level netlink
communication that now resides in nftables source tree instead of
the library. This should help to implement the batching support using
libmnl in follow up patches.

I also spent some significant amount of time running my tests to make
sure that we don't increase the number of bugs that we already have
(I plan to provide a list of those that I have detected and diagnosed,
so anyone else can help us to fix them).

As a side effect, this change should also prepare the ground for
JSON and XML support anytime soon.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agometa: replace rtnl_tc_handle2str and rtnl_tc_str2handle
Pablo Neira Ayuso [Fri, 21 Jun 2013 13:27:11 +0000 (15:27 +0200)] 
meta: replace rtnl_tc_handle2str and rtnl_tc_str2handle

Provide replacements for rtnl_tc_handle2str and rtnl_tc_str2handle,
it removes the dependency with libnl-route.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agometa: use if_nametoindex and if_indextoname
Pablo Neira Ayuso [Sun, 16 Jun 2013 22:43:43 +0000 (00:43 +0200)] 
meta: use if_nametoindex and if_indextoname

Instead of having a cache of ifindex based on libnl. Those functions
basically use rtnetlink as well to perform the translation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: family field in struct handle is unsigned
Pablo Neira Ayuso [Mon, 17 Jun 2013 15:54:56 +0000 (17:54 +0200)] 
rule: family field in struct handle is unsigned

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: get it sync with current include/linux/netfilter/nf_tables.h
Pablo Neira Ayuso [Thu, 13 Jun 2013 15:25:57 +0000 (17:25 +0200)] 
src: get it sync with current include/linux/netfilter/nf_tables.h

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoevaluate: fix range and comparison evaluation
Pablo Neira Ayuso [Wed, 12 Jun 2013 17:36:52 +0000 (19:36 +0200)] 
evaluate: fix range and comparison evaluation

This patch fixes these two commands:

nft add rule ip test test ip saddr 1.1.1.1-2.2.2.2
nft add rule ip test test ip saddr < 1.1.1.1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: fix counter restoration
Eric Leblond [Sat, 8 Jun 2013 23:08:47 +0000 (01:08 +0200)] 
src: fix counter restoration

It was not possible to restore a ruleset countaining counter. The
packets and bytes fields were not known from the parser but they
were in the output of the list command.

This patch fixes the issue by restoring correctly the counters if
they are present in the command.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: display hook info
Eric Leblond [Sat, 8 Jun 2013 23:08:46 +0000 (01:08 +0200)] 
rule: display hook info

It was not possible to restore a ruleset because of missing
hook information. This patch adds hooknum output to list
operation.

[ Mangled this patch to use a string array mapping hook numbers
  and name --pablo ]

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodatatype: concat expression only releases dynamically allocated datatype
Pablo Neira Ayuso [Thu, 6 Jun 2013 11:25:39 +0000 (13:25 +0200)] 
datatype: concat expression only releases dynamically allocated datatype

Eric Leblond reports a crash with the following invalid command:

 nft add rule global filter ip daddr . tcp dport { 192.168.0.1 . 22\; 192.168.0.3 . 89 } drop

Note that the semicolon is incorrect in that concatenation,
it should be a comma.

The backtrace shows:
(gdb) bt
 #0  0x00007ffff6f39295 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 #1  0x00007ffff6f3c438 in __GI_abort () at abort.c:90
 #2  0x00007ffff6f7486b in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7ffff7070d28 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:199
 #3  0x00007ffff6f7eac6 in malloc_printerr (action=3, str=0x7ffff706ccca "free(): invalid pointer", ptr=<optimized out>) at malloc.c:4902
 #4  0x00007ffff6f7f843 in _int_free (av=<optimized out>, p=0x428530, have_lock=0) at malloc.c:3758
 #5  0x000000000041aae8 in xfree (ptr=0x428540 <invalid_type>) at src/utils.c:29
 #6  0x000000000040bc43 in concat_type_destroy (dtype=0x428540 <invalid_type>) at src/datatype.c:690
 #7  0x000000000040cebf in concat_expr_destroy (expr=0x643b90) at src/expression.c:571
[...]

It's trying to release 'invalid_type', which was not dynamically
allocated. Note that before the evaluation step, the invalid type
is attached to the expressions.

Since nftables allocates a dynamic datatype for concatenations in
case that needs to be released in the exit path. All datatypes
except this, are allocated in the BSS. Since we have no way to
differenciate between these two, add a flag so we can recognize
dynamically allocated datatypes.

While at it, rename dtype->type from enum to explicit uint32_t, as
it is used to store the concatenation type mask as well.

Reported-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agocli: reset terminal when CTRL+d is pressed
Eric Leblond [Sun, 2 Jun 2013 10:18:03 +0000 (12:18 +0200)] 
cli: reset terminal when CTRL+d is pressed

The terminal was not correctly resetted when CTRL+d was pressed.
The result was that reset has to be called from shell after exit.

12 years agocli: add quit command
Eric Leblond [Sun, 2 Jun 2013 10:03:13 +0000 (12:03 +0200)] 
cli: add quit command

12 years agorule: list elements in set in any case
Eric Leblond [Fri, 31 May 2013 08:50:32 +0000 (10:50 +0200)] 
rule: list elements in set in any case

"nft list table" command was not displaying the elements of named
set. This was thus not possible to restore a ruleset by using the
listing output. This patch modifies the code to display the elements
of set in all cases.

12 years agodoc: fix inversion of operator and object.
Eric Leblond [Thu, 30 May 2013 13:33:16 +0000 (15:33 +0200)] 
doc: fix inversion of operator and object.

12 years agorule: add flag to display rule handle as comment
Eric Leblond [Thu, 30 May 2013 04:22:46 +0000 (04:22 +0000)] 
rule: add flag to display rule handle as comment

Knowing the rule handle is necessary to be able to delete a single
rule. It was not displayed till now in the output and it was thus
impossible to remove a single rule.
This patch modify the listing output to add a comment containing
the handle when the -a/--handle flag is provided.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agocli: complete basic functionality of the interactive mode
Pablo Neira Ayuso [Tue, 14 May 2013 17:49:13 +0000 (19:49 +0200)] 
cli: complete basic functionality of the interactive mode

This patch adds missing code to get basic interactive mode
operative via `nft -i', including parsing, evaluation,
command execution via netlink and error reporting.

Autocomplete is not yet implemented.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoparser: fix size of internet protocol expressions matching keywords
Patrick McHardy [Mon, 22 Apr 2013 23:08:26 +0000 (01:08 +0200)] 
parser: fix size of internet protocol expressions matching keywords

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoparser: include leading '.' in concat subexpression location
Patrick McHardy [Mon, 22 Apr 2013 17:58:54 +0000 (19:58 +0200)] 
parser: include leading '.' in concat subexpression location

Make error messages point to the entire subexpression.

Before:

filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh}
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^

After:

filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh}
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoexpr: catch missing and excess elements in concatenations
Patrick McHardy [Mon, 22 Apr 2013 16:50:44 +0000 (18:50 +0200)] 
expr: catch missing and excess elements in concatenations

# nft -nn filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh }
<cmdline>:1:50-66: Error: datatype mismatch, expected concatenation of (IPv4 address, internet network service, internet network service), expression has type concatenation of (IPv4 address, internet network service)
filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh }
                                                 ^^^^^^^^^^^^^^^^^

# nft -nn filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh}
<cmdline>:1:76-78: Error: unexpected concat component, expecting concatenation of (IPv4 address, internet network service, internet network service)
filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh}
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agotests: obj-table: update examples to use the current syntax
Pablo Neira Ayuso [Sat, 20 Apr 2013 10:59:16 +0000 (12:59 +0200)] 
tests: obj-table: update examples to use the current syntax

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: set: update examples to use the current syntax
Pablo Neira Ayuso [Sat, 20 Apr 2013 10:54:33 +0000 (12:54 +0200)] 
tests: set: update examples to use the current syntax

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: dictionary: update examples to use the current syntax
Pablo Neira Ayuso [Sat, 20 Apr 2013 10:52:45 +0000 (12:52 +0200)] 
tests: dictionary: update examples to use the current syntax

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: obj-chain: update examples to use the current syntax
Pablo Neira Ayuso [Sat, 20 Apr 2013 10:10:05 +0000 (12:10 +0200)] 
tests: obj-chain: update examples to use the current syntax

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: expr-meta: update examples to use the current syntax
Pablo Neira Ayuso [Sat, 20 Apr 2013 10:08:00 +0000 (12:08 +0200)] 
tests: expr-meta: update examples to use the current syntax

Also enable nftrace, now that nftables kernel-space supports this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agometa: accept uid/gid in numerical
Pablo Neira Ayuso [Sat, 20 Apr 2013 10:06:19 +0000 (12:06 +0200)] 
meta: accept uid/gid in numerical

You can use the user/group name or alternatively the uid/gid.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: feat-adjancent-load-merging: remove ip protocol from rule
Pablo Neira Ayuso [Sat, 20 Apr 2013 09:54:51 +0000 (11:54 +0200)] 
tests: feat-adjancent-load-merging: remove ip protocol from rule

No need to include this, it is now added as a dependency.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: family-bridge: update to use the current syntax
Pablo Neira Ayuso [Sat, 20 Apr 2013 09:53:02 +0000 (11:53 +0200)] 
tests: family-bridge: update to use the current syntax

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agopayload: accept ethertype in hexadecimal
Pablo Neira Ayuso [Sat, 20 Apr 2013 09:51:40 +0000 (11:51 +0200)] 
payload: accept ethertype in hexadecimal

You can use the symbols ip, ip6, arp and vlan, or alternatively
the ethertype protocol number.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: family-ipv6: update to use the current syntax
Pablo Neira Ayuso [Fri, 19 Apr 2013 11:29:11 +0000 (13:29 +0200)] 
tests: family-ipv6: update to use the current syntax

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: fix crash if nft -f wrong_file is passed
Pablo Neira Ayuso [Fri, 19 Apr 2013 10:48:44 +0000 (12:48 +0200)] 
src: fix crash if nft -f wrong_file is passed

Now it displays:

nft -f wrong_file
internal:0:0-0: Error: Could not open file "wrong_file": No such file or directory

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: expr-ct: update examples to use the current syntax
Pablo Neira Ayuso [Thu, 18 Apr 2013 17:25:33 +0000 (19:25 +0200)] 
tests: expr-ct: update examples to use the current syntax

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agomark: fix numeric mark value parsing
Patrick McHardy [Thu, 18 Apr 2013 17:13:16 +0000 (19:13 +0200)] 
mark: fix numeric mark value parsing

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agocmd/netlink: make sure we always have a location in netlink operations
Patrick McHardy [Thu, 18 Apr 2013 15:53:59 +0000 (17:53 +0200)] 
cmd/netlink: make sure we always have a location in netlink operations

Improve error reporting by always using a location in netlink operations.

Signed-off-by: Patrick McHardy<kaber@trash.net>
12 years agotests: family-ipv4: update test to use current syntax
Pablo Neira Ayuso [Thu, 18 Apr 2013 15:45:46 +0000 (17:45 +0200)] 
tests: family-ipv4: update test to use current syntax

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agomain: fix error checking in nft_parse
Pablo Neira Ayuso [Thu, 18 Apr 2013 15:15:05 +0000 (17:15 +0200)] 
main: fix error checking in nft_parse

The bison parser returns 0 in case of success and it returns 1 in
case of error.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonetlink: return error if chain not found
Pablo Neira Ayuso [Thu, 18 Apr 2013 14:33:18 +0000 (16:33 +0200)] 
netlink: return error if chain not found

Before this patch:

nft list chain filter xxx
table filter {
}

After this patch:

nft list chain filter xxx
internal:0:0-0: Error: Could not find chain `xxx' in table `filter: Object not found

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: fix nft list chain
Pablo Neira Ayuso [Thu, 18 Apr 2013 14:28:41 +0000 (16:28 +0200)] 
rule: fix nft list chain

Use netlink_list_chains instead of netlink_list_chain (note the final `s')

After "nft list table filter" shows:

table filter {
        chain input {
        }
}

"nft list chain filter input" shows:

table filter {
}

12 years agorule: allow to list of existing tables
Pablo Neira Ayuso [Thu, 18 Apr 2013 10:28:25 +0000 (12:28 +0200)] 
rule: allow to list of existing tables

You can now specify: nft list tables ip

to obtain the list of all existing tables.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: fix concat expression type propagation
Patrick McHardy [Sun, 14 Apr 2013 22:36:36 +0000 (00:36 +0200)] 
expr: fix concat expression type propagation

Dynamically instantiate a data type to represent all types of a concatenation
and use that for type propagation.

12 years agotypes: add ethernet address type
Patrick McHardy [Mon, 15 Apr 2013 14:16:04 +0000 (16:16 +0200)] 
types: add ethernet address type

Add a new type for ethernet addresses. This is needed since for concatenations
we need fixed sized data types, the generic link layer address doesn't have
a fixed length.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agodatatype: parse/print in all basetypes subsequently
Patrick McHardy [Mon, 15 Apr 2013 14:18:17 +0000 (16:18 +0200)] 
datatype: parse/print in all basetypes subsequently

Go down the chain of basetypes until we find a ->parse()/->print() callback
or symbol table. Needed to invoke the generic link layer address parsing
function for the etheraddr_type.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoexpr: kill EXPR_F_PRIMARY
Patrick McHardy [Sun, 14 Apr 2013 22:39:22 +0000 (00:39 +0200)] 
expr: kill EXPR_F_PRIMARY

Not used anymore, kill it.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agonetlink_delinearize: don't reset source register after read
Patrick McHardy [Thu, 27 Dec 2012 14:16:25 +0000 (15:16 +0100)] 
netlink_delinearize: don't reset source register after read

Range expression use a single load and two comparisons. Don't reset the
source register in netlink_delinearize when reading it.

Fixes: "Relational expression has no left hand side" for range (x-y)
expressions.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agochains: add rename testcases
Patrick McHardy [Sat, 15 Dec 2012 16:25:02 +0000 (17:25 +0100)] 
chains: add rename testcases

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agorule: add rule insertion (prepend) support
Patrick McHardy [Fri, 14 Dec 2012 16:50:10 +0000 (17:50 +0100)] 
rule: add rule insertion (prepend) support

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agochains: add chain rename support
Patrick McHardy [Fri, 14 Dec 2012 16:39:22 +0000 (17:39 +0100)] 
chains: add chain rename support

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agonetlink: fix query requests
Patrick McHardy [Fri, 14 Dec 2012 16:30:06 +0000 (17:30 +0100)] 
netlink: fix query requests

The callback needs to be set before sending the query since nl_wait_for_ack()
already does message reception.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agotests: add loop detection tests
Patrick McHardy [Mon, 10 Dec 2012 16:10:58 +0000 (17:10 +0100)] 
tests: add loop detection tests

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agocmd: fix handle use after free for implicit set declarations
Patrick McHardy [Mon, 10 Dec 2012 15:20:14 +0000 (16:20 +0100)] 
cmd: fix handle use after free for implicit set declarations

The implicit set declaration passes the set's handle to cmd_alloc(), which copies
the pointers to the allocated strings. Later on both the set's handle and the
commands handle are freed, resulting in a use after free.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agorule: reenable adjacent payload merging
Patrick McHardy [Sun, 9 Dec 2012 13:06:08 +0000 (14:06 +0100)] 
rule: reenable adjacent payload merging

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agosets: fix sets using intervals
Patrick McHardy [Sun, 9 Dec 2012 12:35:23 +0000 (13:35 +0100)] 
sets: fix sets using intervals

When using intervals, the initializers set_flags are set to SET_F_INTERVAL,
however that is not propagated back to the set, so the segtree construction
is not performed.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agonetlink: fix endless loop on 64 bit when parsing binops
Patrick McHardy [Sun, 9 Dec 2012 13:55:03 +0000 (14:55 +0100)] 
netlink: fix endless loop on 64 bit when parsing binops

mpz_scan1() returns ULONG_MAX when no more bits are found. Due to assignment
to an unsigned int, this value was truncated on 64 bit and the loop never
terminated.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agorules: change rule handle to 64 bit
Patrick McHardy [Sun, 9 Dec 2012 13:25:27 +0000 (14:25 +0100)] 
rules: change rule handle to 64 bit

Recent kernel versions are using 64 bit for the rule handle.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoexpression: fix constant expression splicing
Patrick McHardy [Sun, 9 Dec 2012 13:02:11 +0000 (14:02 +0100)] 
expression: fix constant expression splicing

Fix reversed order during constant splicing.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agopayload: kill redundant payload protocol expressions during netlink postprocessing
Patrick McHardy [Sun, 9 Dec 2012 12:34:29 +0000 (13:34 +0100)] 
payload: kill redundant payload protocol expressions during netlink postprocessing

Kill payload protocol expressions like "ip protocol tcp" if a higher layer
payload expression already implies this, like "tcp dport 22".

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoseqtree: update mapping data when keeping the base
Patrick McHardy [Sat, 8 Dec 2012 19:42:16 +0000 (20:42 +0100)] 
seqtree: update mapping data when keeping the base

When a prefix expression is followed by another prefix expression using the
same base but a wider prefix, we need to update the mapping data to that of
the second expression.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agotests: add verdict map test
Patrick McHardy [Sat, 8 Dec 2012 19:26:10 +0000 (20:26 +0100)] 
tests: add verdict map test

Signed-off-by: Patrick McHardy <kaber@ŧrash.net>
12 years agosegtree: fix segtree to properly support mappings
Patrick McHardy [Sat, 8 Dec 2012 19:17:17 +0000 (20:17 +0100)] 
segtree: fix segtree to properly support mappings

Requires to use proper types for keys and data and using the key values for reverse
transformation.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agodebug: include verbose message in all BUG statements
root [Sat, 8 Dec 2012 17:08:44 +0000 (18:08 +0100)] 
debug: include verbose message in all BUG statements

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoevaluate: reintroduce type chekcs for relational expressions
Patrick McHardy [Wed, 5 Dec 2012 18:45:22 +0000 (19:45 +0100)] 
evaluate: reintroduce type chekcs for relational expressions

Since the parser can now generate constant expressions of a specific type
not determinaed by the LHS, we need to check that relational expressions
are actually using the correct types to avoid accepting stupid things
like "tcp dport tcp".

12 years agoparser: fix parsing protocol names for protocols which are also keywords
Patrick McHardy [Wed, 5 Dec 2012 18:39:00 +0000 (19:39 +0100)] 
parser: fix parsing protocol names for protocols which are also keywords

"ip protocol tcp" will currently produce a syntax error since tcp is also a keyword
which is expected ot be followed by a tcp header field. Allow to use protocol names
that are also keywords and allocate a constant expression for them.

13 years agotests: fix test, commands now comes before the family and table name
Pablo Neira Ayuso [Fri, 3 Aug 2012 17:56:37 +0000 (19:56 +0200)] 
tests: fix test, commands now comes before the family and table name

Most tests still don't work though. They still need another fix.

Reported-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
13 years agoexpression: Differentiate expr among anonymous structures in struct expr
Tomasz Bursztyka [Thu, 2 Aug 2012 00:31:35 +0000 (00:31 +0000)] 
expression: Differentiate expr among anonymous structures in struct expr

This fixes compilation with gcc-4.7

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
13 years agoerec: Handle returned value properly in erec_print
Tomasz Bursztyka [Thu, 2 Aug 2012 00:31:34 +0000 (00:31 +0000)] 
erec: Handle returned value properly in erec_print

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
13 years agoevaluate: Remove useless variable in expr_evaluate_bitwise()
Tomasz Bursztyka [Thu, 2 Aug 2012 00:31:33 +0000 (00:31 +0000)] 
evaluate: Remove useless variable in expr_evaluate_bitwise()

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
13 years agonetlink: Use the right datatype for verdict
Tomasz Bursztyka [Thu, 2 Aug 2012 00:31:32 +0000 (00:31 +0000)] 
netlink: Use the right datatype for verdict

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
15 years agoadd bridge filter table definitions
Patrick McHardy [Tue, 6 Jul 2010 04:17:01 +0000 (06:17 +0200)] 
add bridge filter table definitions

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agohelp: fix of the -I option in help display
Romain Bignon [Tue, 6 Jul 2010 04:16:37 +0000 (06:16 +0200)] 
help: fix of the -I option in help display

Trivial patch which fixes typo.

Signed-off-by: Romain Bignon <romain@peerfuse.org>
Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agodatatype: reject incompletely parsed integers in integer_type_parse()
Patrick McHardy [Tue, 6 Jul 2010 04:11:48 +0000 (06:11 +0200)] 
datatype: reject incompletely parsed integers in integer_type_parse()

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agodon't use internal_location for files specified on command line
Patrick McHardy [Tue, 6 Jul 2010 04:11:18 +0000 (06:11 +0200)] 
don't use internal_location for files specified on command line

Fixes strange error messages like:

In file included from internal:0:0-0:
files/examples/sets_and_maps:55:2-2: Error: syntax error, unexpected newline, expecting string

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agonetlink: add debugging for missing objects
Patrick McHardy [Tue, 6 Jul 2010 04:08:56 +0000 (06:08 +0200)] 
netlink: add debugging for missing objects

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agonat: validate protocol context when performing transport protocol mappings
Patrick McHardy [Tue, 6 Jul 2010 03:57:23 +0000 (05:57 +0200)] 
nat: validate protocol context when performing transport protocol mappings

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agonetlink: fix nat stmt linearization/parsing
Patrick McHardy [Tue, 6 Jul 2010 03:57:23 +0000 (05:57 +0200)] 
netlink: fix nat stmt linearization/parsing

Fix invalid register use when parsing NAT statements and handle range expressions
during postprocessing. When linearizing, allocate all registers for both proto and
address expressions at once to avoid double use.

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agopayload: fix crash with uncombinable protocols
Patrick McHardy [Tue, 6 Jul 2010 03:57:22 +0000 (05:57 +0200)] 
payload: fix crash with uncombinable protocols

The dependency of non-combinable protocols (f.i. arp + tcp) results in
a relational dependency expression without a datatype, causing a segfault
later on.

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agonetlink: fix creation of base chains with hooknum and priority 0
Patrick McHardy [Tue, 6 Jul 2010 03:57:22 +0000 (05:57 +0200)] 
netlink: fix creation of base chains with hooknum and priority 0

Base chains with both a hook number and priority of zero are created
as regular chains. Fix by adding a BASECHAIN flag indicating that the
chain should be created as a base chain.

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agoutils: fix invalid assertion in xrealloc()
Patrick McHardy [Tue, 6 Jul 2010 03:57:21 +0000 (05:57 +0200)] 
utils: fix invalid assertion in xrealloc()

The pointer is allowed to have the value NULL.

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agonetlink: fix byteorder of RHS of relational meta expression
Patrick McHardy [Tue, 6 Jul 2010 03:57:20 +0000 (05:57 +0200)] 
netlink: fix byteorder of RHS of relational meta expression

The RHS needs to be postprocessed before updating the payload context
for byteorder conversion. Fixes iiftype match reconstruction.

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agodebug: properly parse debug levels
Patrick McHardy [Tue, 6 Jul 2010 03:57:20 +0000 (05:57 +0200)] 
debug: properly parse debug levels

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agobuild: fix endless recursion with SUBDIRS=...
Patrick McHardy [Tue, 6 Jul 2010 03:57:19 +0000 (05:57 +0200)] 
build: fix endless recursion with SUBDIRS=...

Signed-off-by: Patrick McHardy <kaber@trash.net>
15 years agobuild: add 'archive' target
Patrick McHardy [Tue, 6 Jul 2010 03:57:18 +0000 (05:57 +0200)] 
build: add 'archive' target

make archive creates a tar.bz2 from the HEAD version.

Signed-off-by: Patrick McHardy <kaber@trash.net>