]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
7 years agotest: shell: execute shell/run-tests.sh from any directory
Harsha Sharma [Thu, 5 Oct 2017 07:43:47 +0000 (13:13 +0530)] 
test: shell: execute shell/run-tests.sh from any directory

Update shell/run-tests.sh to refer /src/nft with a relative path

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoINSTALL: Update dependency list and configure with libxtables support
Harsha Sharma [Thu, 5 Oct 2017 07:31:09 +0000 (13:01 +0530)] 
INSTALL: Update dependency list and configure with libxtables support

Add configure with libxtables in INSTALL and required dependencies for
the same.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoevaluate: Fix debug output
Phil Sutter [Wed, 4 Oct 2017 13:59:32 +0000 (15:59 +0200)] 
evaluate: Fix debug output

When introducing output_fp, debug output in src/evaluate.c was not
adjusted and therefore broke.

This patch restores eval debug output by applying the following changes:

- Change erec_print() and erec_print_list() to take a struct output_ctx
  pointer as first argument and use output_fp field as destination to
  print to.
- Drop octx_debug_dummy variable and instead use octx pointer from
  struct eval_ctx for debug output.
- Add missing calls to erec_destroy() in eval debug output which should
  eliminate another mem leak.

Fixes: 2535ba7006f22 ("src: get rid of printf")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser_bison: allow to used named limit from dictionaries too
Pablo Neira Ayuso [Mon, 2 Oct 2017 16:20:17 +0000 (18:20 +0200)] 
parser_bison: allow to used named limit from dictionaries too

Allow to use limit objects from dictionaries.

Fixes: c0697eabe832 ("src: add stateful object support for limit")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomnl: fix broken sequence number allocation
Pablo Neira Ayuso [Mon, 2 Oct 2017 12:19:15 +0000 (14:19 +0200)] 
mnl: fix broken sequence number allocation

Wrong arithmetics with pointer.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1178
Fixes: 0d9d04c31481 ("src: make netlink sequence number non-static")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoMerge branch 'ct_rt_syntax_06'
Florian Westphal [Fri, 29 Sep 2017 11:55:54 +0000 (13:55 +0200)] 
Merge branch 'ct_rt_syntax_06'

inet family (and others, e.g. bridge) lack context to figure out the
layer 3 address type.

examples:
ct original saddr $addr
rt nexthop $addr

We can't use $addr, because it might be a set reference, e.g.

ct original saddr @whitelist

currently implemented workaround is to use 'meta nfproto' to provide the
l3 context, e.g.

meta nfproto ip rt nexthop 10.2.3.4

i.e. users need to fill dependency manually.

Pablo suggested to instead specify ip saddr, ip6 saddr:

ct original ip saddr $address

and then let nft handle the dependency injection, these changes do this.
Old syntax is preserved.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: update man page
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
doc: update man page

you can now use "rt ip|ip6 nexthop" and "ct original|reply ip|ip6 saddr|daddr"
to tell nft if you want to match ipv4 or ipv6.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: rt: fix test cases
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
tests: rt: fix test cases

nfproto meta dependency is no longer needed, keep one test
since we still support this syntax.

When meta is not provided, no need to add a dependency because
nft_rt already checks pf number before checking skb->dst.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: rt: add keyword distinction for nexthop vs nexthop6
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
src: rt: add keyword distinction for nexthop vs nexthop6

the rt expression currently always sets NFT_RT_NEXTHOP4 and then
uses the network base to determine if its really supposed to be
NEXTHOP6.

For inet, this will fail because the network base is not known,
so this currently enforces need for "meta nfproto" to dermine the
type.

Allow following syntax instead:
  rt ip nexthop
  rt ip6 nexthop

There is no need for a dependency anymore, as rt expression
checks the hook protocol, ie. NEXTHOP4 will break if the hook pf
is not NFPROTO_IPV4.

Cc: Anders K. Pedersen <akp@cohaesio.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: ct: adjust test case commands
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
tests: ct: adjust test case commands

use 'ip saddr', 'ip6 saddr', etc.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: ct: print nfproto name for some header fields
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
src: ct: print nfproto name for some header fields

this prints "original saddr|daddr $NFPROTO" to make output
symmetric with the syntax that we now prefer on input side.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: update inet/bridge icmp test case
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
tests: update inet/bridge icmp test case

after previous change nft now culls the dependency chain:
'icmpv6 type echo-request' is shown as-is, and not
'meta nfproto ipv6 meta l4proto 58 icmpv6 type echo-request' anymore.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: unifiy meta and ct postprocessing
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
src: unifiy meta and ct postprocessing

From postprocess point of view meta and ct are logically the same,
except that their storage area overlaps (union type), so if we
extract the relevant fields we can move all of it into a single
helper and support dependency store/kill for both expressions.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: ct: add eval part to inject dependencies for ct saddr/daddr
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
src: ct: add eval part to inject dependencies for ct saddr/daddr

