]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
7 years agomnl: do not set NLM_F_CREATE in deletion requests
Pablo Neira Ayuso [Fri, 8 Sep 2017 13:07:05 +0000 (15:07 +0200)] 
mnl: do not set NLM_F_CREATE in deletion requests

This flag is not legal there, it only makes sense for addition requests.
This patch has no impact at all in any of the nf_tables kernel versions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: py: add tests for limit stateful object
Pablo M. Bermudo Garay [Mon, 28 Aug 2017 18:20:49 +0000 (20:20 +0200)] 
tests: py: add tests for limit stateful object

The patch also reorganizes ip/objects.t file.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add flags fo nft_ctx_new
Eric Leblond [Mon, 4 Sep 2017 07:55:57 +0000 (09:55 +0200)] 
src: add flags fo nft_ctx_new

By adding flags to nft_ctx_new, we will have a minimum capabilities
of changing the way the nft_ctx is created.

For now, this patch uses a simple value that allow the user to specify
that he will handle netlink by himself.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add stateful object support for limit
Pablo M. Bermudo Garay [Wed, 23 Aug 2017 20:42:56 +0000 (22:42 +0200)] 
src: add stateful object support for limit

This patch adds support for a new type of stateful object: limit.
Creation, deletion and listing operations are supported.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add nft_ctx_netlink_init()
Pablo Neira Ayuso [Fri, 1 Sep 2017 10:00:21 +0000 (12:00 +0200)] 
src: add nft_ctx_netlink_init()

Add these two new functions to set up netlink sockets in the global
context structure.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonetlink: remove nfsock_open()
Pablo Neira Ayuso [Fri, 1 Sep 2017 09:56:18 +0000 (11:56 +0200)] 
netlink: remove nfsock_open()

Just merge this code to netlink_open_sock().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: move nf_sock into nft_ctx structure
Pablo Neira Ayuso [Fri, 1 Sep 2017 09:51:42 +0000 (11:51 +0200)] 
src: move nf_sock into nft_ctx structure

The idea is to provide a simplistic API for non-netlink wise people.
Add a field in struct nft_ctx to store the socket.

The advanced API that we're planning will just simply leave this unset,
since netlink IO will be exposed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: nft: Fix and enhance synopsis section
Phil Sutter [Thu, 17 Aug 2017 13:38:59 +0000 (15:38 +0200)] 
doc: nft: Fix and enhance synopsis section

This patch addresses shortcomings in the main synopsis section
illustrating possible invocations of nft command:

- Fix font styles to correctly put options into bold font and meta
  characters (brackets, pipes) into normal font.

- Add missing options to synopsis line.

- Use curly braces where either one of the alternatives is required.

- Remove choice="opt" attribute since that is the default anyway.

- Note that --includepath option is allowed to be given multiple times.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoevaluate: convert expr_rt byteorder when evaluating statment arg
Florian Westphal [Sun, 27 Aug 2017 20:24:19 +0000 (22:24 +0200)] 
evaluate: convert expr_rt byteorder when evaluating statment arg

expr_rt might write data in host byte order, so make sure to
convert if needed.

This makes 'tcp option maxseg size rt mtu' actually work, right now such rules
are no-ops because nft_exthdr never increases the mss.

While at it, extend the example to not bother testing non-syn packets.

Reported-by: Matteo Croce <technoboy85@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser: Fix memleaks for STRING token (and derived ones)
Phil Sutter [Fri, 25 Aug 2017 11:17:32 +0000 (13:17 +0200)] 
parser: Fix memleaks for STRING token (and derived ones)

The common paradigm here is that all parser rules converting string
tokens into symbols must free the string token if it's not used anymore.
This is unrelated to the %destructor directive, since that will apply
only if the parser discards the token, which is not the case then.

