]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
10 years agosrc: allow to specify the default policy for base chains
Pablo Neira Ayuso [Tue, 17 Mar 2015 15:36:15 +0000 (16:36 +0100)] 
src: allow to specify the default policy for base chains

The new syntax is:

 nft add chain filter input { hook input type filter priority 0\; policy accept\; }

but the previous syntax is still allowed:

 nft add chain filter input { hook input type filter priority 0\; }

this assumes default policy to accept.

If the base chain already exists, you can update the policy via:

 nft add chain filter input { policy drop\; }

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agosrc: expose table flags
Pablo Neira Ayuso [Thu, 12 Mar 2015 14:15:14 +0000 (15:15 +0100)] 
src: expose table flags

The nf_tables kernel API provides a way to disable a table using the
dormant flag. This patch adds the missing code to expose this feature
through nft.

Basically, if you want to disable a table and all its chains from seen
any traffic, you have to type:

 nft add table filter { flags dormant\; }

to re-enable the table, you have to:

 nft add table filter

this clears the flags.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: fix typo in README
Eric Leblond [Wed, 25 Feb 2015 23:51:08 +0000 (00:51 +0100)] 
tests: regression: fix typo in README

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agomain: display errors through stderr
Pablo Neira Ayuso [Tue, 24 Feb 2015 17:48:16 +0000 (18:48 +0100)] 
main: display errors through stderr

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1000
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agorule: fix object order via nft -f
Pablo Neira Ayuso [Sat, 14 Feb 2015 20:41:23 +0000 (21:41 +0100)] 
rule: fix object order via nft -f

The objects need to be loaded in the following order:

#1 tables
#2 chains
#3 sets
#4 rules

We have to make sure that chains are in place by when we add rules with
jumps/gotos. Similarly, we have to make sure that the sets are in place
by when rules reference them.

Without this patch, you may hit ENOENT errors depending on your ruleset
configuration.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agometa: register pkttype_type datatype
Pablo Neira Ayuso [Sun, 1 Feb 2015 20:54:00 +0000 (21:54 +0100)] 
meta: register pkttype_type datatype

Closes: http://bugzilla.netfilter.org/show_bug.cgi?id=995
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoevaluate: use stmt_evaluate_arg() in all cases
Patrick McHardy [Mon, 12 Jan 2015 10:10:42 +0000 (10:10 +0000)] 
evaluate: use stmt_evaluate_arg() in all cases

When using a symbolic vmap expression, we fail to verify that the map
actually contains verdicts.

Use stmt_evaluate_arg() everywhere to fix this.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoevaluate: check that map expressions' datatype matches mappings
Patrick McHardy [Mon, 12 Jan 2015 12:09:17 +0000 (12:09 +0000)] 
evaluate: check that map expressions' datatype matches mappings

Catch type errors in map expressions using named maps:

# nft add map filter test { type ipv4_addr : inet_service; }
# nft filter output mark set tcp dport map @test
<cmdline>:1:38-42: Error: datatype mismatch, map expects IPv4 address, mapping expression has type internet network service
filter output mark set tcp dport map @test
                       ~~~~~~~~~     ^^^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoevaluate: properly set datatype of map expression
Patrick McHardy [Mon, 12 Jan 2015 11:13:44 +0000 (11:13 +0000)] 
evaluate: properly set datatype of map expression

The datatype of the map expression is the datatype of the mappings.

# nft add map filter test { type ipv4_addr : inet_service; }
# nft filter output mark set ip daddr map @test

Before:

<cmdline>:1:24-41: Error: datatype mismatch: expected packet mark, expression has type IPv4 address
filter output mark set ip daddr map @test
              ~~~~~~~~~^^^^^^^^^^^^^^^^^^

After:

<cmdline>:1:24-41: Error: datatype mismatch: expected packet mark, expression has type internet network service
filter output mark set ip daddr map @test
              ~~~~~~~~~^^^^^^^^^^^^^^^^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoevaluate: verify named map is actually a map
Patrick McHardy [Mon, 12 Jan 2015 11:06:17 +0000 (11:06 +0000)] 
evaluate: verify named map is actually a map

# nft add set filter test { type ipv4_addr; }
# nft filter input ip daddr vmap @test

Before:

<cmdline>:0:0-32: Error: Could not process rule: Invalid argument
filter input ip daddr vmap @test
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

After:

<cmdline>:1:28-32: Error: Expression is not a map
filter input ip daddr vmap @test
                           ^^^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agometa: don't print meta keyword for unqualified meta stmts
Patrick McHardy [Mon, 12 Jan 2015 10:19:19 +0000 (10:19 +0000)] 
meta: don't print meta keyword for unqualified meta stmts

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoevaluate: clean up unused variables (pctx)
Alvaro Neira Ayuso [Mon, 12 Jan 2015 10:03:27 +0000 (10:03 +0000)] 
evaluate: clean up unused variables (pctx)

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoexpr: fix crash when listing non-verdict mappings
Patrick McHardy [Mon, 12 Jan 2015 09:48:39 +0000 (09:48 +0000)] 
expr: fix crash when listing non-verdict mappings

Fix regression introduced by commit 87c2a2205:

  netlink_delinearize: clone on netlink_get_register(), release previous on _set()

When using a non-verdict mapping, the set ref expression is assigned to the
destination register. The next get_register() will attempt to clone it and
crash because of the missing ->clone() callback.

