]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
11 years agoexpr: make expr_binary_error() usable outside of evaluation
Patrick McHardy [Thu, 6 Mar 2014 15:29:52 +0000 (16:29 +0100)] 
expr: make expr_binary_error() usable outside of evaluation

Turn the eval_ctx argument into a list_head to queue the error to.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agosrc: add support for rule human-readable comments
Pablo Neira Ayuso [Wed, 26 Feb 2014 00:51:31 +0000 (01:51 +0100)] 
src: add support for rule human-readable comments

This patch adds support for human-readable comments:

  nft add rule filter input accept comment \"accept all traffic\"

Note that comments *always* come at the end of the rule. This uses
the new data area that allows you to attach information to the rule
via netlink.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: fix chain attribute parsing
Arturo Borrero [Wed, 26 Feb 2014 17:46:59 +0000 (18:46 +0100)] 
netlink: fix chain attribute parsing

The handle's table was being set to the chain name instead of the
chain table attribute.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoct: connlabel matching support
Florian Westphal [Tue, 22 Oct 2013 13:03:52 +0000 (15:03 +0200)] 
ct: connlabel matching support

Takes advantage of the fact that the current maximum label storage area
is 128 bits, i.e. the dynamically allocated extension area in the
kernel will always fit into a nft register.

Currently this re-uses rt_symbol_table_init() to read connlabel.conf.
This works since the format is pretty much the same.

Signed-off-by: Florian Westphal <fw@strlen.de>
11 years agonetlink: delete unused variable
Arturo Borrero [Mon, 17 Feb 2014 10:10:57 +0000 (11:10 +0100)] 
netlink: delete unused variable

The table object that is allocated is unused.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoct: direction should be integer, not bitmask
Florian Westphal [Mon, 17 Feb 2014 00:05:37 +0000 (01:05 +0100)] 
ct: direction should be integer, not bitmask

should always generate cmp op (its enum 0, 1 in kernel).

Note: 'original,reply' will no longer work after this patch.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink_delinearize: meta: fix wrong type in attributes
Florian Westphal [Mon, 17 Feb 2014 15:48:05 +0000 (16:48 +0100)] 
netlink_delinearize: meta: fix wrong type in attributes

We segfault on 'list filter' when meta expr is used as _u8
returns invalid register 0.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: fix prefix expression handling
Patrick McHardy [Mon, 17 Feb 2014 14:06:44 +0000 (14:06 +0000)] 
netlink: fix prefix expression handling

The prefix expression handling is full of bugs:

- netlink_gen_data() is used to construct the prefix mask from the full
  prefix expression. This is both conceptually wrong, the prefix expression
  is *not* data, and buggy, it only assumes network masks and thus only
  handles big endian types.

- Prefix expression reconstruction doesn't check whether the mask is a
  valid prefix and reconstructs crap otherwise. It doesn't reconstruct
  prefixes for anything but network addresses. On top of that its
  needlessly complicated, using the mpz values directly its a simple
  matter of finding the sequence of 1's that extend up to the full width.

- Unnecessary cloning of expressions where a simple refcount increase would
  suffice.

Rewrite that code properly.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink_delinarize: convert *all* bitmask values into individual bit values
Patrick McHardy [Sun, 16 Feb 2014 22:45:19 +0000 (22:45 +0000)] 
netlink_delinarize: convert *all* bitmask values into individual bit values

We're currently only converting bitmask types as direct argument to a
relational expression in the form of a flagcmp (expr & mask neq 0) back
into a list of bit values. This means expressions like:

tcp flags & (syn | ack) == syn | ack

won't be shown symbolically. Convert *all* bitmask values back to a sequence
of inclusive or expressions of the individual bits. In case of a flagcmp,
this sequence is further converted to a list (tcp flags syn,ack).

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agobinop: take care of operator precedence when printing binop arguments
Patrick McHardy [Sun, 16 Feb 2014 20:35:37 +0000 (20:35 +0000)] 
binop: take care of operator precedence when printing binop arguments

When the argument of a binop is a binop itself, we may need to add parens
if the precedence of the argument is lower then the binop.

Before:

tcp flags & syn | ack == syn | ack
tcp flags & syn | ack != syn | ack

After:

tcp flags & (syn | ack) == syn | ack
tcp flags & (syn | ack) != syn | ack

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoevaluate: use flagcmp for single RHS bitmask expression
Patrick McHardy [Sun, 16 Feb 2014 22:47:40 +0000 (22:47 +0000)] 
evaluate: use flagcmp for single RHS bitmask expression

Always use flagcmp for RHS bitmask expressions, independant of whether
only one or an entire list of bitmask expression is specified.

This makes sure that f.i. "tcp flags ack" will match any combinations
of ACK instead of ACK and only ACK.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoMerge branch 'next-3.14' of git.netfilter.org:nftables into next-3.14
Patrick McHardy [Mon, 17 Feb 2014 10:47:32 +0000 (10:47 +0000)] 
Merge branch 'next-3.14' of git.netfilter.org:nftables into next-3.14

11 years agosrc: proto: fixed a rreply symbol
Ana Rey [Mon, 17 Feb 2014 10:46:11 +0000 (10:46 +0000)] 
src: proto: fixed a rreply symbol