While being at it, simplify error handling in parser rule for listing
conntrack helpers (error() won't return NULL) and drop the unused extra
parameter passed to error() in level_type rule.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: call nft_init() and nft_exit() from context routines
Pablo Neira Ayuso [Thu, 24 Aug 2017 15:56:38 +0000 (17:56 +0200)] 
src: call nft_init() and nft_exit() from context routines

So we don't forget all these caches should be placed into struct
nft_ctx.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: release caches from nft_ctx_free() path
Eric Leblond [Thu, 24 Aug 2017 15:52:26 +0000 (17:52 +0200)] 
src: release caches from nft_ctx_free() path

Release existing caches from nft_ctx_free(). Still, the iface cache
should be good to place it in the nft_ctx structure.

Joint work with Pablo Neira.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add nft_run_cmd_*() functions
Eric Leblond [Thu, 24 Aug 2017 15:46:01 +0000 (17:46 +0200)] 
src: add nft_run_cmd_*() functions

Add new function to read nftables command from a file and buffer, that
we can expose as library.

Joint work with Pablo Neira.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add nft_ctx_new() and nft_ctx_free()
Eric Leblond [Thu, 24 Aug 2017 15:23:03 +0000 (17:23 +0200)] 
src: add nft_ctx_new() and nft_ctx_free()

These new functions allows us to allocate and release the context
structure. This is going to be useful for libnftables.

Joint work with Pablo Neira.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomnl: fix error handling in mnl_batch_talk
Eric Leblond [Thu, 24 Aug 2017 15:07:37 +0000 (17:07 +0200)] 
mnl: fix error handling in mnl_batch_talk

If one of the command is failing we should return an error.

Pablo says: "This is not a real issue since nft_netlink() returns an
error in case the list of errors is not empty. But we can indeed
simplify things by removing that explicit assignment in nft_netlink() so
mnl_batch_talk() consistently reports when if an error has happened.

Signee-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser: Fix for memleak when commands fail
Phil Sutter [Thu, 24 Aug 2017 17:14:13 +0000 (19:14 +0200)] 
parser: Fix for memleak when commands fail

In case of failing command evaluation, commands need to be freed as
their memory becomes orphaned afterwards.

Signed-off-by: Phil Sutter <phil@nwl.cc>
7 years agoscanner: Make use of yylex_init_extra()
Phil Sutter [Thu, 24 Aug 2017 17:14:12 +0000 (19:14 +0200)] 
scanner: Make use of yylex_init_extra()

This combines the calls to yylex_init() and yyset_extra().

Signed-off-by: Phil Sutter <phil@nwl.cc>
7 years agoscanner: Fix for wrong parameter type of scanner_destroy()
Phil Sutter [Thu, 24 Aug 2017 17:14:11 +0000 (19:14 +0200)] 
scanner: Fix for wrong parameter type of scanner_destroy()

The function takes the scanner as argument, not the state. This wasn't a
real issue since scanner is a void pointer, which means it's only casted
around without need. So this fix is a rather cosmetic one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
7 years agoscanner: Fix for memleak due to unclosed file pointer
Phil Sutter [Thu, 24 Aug 2017 17:14:10 +0000 (19:14 +0200)] 
scanner: Fix for memleak due to unclosed file pointer

When including a file, it is opened by fopen() and therefore needs to be
closed after scanning has finished using fclose(), otherwise valgrind
will report a memleak.

This patch changes struct input_descriptor to track the opened FILE
pointer instead of the file descriptor so the pointer is available for
closing in scanner_destroy().

While at it, change erec_print() to work on the open FILE pointer so it
doesn't have to call fileno() in beforehand. And as a little bonus, use
C99 initializer of the buffer to get rid of the call to memset().

Note that it is necessary to call erec_print_list() prior to destroying
the scanner, otherwise it will start manipulating an already freed FILE
pointer (and therefore crash the program).

Signed-off-by: Phil Sutter <phil@nwl.cc>
7 years agosrc: Fix debug_proto_ctx()
Phil Sutter [Thu, 24 Aug 2017 16:04:18 +0000 (18:04 +0200)] 
src: Fix debug_proto_ctx()

Debug mask check was done against wrong flag, causing protocol context
debug output being printed when only --debug=netlink was given.

Fixes: be441e1ffdc24 ("src: add debugging mask to context structure")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Initialize struct stmt in _match and _target functions.
Varsha Rao [Sun, 20 Aug 2017 04:55:12 +0000 (10:25 +0530)] 
src: Initialize struct stmt in _match and _target functions.

Initialize structure stmt with stmt_alloc in netlink_parse_target and
netlink_parse_match functions. This patch fixes the gcc warning:

‘stmt’ may be used uninitialized in this function.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser: fix typo
Pablo M. Bermudo Garay [Wed, 23 Aug 2017 20:42:55 +0000 (22:42 +0200)] 
parser: fix typo

Separator was misspelled as "seperator" in a symbol name.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add debugging mask to context structure
Pablo Neira Ayuso [Tue, 22 Aug 2017 16:45:52 +0000 (18:45 +0200)] 
src: add debugging mask to context structure

So this toggle is not global anymore. Update name that fits better with
the semantics of this variable.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomnl: pass struct netlink_ctx to mnl_nft_socket_sendmsg()
Pablo Neira Ayuso [Tue, 22 Aug 2017 16:38:45 +0000 (18:38 +0200)] 
mnl: pass struct netlink_ctx to mnl_nft_socket_sendmsg()

Reduce function footprint.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add struct mnl_ctx
Pablo Neira Ayuso [Tue, 22 Aug 2017 16:32:24 +0000 (18:32 +0200)] 
src: add struct mnl_ctx

This new structure contains the netlink socket and the sequence number.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: remove ifdef DEBUG pollution
Pablo Neira Ayuso [Tue, 22 Aug 2017 16:19:12 +0000 (18:19 +0200)] 
src: remove ifdef DEBUG pollution

Get rid of lots of ifdef DEBUG pollution in the code.

The --debug= option is useful to get feedback from users, so it should
be always there. And we really save nothing from keeping this code away
from the control plane with a compile time option. Just running
tests/shell/ before and after this patch, time shows almost no
difference.

So this patch leaves --enable-debug around to add debugging symbols in
your builds, this is left set on by default.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add maximum number of parser errors to struct nft_ctx
Pablo Neira Ayuso [Tue, 22 Aug 2017 16:09:12 +0000 (18:09 +0200)] 
src: add maximum number of parser errors to struct nft_ctx

Not a global variable anymore.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add include_paths to struct nft_ctx
Pablo Neira Ayuso [Tue, 22 Aug 2017 16:01:44 +0000 (18:01 +0200)] 
src: add include_paths to struct nft_ctx

Not convenient to keep this as static for the upcoming library, so let's
move it where it belongs.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Keep cache in struct nft_ctx
Phil Sutter [Tue, 22 Aug 2017 12:40:04 +0000 (14:40 +0200)] 
src: Keep cache in struct nft_ctx

This is preliminary work for Eric's libnftables patchset.

Cc: Eric Leblond <eric@regit.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
7 years agofiles: add arp filter and add in/output to nat skeleton
Florian Westphal [Wed, 23 Aug 2017 15:54:19 +0000 (17:54 +0200)] 
files: add arp filter and add in/output to nat skeleton

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: add tcp option set support / tcp mss mangling test cases
Florian Westphal [Tue, 8 Aug 2017 11:13:01 +0000 (13:13 +0200)] 
tests: add tcp option set support / tcp mss mangling test cases

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agort: add path mtu support
Florian Westphal [Tue, 4 Jul 2017 22:54:27 +0000 (00:54 +0200)] 
rt: add path mtu support

Only use case is to allow similar behaviour to iptables
TCPMSS --clamp-mss-to-pmtu, by combining this with exthdr statement:

tcp option maxseg size set rt mtu

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add tcp options set support
Florian Westphal [Sun, 11 Dec 2016 17:02:34 +0000 (18:02 +0100)] 
src: add tcp options set support

This adds support for tcp mss mangling:

nft add rule filter input tcp option maxseg size 1200

Its also possible to change other tcp option fields, but
maxseg is one of the more useful ones to change.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: mnl: Remove unused functions.
Varsha Rao [Wed, 16 Aug 2017 14:18:17 +0000 (19:48 +0530)] 
src: mnl: Remove unused functions.

Functions mnl_nft_chain_get(), mnl_nft_rule_add(),
mnl_nft_rule_delete(), mnl_nft_set_get(), mnl_nft_table_get(),
set_get_cb(), table_get_cb() and chain_get_cb() are only defined
but not used, so remove them.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: netlink: Remove unused functions.
Varsha Rao [Wed, 16 Aug 2017 14:18:16 +0000 (19:48 +0530)] 
src: netlink: Remove unused functions.

Remove netlink_add_rule_list(), netlink_dump_table(),
netlink_get_chain(), netlink_get_set(), netlink_get_table(),
netlink_list_chain() functions definitions as they are not
called anywhere in source code.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: cli: Remove cli_display() function.
Varsha Rao [Wed, 16 Aug 2017 14:18:15 +0000 (19:48 +0530)] 
src: cli: Remove cli_display() function.

Remove cli_display() function, as it is not called anywhere in source
code.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: gmputil: Remove mpz_get_be64() function.
Varsha Rao [Wed, 16 Aug 2017 14:18:14 +0000 (19:48 +0530)] 
src: gmputil: Remove mpz_get_be64() function.

mpz_get_be64() is not used anywhere in source code. So remove it.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Remove xt_stmt_() functions.
Varsha Rao [Wed, 16 Aug 2017 14:18:13 +0000 (19:48 +0530)] 
src: Remove xt_stmt_() functions.

Remove functions xt_stmt_alloc(), xt_stmt_release(), xt_stmt_xlate(),
xt_stmt_print(), xt_stmt_destroy() as they are not used. Similarly,
remove structure xt_stmt_ops.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: add test case for ttl/protocol set
Florian Westphal [Wed, 16 Aug 2017 14:12:37 +0000 (16:12 +0200)] 
tests: add test case for ttl/protocol set

nft .. ip ttl set 42

did set the protocol field and left ttl alone, add test cases for this.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoevaluate: shift immediate value when adjusting size for csum fixup
Florian Westphal [Wed, 16 Aug 2017 15:41:30 +0000 (17:41 +0200)] 
evaluate: shift immediate value when adjusting size for csum fixup

nft add rule .. ip ttl set 64

erronously mangles ip protocol instead of ttl.

Because the kernel can't deal with odd-sized data (ttl is one byte) when
doing checksum fixups, so the write to 'ttl' is turned into

[ payload load 2b @ network header + 8 => reg 1 ]
[ bitwise reg 1 = (reg=1 & 0x000000ff ) ^ $new_value ]
[ payload write reg 1 => 2b @ network header + 8 csum_type 1 csum_off 10 csum_flags 0x0 ]

While doing so, we did fail to shift the imm value, i.e.
we clear the wrong half of the u16 (protocol) instead of csum.

The correct mask is 0xff00, and $new_value needs to be shifted
so we leave the protocol value (which is next to ttl) alone.

Fixes: f9069cefdf ("netlink: make checksum fixup work with odd-sized header fields")
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: remove sequence number from struct eval_ctx
Pablo Neira Ayuso [Tue, 15 Aug 2017 16:45:00 +0000 (18:45 +0200)] 
rule: remove sequence number from struct eval_ctx

This field is unused, remove it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: make netlink sequence number non-static
Pablo Neira Ayuso [Mon, 14 Aug 2017 15:47:21 +0000 (17:47 +0200)] 
src: make netlink sequence number non-static

Place sequence number that is allocated per-command on the struct
netlink_ctx structure. This is allocated from nft_run() to correlate
commands with netlink messages for error reporting. Batch support
probing also shares this sequence numbers with commands.

There is an inpendent cache sequence number though, this routine is
called from a different path, usually from the evaluation phase.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoecho: Fix for added delays in rule updates
Phil Sutter [Tue, 15 Aug 2017 11:59:12 +0000 (13:59 +0200)] 
echo: Fix for added delays in rule updates

The added cache update upon every command dealing with rules was a
bummer. Instead, perform the needed cache update only if echo option was
set.

Initially, I tried to perform the cache update from within
netlink_echo_callback(), but that turned into a mess since the shared
socket between cache_init() and mnl_batch_talk() would receive
unexpected new input. So instead update the cache from do_command_add(),
netlink_replace_rule_batch() and do_comand_insert() so it completes
before mnl_batch_talk() starts listening.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: Merge monitor and echo test suites
Phil Sutter [Mon, 14 Aug 2017 23:43:05 +0000 (01:43 +0200)] 
tests: Merge monitor and echo test suites

The two test suites were pretty similar already, and since echo output
is supposed to be identical to monitor output apart from delete
commands, they can be merged together with litte effort.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonetlink: Fix segfault when using --echo flag
Phil Sutter [Mon, 14 Aug 2017 23:43:03 +0000 (01:43 +0200)] 
netlink: Fix segfault when using --echo flag

Commit 07b45939972eb ("src: introduce struct nft_cache") added cache
pointer to struct netlink_mon_handler and the code assumes it is never
NULL. Therefore initialize it in the dummy version of
netlink_mon_handler in netlink_echo_callback().

Fixes: b99c4d072d996 ("Implement --echo option")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomnl: Drop --echo support for non-batch calls
Phil Sutter [Mon, 14 Aug 2017 23:43:02 +0000 (01:43 +0200)] 
mnl: Drop --echo support for non-batch calls

Echo support in nft_mnl_talk() was broken: nft_mnl_talk_cb() passed
cbdata->data as second parameter to netlink_echo_callback() which
expected it to be of type struct netlink_ctx while in fact it was
whatever callers of nft_mnl_talk() passed as callback data (in most
cases a NULL pointer).

I didn't notice this because I didn't test for kernels without support
for transactions. This has been added to nftables in kernel version 3.16
back in 2014. Since then, user space which doesn't support it can't even
add a table anymore. So adding this new feature to the old code path is
really not feasible, therefore drop this broken attempt at supporting
it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoman: use https for wiki link
Daniel Kahn Gillmor [Mon, 14 Aug 2017 17:27:11 +0000 (13:27 -0400)] 
man: use https for wiki link

https works for the wiki, and users should prefer it by default,
whether they are logging in (to protect their credentials) or whether
they're reading data (to protect the integrity of the content).

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoman: Fix typo.
Varsha Rao [Sun, 6 Aug 2017 11:14:21 +0000 (16:44 +0530)] 
man: Fix typo.

The word 'occur' is misspelled as 'ocurr'. This patch fixes it.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: introduce struct nft_cache
Varsha Rao [Sun, 13 Aug 2017 04:30:18 +0000 (10:00 +0530)] 
src: introduce struct nft_cache

Pass variable cache_initialized and structure list_head as members of
structure nft_cache.

Joint work with Pablo Neira.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonft.8: Complete short description of arp family
Phil Sutter [Thu, 10 Aug 2017 17:29:20 +0000 (19:29 +0200)] 
nft.8: Complete short description of arp family

Although not very informational, still better than ending mid-sentence.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonft.8: Describe base chain details
Phil Sutter [Thu, 10 Aug 2017 17:29:19 +0000 (19:29 +0200)] 
nft.8: Describe base chain details

This mostly covers base chain types, but also tries to clarify meaning
of priority values, chain policy and the ominous device parameter.

Command synopsis is adjusted as well to point out which parts of a base
chain definition are optional and which are not.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonft.8: Add note about supported hooks for bridge family
Phil Sutter [Thu, 10 Aug 2017 17:29:18 +0000 (19:29 +0200)] 
nft.8: Add note about supported hooks for bridge family

It is the only address family which lacks a table describing supported
hooks. Since that would be identical to the one for ip/ip6/inet
families, just point there.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonft.8: Review reject statement description
Phil Sutter [Thu, 10 Aug 2017 17:29:17 +0000 (19:29 +0200)] 
nft.8: Review reject statement description

- Describe 'type' argument datatypes in DATA TYPES section, then remove
  value list from reject statement description and refer to that section
  instead.
- Fix synopsis: 'with ...' is optional.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonft.8: Describe conntrack types
Phil Sutter [Thu, 10 Aug 2017 17:29:16 +0000 (19:29 +0200)] 
nft.8: Describe conntrack types

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonft.8: Document operations on ruleset
Phil Sutter [Thu, 10 Aug 2017 17:29:15 +0000 (19:29 +0200)] 
nft.8: Document operations on ruleset

People new to nftables and yet unaware of 'list ruleset' and 'flush
ruleset' commands have a hard time. Therefore put description of those
prominently at the top, even before explaining operations on tables and
chains.

Since 'export ruleset' is closely related, document it here as well and
remove it's sparse description from ADDITIONAL COMMANDS section.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: Add a simple test suite for --echo option
Phil Sutter [Wed, 9 Aug 2017 11:16:43 +0000 (13:16 +0200)] 
tests: Add a simple test suite for --echo option

The fancy thing about this is that it uses the actual echo output to
undo the changes to the rule set.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoImplement --echo option
Phil Sutter [Wed, 9 Aug 2017 11:16:42 +0000 (13:16 +0200)] 
Implement --echo option

When used with add, insert or replace commands, nft tool will print
event notifications just like 'nft monitor' does for the same commands.

Apart from seeing what a given command will turn out in the rule set,
this allows to reliably retrieve a new rule's assigned handle (if used
together with --handle option).