# nft filter input meta mark set ip daddr map { 192.168.0.1 : 123 }
# nft list table filter
Segmentation fault (core dumped)

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoset: remove unused set_clone() function
Patrick McHardy [Mon, 12 Jan 2015 09:51:05 +0000 (09:51 +0000)] 
set: remove unused set_clone() function

The set_clone() function was added by the event monitor patchset and is
unused. It is also broken since it simply initializes the list head to
the list of the original set, so remove it.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoparser: properly fix handling of large integer values
Patrick McHardy [Sun, 11 Jan 2015 23:59:10 +0000 (23:59 +0000)] 
parser: properly fix handling of large integer values

Introduction of the ERROR symbol is an ugly hack. There's no reason
to special case large integer values, the NUM token only exists for
small values that are needed immediately, everything else is passed
as EXPR_SYMBOL to evaluation anyways.

Additionally the error reporting is different from what we'd usually
report, the token is easy to confuse with the bison internal error
token and it even has a name, messing up bison internal diagnostics.

Simply return values to large to be handled by strtoull as STRING.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink_linearize: add register dumping helper function
Patrick McHardy [Sun, 11 Jan 2015 08:34:46 +0000 (08:34 +0000)] 
netlink_linearize: add register dumping helper function

Add a helper function to dump netlink register numbers in preparation
of concat support.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink_delinearize: add register parsing helper function
Patrick McHardy [Sun, 11 Jan 2015 08:28:42 +0000 (08:28 +0000)] 
netlink_delinearize: add register parsing helper function

Add a helper function to parse netlink register numbers in preparation
of concat support.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoconcat: add concat subtype lookup/id helpers
Patrick McHardy [Mon, 22 Dec 2014 16:45:48 +0000 (17:45 +0100)] 
concat: add concat subtype lookup/id helpers

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink_delinearize: cleanup hard to read code
Patrick McHardy [Mon, 22 Dec 2014 16:45:48 +0000 (17:45 +0100)] 
netlink_delinearize: cleanup hard to read code

The netlink parsing code is full of long function calls spawning multiple
lines and in some cases parses netlink attributes multiple times.

Use local variables for the registers and other data required to
reconstruct the expressions and statements and reorder the code in
some cases to move related processing next to each other.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink_delinearize: rename netlink_parse_*_sreg/dreg functions
Patrick McHardy [Mon, 22 Dec 2014 16:45:48 +0000 (17:45 +0100)] 
netlink_delinearize: rename netlink_parse_*_sreg/dreg functions

These are really badly chosen names, use parse_expr and parse_stmt instead.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink: readability fixes
Patrick McHardy [Mon, 22 Dec 2014 16:45:48 +0000 (17:45 +0100)] 
netlink: readability fixes

Improve readability by using local variables for netlink attributes,
ordering variables more logically, don't arbitrarily initialize
some variables in the definition section and in the body and generally
make similar functions look similar.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink: style fixes
Patrick McHardy [Sun, 11 Jan 2015 07:52:49 +0000 (07:52 +0000)] 
netlink: style fixes

Remove style discrepancies between different netlink I/O functions:

- we don't use brackets for single line statements
- most functions don't have a newline between error reporting and exit

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink: style fixes
Patrick McHardy [Mon, 22 Dec 2014 16:45:48 +0000 (17:45 +0100)] 
netlink: style fixes

We include an empty line between variable definitions and code.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink: remove unnecessary temporary variable
Patrick McHardy [Mon, 22 Dec 2014 16:45:48 +0000 (17:45 +0100)] 
netlink: remove unnecessary temporary variable

Waste less space and return the results of the batch/compat
functions directly.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink: fix memory leaks
Patrick McHardy [Sun, 11 Jan 2015 07:54:55 +0000 (07:54 +0000)] 
netlink: fix memory leaks

Fix two memory leaks in netlink event monitor. Also fix a leak related
to all sets, the ->init expression is not freed.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agonetlink_delinearize: fix error handling for invalid registers
Patrick McHardy [Fri, 26 Dec 2014 13:55:41 +0000 (14:55 +0100)] 
netlink_delinearize: fix error handling for invalid registers

netlink_delinearize is prepared to deal with malformed expressions from
the kernel that it doesn't understand. However since expressions are now
cloned unconditionally by netlink_get_register(), we crash before such
errors can be detected for invalid inputs.

Fix by only cloning non-NULL expressions.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoevaluate: add missing datatype compat checks for statement arguments
Patrick McHardy [Sat, 10 Jan 2015 09:23:00 +0000 (09:23 +0000)] 
evaluate: add missing datatype compat checks for statement arguments

Add a helper function to evaluate expressions used as arguments for
statements and report datatype mismatches.

Fixes acceptance of mismatching expressions like:

$ nft filter output meta mark set ip daddr
<cmdline>:1:29-36: Error: datatype mismatch: expected packet mark. expression has type IPv4 address
filter output meta mark set ip daddr
              ~~~~~~~~~~~~~~^^^^^^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoeval: refactor NAT evaluation functions
Patrick McHardy [Sat, 10 Jan 2015 14:41:55 +0000 (14:41 +0000)] 
eval: refactor NAT evaluation functions

The redir and masq evaluation functions include some useless context
updates and checks.

Refactor the NAT code to have a single instance of address and transport
evaluation functions for simplicity and unified error reporting.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agosrc: modify pr_debug() to use printf and introduce to pr_gmp_debug()
Pablo Neira Ayuso [Thu, 8 Jan 2015 12:07:35 +0000 (13:07 +0100)] 
src: modify pr_debug() to use printf and introduce to pr_gmp_debug()

