]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
11 years agoreject: add ICMP code parameter for indicating the type of error
Álvaro Neira Ayuso [Wed, 11 Jun 2014 16:51:03 +0000 (18:51 +0200)] 
reject: add ICMP code parameter for indicating the type of error

This patch allows to indicate the ICMP code field in case that we
use to reject. Before, we have always sent network unreachable error
as ICMP code, now we can explicitly indicate the ICMP code that
we want to use. Examples:

nft add rule filter input tcp dport 22 reject with host-unreach
nft add rule filter input udp dport 22 reject with host-unreach

In this case, it will use the host unreachable code to reject traffic.

The default code field still is network unreachable and we can also
use the rules without the with like that:

nft add rule filter input udp dport 22 reject

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoreject: Use protocol context for indicating the reject type
Álvaro Neira Ayuso [Wed, 11 Jun 2014 16:49:22 +0000 (18:49 +0200)] 
reject: Use protocol context for indicating the reject type

This patch uses the protocol context to initialize the reject type
considering if the transport protocol is tcp, udp, etc. Before this
patch, this was left unset.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoqueue: More compact syntax
Álvaro Neira Ayuso [Tue, 10 Jun 2014 13:26:24 +0000 (15:26 +0200)] 
queue: More compact syntax

This patch allows to use a new syntax more compact and break
the current syntax. This new syntax is more similar than the nftables
syntax that we use usually. We can use range like we have used in
other case in nftables. Here, we have some examples:

Before, If we want to declare a queue, we have used a syntax like this:

 nft add rule test input queue num 1 total 3 options bypass,fanout

If we want to use the queue number 1 and the two next (total 3),
we use a range in the new syntax, for example:

 nft add rule test input queue num 1-3 bypass fanout

Also if we want to use only one queue, the new rules are like:

 nft add rule test input queue num 1 # queue 1

or

 nft add rule test input queue # queue 0

And if we want to add a specific flags we only need to put
what flags we want to use:

 nft add rule test input queue bypass

we don't need to use options and the comma for indicating the
flags.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agocli: fix nft -i command crashes when try to input multi line command
Guruswamy Basavaiah [Sat, 7 Jun 2014 19:14:16 +0000 (00:44 +0530)] 
cli: fix nft -i command crashes when try to input multi line command

When try to input multiline command in "nft -i", it crashes.

Issue is, function cli_append_multiline() return null in case of
multiline command. But in the calling function cli_complete(),
cli_exit is getting called, which in turn calls
rl_callback_handler_remove() and the handler is getting removed.

 [root@localhost ~]# nft -i
 nft> add table filter
 nft> list table \

 readline: readline_callback_read_char() called with no handler!
 Aborted (core dumped)
 [root@localhost ~]#

After this patch, it shows:

 nft> list table \
 .... filter
 table ip filter {
 }
 nft>

The ".... " prompt is used to indicate a multiline command, similar to
what Python does.

Signed-off-by: Guruswamy Basavaiah <guru2018@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: change type of chain.priority from unsigned int to int
Hendrik Schwartke [Mon, 9 Jun 2014 21:39:32 +0000 (23:39 +0200)] 
src: change type of chain.priority from unsigned int to int

This removes a bug that displays strange hook priorities
like "type route hook output priority 4294967146".

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: Allow to invert the ranges
Álvaro Neira Ayuso [Wed, 28 May 2014 10:08:22 +0000 (12:08 +0200)] 
netlink: Allow to invert the ranges

This patch fix the bug:

http://bugzilla.netfilter.org/show_bug.cgi?id=924

Before, nftables doesn't permit invert ranges. This patch allows
add rules like this:

nft add rule ip test input ip daddr != 192.168.1.2-192.168.1.55
or
nft add rule ip test input ip daddr == 192.168.1.2-192.168.1.55

Also, we still have the option for adding rules like this:

sudo nft add rule ip test output frag id 33-45

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agopayload: Update the context only in equality relations
Álvaro Neira Ayuso [Mon, 2 Jun 2014 14:44:11 +0000 (16:44 +0200)] 
payload: Update the context only in equality relations

If we add this rule:

sudo nft add rule ip test input ip protocol != icmp

and we try to list the rules in the table test, nftables
show this error:

nft: src/payload.c:76: payload_expr_pctx_update: Assertion `expr->op == OP_EQ' failed.

This patch change the function payload_match_postprocess for updating
only the context in equality relations case.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoscanner: Add udplite token
Álvaro Neira Ayuso [Tue, 27 May 2014 14:30:11 +0000 (16:30 +0200)] 
scanner: Add udplite token

If we add a udplite rule, we can't because we have forgot
to add this token in the scanner.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: fix crash if kernel doesn't support nfnetlink / nf_tables
Pablo Neira Ayuso [Wed, 28 May 2014 08:27:01 +0000 (10:27 +0200)] 
netlink: fix crash if kernel doesn't support nfnetlink / nf_tables

When trying to close a descriptor which failed to be opened.

==6231== Process terminating with default action of signal 11 (SIGSEGV)
==6231==  Access not within mapped region at address 0x0
==6231==    at 0x5503E21: mnl_socket_close (socket.c:248)
==6231==    by 0x40517F: netlink_close_sock (netlink.c:68)
==6231==    by 0x400EFEE: _dl_fini (dl-fini.c:253)
==6231==    by 0x5740AA0: __run_exit_handlers (exit.c:77)
==6231==    by 0x5740B24: exit (exit.c:99)
==6231==    by 0x40F16F: netlink_open_error (netlink.c:105)
==6231==    by 0x405642: netlink_open_sock (netlink.c:54)
==6231==    by 0x424E6C: __libc_csu_init (in /usr/sbin/nft)
==6231==    by 0x5728924: (below main) (libc-start.c:219)
==6231==  If you believe this happened as a result of a stack
==6231==  overflow in your program's main thread (unlikely but
==6231==  possible), you can try to increase the size of the
==6231==  main thread stack using the --main-stacksize= flag.
==6231==  The main thread stack size used in this run was 8388608.

Closes: http://bugzilla.netfilter.org/show_bug.cgi?id=881
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoparser: use symbolic expression for ether too
Pablo Neira Ayuso [Tue, 27 May 2014 15:24:39 +0000 (17:24 +0200)] 
parser: use symbolic expression for ether too

Like in 0dbced3 ("parser: use symbolic expressions for parsing
keywords as protocol values"), convert `ether' to use a symbolic
expression.

