]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
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>
11 years agonetlink: add support to set meta keys
Pablo Neira Ayuso [Thu, 26 Dec 2013 19:23:07 +0000 (20:23 +0100)] 
netlink: add support to set meta keys

Arturo Borrero added kernel support to set meta keys in
http://patchwork.ozlabs.org/patch/305281/ and the corresponding
library support in http://patchwork.ozlabs.org/patch/305283/.

This patch enhances nft to use this new kernel feature. The
following example shows how to set the packet mark.

% nft add rule ip filter input meta mark set 22
% nft list table filter
table ip filter {
        chain input {
                 type filter hook input priority 0;
                 meta mark set 0x00000016
        }
}

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: fix dictionary feature with data mappings
Pablo Neira Ayuso [Fri, 27 Dec 2013 11:48:40 +0000 (12:48 +0100)] 
netlink: fix dictionary feature with data mappings

This patch fixes dictionary feature, that allows you to conditionally
set packet fields based on a given selector, eg.

 add rule ip filter input meta dnat set tcp dport map { 22 => 1.1.1.1, 23 => 2.2.2.2 }

This means that traffic flowing to tcp port 22 is dnatted to address
1.1.1.1 and tcp port 23 is dnatted to address 2.2.2.2.

This feature was partially broken by aae836a ("src: use libnftables")
although it also needs the kernel fix ("netfilter: nf_tables: fix wrong
datatype in nft_validate_data_load()").

This patch also fixes endianness issues when displaying the mark
via `list table' related to list_setelem_cb() since the byteorder
was left unset for the data part of a set element.

 meta mark set tcp dport map { telnet => 0x02000000, ssh => 0x01000000}
                                            ^                  ^
Note the wrong endianness in the example above.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: print netlink message if if --debug=netlink in mnl_talk()
Pablo Neira Ayuso [Fri, 27 Dec 2013 11:36:12 +0000 (12:36 +0100)] 
mnl: print netlink message if if --debug=netlink in mnl_talk()

Useful for debugging purposes.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: don't set NLM_F_ACK flag in mnl_nft_rule_batch_[add|del]
Pablo Neira Ayuso [Sat, 7 Dec 2013 19:06:30 +0000 (20:06 +0100)] 
mnl: don't set NLM_F_ACK flag in mnl_nft_rule_batch_[add|del]

If the NLM_F_ACK flag is unset, the kernel still explicitly reports
errors. Thus, we can save the handling of many explicit (useless) ack
messages that indicate success.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: fix rule flushing atomically
Pablo Neira Ayuso [Fri, 6 Dec 2013 09:24:20 +0000 (10:24 +0100)] 
src: fix rule flushing atomically

nft is currently retrieving the list of rule from the kernel, then
deleting each rule one by one. This is slow and not safe. Fix it
by sending a deletion command in a batch without specifying the
chain.

This change requires the kernel fix entitled:
netfilter: nf_tables: fix missing rules flushing per table

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: fix inconsistent name usage in nft_*_nlmsg_build_hdr calls
Arturo Borrero [Mon, 2 Dec 2013 16:07:18 +0000 (17:07 +0100)] 
mnl: fix inconsistent name usage in nft_*_nlmsg_build_hdr calls

Minor fix, given that all those functions are aliases.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoparser: add 'delete map' syntax
Phil Oester [Sat, 30 Nov 2013 20:41:21 +0000 (12:41 -0800)] 
parser: add 'delete map' syntax

Creating a map is done via "add map".  However, to delete a map requires using
"delete set", which is confusing.  Add the appropriate synonym to parser.
The downside to this is that one can now delete a set with "delete map", but
this seems a minor issue.  It could of course be fixed by adding a new
CMD_OBJ_MAP.

This closes netfilter bugzilla #879.

Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agorule: missing set cleanup in do_command_list
Phil Oester [Sat, 30 Nov 2013 20:15:52 +0000 (12:15 -0800)] 
rule: missing set cleanup in do_command_list

When listing a table in interactive mode, the set list is not cleaned up.  Thus
the number of displayed sets grows with each successive listing.  Attached
patch adds the necessary list cleanup to do_command_list.

Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexamples: adjust new chain type syntax in sets_and_maps file
Phil Oester [Fri, 29 Nov 2013 20:32:29 +0000 (12:32 -0800)] 
examples: adjust new chain type syntax in sets_and_maps file

This example file has not been updated with new syntax.

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoparser: segfault in top scope define
Phil Oester [Fri, 29 Nov 2013 20:30:04 +0000 (12:30 -0800)] 
parser: segfault in top scope define

nft segfaults if a symbol is added in top_scope, because of a missing
init_list_head.  Trivial example:

    define ip_set = {192.168.1.2, 192.168.2.3}
    add rule filter output ip daddr $ip_set counter

This closes netfilter bugzilla #877.

Reported-by: Anand Raj Manickam <anandrm@gmail.com>
Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: relax restriction on UID/GID parsing
Pablo Neira Ayuso [Fri, 29 Nov 2013 10:23:09 +0000 (11:23 +0100)] 
meta: relax restriction on UID/GID parsing

nft is currently rejecting unknown UID/GID if they don't exist in the
system, relax this as Bjørnar Ness considers this is a valid scenario.
Now this only reports an error if you pass an unknown user (expressed as
string or if the UID/GID goes above 32 bits).

Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: fix endianness in UID/GID
Pablo Neira Ayuso [Fri, 29 Nov 2013 10:28:07 +0000 (11:28 +0100)] 
meta: fix endianness in UID/GID

 add rule filter output meta skuid vmap { 1000 => accept }
 list table filter
 meta skuid map { 3892510720 => accept}
                  ^--------^
        this is 1000 in network byte order

Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: improve rule deletion per chain
Pablo Neira Ayuso [Sun, 24 Nov 2013 19:06:51 +0000 (20:06 +0100)] 
netlink: improve rule deletion per chain

With this patch, nft asks the kernel for deleting all rules in a chain.
This replaces the current behaviour that requires to dump all the rules,
then iterate over that list to delete one by one, which is prone to races
and slowier.

After this patch, the following two commands are equivalent:

 nft flush chain filter input
 nft delete rule filter input

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agodatatype: fix missing nul-terminated string in string_type_print
Pablo Neira Ayuso [Sun, 24 Nov 2013 18:49:15 +0000 (19:49 +0100)] 
datatype: fix missing nul-terminated string in string_type_print

Thomas Berger reported that he is seeing garbage after valid string
values, eg.

fwtest01 ~ # nft -i
nft> table filter
nft> add chain filter input
nft> add rule filter input meta iifname "lo" accept
nft> list table filter
table ip filter {
        chain input {
                 meta iifname "lo�.�" accept
        }
...

The buffer that is allocated in the stack does not include room to
nul-terminate the string accordingly. This patch fixes bugzilla
report #872:

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

Reported-by: Thomas Berger <loki@lokis-chaos.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: only display wanted chain in listing
Eric Leblond [Mon, 18 Nov 2013 07:40:21 +0000 (08:40 +0100)] 
netlink: only display wanted chain in listing

When specifying a chain to list, all created chains were displayed
with a void content:

 # nft list chain filter
 table ip filter {
   chain input {
   }

   chain new {
    counter packets 17971 bytes 2380637 accept
    counter packets 0 bytes 0 accept
   }
  }

With the attached patch, only the asked chain is displayed:

  # nft list chain filter
  table ip filter {
   chain new {
    counter packets 17971 bytes 2380637 accept # handle 36
    counter packets 0 bytes 0 accept # handle 40
   }
  }

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoverdict: fix delinearize in case of jump
Eric Leblond [Sun, 17 Nov 2013 23:54:45 +0000 (00:54 +0100)] 
verdict: fix delinearize in case of jump

The name of the chain was not handled in case of a jump or a goto.
This patch adds parsing of the chain.

Reported-by: Alex Chapman <ajchapman88@hotmail.co.uk>
Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agojump: fix logic in netlink linearize
Eric Leblond [Sun, 17 Nov 2013 23:54:44 +0000 (00:54 +0100)] 
jump: fix logic in netlink linearize

Logic in the test was inverted. The result was the jump string
not to be set.

Reported-by: Alex Chapman <ajchapman88@hotmail.co.uk>
Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpression: fix indent
Eric Leblond [Sun, 17 Nov 2013 23:54:43 +0000 (00:54 +0100)] 
expression: fix indent

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonftables: delete debian/ directory
Arturo Borrero [Thu, 14 Nov 2013 15:44:38 +0000 (16:44 +0100)] 
nftables: delete debian/ directory

The debian/ dir does not belong here, we already discussed this
with Debian maintainers many times before.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agobuild: relax compilation not to break on warning
Pablo Neira Ayuso [Mon, 4 Nov 2013 11:34:39 +0000 (12:34 +0100)] 
build: relax compilation not to break on warning

Remove -Werror, as bison and flex generate unclean code that may
break compilation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoparser: fix warning on deprecated directive in bison
Pablo Neira Ayuso [Mon, 4 Nov 2013 10:30:41 +0000 (11:30 +0100)] 
parser: fix warning on deprecated directive in bison

src/parser.y:93.1-13: warning: deprecated directive, use ‘%name-prefix’ [-Wdeprecated]
 %name-prefix="nft_"
 ^^^^^^^^^^^^^
Reported-by: Anatol Pomozov <anatol.pomozov@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agopayload: fix ethernet type protocol matching
Pablo Neira Ayuso [Wed, 30 Oct 2013 12:33:50 +0000 (13:33 +0100)] 
payload: fix ethernet type protocol matching

This fixes ethernet type protocol matching, which is needed
to match network layer information, eg.

 nft add rule bridge filter input ip protocol icmp counter

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink_linearize: finish reject support
Pablo Neira Ayuso [Fri, 25 Oct 2013 15:01:58 +0000 (17:01 +0200)] 
netlink_linearize: finish reject support

This patch finishes the reject support.

Reported-by: Jiri Benc <jbenc@redhat.com>
Tested-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agostatement: avoid huge rodata array
Florian Westphal [Tue, 22 Oct 2013 12:35:02 +0000 (14:35 +0200)] 
statement: avoid huge rodata array

commit b259d1a ('src: operational limit match') creates huge
array, increasing nft binary size from ~240k to ~5m on x86_64.

Use switch statement instead.

Signed-off-by: Florian Westphal <fw@strlen.de>
11 years agosrc: operational limit match
Phil Oester [Sat, 5 Oct 2013 16:44:56 +0000 (09:44 -0700)] 
src: operational limit match

The nft limit match currently does not work at all.  Below patches to nftables,
libnftables, and kernel address the issue.  A few notes on the implementation:

- Removed support for nano/micro/milli second limits.  These seem pointless,
  given we are using jiffies in the limit match, not a hpet.  And who really
  needs to limit items down to sub-second level??

- 'depth' member is removed as unnecessary.  All we need in the kernel is the
  rate and the unit.

- 'stamp' member becomes the time we need to next refresh the token bucket,
  instead of being updated on every packet which goes through the match.

This closes netfilter bugzilla #827, reported by Eric Leblond.

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: fix return code
Arturo Borrero Gonzalez [Fri, 11 Oct 2013 11:03:08 +0000 (13:03 +0200)] 
src: fix return code

Exit with NFT_EXIT_FAILURE if something went wrong in the netlink code.

Before this patch:

internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]

0

After this patch:

internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]

1

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: fix nft flush operation
Eric Leblond [Wed, 2 Oct 2013 23:08:08 +0000 (01:08 +0200)] 
netlink: fix nft flush operation

nft_netlink function is already calling mnl_batch_end and
mnl_batch_begin so it is not necessary to do it in the
netlink_flush_rules function. Doing this result in a invalid
netlink message which is discarded by the kernel.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: only flush asked table/chain
Eric Leblond [Wed, 2 Oct 2013 23:08:07 +0000 (01:08 +0200)] 
netlink: only flush asked table/chain

The flush operation was not limiting the flush to the table or
chain specified on command line. The result was that all the rules
for a given family are flush independantly of the flush command.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: suppress useless variable
Eric Leblond [Wed, 2 Oct 2013 23:08:06 +0000 (01:08 +0200)] 
netlink: suppress useless variable

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: fix typo in comment
Eric Leblond [Wed, 2 Oct 2013 23:08:05 +0000 (01:08 +0200)] 
mnl: fix typo in comment

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: Add support for IPv6 NAT
Eric Leblond [Sun, 29 Sep 2013 09:53:29 +0000 (11:53 +0200)] 
src: Add support for IPv6 NAT

This patch adds support for IPv6 NAT. It adds IPv6 support in
evaluation and in delinearization which were the only missing parts.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: fix IPv6 prefix computation
Eric Leblond [Sun, 29 Sep 2013 09:53:28 +0000 (11:53 +0200)] 
netlink: fix IPv6 prefix computation

The prefix building algorithm in netlink phase was incorrect in
IPv6.

For example, when adding the following rule
 nft add rule ip6 nat postrouting ip6 saddr 2::/64 --debug=all

we had:

 ip6 nat postrouting 0 0
  [ payload load 16b @ network header + 8 => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0x00000000 0x99361540 0x00007f8d 0x2e33a1eb ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ]
  [ cmp eq reg 1 0x00000200 0x00000000 0x00000000 0x00000000 ]

With the patch the result is as expected:

 ip6 nat postrouting 0 0
  [ payload load 16b @ network header + 8 => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0xffffffff 0xffffffff 0x00000000 0x00000000 ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ]
  [ cmp eq reg 1 0x00000200 0x00000000 0x00000000 0x00000000 ]

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoinclude: cache a copy of nfnetlink.h
Tomasz Bursztyka [Mon, 30 Sep 2013 09:22:42 +0000 (12:22 +0300)] 
include: cache a copy of nfnetlink.h

If nft is compiled without nftables Linux kernel headers installed, we
hit a compilation error:

src/mnl.c: In function ‘mnl_batch_put’:
src/mnl.c:117:16: error: ‘NFNL_SUBSYS_NFTABLES’ undeclared (first use in
this function)
src/mnl.c:117:16: note: each undeclared identifier is reported only once
for each function it appears in
src/mnl.c: In function ‘mnl_batch_begin’:
src/mnl.c:125:16: error: ‘NFNL_MSG_BATCH_BEGIN’ undeclared (first use in
this function)
src/mnl.c: In function ‘mnl_batch_end’:
src/mnl.c:130:16: error: ‘NFNL_MSG_BATCH_END’ undeclared (first use in
this function)

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: add rule batching support
Pablo Neira Ayuso [Sun, 22 Sep 2013 18:41:03 +0000 (20:41 +0200)] 
src: add rule batching support

This patch allows nft to put all rule update messages into one
single batch that is sent to the kernel if `-f' option is used.
In order to provide fine grain error reporting, I decided to
to correlate the netlink message sequence number with the
correspoding command sequence number, which is the same. Thus,
nft can identify what rules trigger problems inside a batch
and report them accordingly.

Moreover, to avoid playing buffer size games at batch building
stage, ie. guess what is the final size of the batch for this
ruleset update will be, this patch collects batch pages that
are converted to iovec to ensure linearization when the batch
is sent to the kernel. This reduces the amount of unnecessary
memory usage that is allocated for the batch.

This patch uses the libmnl nlmsg batching infrastructure and it
requires the kernel patch entitled (netfilter: nfnetlink: add batch
support and use it from nf_tables).

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: iif/oifname should be host byte order
Florian Westphal [Fri, 20 Sep 2013 14:01:33 +0000 (16:01 +0200)] 
meta: iif/oifname should be host byte order

src/nft add rule filter output meta oifname eth0

doesn't work on x86.  Problem is that nft declares these as
BYTEORDER_INVALID, but when converting the string mpz_import_data
treats INVALID like BIG_ENDIAN.

[ cmp eq reg 1 0x00000000 0x00000000 0x65000000 0x00306874 ]

as kernel nft_cmp_eval basically boils down to

memcmp(reg, skb->dev->name, sizeof(reg) comparision fails.

with patch:
[ cmp eq reg 1 0x30687465 0x00000000 0x00000000 0x00000000 ]

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: use uint32_t instead of size_t for attribute length
Pablo Neira Ayuso [Thu, 19 Sep 2013 20:57:47 +0000 (22:57 +0200)] 
netlink: use uint32_t instead of size_t for attribute length

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 agodisplay family in table listing
Eric Leblond [Mon, 16 Sep 2013 16:27:38 +0000 (18:27 +0200)] 
display family in table listing

As family was not displayed in table listing, it was not possible
to restore an ipv6 table saved via 'nft list table ip6 TABLE'.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoUpdate chain creation format.
Eric Leblond [Mon, 16 Sep 2013 16:27:37 +0000 (18:27 +0200)] 
Update chain creation format.

type keyword is now mandatory when creating a new chain. This
patc halso implement the change required following the usage of human
notation in hook.

It also suppressed non currently supported mangle chains.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoSuppress non working examples.
Eric Leblond [Mon, 16 Sep 2013 16:27:36 +0000 (18:27 +0200)] 
Suppress non working examples.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonat: add mandatory family attribute
Eric Leblond [Mon, 16 Sep 2013 16:27:35 +0000 (18:27 +0200)] 
nat: add mandatory family attribute

NFT_EXPR_NAT_FAMILY is a mandatory attribute for NAT rules and
it was not set by nftables.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agolog: s/threshold/queue-threshold/
Florian Westphal [Fri, 13 Sep 2013 14:44:48 +0000 (16:44 +0200)] 
log: s/threshold/queue-threshold/

on input we expect "queue-threshold" token, so use the same
name when printing the output.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 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

11 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>
11 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>
11 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>
11 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>
11 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>
11 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>