nft has enough context to determine if a dependeny is needed.

add rule ip filter ct original ip6 saddr
allows nft to generate an error due to conflicting bases (ip vs ip6).

add rule inet filter ct original ip6 saddr
allows nft to inject an ipv6 dependency expression.

add rule inet filter ct original saddr
will print an error and will suggest to add ip/ip6 keyword.

Delinerize and print support will be added in followup patches.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: ct: store proto base of ct key, if any
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
src: ct: store proto base of ct key, if any

ct keys can match on network and tranasport header protocol
elements, such as port numbers or ip addresses.

Store this base type so a followup commit can store and kill
dependencies, e.g. if bsae is network header we might be able
to kill an earlier expression because the dependency is implicit.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: add alternate syntax for ct saddr
Florian Westphal [Fri, 29 Sep 2017 11:54:21 +0000 (13:54 +0200)] 
src: add alternate syntax for ct saddr

current syntax is:

ct original saddr $address

problem is that in inet, bridge etc. we lack context to
figure out if this should fetch ipv6 or ipv4 from the conntrack
structure.

$address might not exist, rhs could e.g. be a set reference.

One way to do this is to have users manually specifiy the dependeny:

ct l3proto ipv4 ct original saddr $address

Thats ugly, and, moreover, only needed for table families
other than ip or ipv6.

Pablo suggested to instead specify ip saddr, ip6 saddr:

ct original ip saddr $address

and let nft handle the dependency injection.

This adds the required parts to the scanner and the grammar, next
commit adds code to eval step to make use of this.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agomain: Drop stdout hack to expose nft_print() implementation issues
Phil Sutter [Fri, 29 Sep 2017 11:26:22 +0000 (13:26 +0200)] 
main: Drop stdout hack to expose nft_print() implementation issues

This was helpful when testing nft_print() implementation, but breaks
'nft --help' output. Also, with this in place typical printf-debugging
would have to use stderr at all times which is confusing at least.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomain: Flush output from nft_gmp_print()
Phil Sutter [Fri, 29 Sep 2017 11:26:21 +0000 (13:26 +0200)] 
main: Flush output from nft_gmp_print()

This adds a missing call to fflush() to nft_gmp_print() just like in
nft_print(). This is strictly not necessary since usually
nft_gmp_print() is followed by a call to nft_print() but better not rely
upon this assumption.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: get rid of printf
Phil Sutter [Thu, 28 Sep 2017 15:17:45 +0000 (17:17 +0200)] 
src: get rid of printf

This patch introduces nft_print()/nft_gmp_print() functions which have
to be used instead of printf to output information that were previously
send to stdout. These functions print to a FILE pointer defined in
struct output_ctx. It is set by calling:

| old_fp = nft_ctx_set_output(ctx, new_fp);

Having an application-defined FILE pointer is actually quite flexible:
Using fmemopen() or even fopencookie(), an application gains full
control over what is printed and where it should go to.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: Refactor chain_print_declaration()
Phil Sutter [Thu, 28 Sep 2017 15:17:44 +0000 (17:17 +0200)] 
rule: Refactor chain_print_declaration()

Instead of having two nearly identical printf() calls for netdev and
other chains, print the common parts separately and include the device
bit only for netdev chains.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoerec_print: Pass output FILE pointer to netlink_dump_expr()
Phil Sutter [Thu, 28 Sep 2017 15:17:43 +0000 (17:17 +0200)] 
erec_print: Pass output FILE pointer to netlink_dump_expr()

It was a bit odd that erec_print() outputs to a given FILE pointer but
then calls netlink_dump_expr() which just prints to stdout. Fix this by
passing the given FILE pointer along so output is guaranteed to go to
the same destination.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexthdr: Simplify tcp option printing a bit
Phil Sutter [Thu, 28 Sep 2017 15:17:42 +0000 (17:17 +0200)] 
exthdr: Simplify tcp option printing a bit

This eliminates the need for that temporary buffer.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: Use C99-style initializer in cache_init()
Phil Sutter [Thu, 28 Sep 2017 15:17:41 +0000 (17:17 +0200)] 
rule: Use C99-style initializer in cache_init()

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agobison: permit keywords in list_stmt_expressions
Florian Westphal [Tue, 27 Jun 2017 00:34:17 +0000 (02:34 +0200)] 
bison: permit keywords in list_stmt_expressions

'ct event set label' and 'ct event set new or label' work, but
'ct event set new, label' did not:

  nft add rule filter input ct event set new,label
  Error: syntax error, unexpected label