Here are some examples of how it works:

| # nft --echo --handle add table ip t
| add table ip t
|
| # nft --echo --handle add chain ip t c \
|  '{ type filter hook forward priority 0; }'
| add chain ip t c { type filter hook forward priority 0; policy accept; }
|
| # nft --echo --handle add rule ip t c tcp dport '{22, 80}' accept
| add rule ip t c tcp dport { ssh, http } accept # handle 2
|
| # nft --echo --handle add set ip t ipset '{ type ipv4_addr; \
|  elements = { 192.168.0.1, 192.168.0.2 }; }'
| add set ip t ipset { type ipv4_addr; }
| add element ip t ipset { 192.168.0.1 }
| add element ip t ipset { 192.168.0.2 }

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonetlink: Pass nlmsg flags from rule.c
Phil Sutter [Wed, 9 Aug 2017 11:16:41 +0000 (13:16 +0200)] 
netlink: Pass nlmsg flags from rule.c

There is no point in checking value of excl in each called function.
Just do it in a single spot and pass resulting flags.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: fix arp chain test
Florian Westphal [Tue, 8 Aug 2017 09:02:34 +0000 (11:02 +0200)] 
tests: fix arp chain test

The forward chain isn't supported anymore (on kernel side it only worked
if bridge netfilter 'call-arptables' sysctl is on), so this test now fails
with nf-next kernel.