Modify pr_debug() to use printf so we get debugging traces for
proto-ctx when --with-mini-gmp is enabled.

Add pr_gmp_debug(), this is disabled with --with-mini-gmp since it
relies on the gmp_printf(), which is not available in the mini-gmp
implementation.

Suggested by Patrick.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agobuild: use -Wno-sign-compare to avoid compilation warning in mini-gmp.c
Pablo Neira Ayuso [Thu, 8 Jan 2015 12:28:26 +0000 (13:28 +0100)] 
build: use -Wno-sign-compare to avoid compilation warning in mini-gmp.c

  CC     mini-gmp.o
mini-gmp.c: In function ‘mpn_get_str_bits’:
mini-gmp.c:1176:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
mini-gmp.c: In function ‘mpz_and’:
mini-gmp.c:3650:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
mini-gmp.c: In function ‘mpz_ior’:
mini-gmp.c:3723:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
mini-gmp.c: In function ‘mpz_xor’:
mini-gmp.c:3792:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
mini-gmp.c: In function ‘mpz_set_str’:
mini-gmp.c:4167:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agobuild: add --with-mini-gmp switch to disable linking libgmp
Steven Barth [Thu, 8 Jan 2015 06:54:34 +0000 (07:54 +0100)] 
build: add --with-mini-gmp switch to disable linking libgmp

This allows to disable linking the >400 KB big libgmp and replace it
with the builtin mini-gmp which only increases size by ~30KB.

Enabling this selectively decreases debugging verbosity (pr_debug).

Signed-off-by: Steven Barth <cyrus@openwrt.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agodoc: add a reference to the wiki page in the man page
Arturo Borrero [Wed, 7 Jan 2015 16:03:09 +0000 (17:03 +0100)] 
doc: add a reference to the wiki page in the man page

Let's add a pointer in the man page to the wiki page.

Requested-by: Dan Jacobson <jidanni@jidanni.org>
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoerec: use stdio vasprintf instead of gmp_vasprintf
Steven Barth [Tue, 6 Jan 2015 22:40:24 +0000 (23:40 +0100)] 
erec: use stdio vasprintf instead of gmp_vasprintf

Use stdio's vasprintf instead of gmp_vasprintf which is not part
of the mini-gmp function subset. Furthermore convert the only
gmp-specific user and allow the compiler to verify format-strings.

Signed-off-by: Steven Barth <cyrus@openwrt.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agodatatype: use mpz_set_str instead of gmp_sscanf
Steven Barth [Tue, 6 Jan 2015 22:40:23 +0000 (23:40 +0100)] 
datatype: use mpz_set_str instead of gmp_sscanf

This simplifies the integer parsing logic and restricts it to
functions being part of the mini-gmp subset.

Signed-off-by: Steven Barth <cyrus@openwrt.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoparser: rename VERSION token to HDRVERSION
Steven Barth [Tue, 6 Jan 2015 22:40:22 +0000 (23:40 +0100)] 
parser: rename VERSION token to HDRVERSION

A token name of VERSION results in a macro being defined
with the same name. This prevents inclusion of config.h
in commonly used headers.

Signed-off-by: Steven Barth <cyrus@openwrt.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoevaluate: reject: fix dependency generation from nft -f
Pablo Neira Ayuso [Tue, 6 Jan 2015 20:28:53 +0000 (21:28 +0100)] 
evaluate: reject: fix dependency generation from nft -f

When nft -f is used, ctx->cmd points to the table object, which
contains the corresponding chain, set and rule lists. The reject
statement evaluator relies on ctx->cmd->rule to add the payload
dependencies, which is doesn't point to the rule in that case.

This patch adds the rule context to the eval_ctx structure to update
the rule list of statements when generating dependencies, as the reject
statement needs.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=993
Reported-by: Ting-Wei Lan <lantw44@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agopayload: assert when accessing inner transport header
Pablo Neira Ayuso [Sun, 4 Jan 2015 22:22:57 +0000 (23:22 +0100)] 
payload: assert when accessing inner transport header