There is a bug with rreply symbol. The rreply and reply symbol were the same.

There is a reproduction of this bug here:
$ sudo nft add rule arp art-t filter arp operation reply
$ sudo nft list table arp art-t
table arp art-t {
        chain filter {
 type filter hook input priority 0;
                 arp operation 512
        }
}

$ sudo nft add rule arp art-t filter arp operation rreply
$ sudo nft list table arp art-t
table arp art-t {
        chain filter {
 type filter hook input priority 0;
                 arp operation 512  <=====
                 arp operation 512  <=====
        }
}

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agosrc: proto: fixed a rreply symbol
Ana Rey [Mon, 17 Feb 2014 10:46:11 +0000 (10:46 +0000)] 
src: proto: fixed a rreply symbol

There is a bug with rreply symbol. The rreply and reply symbol were the same.

There is a reproduction of this bug here:
$ sudo nft add rule arp art-t filter arp operation reply
$ sudo nft list table arp art-t
table arp art-t {
        chain filter {
 type filter hook input priority 0;
                 arp operation 512
        }
}

$ sudo nft add rule arp art-t filter arp operation rreply
$ sudo nft list table arp art-t
table arp art-t {
        chain filter {
 type filter hook input priority 0;
                 arp operation 512  <=====
                 arp operation 512  <=====
        }
}

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agometa: remove line break when printing priority
Pablo Neira Ayuso [Wed, 12 Feb 2014 12:47:43 +0000 (13:47 +0100)] 
meta: remove line break when printing priority

The line break is added after printing the rule.

11 years agonetlink_linearize: fix flagcmp op
Patrick McHardy [Sun, 16 Feb 2014 18:33:16 +0000 (18:33 +0000)] 
netlink_linearize: fix flagcmp op

Florian reports that flag comparisons generate incorrect instructions:

$ nft --debug=netlink add rule filter output ct labels foo
ip filter output 0 0
 [ ct load labels => reg 1 ]
 [ bitwise reg 1 = (reg=1 & 0x00000001 0x00000000 0x00000000 0x00000000 ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ]
 [ cmp neq reg 1 0x00000001 0x00000000 0x00000000 0x00000000 ]

The "cmp new" should compare to zero. This was broken by commit aae836a7
(src: use libnftables by using expr->right instead of zero.

Slightly rearrange the code as well to prevent similar problems in the
future.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoeval: use list_splice_tail() properly
Patrick McHardy [Thu, 6 Feb 2014 17:20:11 +0000 (17:20 +0000)] 
eval: use list_splice_tail() properly

We need a real list_head to splice both the command and potential new commands
added during evaluation.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink: add netlink specific location
Patrick McHardy [Wed, 5 Feb 2014 19:50:43 +0000 (19:50 +0000)] 
netlink: add netlink specific location

Add a netlink_location and use it for error messages instead of internal_location.

internal:0:0-0: Error: Could not add set: Operation not permitted
=>
netlink: Error: Could not add set: Operation not permitted

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agocmd: initialize cmd list and use list_splice_tail() for adding to command list
Patrick McHardy [Wed, 5 Feb 2014 19:03:40 +0000 (19:03 +0000)] 
cmd: initialize cmd list and use list_splice_tail() for adding to command list

With incremental evaluation we're first evaluating the command before
adding it to the global command list, so the command's list_head is
uninitialized during evaluation. We need to initialize it to handle the
case that an implicit set declaration will prepend a command to the list.

Also list_splice_tail() needs to be used instead of list_add_tail() to
add the entire list of commands.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agofiles: add inet filter table definition
Patrick McHardy [Wed, 5 Feb 2014 13:37:12 +0000 (13:37 +0000)] 
files: add inet filter table definition

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoparser: prohibit redefinitions of symbols and verify existance on use
Patrick McHardy [Tue, 4 Feb 2014 11:22:31 +0000 (11:22 +0000)] 
parser: prohibit redefinitions of symbols and verify existance on use

This patch fixes some incorrect behaviour of symbolic variables:

- prohibit redefining an existing symbol
- verify existance of a symbolic variable during parsing instead of evaluation

The second point makes sure we don't allow recursive definitions (var = $var),
which lead to a crash due to stack exhaustion.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agotests: add two tests for error reporting
Patrick McHardy [Tue, 4 Feb 2014 08:27:22 +0000 (08:27 +0000)] 
tests: add two tests for error reporting

Mixed syntactical and non-syntactical errors in individual commands and
blocks.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoparser: evaluate commands immediately after parsing
Patrick McHardy [Tue, 4 Feb 2014 08:09:27 +0000 (08:09 +0000)] 
parser: evaluate commands immediately after parsing

We currently do parsing and evaluation in two seperate stages. This means
that if any error occurs during parsing, we won't evaluate the syntactical
correct commands and detect possible evaluation errors in them.

In order to improve error reporting, change this to evaluate every command
as soon as it is fully parsed.

With this in place, the ruleset can be fully validated and all errors
reported in one step:

tests/error.1:6:23-23: Error: syntax error, unexpected newline
filter input tcp dport
                      ^
tests/error.1:7:24-26: Error: datatype mismatch, expected internet network service, expression has type Internet protocol
filter input tcp dport tcp
             ~~~~~~~~~ ^^^
tests/error.1:8:24-32: Error: Right hand side of relational expression (==) must be constant
filter input tcp dport tcp dport
             ~~~~~~~~~~^^^^^^^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoparser: recover from errors in any block
Patrick McHardy [Tue, 4 Feb 2014 08:09:27 +0000 (08:09 +0000)] 
parser: recover from errors in any block

Move error recovery to the common_block definition to handle errors
in any block. Queue those errors and abort parsing once a threshold
is reached.

With this in place, we can continue parsing when errors occur and
show all of them to the user at once.

tests/error.1:3:8-8: Error: syntax error, unexpected '{', expecting string
filter {
       ^
tests/error.1:4:13-13: Error: syntax error, unexpected newline
filter input
            ^
tests/error.1:5:17-17: Error: syntax error, unexpected newline
filter input tcp
                ^
tests/error.1:6:23-23: Error: syntax error, unexpected newline
filter input tcp dport

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoparser: close scope when encountering an error in a table or chain block
Patrick McHardy [Tue, 4 Feb 2014 08:09:27 +0000 (08:09 +0000)] 
parser: close scope when encountering an error in a table or chain block

Close the scopes when destroying a table_block/chain_block. Also add
assertions to open_scope()/close_scope() to catch memory corruption
early.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoerec: skip includes with INDESC_INTERNAL
Patrick McHardy [Tue, 4 Feb 2014 08:09:27 +0000 (08:09 +0000)] 
erec: skip includes with INDESC_INTERNAL

Don't display "In file included from internal:0:0-0:" for errors occuring
in a parsed file.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoscanner: update last_line in struct location
Patrick McHardy [Tue, 4 Feb 2014 08:09:27 +0000 (08:09 +0000)] 
scanner: update last_line in struct location

Currently always has the value 0.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoscanner: don't update location's line_offset for newlines
Patrick McHardy [Tue, 4 Feb 2014 08:09:27 +0000 (08:09 +0000)] 
scanner: don't update location's line_offset for newlines

When reset_pos() is invoked, YY_USER_ACTION() has already advanced the
line offset to the next line. This causes errors for unexpected newlines
to incorrectly show the following line when reading from files.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoevaluate: determine implicit relational op before RHS constant checks
Patrick McHardy [Tue, 4 Feb 2014 08:09:27 +0000 (08:09 +0000)] 
evaluate: determine implicit relational op before RHS constant checks

The symbol for the relational op is shown in the error message. Since
OP_IMPLICIT doesn't have a symbol, (null) is shown. Fix by determining
the implicit op before checking for constants.

Error: Right hand side of relational expression ((null)) must be constant
=>
Error: Right hand side of relational expression (==) must be constant

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoMerge branch 'master' into next-3.14
Pablo Neira Ayuso [Mon, 3 Feb 2014 18:54:07 +0000 (19:54 +0100)] 
Merge branch 'master' into next-3.14

11 years agomnl: fix inclusion of last rule in batch page
Pablo Neira Ayuso [Thu, 30 Jan 2014 15:44:58 +0000 (16:44 +0100)] 
mnl: fix inclusion of last rule in batch page

This patch fixes the inclusion of the last rule that didn't fit
into a batch page.

When using sets this has manifested with the -EBUSY error when deleting
the table (it was still containing unused sets after the flush).

The following command line works fine here:

nft -f test ; nft flush table filter ; nft delete chain filter output; nft delete table filter

Tested using this kernel patch: http://patchwork.ozlabs.org/patch/314143/

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoRevert "set: add abstract set descriptions"
Patrick McHardy [Thu, 23 Jan 2014 17:47:06 +0000 (17:47 +0000)] 
Revert "set: add abstract set descriptions"

This reverts commit 2f61f093c3149465f2a68764b25c817adbe87fcd.

Crap, accidentally committed this.

11 years agoruleset: add XML/JSON export
Arturo Borrero Gonzalez [Thu, 23 Jan 2014 17:42:34 +0000 (17:42 +0000)] 
ruleset: add XML/JSON export

This patch adds the following operation:

 :~# nft export <xml|json>

The XML/JSON output is provided raw by libnftnl, thus without format.

In case of XML, you can give format with the `xmllint' tool from libxml2-tools:
 :~# nft list ruleset xml | xmllint --format -

In case of JSON, you can use `json_pp' from perl standar package:
 :~# nft list ruleset json | json_pp

A format field is added in struct cmd, and it will be reused in the import
operation.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoset: add abstract set descriptions
Patrick McHardy [Wed, 22 Jan 2014 20:53:12 +0000 (20:53 +0000)] 
set: add abstract set descriptions

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agocmd: add create command for tables and chains
Patrick McHardy [Tue, 21 Jan 2014 12:39:31 +0000 (12:39 +0000)] 
cmd: add create command for tables and chains

We currently always use NLM_F_EXCL for add, which makes adding existing
chains or tables fail. There's usually no reason why you would care about
this, so change "add" to not use NLM_F_EXCL and add a new "create" command
in case you do care.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agobump release number to 0.100
Pablo Neira Ayuso [Mon, 20 Jan 2014 14:09:36 +0000 (15:09 +0100)] 
bump release number to 0.100

Signed-off-by: Pablo Neira Ayuso <pablo@gnumonks.org>
11 years agobuild: use libnftnl instead of libnftables in configure.in
Pablo Neira Ayuso [Mon, 20 Jan 2014 14:02:50 +0000 (15:02 +0100)] 
build: use libnftnl instead of libnftables in configure.in

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoMerge remote-tracking branch 'origin/master' into next-3.14
Patrick McHardy [Mon, 20 Jan 2014 13:38:40 +0000 (13:38 +0000)] 
Merge remote-tracking branch 'origin/master' into next-3.14

11 years agonftables: version 0.099 v0.099
Patrick McHardy [Mon, 20 Jan 2014 09:56:05 +0000 (09:56 +0000)] 
nftables: version 0.099

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agouse new libnftnl library name
Pablo Neira Ayuso [Mon, 20 Jan 2014 09:49:21 +0000 (10:49 +0100)] 
use new libnftnl library name

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

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: fix chain type autoloading
Pablo Neira Ayuso [Fri, 17 Jan 2014 12:20:39 +0000 (13:20 +0100)] 
mnl: fix chain type autoloading

Add missing NLM_F_CREATE flag when creating new chains to trigger
module autoloading in the kernel.

Reported-by: Ana Rey Botello <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agodatatype: add time type parser and adapt output
Pablo Neira Ayuso [Thu, 16 Jan 2014 21:01:02 +0000 (22:01 +0100)] 
datatype: add time type parser and adapt output

This patch allows to specify a string to indicate the time, eg.

nft add rule filter output ct expiration \"1d2h3m4s\" counter

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoMerge remote-tracking branch 'origin/master' into next-3.14
Patrick McHardy [Thu, 16 Jan 2014 20:39:20 +0000 (20:39 +0000)] 
Merge remote-tracking branch 'origin/master' into next-3.14

Signed-off-by: Patrick McHardy <kaber@trash.net>
Conflicts:
include/nftables.h
src/main.c

11 years agoset: make set initializer parsable
Patrick McHardy [Thu, 16 Jan 2014 20:01:56 +0000 (20:01 +0000)] 
set: make set initializer parsable

If a set contains elements, the output is not parsable since the
elements = { ... } is not understood by the parser. Fix this and
also add support for creating constant sets (which only makes sense
when using an initializer).

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoset: make set flags output parsable
Patrick McHardy [Thu, 16 Jan 2014 20:01:56 +0000 (20:01 +0000)] 
set: make set flags output parsable

This patch fixes two problems:

- the output of "nft list table ..." is not parsable if sets are included
  because the parser can't parse the flags.

- set flags can't be specified during set creation.

To fix this, the set output is changed to:

- not print each flag on a single line
- prefix the flags with "flags "
- only show the interval flag since all others are for internal use only

The parser is changed to parse the flags specified in a set declaration.
This allows to parse empty sets. The following patch will take care of
parsing sets that are already populated.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agosrc: use ':' instead of '=>' in dictionaries
Pablo Neira Ayuso [Thu, 16 Jan 2014 17:31:16 +0000 (18:31 +0100)] 
src: use ':' instead of '=>' in dictionaries

Replace => by : to make it easier for most shell users, as
> implies a redirection, let's avoid possible confusion that
may result if you forget to escape it.

This works fine if you don't forget to add space between the
key and the value. If you forget to add the space, depending
on the case, the scanner may recognize it correctly or process
it as a string.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: add new --debug=mnl option to enable libmnl debugging
Pablo Neira Ayuso [Thu, 16 Jan 2014 16:42:02 +0000 (17:42 +0100)] 
src: add new --debug=mnl option to enable libmnl debugging

This allows you to dump the netlink message that is send via
libmnl.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agobuild: fix recursive parser.h inclusion
Patrick McHardy [Thu, 16 Jan 2014 18:12:06 +0000 (18:12 +0000)] 
build: fix recursive parser.h inclusion

Ocassionally when regenerating the scanner or parser (not sure which),
recursive inclusion of the parser.h file occurs. The reason is that
bison doesn't generate a header sandwich to protect against this (*sigh*).

Change the makefile to do this manually.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoparser: use symbolic expressions for parsing keywords as protocol values
Patrick McHardy [Thu, 16 Jan 2014 16:54:18 +0000 (16:54 +0000)] 
parser: use symbolic expressions for parsing keywords as protocol values

For "meta protocol" and the "meta nfproto" expressions, we need to be
able to parse "ip", "ip6", "vlan" and "arp" as protocol values.

Since the interpretation depends on the LHS of the relaltional expression,
we need to use symbolic expressions instead of constants to defer parsing
to the evaluation phase.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoMerge remote-tracking branch 'origin/master' into next-3.14
Patrick McHardy [Thu, 16 Jan 2014 17:22:56 +0000 (17:22 +0000)] 
Merge remote-tracking branch 'origin/master' into next-3.14

Signed-off-by: Patrick McHardy <kaber@trash.net>
Conflicts:
src/payload.c

11 years agosegtree: fix decomposition of unclosed intervals
Patrick McHardy [Thu, 16 Jan 2014 17:11:12 +0000 (17:11 +0000)] 
segtree: fix decomposition of unclosed intervals

If intervals are directly adjacent or extend to the right end of the dimension,
they are not closed by a EXPR_F_INTERVAL_END entry. This leads to multiple
errors when decomposing the intervals:

- the last unclosed interval is not shown at all.

- if a range is unclosed and the set is a map, the starting point of the
  next interval is set to the data, not the key, leading to nonsensical
  output.

- if a prefix is unclosed, the interval is assumed to be a prefix as well
  and the same starting point is kept. This makes sense for cases like
  192.168.0.0/24, 192.168.0.0/16, but leads to hard to understand
  results if the next interval is not representable as a prefix.

Fix this by doing two things:

- add an EXPR_F_INTERVAL_END element for each unclosed interval during
  preprocessing.

- process the final unclosed interval extending to the right end of the
  dimension, if present.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agosegtree: only use prefix expressions for ranges for selected datatypes
Patrick McHardy [Thu, 16 Jan 2014 17:11:12 +0000 (17:11 +0000)] 
segtree: only use prefix expressions for ranges for selected datatypes

It is uncommon to represent f.i. port number ranges as prefix expressions.

Introduce a datatype DTYPE_F_PREFIX flag to indicate that the preferred
representation of a range is a prefix and use it for segtree decomposition
to decide whether to use a range or prefix expression.

The ipaddr, ip6addr, mark and realm datatypes are changed to include the
DTYPE_F_PREFIX flag.

This fixes completely unreadable output in cases where the ranges are
representable as prefixes, f.i. in case of port number:

{ 0/6 => jump chain1, 0/5 => jump chain2, 0/4 => continue}

becomes:

{ 0-1023 => jump chain1, 1024-2047 => jump chain2, 2048-4095 => continue}

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoparser: fix compilation breakage
Patrick McHardy [Thu, 16 Jan 2014 17:11:12 +0000 (17:11 +0000)] 
parser: fix compilation breakage

Commit 0bd59cf4da (parser: fix parsing of ethernet protocol types) broke
compilation:

src/parser.y:26:22: fatal error: if_ether.h: No such file or directory

Should be netinet/if_ether.h.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoexpression: fix output of verdict maps
Pablo Neira [Mon, 13 Jan 2014 12:39:16 +0000 (13:39 +0100)] 
expression: fix output of verdict maps

% nft list table filter
table ip filter {
...
chain output {
...
ip saddr map { 1.1.1.1 => accept}
}
}

It displays 'map' instead of 'vmap'. Fix it by checking the mapping
type in map_expr_print().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agopayload: fix inconsistency in ethertype output
Pablo Neira Ayuso [Wed, 15 Jan 2014 20:20:37 +0000 (21:20 +0100)] 
payload: fix inconsistency in ethertype output

Use ip6 instead of ipv6.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agopayload: fix crash when wrong ethernet protocol type is used
Pablo Neira Ayuso [Wed, 15 Jan 2014 20:19:02 +0000 (21:19 +0100)] 
payload: fix crash when wrong ethernet protocol type is used

nft add rule ip filter output meta protocol xyz counter
                                            ^^^

This fix is similar to 4097ad7 ("meta: fix crash when parsing
unresolvable mark values").

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoparser: fix parsing of ethernet protocol types
Pablo Neira Ayuso [Wed, 15 Jan 2014 20:12:38 +0000 (21:12 +0100)] 
parser: fix parsing of ethernet protocol types

This allows us to use the protocol type keyword, eg.

nft add rule ip filter output meta protocol ip6 counter
                                            ^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoMerge remote-tracking branch 'origin/master' into next-3.14
Patrick McHardy [Wed, 15 Jan 2014 15:45:02 +0000 (15:45 +0000)] 
Merge remote-tracking branch 'origin/master' into next-3.14

Signed-off-by: Patrick McHardy <kaber@trash.net>
Conflicts:
include/nftables.h
src/main.c

11 years agoexpr: relational: don't surpress '==' for LHS binops in output
Patrick McHardy [Wed, 15 Jan 2014 15:39:10 +0000 (15:39 +0000)] 
expr: relational: don't surpress '==' for LHS binops in output

This patch changes the output of relational expressions to not surpress
the '==' when the LHS is a binop, f.i.

... meta mark & 0x00000003 0x00000001

becomes

... meta mark & 0x00000003 == 0x00000001

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink: use stdout for debugging
Pablo Neira Ayuso [Wed, 15 Jan 2014 14:56:57 +0000 (15:56 +0100)] 
netlink: use stdout for debugging

Suggested-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosegtree: add new segtree debugging option
Pablo Neira Ayuso [Wed, 15 Jan 2014 12:14:25 +0000 (13:14 +0100)] 
segtree: add new segtree debugging option

Currently, nft displays the debugging information if it's compiled with
--enable-debug (which seems a good idea) and when intervals are used
in maps. Add a new option to enable debugging to segtree, so we only
get this information when explicitly requested.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoMerge branch 'master' into next-3.14
Patrick McHardy [Wed, 15 Jan 2014 11:59:16 +0000 (11:59 +0000)] 
Merge branch 'master' into next-3.14

Signed-off-by: Patrick McHardy <kaber@trash.net>
Conflicts:
src/payload.c

11 years agopayload: fix name of eth_proto
Patrick McHardy [Wed, 15 Jan 2014 11:57:28 +0000 (11:57 +0000)] 
payload: fix name of eth_proto

It's "ether" now since we've changed the keyword.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoMerge branch 'master' into next-3.14
Patrick McHardy [Wed, 15 Jan 2014 11:55:39 +0000 (11:55 +0000)] 
Merge branch 'master' into next-3.14

Signed-off-by: Patrick McHardy <kaber@trash.net>
Conflicts:
src/meta.c
src/parser.y

11 years agometa: fix mismerge
Patrick McHardy [Wed, 15 Jan 2014 11:53:23 +0000 (11:53 +0000)] 
meta: fix mismerge

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agometa: don't require "meta" keyword for a subset of meta expressions
Patrick McHardy [Wed, 15 Jan 2014 07:35:20 +0000 (07:35 +0000)] 
meta: don't require "meta" keyword for a subset of meta expressions

Don't require the meta keyword for mark, iif, oif, iifname, oifname,
skuid, skgid, nftrace, rtclassid and secmark.

The protocol and length types still need the meta keyword to avoid
grammar conflicts.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Conflicts:
src/parser.y

11 years agoexpr: remove secmark from ct and meta expression
Patrick McHardy [Wed, 15 Jan 2014 11:11:10 +0000 (11:11 +0000)] 
expr: remove secmark from ct and meta expression

The secctx should be used instead of the secmark. Remove for now.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agometa: don't require "meta" keyword for a subset of meta expressions
Patrick McHardy [Wed, 15 Jan 2014 07:35:20 +0000 (07:35 +0000)] 
meta: don't require "meta" keyword for a subset of meta expressions

Don't require the meta keyword for mark, iif, oif, iifname, oifname,
skuid, skgid, nftrace, rtclassid and secmark.

The protocol and length types still need the meta keyword to avoid
grammar conflicts.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoexpr: remove secmark from ct and meta expression
Patrick McHardy [Wed, 15 Jan 2014 11:11:10 +0000 (11:11 +0000)] 
expr: remove secmark from ct and meta expression

The secctx should be used instead of the secmark. Remove for now.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoscanner: add aliases to symbols for easier interaction with most shells
Pablo Neira Ayuso [Tue, 14 Jan 2014 14:55:14 +0000 (15:55 +0100)] 
scanner: add aliases to symbols for easier interaction with most shells

These symbols need to be escaped in bash and if you use them without
escaping then, it can lead to confusion. This patch adds nominal
aliases, eg.

 nft add rule filter output meta mark and 0x3 eq 0x1

as an alternative to:

 nft add rule filter output meta mark \& 0x3 == 0x1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: scanner: fixed problem with ipv6 address
Ana Rey [Wed, 15 Jan 2014 07:42:28 +0000 (07:42 +0000)] 
nft: scanner: fixed problem with ipv6 address

There is a problem with the follow ipv6 address combination:

nft add rule ip6 t_ip61 filter-input ip6 saddr ::1234:1234:1234:1234:1234:1234:1234

1234::1234:1234:1234:1234:1234:1234
1234:1234::1234:1234:1234:1234:1234
1234:1234:1234::1234:1234:1234:1234
1234:1234:1234:1234::1234:1234:1234
1234:1234:1234:1234:1234::1234:1234
::1234:1234:1234:1234:1234:1234
1234::1234:1234:1234:1234:1234
1234:1234::1234:1234:1234:1234
1234:1234:1234::1234:1234:1234
1234:1234:1234:1234::1234:1234
::1234:1234:1234:1234:1234
1234::1234:1234:1234:1234
1234:1234::1234:1234:1234
1234:1234:1234::1234:1234
::1234:1234:1234:1234
1234::1234:1234:1234
1234:1234::1234:1234
::1234:1234:1234
1234::1234:1234

The problem was in the scanner (src/scanner.l). Several brackets were missed
and the result was an incorrect interpretation.

Fix it by adding some brackets in a regular expression in src/scanner.l

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoscanner: rename address selector from 'eth' to 'ether'
Pablo Neira Ayuso [Tue, 14 Jan 2014 11:07:44 +0000 (12:07 +0100)] 
scanner: rename address selector from 'eth' to 'ether'

eth may easily occur when using ifname masks. This could be also
fixed by interpreting 'eth' as a simple string in the parser but
I think this selector also looks more similar to what we use in
tcpdump.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoMerge remote-tracking branch 'origin/master' into next-3.14
Patrick McHardy [Tue, 14 Jan 2014 12:38:12 +0000 (12:38 +0000)] 
Merge remote-tracking branch 'origin/master' into next-3.14

11 years agoRevert "parser: replace "vmap" keyword by "map""
Patrick McHardy [Tue, 14 Jan 2014 12:37:36 +0000 (12:37 +0000)] 
Revert "parser: replace "vmap" keyword by "map""

This reverts commit 5e8f8a1807917f92e568437598670b0026462c1c.

I missed that this introduces shift-reduce conflicts. Revert for now.

11 years agoMerge remote-tracking branch 'origin/master' into next-3.14
Patrick McHardy [Tue, 14 Jan 2014 12:31:38 +0000 (12:31 +0000)] 
Merge remote-tracking branch 'origin/master' into next-3.14

11 years agoparser: replace "vmap" keyword by "map"
Patrick McHardy [Tue, 14 Jan 2014 12:30:48 +0000 (12:30 +0000)] 
parser: replace "vmap" keyword by "map"

Consistently use "map" to express mappings.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agofiles: replace interpreter during installation
Arturo Borrero Gonzalez [Mon, 13 Jan 2014 09:37:45 +0000 (09:37 +0000)] 
files: replace interpreter during installation

Many systems (for example Debian) don't recognice `#!nft -f' as a
valid interpreter.

A short way to handle this is to provide the full path to the interpreter
in the shebang.
That is what this patch does: update the shebang's path during installation.

For example, if you are installing under /usr/local, the shebang becomes:
 #!/usr/local/sbin/nft -f

If using --prefix=/, then:
 #!/sbin/nft -f

NOTE: If the shebang in source files are changed in a future, this sed script
should be updated as well.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonftables: drop hard coded install using root user owner and group
Kevin Fenzi [Mon, 13 Jan 2014 06:36:45 +0000 (06:36 +0000)] 
nftables: drop hard coded install using root user owner and group

Packaging systems build as a non priv user, so can't install as root. Users
installing from source can 'sudo make install' or run 'make install' as root

Signed-off-by: Kevin Fenzi <kevin@scrye.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink: fix wrong type in attributes
Pablo Neira Ayuso [Fri, 10 Jan 2014 12:47:57 +0000 (13:47 +0100)] 
netlink: fix wrong type in attributes

Fix inconsistent attribute types in meta and cmp expressions, use
uint32_t. This problem was added when converting nft to use libmnl
and libnftables.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoMerge remote-tracking branch 'origin/master' into next-3.14
Patrick McHardy [Fri, 10 Jan 2014 12:26:35 +0000 (12:26 +0000)] 
Merge remote-tracking branch 'origin/master' into next-3.14

11 years agometa: fix crash when parsing unresolvable mark values
Patrick McHardy [Fri, 10 Jan 2014 09:28:37 +0000 (09:28 +0000)] 
meta: fix crash when parsing unresolvable mark values

*res has undefined contents, set to NULL before invoking the parse function
to make sure the test for != NULL doesn't falsely return true.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agodatatype: revert "fix crash if wrong integer type is passed"
Patrick McHardy [Fri, 10 Jan 2014 09:28:37 +0000 (09:28 +0000)] 
datatype: revert "fix crash if wrong integer type is passed"

Revert commit a320531e7:

We have generic type checks that handle this case just fine and indeed
the bugzilla entry mentioned in the reverted patch states:

BUG: invalid input descriptor type 538976288
nft: src/erec.c:100: erec_print: Assertion `0' failed.
Abandon

So the problem is not related to datatypes at all and generic type
checking works perfectly fine:

<cmdline>:1:52-57: Error: datatype mismatch, expected Ethernet protocol, expression has type Internet protocol
add rule ip6 filter input position 4 meta protocol icmpv6 accept
                                     ~~~~~~~~~~~~~ ^^^^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoerec: fix error markup for errors starting at column 0
Patrick McHardy [Fri, 10 Jan 2014 09:28:37 +0000 (09:28 +0000)] 
erec: fix error markup for errors starting at column 0

For errors starting at column 0, we must not subtract 1 to avoid underflow.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonftables: shorten "could not process rule in batch" message
Patrick McHardy [Fri, 10 Jan 2014 09:28:37 +0000 (09:28 +0000)] 
nftables: shorten "could not process rule in batch" message

Remove the "in batch" part, it makes most messages exceed a single line, the
user doesn't care about this and we process even single rules in "batches".

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink_delinearize: fix compiler warning
Patrick McHardy [Thu, 9 Jan 2014 21:59:29 +0000 (21:59 +0000)] 
netlink_delinearize: fix compiler warning

src/netlink_delinearize.c: In function ‘meta_match_postprocess’:
src/netlink_delinearize.c:660:3: warning: passing argument 1 of ‘expr->left->ops->pctx_update’ from incompatible pointer type [enabled by default]
src/netlink_delinearize.c:660:3: note: expected ‘struct proto_ctx *’ but argument is of type ‘struct rule_pp_ctx *’

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoMerge remote-tracking branch 'origin/master' into next-3.14
Patrick McHardy [Thu, 9 Jan 2014 18:55:50 +0000 (18:55 +0000)] 
Merge remote-tracking branch 'origin/master' into next-3.14

11 years agonftables: fix supression of "permission denied" errors
Patrick McHardy [Thu, 9 Jan 2014 18:54:02 +0000 (18:54 +0000)] 
nftables: fix supression of "permission denied" errors

Introduction of batch support broke displaying of EPERM since those are
generated by the kernel before batch processing starts and thus have the
sequence number of the NFNL_MSG_BATCH_BEGIN message instead of the
command messages. Also only a single error message is generated for the
entire batch.

This patch fixes this by noting the batch sequence number and displaying
the error for all commands since this is what would happen if the
permission check was inside batch processing as every other check.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agometa: add l4proto support
Patrick McHardy [Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)] 
meta: add l4proto support

Add support for the meta l4proto type. This is used in the inet table to
match on the transport layer protocol without requiring the network layer
protocol to be known, allowing to use transport header matches that apply
to both IPv4 and IPv6.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agometa: add nfproto support
Patrick McHardy [Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)] 
meta: add nfproto support

Add support for the meta nfproto type, which refers to the AF from the
netfilter hook ops. This is needed to get the actual family of a packet
in the dummy NFPROTO_INET family.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoproto: add support for meta templates
Patrick McHardy [Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)] 
proto: add support for meta templates

The following two patches will add two new meta expression types that are
used as dependencies in the inet table. To reuse the existing dependency
generation code, add a slightly hackish way to specify meta expressions
as payload dependencies.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink_delinearize: remove implied meta expressions
Patrick McHardy [Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)] 
netlink_delinearize: remove implied meta expressions

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonftables: add support for the "inet" family
Patrick McHardy [Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)] 
nftables: add support for the "inet" family

Add support for the mixed IPv4/IPv6 "inet" family. This mainly consist
of adding the "inet" <-> NFPROTO_INET mapping in the parser and netlink
support functions.

Additionally add the definitions for the inet filter table.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoinclude: resync nftables.h with kernel
Patrick McHardy [Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)] 
include: resync nftables.h with kernel

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoct expr: protocol context updates and dynamic typing
Patrick McHardy [Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)] 
ct expr: protocol context updates and dynamic typing

Include the protocols defined through relational ct expressions in the
protocol context and use the protocol context to dynamically determine
the types of network and transport layer ct expression types.

Before:

$ nft filter output ct proto-dst ssh
<cmdline>:1:28-30: Error: Can't parse symbolic invalid expressions
filter output ct proto-dst ssh
                           ^^^
$ nft filter output ip protocol tcp ct proto-dst ssh
<cmdline>:1:44-46: Error: Can't parse symbolic invalid expressions
filter output ip protocol tcp ct proto-dst ssh
                                           ^^^
$ nft filter output ct protocol tcp ct proto-dst ssh
<cmdline>:1:44-46: Error: Can't parse symbolic invalid expressions
filter output ct protocol tcp ct proto-dst ssh
                                           ^^^
After:

$ nft filter output ct proto-dst ssh
<cmdline>:1:28-30: Error: Can't parse symbolic invalid expressions
filter output ct proto-dst ssh
                           ^^^
$ nft filter output ip protocol tcp ct proto-dst ssh
$ nft filter output ct protocol tcp ct proto-dst ssh

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoproto: add debugging for protocol context updates
Patrick McHardy [Wed, 8 Jan 2014 13:02:16 +0000 (13:02 +0000)] 
proto: add debugging for protocol context updates

Add a new debugging level to debug updates to the protocol context.

Sample output:

<cmdline>:1:15-23: Evaluate
filter output tcp dport ssh
              ^^^^^^^^^
tcp

update transport layer protocol context:
 link layer          : none
 network layer       : ip
 transport layer     : tcp <-

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoproto: add helper function to update protocol context
Patrick McHardy [Wed, 8 Jan 2014 13:02:15 +0000 (13:02 +0000)] 
proto: add helper function to update protocol context

Add a helper function which is to be used to update the protocol update.

Signed-off-by: Patrick McHardy <ksber@trash.net<
11 years agoexpr: add protocol context update callback
Patrick McHardy [Wed, 8 Jan 2014 13:02:15 +0000 (13:02 +0000)] 
expr: add protocol context update callback

Add a callback function to the expression ops to update the protocol
context for relational protocol expressions (EXPR_F_PROTOCOL).

Also set the EXPR_F_PROTOCOL flag for IIFTYPE meta expressions to make
sure the callback is invoked when necessary.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonftables: generic procotol contexts
Patrick McHardy [Wed, 8 Jan 2014 13:02:15 +0000 (13:02 +0000)] 
nftables: generic procotol contexts

Currently the context of higher layer protocols is specific to payload
expressions with some special cases for meta IIFTYPE expressions. This
approach has a few shortcomings, concretely there are more expression
types which define upper layer protocols like the ct expression and two
upcoming new types for the meta expression.

Replace the payload context by a generic protocol context to deal with
this. This patch just splits off the requires parts from the payload
expression without any functional changes, the following patches will
add further functionality for other expressions.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoexpr: replace PAYLOAD_PROTOCOL_EXPR by generic flag
Patrick McHardy [Wed, 8 Jan 2014 13:02:15 +0000 (13:02 +0000)] 
expr: replace PAYLOAD_PROTOCOL_EXPR by generic flag

Introduce a generic flag to indicate that an expression describes the
upper layer protocol as replacement for the payload specific flag.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agosrc: add support for queue
Eric Leblond [Sun, 29 Dec 2013 18:28:10 +0000 (19:28 +0100)] 
src: add support for queue

This patch adds support for the queue target. It is now possible
to specify rule sending packet to a given queue and using load
balancing:

  nft add rule filter output queue num 3 total 2 options fanout

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>