In nftables one can filter/test arp packets in bridge family directly.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: netlink: Subscribe nft monitor and nft monitor trace to respective groups.
Varsha Rao [Wed, 2 Aug 2017 11:43:08 +0000 (12:43 +0100)] 
src: netlink: Subscribe nft monitor and nft monitor trace to respective groups.

Subscribe nft monitor to both NFNLGRP_NFTABLES and NFNLGRP_NFTRACE.
nft monitor trace subscribes only to NFNLGRP_NFTRACE. Other event
reporting options to only NFNLGRP_NFTABLES.

Joint work with Pablo Neira.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: handle rule tracing as an monitor object
Pablo Neira Ayuso [Wed, 2 Aug 2017 11:43:04 +0000 (12:43 +0100)] 
src: handle rule tracing as an monitor object

Traces are not an event type, they should be handled as an object.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomnl: Consolidate mnl_batch_talk() parameters
Phil Sutter [Fri, 28 Jul 2017 11:55:45 +0000 (13:55 +0200)] 
mnl: Consolidate mnl_batch_talk() parameters

The single caller of this function passes struct netlink_ctx fields as
the first two parameters. This can be simplified by passing the context
object itself and having mnl_batch_talk() access it's fields instead.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoman: Document nft monitor ruleset.
Varsha Rao [Sun, 30 Jul 2017 18:56:02 +0000 (00:26 +0530)] 
man: Document nft monitor ruleset.