Instead of segfaulting due to out of bound access access to protocol
context array ctx->protocol[base].location from proto_ctx_update().

 # nft add rule filter input ah nexthdr tcp
 nft: payload.c:88: payload_expr_pctx_update: Assertion `left->payload.base + 1 <= (__PROTO_BASE_MAX - 1)' failed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: revisit chain tests
Pablo Neira Ayuso [Thu, 18 Dec 2014 12:36:24 +0000 (13:36 +0100)] 
tests: regression: revisit chain tests

Make sure support chain don't stop working.

Remove some minor mistakes and out of scope tests from chain*.t

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: named sets work
Pablo Neira Ayuso [Thu, 18 Dec 2014 12:30:59 +0000 (13:30 +0100)] 
tests: regression: named sets work

Those tests work already, enable them.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoparser: alloc specifying concat types in set declarations
Patrick McHardy [Sat, 13 Dec 2014 07:50:36 +0000 (07:50 +0000)] 
parser: alloc specifying concat types in set declarations

Support specification of concat types in set declarations:

add set filter test {
type ipv4_addr . inet_service
}

Netlink delinearization is changed to reconstruct the type from the id.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agodatatype: change concat_type_alloc() to construct type from id
Patrick McHardy [Sat, 13 Dec 2014 07:50:35 +0000 (07:50 +0000)] 
datatype: change concat_type_alloc() to construct type from id

The kernel only stored the id so we need to be able to reconstruct
the datatype from the id only.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoutils: add fls()
Patrick McHardy [Sat, 13 Dec 2014 07:50:35 +0000 (07:50 +0000)] 
utils: add fls()

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agodatatype: add define for maximum number of bits and mask of datatype id
Patrick McHardy [Sat, 13 Dec 2014 07:50:35 +0000 (07:50 +0000)] 
datatype: add define for maximum number of bits and mask of datatype id

The id of concat datatypes is composed of the ids of the individual
datatypes. Add a define for the number of bits for each datatype id
and a mask.

The number of bits is chosen as 6, allowing for 63 datatypes, or twice
as much as we currently have. This allows for concatenations of 5
types using 32 bits.

The value is statically chosen instead of basing it on the current
numbers of datatypes since we don't want the maximum concatenation
size to vary between versions, also new versions are supposed to be
able to propery parse a ruleset generated by an older version.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agodatatype: add new subtypes field to account number of concat data types
Patrick McHardy [Sat, 13 Dec 2014 07:50:34 +0000 (07:50 +0000)] 
datatype: add new subtypes field to account number of concat data types

Using the size is confusing since it usually holds the size of
the data. Add a new "subtypes" member, which holds the number
of datatypes the concat type is made of.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agodatatype: generate name for concat types
Patrick McHardy [Sat, 13 Dec 2014 07:50:34 +0000 (07:50 +0000)] 
datatype: generate name for concat types

The name of a concat type is the names of the individual types concatenated
using a '.'.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agoBump version to v0.4 v0.4
Pablo Neira Ayuso [Mon, 15 Dec 2014 22:49:59 +0000 (23:49 +0100)] 
Bump version to v0.4

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agodatatype: missing byteorder in string_type
Pablo Neira Ayuso [Sun, 14 Dec 2014 17:01:00 +0000 (18:01 +0100)] 
datatype: missing byteorder in string_type

nft add rule filter input iifname { "lo", "eth0" } counter

Now the listing shows:

iifname { "lo", "eth0"}

instead of:

iifname { "", ""}

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agobuild: restore --disable-debug
Pablo Neira Ayuso [Sun, 14 Dec 2014 19:59:16 +0000 (20:59 +0100)] 
build: restore --disable-debug

Fix fallout from the automake conversion. Display after configuration
if it is enabled or not.

Reported-by: Steven Barth <cyrus@openwrt.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: log.t: this works for bridge and arp since 3.17
Pablo Neira Ayuso [Sat, 13 Dec 2014 18:11:57 +0000 (19:11 +0100)] 
tests: regression: log.t: this works for bridge and arp since 3.17

So tests log statement for those two families too and remove the
tests/selectors that are ip and ip6 specific, they don't belong here.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: simplify run_test_file() in case `-e' is used
Pablo Neira Ayuso [Sat, 13 Dec 2014 18:05:38 +0000 (19:05 +0100)] 
tests: regression: simplify run_test_file() in case `-e' is used

Avoid copy&paste coding style pattern by simplifying the code that
handles the `-e' option that allows us to run known broken tests.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: fix wrong number of test files
Pablo Neira Ayuso [Sat, 13 Dec 2014 17:57:06 +0000 (18:57 +0100)] 
tests: regression: fix wrong number of test files

Always increment the test file counter for each test file in the list.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoparser: use 'redirect to PORT' instead of 'redirect :PORT'
Pablo Neira Ayuso [Fri, 12 Dec 2014 18:26:46 +0000 (19:26 +0100)] 
parser: use 'redirect to PORT' instead of 'redirect :PORT'

Small syntax update suggested by Patrick.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: redirect.t: fix bogus errors
Pablo Neira Ayuso [Fri, 12 Dec 2014 18:11:05 +0000 (19:11 +0100)] 
tests: regression: redirect.t: fix bogus errors

Separate values in set, otherwise bash interprets the brackets
and the test reports an error.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: adapt nat tests to use random-fully
Pablo Neira Ayuso [Fri, 12 Dec 2014 17:45:03 +0000 (18:45 +0100)] 
tests: regression: adapt nat tests to use random-fully