This fixes:

 # nft add rule ip filter input meta iiftype ether
 # nft list table filter
 table ip filter {
...
iiftype 256

which was converted to network byte order.

Reported-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: don't add table/chain/set to ctx->list in the event path
Pablo Neira Ayuso [Thu, 22 May 2014 13:17:20 +0000 (15:17 +0200)] 
netlink: don't add table/chain/set to ctx->list in the event path

The delinearize functions for tables, chains and sets add these objects
to the ctx->list. In the chain case, this is not required. Regarding
tables and sets, those are added to the cache.

This patch implicitly fixes an use chain object after free that result
in random crashes.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink_delinearize: fix double free in relational_binop_postprocess()
Pablo Neira Ayuso [Thu, 22 May 2014 12:29:23 +0000 (14:29 +0200)] 
netlink_delinearize: fix double free in relational_binop_postprocess()

free(expr->right) and free(value) point to the same object, so one
single free() is enough.

This manifests in valgrind with:

==4020== Invalid read of size 4
==4020==    at 0x40A429: expr_free (expression.c:65)
==4020==    by 0x414032: expr_postprocess (netlink_delinearize.c:747)
==4020==    by 0x414C33: netlink_delinearize_rule (netlink_delinearize.c:883)
==4020==    by 0x411305: netlink_events_cb (netlink.c:1692)
==4020==    by 0x55040AD: mnl_cb_run (callback.c:77)
==4020==    by 0x4171E4: nft_mnl_recv (mnl.c:45)
==4020==    by 0x407B44: do_command (rule.c:895)
==4020==    by 0x405C6C: nft_run (main.c:183)
==4020==    by 0x405849: main (main.c:334)
==4020==  Address 0x5d126f8 is 56 bytes inside a block of size 120 free'd
==4020==    at 0x4C2AF5C: free (vg_replace_malloc.c:446)
==4020==    by 0x41402A: expr_postprocess (netlink_delinearize.c:746)
==4020==    by 0x414C33: netlink_delinearize_rule (netlink_delinearize.c:883)
==4020==    by 0x411305: netlink_events_cb (netlink.c:1692)
==4020==    by 0x55040AD: mnl_cb_run (callback.c:77)
==4020==    by 0x4171E4: nft_mnl_recv (mnl.c:45)
==4020==    by 0x407B44: do_command (rule.c:895)
==4020==    by 0x405C6C: nft_run (main.c:183)
==4020==    by 0x405849: main (main.c:334)
==4020==

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoparser: remove the "new" and "destroy" tokens from the scanner
Pablo Neira Ayuso [Mon, 19 May 2014 17:42:46 +0000 (19:42 +0200)] 
parser: remove the "new" and "destroy" tokens from the scanner

These new tokens were introduced in f9563c0 ("src: add events reporting")
to allow filtering based on the event type.

This confuses the parser when parsing the "new" token:

test:32:33-35: Error: syntax error, unexpected new
add rule filter output ct state new,established counter
                                ^^^

This patch fixes this by replacing these event type tokens by the
generic string token, which is then interpreted during the parsing.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: add table netlink messages to the batch
Pablo Neira Ayuso [Mon, 19 May 2014 10:21:46 +0000 (12:21 +0200)] 
src: add table netlink messages to the batch

This patch moves the table messages to the netlink batch that
is sent to kernel-space.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: add chain netlink messages to the batch
Pablo Neira Ayuso [Mon, 19 May 2014 10:21:23 +0000 (12:21 +0200)] 
src: add chain netlink messages to the batch

This patch moves the chain netlink messages to the big netlink
batch that is sent to kernel-space.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: add set netlink message to the batch
Pablo Neira Ayuso [Mon, 19 May 2014 10:18:04 +0000 (12:18 +0200)] 
src: add set netlink message to the batch

This patch moves the netlink set messages to the batch that contains
the rules. This helps to speed up rule-set restoration time by
changing the operational. To achieve this, an internal set ID which
is unique to the batch is allocated as suggested by Patrick.

To retain backward compatibility, nft initially guesses if the
kernel supports set in batches. Otherwise, it falls back to the
previous (slowier) operational.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: split talk() and recv() functions
Arturo Borrero [Mon, 28 Apr 2014 14:48:09 +0000 (16:48 +0200)] 
mnl: split talk() and recv() functions

Let's split talk() and recv() functions, so they can be used independently.

While at it, lets rename mnl_talk() to nft_mnl_talk() so we avoid potential
clashes with other functions in external libs.

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>
11 years agosrc: add events reporting
Arturo Borrero [Wed, 16 Apr 2014 16:43:17 +0000 (18:43 +0200)] 
src: add events reporting

This patch adds a basic events reporting option to nft.

The syntax is:
 % nft monitor [new|destroy] [tables|chains|rules|sets|elements] [xml|json]

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: add socket error reporting helper function
Arturo Borrero [Mon, 14 Apr 2014 10:17:41 +0000 (12:17 +0200)] 
netlink: add socket error reporting helper function

This patch adds a simple helper function to report errors while
opening the Netlink socket.

To help users to diagnose problems, a new NFT_EXIT_NONL exit code is included,
which is 3.

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>
11 years agonetlink: refactorize set_elem conversion from netlink
Arturo Borrero [Mon, 14 Apr 2014 10:17:35 +0000 (12:17 +0200)] 
netlink: refactorize set_elem conversion from netlink

Lets refactorize set_elem handling.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: add netlink_delinearize_table() func
Arturo Borrero [Mon, 14 Apr 2014 10:17:30 +0000 (12:17 +0200)] 
netlink: add netlink_delinearize_table() func

This code is suitable to be reusable.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: add netlink_delinearize_chain() func
Arturo Borrero [Mon, 14 Apr 2014 10:17:24 +0000 (12:17 +0200)] 
netlink: add netlink_delinearize_chain() func

Let's make this code reusable.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agorule: generalize chain_print()
Arturo Borrero [Mon, 14 Apr 2014 10:17:19 +0000 (12:17 +0200)] 
rule: generalize chain_print()

Lest generalize the chain_print() function, so we can print a plain chain
as the user typed in the basic CLI.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: add netlink_delinearize_set() func
Arturo Borrero [Mon, 14 Apr 2014 10:17:14 +0000 (12:17 +0200)] 
netlink: add netlink_delinearize_set() func

Let's factorize this code, so it can be reused.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agorule: allow to print sets in plain format
Arturo Borrero [Mon, 14 Apr 2014 10:17:08 +0000 (12:17 +0200)] 
rule: allow to print sets in plain format

Allow to print sets with or without format.

This is useful in situations where we want to print more or less the same
the user typed (IOW, in one single line, and with family/table info).

While at it, make family2str() function public, so it can be used in
other places.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: Add support for input and output bridge interface name
Tomasz Bursztyka [Mon, 14 Apr 2014 12:41:30 +0000 (15:41 +0300)] 
meta: Add support for input and output bridge interface name

Add support to get an input or output bridge interface name through the
relevant meta keys.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoBump version to v0.2 v0.2
Patrick McHardy [Mon, 14 Apr 2014 10:56:03 +0000 (12:56 +0200)] 
Bump version to v0.2

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agodoc: fix make install problems
Patrick McHardy [Mon, 14 Apr 2014 10:04:31 +0000 (12:04 +0200)] 
doc: fix make install problems

-e   INSTALL doc
/usr/bin/install: cannot stat 'doc/nftables.8': No such file or directory
make[1]: *** [install] Error 1
make: *** [doc] Error 2

Rename everything to nft.* to fix this up.

Reported-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agodoc: change documentation license to CC BY-SA 4.0
Patrick McHardy [Mon, 14 Apr 2014 06:52:43 +0000 (08:52 +0200)] 
doc: change documentation license to CC BY-SA 4.0

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agodoc: fix programlisting indentation
Patrick McHardy [Mon, 14 Apr 2014 06:37:26 +0000 (08:37 +0200)] 
doc: fix programlisting indentation

Since programlistings are used literally, the should not be indented.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agodatatypes: rename some types for more consistency
Patrick McHardy [Sun, 13 Apr 2014 10:58:25 +0000 (12:58 +0200)] 
datatypes: rename some types for more consistency

Add some more consistency by using _addr for all address types, _proto
for all protocol types and iface_ for all interface types.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agodoc: documentation update
Patrick McHardy [Wed, 26 Mar 2014 12:28:59 +0000 (12:28 +0000)] 
doc: documentation update

Signed-off-by: Patrick McHardy
11 years agobuild: fix documentation build
Patrick McHardy [Mon, 14 Apr 2014 06:18:47 +0000 (08:18 +0200)] 
build: fix documentation build

Handle the docbook2x-man mess that is called differently on different distributions.
Also switch to dblatex since db2pdf is unable to handle XML on Fedora (and probably
other distributions).

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink: fix length value of concat data
Patrick McHardy [Mon, 14 Apr 2014 05:41:04 +0000 (07:41 +0200)] 
netlink: fix length value of concat data

The length is measured in bytes, not bits.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agogmputil: use MSF/LSF in import/export functions dependant on host byte order
Patrick McHardy [Sat, 12 Apr 2014 08:40:08 +0000 (10:40 +0200)] 
gmputil: use MSF/LSF in import/export functions dependant on host byte order

For data of byteorder BYTEORDER_HOST_ENDIAN we need to set the word order
dependant on the host byte order.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoexpression: fix constant expression allocation on big endian
Arturo Borrero Gonzalez [Sat, 12 Apr 2014 08:40:08 +0000 (10:40 +0200)] 
expression: fix constant expression allocation on big endian

When allocating a constant expression, a pointer to the data is passed
to the allocation function. When the variable used to store the data
is larger than the size of the data type, this fails on big endian since
the most significant bytes (being zero) come first.

Add a helper function to calculate the proper address for the cases
where this is needed.

This currently affects symbolic tables for values < u64 and payload
dependency generation for protocol values < u32.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoMerge branch 'master' of git.netfilter.org:nftables
Patrick McHardy [Fri, 11 Apr 2014 13:55:24 +0000 (15:55 +0200)] 
Merge branch 'master' of git.netfilter.org:nftables

11 years agoparser: fix ether keyword clash
Patrick McHardy [Fri, 11 Apr 2014 13:50:15 +0000 (15:50 +0200)] 
parser: fix ether keyword clash

Due to the renaming of the "eth" keyword to "ether", parsing of arphrd
type "ether" fails.

Fix similar to TCP, UDP etc by allocating a constant arphrd expression for
the ether keyword without a following key.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agobuild: drop AC_FUNC_MALLOC/REALLOC
Florian Westphal [Thu, 10 Apr 2014 10:27:07 +0000 (12:27 +0200)] 
build: drop AC_FUNC_MALLOC/REALLOC

Two issues with these:
1. They compile & run a test program, which won't work when cross-compiling
2. When libnftnl has just been installed and is not (yet) in linker path, the
test fails since loader won't find libnftnl.

In that case configure will succeed without obvious errors, but config.h
re-defines malloc/realloc with rpl_ prefix, which then results in a
linker error ("undefined reference to `rpl_realloc'") on 'make'.

These macros are only useful to check that malloc(0) returns non-NULL
and that realloc(NULL, ... works.

For nftables the former is irrelevant and the latter a safe assumption,
so lets just remove them.

Signed-off-by: Florian Westphal <fw@strlen.de>
11 years agoutils: fix -Wcast-align warnings on sparc
Patrick McHardy [Wed, 9 Apr 2014 14:51:21 +0000 (16:51 +0200)] 
utils: fix -Wcast-align warnings on sparc

The cast to char * in the container_of() marcro causes warnings for all
list iteration helpers on sparc:

warning: cast increases required alignment of target type [-Wcast-align]

Fix by using a void * for address calculations.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agorule: fix crash in set listing
Ana Rey [Tue, 8 Apr 2014 08:19:41 +0000 (10:19 +0200)] 
rule: fix crash in set listing

It fixes an invalid read that is shown by valgrind.

==3962== Invalid read of size 4
==3962==    at 0x407040: do_command (rule.c:692)
==3962==    by 0x40588C: nft_run (main.c:183)
==3962==    by 0x405469: main (main.c:334)
==3962==  Address 0x10 is not stack'd, malloc'd or (recently) free'd

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: do not suppress OP_EQ when RHS is bitmask type
Florian Westphal [Mon, 17 Mar 2014 22:03:43 +0000 (23:03 +0100)] 
expr: do not suppress OP_EQ when RHS is bitmask type

bitmask types default to flagcmp now, thus do not suppress OP_EQ.  Else,

rule filter output tcp flags syn
rule filter output tcp flags == syn

are both displayed as 'flags syn'.

Signed-off-by: Florian Westphal <fw@strlen.de>
11 years agonftables: Fix list of sets by family
Ana Rey [Fri, 28 Mar 2014 12:30:27 +0000 (12:30 +0000)] 
nftables: Fix list of sets by family

Fix the result of command line 'nft list sets FAMILY'. It shows the
following error message:

"Error: syntax error, unexpected end of file, expecting string"

Now, it is possible shows right this information:

$ sudo nft -nna list sets ip
        set set_test {
                type ipv4_address
                elements = { 192.168.3.45, 192.168.3.43, 192.168.3.42, 192.168.3.4}
        }
set set_test2 {
                type ipv4_address
                elements = { 192.168.3.43, 192.168.3.42, 192.168.3.4}
        }
set set0 {
                type ipv4_address
                flags constant
                elements = { 127.0.0.12, 12.11.11.11}
        }

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoct: add support for setting ct mark
Arturo Borrero [Wed, 12 Mar 2014 18:03:19 +0000 (19:03 +0100)] 
ct: add support for setting ct mark

This patch adds the possibility to set ct keys using nft. Currently, the
connection mark is supported. This functionality enables creating rules
performing the same action as iptables -j CONNMARK --save-mark. For example:

table ip filter {
chain postrouting {
type filter hook postrouting priority 0;
ip protocol icmp ip daddr 8.8.8.8 ct mark set meta mark
}
}

My patch is based on the original http://patchwork.ozlabs.org/patch/307677/
by Kristian Evensen <kristian.evensen@gmail.com>.

I simply did a rebase and some testing. To test, I added rules like these:
 counter meta mark set 1 counter
 counter ct mark set mark counter
 counter ct mark 1 counter

The last matching worked as expected, which means the second rule is also
working as expected.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Acked-by: Kristian Evensen <kristian.evensen@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: fix expr_binary_error()-related compilation warnings
Arturo Borrero [Wed, 12 Mar 2014 15:53:22 +0000 (16:53 +0100)] 
src: fix expr_binary_error()-related compilation warnings

The commit e7b43ec0 [expr: make expr_binary_error() usable outside of evaluation]
seem to change expr_binary_error() interface.

Later, several compilation warning appears.

The expr_binary_error() function and expr_error() macro both expect
`struct list_head *', so I simply changed callers to send `ctx->msgs'.

[...]
src/evaluate.c: In function ‘byteorder_conversion’:
src/evaluate.c:166:3: warning: passing argument 1 of ‘expr_binary_error’ from incompatible pointer type [enabled by default]
In file included from src/evaluate.c:21:0:
include/expression.h:275:12: note: expected ‘struct list_head *’ but argument is of type ‘struct eval_ctx *’
src/evaluate.c: In function ‘expr_evaluate_symbol’:
src/evaluate.c:204:4: warning: passing argument 1 of ‘expr_binary_error’ from incompatible pointer type [enabled by default]
In file included from src/evaluate.c:21:0:
include/expression.h:275:12: note: expected ‘struct list_head *’ but argument is of type ‘struct eval_ctx *’
[...]

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agodatatype: don't leak file ptr on error
Florian Westphal [Sun, 9 Mar 2014 10:57:46 +0000 (11:57 +0100)] 
datatype: don't leak file ptr on error

Signed-off-by: Florian Westphal <fw@strlen.de>
11 years agosegtree: sort set elements before decomposition
Patrick McHardy [Fri, 7 Mar 2014 10:30:10 +0000 (11:30 +0100)] 
segtree: sort set elements before decomposition

The decomposition phase currently depends on the kernel returning elements
in sorted order. This is a fragile assumption, change the code to sort the
elements itself.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoset: properly account set size when merging recursive set definitions
Patrick McHardy [Fri, 7 Mar 2014 10:20:26 +0000 (11:20 +0100)] 
set: properly account set size when merging recursive set definitions

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoparser: add grammatical distinction for verdict maps
Patrick McHardy [Mon, 17 Feb 2014 19:43:36 +0000 (19:43 +0000)] 
parser: add grammatical distinction for verdict maps

Currently the parser accepts verdicts in regular maps and non-verdicts
in verdict maps and we have to check matching types during evaluation.
Add grammar rules for verdict maps and seperate them from regular maps.
This has a couple of advantages:

- We recognize verdict maps completely in the parser and any attempt to
  mix verdicts and other expressions will result in a syntax error.
  So far this hasn't actually been checked.

- Using verdicts in non-verdict mappings will also result in a syntax
  error instead of a datatype mismatch.

- There's a grammatical distinction between dictionaries and verdict
  maps, which are actually statements.

This is needed as preparation for a following patch to turn verdicts
into pure statements, which in turn is needed to reinstate support for
using the queue verdict in maps, which was broken by the introduction
of the queue statement.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink: use set location for IO errors
Patrick McHardy [Fri, 7 Mar 2014 09:57:08 +0000 (10:57 +0100)] 
netlink: use set location for IO errors

We currently crash when reporting a permission denied error for set additions.
This is due to using the wrong location, fix by passing in the set location.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoset: abort on interval conflicts
Patrick McHardy [Thu, 6 Mar 2014 15:26:09 +0000 (16:26 +0100)] 
set: abort on interval conflicts

We currently print a debug message (with debugging) and continue. Output
a proper error message and abort.

While at it, make sure we only report a conflict if there actually is one.
This is not the case similar actions, IOW in case of sets, never, in case
of maps, only if the mapping differs.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoexpr: add comparison function for singleton expressions
Patrick McHardy [Thu, 6 Mar 2014 16:03:19 +0000 (17:03 +0100)] 
expr: add comparison function for singleton expressions

Singed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoexpr: make expr_binary_error() usable outside of evaluation
Patrick McHardy [Thu, 6 Mar 2014 15:29:52 +0000 (16:29 +0100)] 
expr: make expr_binary_error() usable outside of evaluation

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

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

This patch adds support for human-readable comments:

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

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

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

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

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

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

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

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

The table object that is allocated is unused.

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

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

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

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

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

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

The prefix expression handling is full of bugs:

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

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

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

Rewrite that code properly.

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

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

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

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

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

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

Before:

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

After:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The line break is added after printing the rule.

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

Florian reports that flag comparisons generate incorrect instructions:

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

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

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

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

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

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

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

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

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

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

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

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

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

This patch fixes some incorrect behaviour of symbolic variables:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Currently always has the value 0.

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

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

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

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

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

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

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

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

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

The following command line works fine here:

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

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

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

This reverts commit 2f61f093c3149465f2a68764b25c817adbe87fcd.

Crap, accidentally committed this.

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

This patch adds the following operation:

 :~# nft export <xml|json>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

This patch fixes two problems:

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

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

To fix this, the set output is changed to:

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

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

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

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

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

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

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

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

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

Change the makefile to do this manually.

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