This changes the definition to also contain keyword symbol expressions.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: parser_bison: rename ct_block to ct_helper_block
Florian Westphal [Wed, 24 May 2017 18:05:54 +0000 (20:05 +0200)] 
src: parser_bison: rename ct_block to ct_helper_block

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: prepare for future ct timeout policy support
Florian Westphal [Wed, 24 May 2017 18:05:54 +0000 (20:05 +0200)] 
src: prepare for future ct timeout policy support

Change all places that expect ct helper tokens (ct helper configuration)
to CT HELPER.  ct_obj_kind is removed.

When we add ct timeout support, we will add a new ct_timeout_block,
plus extra rules.  We won't extend ct_block, it prevents the parser
from detecting bogus syntax that only makes sense for ct helper but
not for something else for instance.

ct_block should be renamed to ct_helper_block, will be done in
followup patch.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: ct: remove unused functions
Florian Westphal [Wed, 27 Sep 2017 15:07:21 +0000 (17:07 +0200)] 
src: ct: remove unused functions

since commit b0c2606ed02fed828ab7c34227e355f5542bc925
("parser_bison: use keywords in ct expression") we no longer
abuse string for this, so there are no users of these helpers
anymore.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: store expression as set key instead of data type
Florian Westphal [Thu, 14 Sep 2017 20:59:13 +0000 (22:59 +0200)] 
src: store expression as set key instead of data type

Doing so retains legth information in case of unqualified data types,
e.g. we now have 'meta iifname' expression instead of an (unqualified)
string type.

This allows to eventually use iifnames as set keys without adding yet
another special data type for them.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoevaluate: prepare to store expr key rather than datatype
Florian Westphal [Fri, 15 Sep 2017 00:46:16 +0000 (02:46 +0200)] 
evaluate: prepare to store expr key rather than datatype

currently set definitions store a datatype rather than
an expression.

In order to support use of unqualified data types (string in particular),
this prepares implicit set definition helper to expect an expression instead
of plain data type.  This also has the advantage that we can use EXPR_CONCAT
to retain the original expressions when key concatentation is used, e.g.
'meta iifname . tcp dport'.  The netlink serialization code can use
this info to store individual key lengths independently of data types.

Would also allow later on to store the original names of the
expressions, e.g. "ip daddr", in the kernel to support a future
typeof keyword, e.g. 'type typeof(ip daddr)' instead of 'type ipv4_addr'.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser_bison: allow helper keyword in ct object kind
Pablo Neira Ayuso [Tue, 26 Sep 2017 16:16:57 +0000 (18:16 +0200)] 
parser_bison: allow helper keyword in ct object kind

The helper keyword clashes with the string rule, make sure we still
accept ct helper object types from the parser.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser_bison: use keywords in ct expression
Pablo Neira Ayuso [Tue, 26 Sep 2017 15:00:58 +0000 (17:00 +0200)] 
parser_bison: use keywords in ct expression

Using string give us more chances to hit shift/reduce conflicts when
extending this grammar, more specifically, from the stmt_expr rule, so
add keywords for this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser_bison: consolidate stmt_expr rule
Pablo Neira Ayuso [Fri, 22 Sep 2017 16:01:18 +0000 (18:01 +0200)] 
parser_bison: consolidate stmt_expr rule

Extend stmt_expr and use it from all of our statement rules. Add more
rules to describe what we take from statement expressions, instead of
reusing rhs_expr which is allowing way more things that we actually need
here. This is causing us problems when extending the grammar.

After this patch, you will hit this:

parser_bison.y: warning: 2 shift/reduce conflicts [-Wconflicts-sr]

However, this is fixed by the follow up patches:

parser_bison: allow helper keyword in ct object kind
parser_bison: use keywords in ct expression

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoinclude: remove outdated comment
JingPiao Chen [Sat, 23 Sep 2017 09:11:22 +0000 (17:11 +0800)] 
include: remove outdated comment

Remove outdated comment, format field in struct cmd have moved in commit
788687b03e37 ("src: interpret the event type from the evaluation step").

Signed-off-by: JingPiao Chen <chenjingpiao@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomonitor: Fix for incorrect debug_mask
Phil Sutter [Thu, 21 Sep 2017 18:38:02 +0000 (20:38 +0200)] 
monitor: Fix for incorrect debug_mask

The field 'debug_mask' of struct netlink_mon_handler was left
uninitialized in do_command_monitor() so it contained garbage from the
stack. Fix this by initializing it with the debug_mask value from struct
netlink_ctx.

While being at it, change the code to make use of C99-style initializer,
which will also avoid things like this in future.

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 agomain: Fix for return of uninitialized variable in nft_run_cmd_from_filename()
Phil Sutter [Thu, 21 Sep 2017 13:10:39 +0000 (15:10 +0200)] 
main: Fix for return of uninitialized variable in nft_run_cmd_from_filename()

If scanner_read_file() failed, the function would return an
uninitialized value.

Fixes: 3db28321b64a6 ("src: add nft_run_cmd_*() functions")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
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>