This adapts test to the change that happened in d9a9a79 ('stmt: rename
nat "random-fully" option to "fully-random"').

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agodatatype: print datatype name in datatype_print() BUG message
Patrick McHardy [Thu, 11 Dec 2014 10:05:37 +0000 (10:05 +0000)] 
datatype: print datatype name in datatype_print() BUG message

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agodtype: fix memory leak in concat_type_destroy()
Patrick McHardy [Sat, 13 Sep 2014 09:07:49 +0000 (10:07 +0100)] 
dtype: fix memory leak in concat_type_destroy()

Free allocated memory for ->desc.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agometa: properly align types in meta_template table
Patrick McHardy [Thu, 11 Dec 2014 20:33:39 +0000 (20:33 +0000)] 
meta: properly align types in meta_template table

Don't use arbitrary amounts of spaces. The remaining table is
properly aligned, fix the new types.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agostmt: rename nat "random-fully" option to "fully-random"
Patrick McHardy [Thu, 11 Dec 2014 22:06:48 +0000 (22:06 +0000)] 
stmt: rename nat "random-fully" option to "fully-random"

Use proper english for full randomization option.

Signed-off-by: Patrick McHardy
10 years agodtype: remove unnecessary icmp* parse/print functions
Patrick McHardy [Wed, 10 Dec 2014 22:13:51 +0000 (22:13 +0000)] 
dtype: remove unnecessary icmp* parse/print functions

Just setting the .sym_tbl correctly is all we need.

Signed-off-by: Patrick McHardy <kaber@trash.net>
10 years agorule: fix segmentation faults on kernels without nftables support
Pablo Neira Ayuso [Mon, 8 Dec 2014 19:03:42 +0000 (20:03 +0100)] 
rule: fix segmentation faults on kernels without nftables support

 # nft list sets
 Segmentation fault

 # nft list sets
 <cmdline>:1:1-9: Error: Could not receive sets from kernel: Protocol error
 list sets
 ^^^^^^^^^

Fix same bug in `nft list tables'.

Don't cleanup the table object for these commands since it is NULL.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonetlink: fix listing of range set elements in host byteorder
Pablo Neira Ayuso [Sun, 7 Dec 2014 23:25:13 +0000 (00:25 +0100)] 
netlink: fix listing of range set elements in host byteorder

We have to switch the byteorder of the element in
netlink_delinearize_setelem() for non-range values only.

This fixes the listing of:

  nft add rule filter input ct mark { 0x10-0x20 } counter

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonetlink_delinearize: fix listing of set members in host byteorder using integer_type
Pablo Neira Ayuso [Mon, 8 Dec 2014 21:14:09 +0000 (22:14 +0100)] 
netlink_delinearize: fix listing of set members in host byteorder using integer_type

 nft list table filter
 ...
        cpu { 5033164833554432, 0, 16777216} counter packets 8 bytes 344

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agosrc: generate set members using integer_type in the appropriate byteorder
Pablo Neira Ayuso [Mon, 8 Dec 2014 19:26:30 +0000 (20:26 +0100)] 
src: generate set members using integer_type in the appropriate byteorder

Rules with header fields that rely on the generic integer datatype
from sets are not matching, eg.

 nft add rule filter input udp length { 9 } counter

This set member is an integer represented in host byte order, which
obviously doesn't match the header field (in network byte order).

Since the integer datatype has no specific byteorder, we have to rely
on the expression byteorder instead when configuring the context,
before we evaluate the list of set members.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agopayload: fix endianess issue in payload_expr_pctx_update()
Pablo Neira Ayuso [Thu, 4 Dec 2014 13:18:59 +0000 (14:18 +0100)] 
payload: fix endianess issue in payload_expr_pctx_update()

Use constant_data_ptr() to point to the right memory position on
big endian when exporting data that is stored in a larger variable.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Tested-by: Christophe Leroy <christophe.leroy@c-s.fr>
10 years agodatatype: fix name of icmp* code
Eric Leblond [Tue, 2 Dec 2014 23:02:51 +0000 (00:02 +0100)] 
datatype: fix name of icmp* code

The name of datatypes can be used in set definition so they should
follow the same logic (and maybe not contain space to avoid problem
with parsing).

This patch adds an underscore to the name of the icmp* code
datatype.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoscanner: don't bug on too large values
Pablo Neira Ayuso [Sun, 30 Nov 2014 21:52:20 +0000 (22:52 +0100)] 
scanner: don't bug on too large values

Add a new ERROR symbol to handle scanning of too large values.

 <cmdline>:1:36-99: Error: bad value '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
 add rule ip test-ip4 input ct mark 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
instead of:

 BUG: nft: scanner.l:470: nft_lex: Assertion `0' failed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: any/ct: remove wrong output
Pablo Neira Ayuso [Sun, 30 Nov 2014 20:56:46 +0000 (21:56 +0100)] 
tests: regression: any/ct: remove wrong output

ct mark 0x32-0x45

displays:

ct mark >= 0x00000032 ct mark <= 0x00000045
                                 ^^^^^^^^^^
instead of ct mark <= 0x45000000
                      ^^^^^^^^^^

Remove the custom output so this displays a warning. nft should
(at some point) merge the two statements into one single to express
the range from the netlink_delinearize step.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: fix "Listing is broken" instead of output mismatch
Pablo Neira Ayuso [Sun, 30 Nov 2014 20:39:24 +0000 (21:39 +0100)] 
tests: regression: fix "Listing is broken" instead of output mismatch

If the output string doesn't match the input, indicate that the output
mismatches instead of the misleading "Listing is broken".

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agometa: set base field on clones
Pablo Neira Ayuso [Sun, 30 Nov 2014 21:27:27 +0000 (22:27 +0100)] 
meta: set base field on clones

Set missing field on meta expression clone.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonetlink_delinearize: clone on netlink_get_register(), release previous on _set()
Pablo Neira Ayuso [Mon, 24 Nov 2014 18:25:23 +0000 (19:25 +0100)] 
netlink_delinearize: clone on netlink_get_register(), release previous on _set()

If we add this rule:

  nft add rule filter input meta length 33-55

the listing shows:

  meta length >= 33 meta length <= 754974720

The two meta statements share the same left-hand side, thus, only the
first one is converted from network byte order to host byte order.

Update netlink_get_register() to return a clone so each left-hand side
has its own left-hand side.

Moreover, release the existing register before overriding it with fresh
expressions in netlink_set_register().

Thefore, if you manipulate a register from any of the existing parse
functions, you have to re-set it again to place fresh modified clone.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoscanner: fix reading of really long line
Eric Leblond [Sat, 29 Nov 2014 16:24:38 +0000 (17:24 +0100)] 
scanner: fix reading of really long line

Current code is causing a failure in adding a set containing
a really long list of elements. The failure occurs as soon as
the line is longer than flex read buffer.

When a line is longer than scanner buffer size, the code in YY_INPUT
forces a rewind to the beginning of the string because it does not
find a end of line. The result is that the string is never parsed.

This patch updates the code by rewinding till we found a space.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agodatatype: relax datatype check in integer_type_parse()
Pablo Neira Ayuso [Fri, 28 Nov 2014 20:20:59 +0000 (21:20 +0100)] 
datatype: relax datatype check in integer_type_parse()

Otherwise parsing with basetypes doesn't work. Now nft displays
an error when the symbolic constant is not correct:

 <cmdline>:1:29-31: Error: Could not parse conntrack state
 add rule test test ct state xxx accept
                             ^^^

Use .sym_tbl instead and default on the symbol_constant_parse()
function from the ethertype and pkttype, this simplifies the code and
(more importantly) it avoids a breakage after the change in
integer_type_parse().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agodatatype: fix crash when using basetype instead of symbolic constants
Pablo Neira Ayuso [Fri, 28 Nov 2014 18:04:21 +0000 (19:04 +0100)] 
datatype: fix crash when using basetype instead of symbolic constants

The following example:

 # nft add rule filter input ct state 8 accept
 Segmentation fault

leads to a crash because we have the following datatype relation:

 ct_state -> bitmask -> integer

The bitmask, which is an intermediate basetype, has no parse()
function, this leads to a crash in symbolic_constant_parse().

Patrick suggested to walk down the chain until we find a parser
function.

Reported-by: leroy christophe <christophe.leroy@c-s.fr>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoevaluate: reject: fix crash on NULL location with bridge and tcp reset
Alvaro Neira [Wed, 26 Nov 2014 11:07:51 +0000 (12:07 +0100)] 
evaluate: reject: fix crash on NULL location with bridge and tcp reset

If we use tcp reset with a network protocol that tcp is not supported,
we display an error. This error use the reject.expr location which is NULL,
therefore we have a crash. This patch replaces it using the reject statement
to display the error like:

Rule:
 nft add bridge filter input ether type vlan reject with tcp reset
Output:
 <cmdline>:1:46-51: Error: cannot reject this ether type
 add rule bridge filter input ether type vlan reject with tcp reset
                              ~~~~~~~~~~~~~~~ ^^^^^^

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agobuild: add missing \ in src/Makefile.am (AM_CPPFLAGS)
David Kozub [Tue, 25 Nov 2014 17:51:43 +0000 (18:51 +0100)] 
build: add missing \ in src/Makefile.am (AM_CPPFLAGS)

The missing \ at the end of the line causes LIBMNL_CFLAGS and LIBNFTNL_CFLAGS
to be ignored. This causes build failure if the libmnl or libnftnl headers are
not in a path that's already searched by the C compiler.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: test masquerade from nat/postrouting too
Pablo Neira Ayuso [Mon, 24 Nov 2014 11:49:52 +0000 (12:49 +0100)] 
tests: regression: test masquerade from nat/postrouting too

We can specify several chains in the tests, so test this from
postrouting too.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: fix bogus error due to bash
Pablo Neira Ayuso [Sun, 23 Nov 2014 21:05:12 +0000 (22:05 +0100)] 
tests: regression: fix bogus error due to bash

This suppresses several superfluous errors:

 any/meta.t: ERROR: line 168: nft add rule ip test-ip4 input meta iifgroup {11,33}: This rule should not have failed.
 any/meta.t: ERROR: line 178: nft add rule ip test-ip4 input meta oifgroup {11,33}: This rule should not have failed.
 ip/masquerade.t: ERROR: line 23: nft add rule ip4 test-ip4 output tcp dport {1,2,3,4,5,6,7,8,101,202,303,1001,2002,3003} masquerade: This rule should not have failed.
 ip6/masquerade.t: ERROR: line 23: nft add rule ip6 test-ip6 output tcp dport {1,2,3,4,5,6,7,8,101,202,303,1001,2002,3003} masquerade: This rule should not have failed.

This needs a space before the list of elements in the set, otherwise
bash here misinterprets the set.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: don't use -nnn for non-list commands
Pablo Neira Ayuso [Sun, 23 Nov 2014 20:48:05 +0000 (21:48 +0100)] 
tests: regression: don't use -nnn for non-list commands

Not useful, they just bloat the nft-tests.py output.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests: regression: any/queue.t: use new syntax
Pablo Neira Ayuso [Sun, 23 Nov 2014 20:46:30 +0000 (21:46 +0100)] 
tests: regression: any/queue.t: use new syntax

queue options are now expressed as flags, so you have to use
comma separated values.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoparser: restore named vmap
Pablo Neira Ayuso [Sun, 23 Nov 2014 19:13:03 +0000 (20:13 +0100)] 
parser: restore named vmap

For example:

nft add map filter my_vmap { type ipv4_addr : verdict\; }
nft add element filter my_vmap { 1.0.0.0 : drop}
nft add rule filter input ip saddr vmap @my_vmap

Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agosrc: restore nft --debug
Pablo Neira Ayuso [Sun, 23 Nov 2014 19:55:24 +0000 (20:55 +0100)] 
src: restore nft --debug

Add -DDEBUG to enable --debug option by default as it used to be before
the autotools conversion.

Fixes: 5fa8e49 ("build: autotools conversion")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonetlink: don't bug on unknown events
Pablo Neira Ayuso [Fri, 14 Nov 2014 17:36:14 +0000 (18:36 +0100)] 
netlink: don't bug on unknown events

We will likely have new ones in the future, silently skip them. If the
user wants to see them, it just needs to upgrade.

This is currently causing us problems with kernels that deliver the
generation counter event.

term1# nft add table test

term2# nft monitor
nft: netlink.c:2063: netlink_events_cb: Assertion `0' failed.
Aborted

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agobuild: add autotools support for the 'files' subdir
Giorgio Dal Molin [Wed, 12 Nov 2014 16:41:06 +0000 (17:41 +0100)] 
build: add autotools support for the 'files' subdir

Added support to install some 'nft' scripts under
'${sysconfdir}/nftables', typically '/etc/nftables'.

Signed-off-by: Giorgio Dal Molin <giorgio.nicole@arcor.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agobuild: add autotools support for the 'doc' subdir
Giorgio Dal Molin [Wed, 12 Nov 2014 16:41:05 +0000 (17:41 +0100)] 
build: add autotools support for the 'doc' subdir

'nft' documentation is originally contained in the XML file 'doc/nft.xml'.
Processing this file with the proper tools we can obtain a PDF document,
 'nft.pdf', and a unix man page, 'nft.8'.

To produce the PDF we need the tool 'dblatex' (current release
pypi.python.org/pypi/dblatex/0.3.5).

To produce the man page we use the tool 'docbook2man'; it is part of the
package 'docbook2X' (docbook2x.sourceforge.net). On some linux
distributions the tool can have slightly different names as 'docbook2x-man'
or 'db2x_docbook2man' so we search for all three names and use the first
one found and issue the command:

 # ${DB2MAN} --xinclude $<

Signed-off-by: Giorgio Dal Molin <giorgio.nicole@arcor.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agobuild: autotools conversion
Pablo Neira Ayuso [Thu, 6 Nov 2014 16:09:44 +0000 (17:09 +0100)] 
build: autotools conversion

1) This removes former Makefiles and install-sh (which is now
   automagically imported via autoreconf).

 Makefile.defs.in
 Makefile.in
 Makefile.rules.in
 src/Makefile.in
 install-sh (now automagically imported via autoreconf).

2) CFLAGS are left almost same, they are integrated into Make_global.am.
   Use AM_CPPFLAGS to set the CFLAGS set by pkgconfig.

3) Add m4 directory to the tree which only contains the .gitignore
   file. Update .gitignore file to skip autogenerated files.

4) include <config.h> whenever required.

5) Minor adjustments to scanner.l and parser_bison.y to compile cleanly
   with autotools.

6) Add %option outfile=lex.yy.c to scanner.l, otherwise I hit this error
   here:

        gcc -DHAVE_CONFIG_H -I. -I..  -I../include -DDEFAULT_INCLUDE_PATH="\"/usr/etc\""  -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wdeclaration-after-statement -Wsign-compare -Winit-self -Wformat-nonliteral -Wformat-security -Wmissing-format-attribute -Wcast-align -Wundef -Wbad-function-cast -g -O2 -MT mnl.o -MD -MP -MF $depbase.Tpo -c -o mnl.o mnl.c &&\
        mv -f $depbase.Tpo $depbase.Po
/bin/sh ../build-aux/ylwrap scanner.l lex.yy.c scanner.c -- flex
make[3]: *** [scanner.c] Error 1
make[3]: Leaving directory `/home/pablo/devel/scm/git-netfilter/nftables/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/pablo/devel/scm/git-netfilter/nftables/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/pablo/devel/scm/git-netfilter/nftables'
make: *** [all] Error 2

7) Add Makefile.am for include/ (contributed by Giorgio Dal Molin).