Add documentation for nft monitor ruleset command.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: nft monitor ruleset
Varsha Rao [Fri, 28 Jul 2017 05:22:09 +0000 (10:52 +0530)] 
src: nft monitor ruleset

This patch adds event reporting for ruleset, which prints only ruleset
events.

Syntax : nft monitor ruleset

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/monitor: Clear ruleset after testing
Phil Sutter [Tue, 25 Jul 2017 18:39:44 +0000 (20:39 +0200)] 
tests/monitor: Clear ruleset after testing

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/monitor: Simplify testcases
Phil Sutter [Tue, 25 Jul 2017 18:39:43 +0000 (20:39 +0200)] 
tests/monitor: Simplify testcases

By introducing 'O -' indicating that output should be identical as
input, testcases can be simplified quite a bit.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomonitor: Fix printing of set declarations
Phil Sutter [Tue, 25 Jul 2017 18:39:42 +0000 (20:39 +0200)] 
monitor: Fix printing of set declarations

The optional attributes 'flags', 'gc-interval' and 'timeout' have to be
delimited by stmt_separator (either newline or semicolon), not 'nl'
which is set to whitespace by set_print_plain().

In order to restore readability, change stmt_separator to include a
single whitespace after the semicolon.

Here's monitor output for the following command:

| # nft add set ip t testset { type inet_service; \
| timeout 60s; gc-interval 120s; }

Before this patch:

| add set ip t testset { type inet_service;timeout 1m gc-interval 2m }

With this patch applied:

| add set ip t testset { type inet_service; timeout 1m; gc-interval 2m; }

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agotests/monitor: Add a small README
Phil Sutter [Tue, 25 Jul 2017 14:56:29 +0000 (16:56 +0200)] 
tests/monitor: Add a small README

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agotests/monitor: Ignore newgen messages in output
Phil Sutter [Tue, 25 Jul 2017 14:56:24 +0000 (16:56 +0200)] 
tests/monitor: Ignore newgen messages in output

Predicting the new ID value is not feasible and neither is implementing
support for regular expressions when matching monitor output, so simply
ignore them.

Also use diff option '-w' instead of '-Z' to ignore all whitespace, not
just at EOL.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agomonitor: Print NEWGEN events
Phil Sutter [Wed, 19 Jul 2017 14:32:57 +0000 (16:32 +0200)] 
monitor: Print NEWGEN events