The doc/ and files/ conversion to automake will come in follow up
patches but 'make distcheck' already works.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoinclude: add cli.h
Pablo Neira Ayuso [Thu, 6 Nov 2014 17:28:33 +0000 (18:28 +0100)] 
include: add cli.h

Needed by follow up patches to use autotools.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agorename parser.y to parser_bison.y
Pablo Neira Ayuso [Thu, 6 Nov 2014 12:34:48 +0000 (13:34 +0100)] 
rename parser.y to parser_bison.y

The conversion to the autotools need this.

Make sure you remove the autogenerated parser.c and parser.h from
your tree.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agobuild: use AC_PROG_YACC and AM_PROG_LEX
Pablo Neira Ayuso [Thu, 6 Nov 2014 11:45:32 +0000 (12:45 +0100)] 
build: use AC_PROG_YACC and AM_PROG_LEX

To check for bison and flex installed on the system.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agobuild: use PKG_CHECK_MODULES to check for libmnl and libnftnl
Pablo Neira Ayuso [Thu, 6 Nov 2014 11:43:43 +0000 (12:43 +0100)] 
build: use PKG_CHECK_MODULES to check for libmnl and libnftnl

Also check for required library versions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agosrc: Add cgroup support in meta expresion
Ana Rey [Mon, 3 Nov 2014 17:10:51 +0000 (18:10 +0100)] 
src: Add cgroup support in meta expresion

The new attribute of meta is "cgroup".

Example of use in nft:

 # nft add rule ip test output meta cgroup != 0x100001 counter drop

Moreover, this adds tests to the meta.t test file.

The kernel support is addedin the commit:
ce67417 ("netfilter: nft_meta: add cgroup support")

The libnftnl  support is add in the commit:
1d4a480 ("expr: meta: Add cgroup support")

More information about the steps to use cgroup:
https://www.kernel.org/doc/Documentation/cgroups/net_cls.txt

More info about cgroup in iptables:
http://git.kernel.org/cgit/linux/kernel/git/pablo/nftables.git/commit/net/netfilter/xt_cgroup.c?id=82a37132f300ea53bdcd812917af5a6329ec80c3

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoinclude: refresh cached copy of nf_tables.h
Pablo Neira Ayuso [Mon, 10 Nov 2014 17:07:24 +0000 (18:07 +0100)] 
include: refresh cached copy of nf_tables.h

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoparser: allow both nat_flags and port specification in redirect
Arturo Borrero [Fri, 7 Nov 2014 11:39:35 +0000 (12:39 +0100)] 
parser: allow both nat_flags and port specification in redirect

This patch changes the parser to permit both nat_flags and port specification
in the redirect expression.

The resulting syntax is:
 % nft add rule nat prerouting redirect [port] [nat_flags]