Now that they contain process information, they're actually interesting.
For backwards compatibility, print process information only if it was
present in the message.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agotests: Add basic monitor testing framework
Phil Sutter [Wed, 19 Jul 2017 13:05:29 +0000 (15:05 +0200)] 
tests: Add basic monitor testing framework

This implements testing of 'nft monitor' output correctness and adds a
number of testcases for named sets.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agomonitor: Fix printing of range elements in named sets
Arturo Borrero Gonzalez [Wed, 19 Jul 2017 13:05:28 +0000 (15:05 +0200)] 
monitor: Fix printing of range elements in named sets

If you add set elements to interval sets, the output is wrong.
Fix this by caching first element of the range (first event),
then wait for the second element of the range (second event) to
print them both at the same time.

We also avoid printing the first null element required in the RB tree.

Before this patch:

% nft add element t s {10-20, 30-40}
add element ip t s { 0 }
add element ip t s { 10 }
add element ip t s { ftp }
add element ip t s { 30 }
add element ip t s { 41 }

After this patch:

% nft add element t s {10-20, 30-40}
add element ip t s { 10-20 }
add element ip t s { 30-40 }

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosegtree: Introduce flag for half-open range elements
Phil Sutter [Wed, 19 Jul 2017 13:05:27 +0000 (15:05 +0200)] 
segtree: Introduce flag for half-open range elements

This flag is required by userspace only, so can live within userdata.
It's sole purpose is for 'nft monitor' to detect half-open ranges (which
are comprised of a single element only).

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: netlink: Remove variable nf_mon_sock.
Varsha Rao [Wed, 19 Jul 2017 12:34:07 +0000 (18:04 +0530)] 
src: netlink: Remove variable nf_mon_sock.

Remove variable nf_mon_sock of type structure mnl_socket to avoid
duplicity. Instead variable nf_sock of the same type is passed as
argument to netlink_monitor(). Also remove netlink_open_mon_sock()
function definition, which is no longer required.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: Allow passing the parent set to set_expr_alloc()
Phil Sutter [Wed, 12 Jul 2017 12:14:16 +0000 (14:14 +0200)] 
src: Allow passing the parent set to set_expr_alloc()

Usually one wants to at least initialize set_flags from the parent, so
make allocation of a set's set expression more convenient.

The idea to do this came when fixing an issue with output formatting of
larger anonymous sets in nft monitor: Since
netlink_events_cache_addset() didn't initialize set_flags,
calculate_delim() didn't detect it's an anonymous set and therefore
added newlines to the output.

Reported-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Fixes: a9dc3ceabc10f ("expression: print sets and maps in pretty format")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosegtree: Fix expr_value_cmp()
Phil Sutter [Thu, 6 Jul 2017 14:25:28 +0000 (16:25 +0200)] 
segtree: Fix expr_value_cmp()

Instead of returning the result of mpz_cmp(), this function returned 1
unless both elements were equal and the first one had
EXPR_F_INTERVAL_END set.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agomonitor: add debug messages
Arturo Borrero Gonzalez [Wed, 12 Jul 2017 11:29:49 +0000 (13:29 +0200)] 
monitor: add debug messages

Add some debug messages in the monitor/trace code paths to ease development
and debugging in case of errors.

After this patch, running 'nft monitor --debug=mnl,netlink' is more verbose.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agocli: fix heap buffer overflow
Eric Leblond [Mon, 10 Jul 2017 22:32:55 +0000 (00:32 +0200)] 
cli: fix heap buffer overflow

This patch fixes an invalid read when an empty command was sent.

Found via nft running ASAN and entering an empty command:

nft>

=================================================================
==19540==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000008c6f at pc 0x55e3b561704d bp 0x7fffe9a33ac0 sp 0x7fffe9a33ab8
READ of size 1 at 0x602000008c6f thread T0
    #0 0x55e3b561704c in cli_append_multiline /home/eric/git/netfilter/nftables/src/cli.c:65
    #1 0x55e3b561725b in cli_complete /home/eric/git/netfilter/nftables/src/cli.c:109
    #2 0x7f6e0c2ccac2 in rl_callback_read_char (/lib/x86_64-linux-gnu/libreadline.so.7+0x2fac2)
    #3 0x55e3b5617ba6 in cli_init /home/eric/git/netfilter/nftables/src/cli.c:199
    #4 0x55e3b5573b75 in main /home/eric/git/netfilter/nftables/src/main.c:381
    #5 0x7f6e0bc9b2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
    #6 0x55e3b55725a9 in _start (/usr/local/sbin/nft+0x445a9)

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoscanner: free filename when destroying scanner
Eric Leblond [Mon, 10 Jul 2017 22:32:54 +0000 (00:32 +0200)] 
scanner: free filename when destroying scanner

To be able to do so we duplicate the name in the indesc if it is
set.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoevaluate: fix build with clang
Eric Leblond [Mon, 10 Jul 2017 22:32:53 +0000 (00:32 +0200)] 
evaluate: fix build with clang

Building with a recent clang was failing due to the following error:

src/evaluate.c|450 col 45| error: initializer element is not constant
||    static const unsigned int max_tcpoptlen = 15 * 4 * BITS_PER_BYTE - tcphdrlen;
||                                              ^~

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoparser: error if needed at EOF
Eric Leblond [Mon, 10 Jul 2017 22:32:52 +0000 (00:32 +0200)] 
parser: error if needed at EOF

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoparser: fix bison warnings
Eric Leblond [Mon, 10 Jul 2017 22:32:51 +0000 (00:32 +0200)] 
parser: fix bison warnings

We had the following warnings

parser_bison.y:1089:10: warning: variable 'cmd' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
                                        if (erec != NULL) {
                                            ^~~~~~~~~~~~
parser_bison.y:1095:39: note: uninitialized use occurs here
                                (yyval.cmd) = cmd_alloc(CMD_LIST, cmd, &(yyvsp[0].handle), &(yyloc), NULL);
                                                                  ^~~
parser_bison.y:1089:6: note: remove the 'if' if its condition is always true
                                        if (erec != NULL) {
                                        ^~~~~~~~~~~~~~~~~~
parser_bison.y:1080:12: note: initialize the variable 'cmd' to silence this warning
                                int cmd;
                                       ^
                                        = 0

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoparser: fix memory leak in set creation
Eric Leblond [Mon, 10 Jul 2017 22:32:50 +0000 (00:32 +0200)] 
parser: fix memory leak in set creation

sudo  ASAN_SYMBOLIZER_PATH=/usr/lib/llvm-3.9/bin/llvm-symbolizer  nft add set inet filter blacklisddddddddddddddddddddt {type inet_service \;}

=================================================================
==25152==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 13 byte(s) in 1 object(s) allocated from:
    #0 0x45cca0 in __interceptor_strdup (/usr/local/sbin/nft+0x45cca0)
    #1 0x593cb1 in xstrdup /home/eric/git/netfilter/nftables/src/utils.c:75:8
    #2 0x5bccb2 in nft_lex /home/eric/git/netfilter/nftables/src/scanner.l:566:22
    #3 0x5cb363 in nft_parse /home/eric/git/netfilter/nftables/src/parser_bison.c:4366:16
    #4 0x505a37 in nft_run /home/eric/git/netfilter/nftables/src/main.c:246:8
    #5 0x50771f in main /home/eric/git/netfilter/nftables/src/main.c:392:6
    #6 0x7ff7befdb2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

SUMMARY: AddressSanitizer: 13 byte(s) leaked in 1 allocation(s).
Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: fix memory leak when listing rules
Eric Leblond [Mon, 10 Jul 2017 22:32:49 +0000 (00:32 +0200)] 
src: fix memory leak when listing rules

When listing rules we were calling strdup on the table name
but variable was just used locally.

Found via `nft list ruleset` run with ASAN:

Direct leak of 4 byte(s) in 1 object(s) allocated from:
    #0 0x45cca0 in __interceptor_strdup (/usr/local/sbin/nft+0x45cca0)
    #1 0x593c71 in xstrdup /home/eric/git/netfilter/nftables/src/utils.c:75:8
    #2 0x513b34 in do_list_ruleset /home/eric/git/netfilter/nftables/src/rule.c:1388:23
    #3 0x50e178 in do_command_list /home/eric/git/netfilter/nftables/src/rule.c:1500:10
    #4 0x50d3ea in do_command /home/eric/git/netfilter/nftables/src/rule.c:1696:10
    #5 0x5061ae in nft_netlink /home/eric/git/netfilter/nftables/src/main.c:207:9
    #6 0x505b87 in nft_run /home/eric/git/netfilter/nftables/src/main.c:255:8
    #7 0x50771f in main /home/eric/git/netfilter/nftables/src/main.c:392:6
    #8 0x7fa1f326d2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: Remove __init and __exit macro definitions.
Varsha Rao [Mon, 17 Jul 2017 11:59:07 +0000 (13:59 +0200)] 
src: Remove __init and __exit macro definitions.

Add nft_init and nft_exit functions, which calls _init and _exit
functions in main.c file. Remove __init and __exit macro definitions as
libnftables library will be created soon. Rename realm_table_init() and
realm_table_exit() functions to avoid ambiguity as
realm_table_rt_init(), realm_table_meta_init, realm_table_rt_exit() and
realm_table_meta_exit() in rt.c and meta.c files.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoinclude: Pass nf_sock where needed as parameter
Pablo Neira Ayuso [Fri, 7 Jul 2017 23:37:23 +0000 (05:07 +0530)] 
include: Pass nf_sock where needed as parameter

This socket should not be global, it is also hidden in many layers of
code. Expose it as function parameters to decouple the netlink socket
handling logic from the command parsing, evaluation and bytecode
generation.

Joint work with Varsha Rao.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agorename struct ct to ct_helper
Florian Westphal [Wed, 24 May 2017 18:10:44 +0000 (20:10 +0200)] 
rename struct ct to ct_helper

Its misleading, this structure holds members for ct_helper object
infrastructure, rename it.

Signed-off-by: Florian Westphal <fw@strlen.de>
8 years agoparser: compact list of rhs keyword expressions
Florian Westphal [Wed, 27 Jul 2016 13:16:32 +0000 (15:16 +0200)] 
parser: compact list of rhs keyword expressions

Condenses the copy/pastry via a define to avoid repeating this
when the list gets extended.

Based on earlier patch from Pablo.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
8 years agoexhtdr: pacify compiler warning
Florian Westphal [Thu, 13 Jul 2017 14:02:31 +0000 (16:02 +0200)] 
exhtdr: pacify compiler warning

gcc 7.1.1 complains:

exthdr.c:41:31: warning: ‘%d’ directive output may be truncated writing between 1 and 8 bytes into a region of size 3 [-Wformat-truncation=]
    snprintf(buf, sizeof buf, "%d", offset);
                               ^~
This warning is incorrect, as offset is limited by tcp option ranges,
but gcc doesn't know this. Increase buffer to avoid the warning.

Signed-off-by: Florian Westphal <fw@strlen.de>
8 years agotcpopt: make tcptopt structs static
Florian Westphal [Thu, 13 Jul 2017 13:50:30 +0000 (15:50 +0200)] 
tcpopt: make tcptopt structs static

not used outside of tcpopt.c, so unexport from header file and
make them static.

Signed-off-by: Florian Westphal <fw@strlen.de>
8 years agoinclude: Remove datatype_register().
Varsha Rao [Fri, 30 Jun 2017 09:26:19 +0000 (14:56 +0530)] 
include: Remove datatype_register().

Remove datatype_register() function and its calling __init functions.
Add arguments of datatype_register() function to datatype array.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoman: add include statement documentation.
Ismo Puustinen [Wed, 28 Jun 2017 08:16:57 +0000 (11:16 +0300)] 
man: add include statement documentation.

Add to man page information about using the wildcard include statements.

Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agotests: update include directory tests to support wildcard syntax.
Ismo Puustinen [Tue, 27 Jun 2017 12:14:59 +0000 (15:14 +0300)] 
tests: update include directory tests to support wildcard syntax.

Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoscanner: support for wildcards in include statements.
Ismo Puustinen [Tue, 27 Jun 2017 12:14:58 +0000 (15:14 +0300)] 
scanner: support for wildcards in include statements.

Use glob() to find paths in include statements. The rules are these:

  1. If no files can be found in the pattern with wildcards, do not
     return an error.
  2. Do not match any files beginning with '.'.
  3. Do not handle include directories anymore. For example, the
     statement:
       include "foo/"
     would now need to be rewritten:
       include "foo/*"

Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agotests: py: Fail test forcefully when bug is not fixed
Shyam Saini [Wed, 21 Jun 2017 08:47:45 +0000 (14:17 +0530)] 
tests: py: Fail test forcefully when bug is not fixed

When we have "fail" in the test cases then py test doesn't complain
anything, but the test should complain if the fix is not applied.

Before applying 986dea8a4a9d ("evaluate: avoid reference to multiple src
data in statements which set values"), nft throws following error
message and exits with error code 134.

$ nft add rule x y tcp dport set { 0 , 1 }
  BUG: unknown expression type set reference
  nft: netlink_linearize.c:696: netlink_gen_expr: Assertion `0' failed.
  Aborted

This commit enforces nft-test.py to throw error message when the fix
is not applied.

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: add --check option flag
Pablo M. Bermudo Garay [Fri, 23 Jun 2017 16:38:25 +0000 (18:38 +0200)] 
src: add --check option flag

Sometimes it can be useful to test if a command is valid without
applying any change to the rule-set. This commit adds a new option
flag (-c | --check) that performs a dry run execution of the commands.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: add new generic context structure nft_ctx
Pablo M. Bermudo Garay [Fri, 23 Jun 2017 16:38:24 +0000 (18:38 +0200)] 
src: add new generic context structure nft_ctx

The new structure nft_ctx is meant to be used as a generic container of
context information.

This is a preparatory patch. So at the moment the struct just carry
output_ctx on his path through main.c and cli.c.

Based on original idea from Eric Leblond.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agotests: shell: Test input descriptors for included files
Shyam Saini [Fri, 23 Jun 2017 12:05:56 +0000 (17:35 +0530)] 
tests: shell: Test input descriptors for included files

Before b14572f72aac ("erec: Fix input descriptors for included files"),
nft error message was pointing to wrong file. But after this commit it
points to right file.

This patch adds a new test for this commit.

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agotests: shell: Add test for incomplete set add set command
Shyam Saini [Fri, 23 Jun 2017 12:05:55 +0000 (17:35 +0530)] 
tests: shell: Add test for incomplete set add set command

Before c6cd7c22548a ("src: fix crash when inputting an incomplete set
add command") commit, if we run nft with incomplete "add set" command it
caused segmentation fault and exit with error code 139 and further it
didn't throw any error message.

  For example:
    $ sudo nft add set t s

But after the aforementioned commit it throws syntax error message and
exits with return value 1.

  For example:
    $ sudo nft add set t s
    <cmdline>:1:12-12: Error: syntax error, unexpected newline, expecting '{'
    add set t s
               ^
This commit tests changes made in such commit.

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoevaluate: Better error reporting for bad set references
Pablo Neira Ayuso [Mon, 19 Jun 2017 11:59:33 +0000 (13:59 +0200)] 
evaluate: Better error reporting for bad set references

In case you refer to an unexisting set, bail out with:

 # nft add table x
 # nft add chain x y
 # nft add rule x y ip protocol vmap @reject_to_rule2;
 <cmdline>:1:31-46: Error: Set 'reject_to_rule2' does not exist
 add rule x y ip protocol vmap @reject_to_rule2
                               ^^^^^^^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>