The port specification requires a bit of context regardin the transport
protocol. Some examples:
 % nft add rule nat prerouting tcp dport 22 redirect :23
 % nft add rule add prerouting udp dport 53 redirect :5353

The nat_flags argument is the last argument:
 % nft add rule nat prerouting tdp dport 80 redirect :8080 random

The port specification can be a range:
 % nft add rule nat prerouting tcp dport 80 redirect :8080-8090 random

While at it, the regression tests files are updated.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests/regression: redirect: fix invalid syntax
Arturo Borrero [Fri, 7 Nov 2014 11:39:30 +0000 (12:39 +0100)] 
tests/regression: redirect: fix invalid syntax

This patch fixes invalid syntax in the redirect test files.

I used ' ;ok' instead of ';ok', and ' ;nok' instead of ';fail'.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agotests/regression: masquerade: fix invalid syntax
Arturo Borrero [Fri, 7 Nov 2014 11:39:24 +0000 (12:39 +0100)] 
tests/regression: masquerade: fix invalid syntax

This patch fixes invalid syntax in the masquerade test files.

I used ' ;ok' instead of ';ok', and ' ;nok' instead of ';fail'.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agonft: don't resolve hostnames by default
Arturo Borrero [Thu, 6 Nov 2014 08:05:28 +0000 (09:05 +0100)] 
nft: don't resolve hostnames by default

This patch changes the default behaviour of nft to not translate IP
addresses to hostnames when printing rules if no options are passed.

The options regarding translations after this patch are:

 <no -n/-N>             show IP addresses numerically (default behaviour)
 -n                     show IP addresses numerically
 -nn                    show Internet services and uid/gid numerically
 -nnn                   show protocols numerically
 -N (--reversedns)      translate IP addresses to names

The idea is to avoid breaking existing scripts that most likely rely on
'-n' to save the ruleset, so we reduce the impact of this patch and
provide a default behaviour that doesn't generate network traffic when
listing / saving the ruleset.

Joint work with Pablo.

Suggested-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoutils: indicate file and line on memory allocation errors
Pablo Neira Ayuso [Tue, 4 Nov 2014 13:27:22 +0000 (14:27 +0100)] 
utils: indicate file and line on memory allocation errors

For example:

 src/netlink.c:179: Memory allocation failure

This shouldn't happen, so this allows us to identify at what point the
memory allocation failure has happened. It may be helpful to identify
bugs.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agosrc: add redirect support
Arturo Borrero [Mon, 3 Nov 2014 20:20:11 +0000 (21:20 +0100)] 
src: add redirect support

This patch adds redirect support for nft.

The syntax is:

 % nft add rule nat prerouting redirect [port] [nat_flags]

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agometa: Add support for datatype devgroup
Ana Rey [Thu, 23 Oct 2014 12:44:19 +0000 (14:44 +0200)] 
meta: Add support for datatype devgroup

This adds the new devgroup datatype to get the group name from
/etc/iproute2/group file.

Example of use:

nft add rule ip test input meta iifgroup 0 counter
nft add rule ip test input meta iifgroup default counter

Moreover, It adds tests in meta.t test file.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoevaluate: reject: enhance the error support throwing message with more details
Alvaro Neira [Thu, 23 Oct 2014 17:36:57 +0000 (19:36 +0200)] 
evaluate: reject: enhance the error support throwing message with more details

If we add a rule like:

nft add rule bridge filter input ether type ip reject with icmpv6 type no-route

We throw an error like:

<cmdline>:1:44-49: Error: conflicting protocols specified: ip vs ip6
add rule bridge filter input ether type ip reject with icmpv6 type no-route

Now, we are going to show in which part of the rule, we have the conflict:

<cmdline>:1:51-75: Error: conflicting protocols specified: ip vs ip6
add rule bridge filter input ether type ip reject with icmpv6 type no-route
                             ~~~~~~~~~~~~~        ^^^^^^^^^^^^^^^^^^^^^^^^^

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
10 years agoevaluate: reject: check the context in reject without reason for bridge and inet...
Alvaro Neira [Thu, 23 Oct 2014 17:36:56 +0000 (19:36 +0200)] 
evaluate: reject: check the context in reject without reason for bridge and inet tables

In rules like:

  nft add rule inet filter input reject
or
  nft add rule bridge filter input reject

we use icmpx to reject it. But if we have network context, we also use type of
reject. With this patch, we check the network context. If we don't have context,
we still use icmpx. However, if we have rules with network context like:

  nft add rule inet meta nfproto ipv4 reject
or
  nft add rule bridge ether type ipv6 reject

We are going to use icmp or icmpv6 to reject it taking into account the network
context.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>