]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
6 years agoconfigure.ac: Fix a2x check
Luis Ressel [Sun, 17 Mar 2019 17:19:11 +0000 (18:19 +0100)] 
configure.ac: Fix a2x check

* If enable_man_doc is set, but a2x can't be found, configure should
  fail instead of silently disabling man page creation.

* The AS_IF block checking $need_a2x is never active (need_a2x has been
  removed from configure.ac in 13e44a608 and a277479dc).

* AC_CHECK_PROG(VAR, ...) is a noop if VAR is already set, allowing the
  user to explicitly specify the (path to the) binary in VAR. Adjust the
  AS_IF check to account for this.

Signed-off-by: Luis Ressel <aranea@aixah.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: file descriptor leak in include_file()
Pablo Neira Ayuso [Fri, 15 Mar 2019 10:31:50 +0000 (11:31 +0100)] 
src: file descriptor leak in include_file()

File that contains the ruleset is never closed, track open files through
the nft_ctx object and close them accordingly.

Reported-by: Václav Zindulka <vaclav.zindulka@tlapnet.cz>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoparser_bison: no need for statement separator for ct object commands
Pablo Neira Ayuso [Thu, 14 Mar 2019 10:04:37 +0000 (11:04 +0100)] 
parser_bison: no need for statement separator for ct object commands

Otherwise, this forces user to place a double semi-colon to skip a
parser error in a multi-line commands:

 # nft add "ct helper ip filter test { type \"ftp\" protocol tcp; };add rule filter test ct helper set \"ftp\""
 Error: syntax error, unexpected add, expecting end of file or newline or semicolon
 add ct helper ip filter test { type "ftp" protocol tcp; };add rule filter test ct helper set "ftp"
                                                           ^^^

Reported-by: Laura Garcia <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: shell: bogus EBUSY on helper deletion from transaction
Pablo Neira Ayuso [Thu, 14 Mar 2019 09:41:45 +0000 (10:41 +0100)] 
tests: shell: bogus EBUSY on helper deletion from transaction

Reported-by: Laura Garcia <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: shell: bogus ENOENT on element deletion in interval set
Pablo Neira Ayuso [Tue, 12 Mar 2019 11:31:04 +0000 (12:31 +0100)] 
tests: shell: bogus ENOENT on element deletion in interval set

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: shell: bogus EBUSY in set deletion after flush
Pablo Neira Ayuso [Fri, 8 Mar 2019 13:31:50 +0000 (14:31 +0100)] 
tests: shell: bogus EBUSY in set deletion after flush

flush chain ip filter group_7933

Removes all rules, including references to set 'group_7933', however:

delete map ip filter group_7933

results in:

delete.nft:6:1-32: Error: Could not process rule: Device or resource busy
delete map ip filter group_7933
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: add test case for anon set abort.
Florian Westphal [Thu, 7 Mar 2019 19:43:56 +0000 (20:43 +0100)] 
tests: add test case for anon set abort.

This triggers kernel crash in 5.0, see
https://bugzilla.netfilter.org/show_bug.cgi?id=1325

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoevaluate: misleading error reporting with sets and maps
Pablo Neira Ayuso [Wed, 6 Mar 2019 10:56:59 +0000 (11:56 +0100)] 
evaluate: misleading error reporting with sets and maps

When trying to list a map content, if set is used, nft reports:

 # nft list set filter group_7933
 Error: No such file or directory; did you mean set ‘group_7933’ in table ip ‘filter’?
 list set filter group_7933
                 ^^^^^^^^^^

Which is confusing in case user wants to list an existing map:

 # nft list map filter group_7933
 table ip filter {
        map group_7933 {
                type ipv4_addr : classid
                flags interval
                elements = { 10.4.22.0/24 : 1:c7cb }
        }
 }

Instead, give a hint to user that probably wants to list a map, not a set:

 # nft list set filter group_7933
 Error: No such file or directory; did you mean map ‘group_7933’ in table ip ‘filter’?
 list set filter group_7933
                 ^^^^^^^^^^

Fixes: 285bb67a11ad ("src: introduce simple hints on incorrect set")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosegtree: add missing non-matching segment to set in flat representation
Pablo Neira Ayuso [Tue, 5 Mar 2019 23:51:03 +0000 (00:51 +0100)] 
segtree: add missing non-matching segment to set in flat representation

 # cat test.nft
 add set x y { type ipv4_addr; }
 add element x y { 10.0.24.0/24 }
 # nft -f test.nft
 # nft delete element x y { 10.0.24.0/24 }

bogusly returns -ENOENT. The non-matching segment (0.0.0.0 with end-flag
set on) is not added to the set in the example above.

This patch also adds a test to cover this case.

Fixes: 4935a0d561b5 ("segtree: special handling for the first non-matching segment")
Reported-by: Václav Zindulka <vaclav.zindulka@tlapnet.cz>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosegtree: remove dummy debug_octx
Pablo Neira Ayuso [Tue, 5 Mar 2019 12:13:52 +0000 (13:13 +0100)] 
segtree: remove dummy debug_octx

Breaks custom-defined configuration in library mode, ie. user may want
to store output in a file, instead of stderr.

Fixes: 35f6cd327c2e ("src: Pass stateless, numeric, ip2name and handle variables as structure members.")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosegtree: fix crash when debug mode is active
Florian Westphal [Mon, 4 Mar 2019 00:06:05 +0000 (01:06 +0100)] 
segtree: fix crash when debug mode is active

We must set output_fp to sensible filep, else crash.

Reported-by: Václav Zindulka <vaclav.zindulka@tlapnet.cz>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agodoc: update goto/jump help text
Florian Westphal [Fri, 22 Feb 2019 16:33:09 +0000 (17:33 +0100)] 
doc: update goto/jump help text

pointed out by redsh on #netfilter: uses "of" instead of "or".
While at it, explain continue and update return statement.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoparser_json: Respect base chain priority
Phil Sutter [Tue, 26 Feb 2019 21:13:42 +0000 (22:13 +0100)] 
parser_json: Respect base chain priority

Priority value was parsed but not assigned to allocated chain object.

Fixes: 586ad210368b7 ("libnftables: Implement JSON parser")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Fix memleaks in echo support
Phil Sutter [Tue, 26 Feb 2019 21:13:41 +0000 (22:13 +0100)] 
json: Fix memleaks in echo support

When extracting netlink message data for populating JSON objects with
handles, allocated nftnl objects were not freed. Though since freeing
these objects also frees retrieved string attributes, copy them using
strdupa() which takes care of memory deallocation upon function return.
This is ideal since these strings are used only to find the right JSON
object to insert the handle into.

Fixes: bb32d8db9a125 ("JSON: Add support for echo option")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoparser_json: Use xstrdup() when parsing rule comment
Phil Sutter [Tue, 26 Feb 2019 21:13:40 +0000 (22:13 +0100)] 
parser_json: Use xstrdup() when parsing rule comment

Use xstrdup() instead of plain strdup() for consistency (and implicit
ENOMEM checking).

Fixes: 586ad210368b7 ("libnftables: Implement JSON parser")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoparser_json: Duplicate chain name when parsing jump verdict
Phil Sutter [Tue, 26 Feb 2019 21:13:39 +0000 (22:13 +0100)] 
parser_json: Duplicate chain name when parsing jump verdict

Since verdict expression frees the chain name, pass a newly allocated
string to it. Otherwise double free happens because json_decref() frees
the string property value as well.

Fixes: d1057a5feb5fd ("JSON: Simplify verdict statement parsing")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agolibnftables: Print errors before freeing commands
Phil Sutter [Tue, 26 Feb 2019 21:13:38 +0000 (22:13 +0100)] 
libnftables: Print errors before freeing commands

Commands may contain data printed by an error record, so make sure
cmd_free() is not called before erec_print_list() has returned.

Fixes: 778de37d82e7b ("libnftables: Keep cmds list outside of parser_state")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: shell: flush after rule deletion
Pablo Neira Ayuso [Fri, 15 Feb 2019 10:05:43 +0000 (11:05 +0100)] 
tests: shell: flush after rule deletion

Flush after rule deletion should hit no ENOENT.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: expr: fix build failure with json support
Florian Westphal [Tue, 12 Feb 2019 12:21:10 +0000 (13:21 +0100)] 
src: expr: fix build failure with json support

Fixes: e3f195777ee54 ("src: expr: remove expr_ops from struct expr")
Reported-by: Mikhail Morfikov <mmorfikov@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agosrc: expr: remove expr_ops from struct expr
Florian Westphal [Fri, 8 Feb 2019 16:02:23 +0000 (17:02 +0100)] 
src: expr: remove expr_ops from struct expr

size of struct expr changes from 144 to 128 bytes on x86_64.
This doesn't look like much, but large rulesets can have tens of thousands
of expressions (each set element is represented by an expression).

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agosrc: expr: add expression etype
Florian Westphal [Fri, 8 Feb 2019 16:02:22 +0000 (17:02 +0100)] 
src: expr: add expression etype

Temporary kludge to remove all the expr->ops->type == ... patterns.
Followup patch will remove expr->ops, and make expr_ops() lookup
the correct expr_ops struct instead to reduce struct expr size.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agosrc: expr: add and use internal expr_ops helper
Florian Westphal [Fri, 8 Feb 2019 16:02:21 +0000 (17:02 +0100)] 
src: expr: add and use internal expr_ops helper

This helper will eventually lookup the correct expr_ops
struct, so we can get rid of the expr->ops pointer.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: payload: export and use payload_expr_cmp
Florian Westphal [Fri, 8 Feb 2019 16:02:20 +0000 (17:02 +0100)] 
src: payload: export and use payload_expr_cmp

expr->ops is going away, so export payload cmp and use it directly.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: expr: add and use expr_name helper
Florian Westphal [Fri, 8 Feb 2019 16:02:19 +0000 (17:02 +0100)] 
src: expr: add and use expr_name helper

Currently callers use expr->ops->name, but follouwp patch will remove the
ops pointer from struct expr.  So add this helper and use it everywhere.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: shell: exercise abort path with anonymous set that is bound to rule
Pablo Neira Ayuso [Fri, 1 Feb 2019 20:28:46 +0000 (21:28 +0100)] 
tests: shell: exercise abort path with anonymous set that is bound to rule

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoinclude: add cplusplus guards for extern
Pablo Neira Ayuso [Mon, 28 Jan 2019 09:42:02 +0000 (10:42 +0100)] 
include: add cplusplus guards for extern

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Phil Sutter <phil@nwl.cc>
6 years agometa: add iifkind and oifkind support
wenxu [Thu, 24 Jan 2019 14:23:49 +0000 (22:23 +0800)] 
meta: add iifkind and oifkind support

This can be used to match the kind type of iif or oif
interface of the packet.  Example:

add rule inet raw prerouting meta iifkind "vrf" accept

Signed-off-by: wenxu <wenxu@ucloud.cn>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: fix up expected payloads after expr merge change
Florian Westphal [Fri, 25 Jan 2019 14:09:41 +0000 (15:09 +0100)] 
tests: fix up expected payloads after expr merge change

nft currently doesn't do payload merging anymore in some cases,
so fix up the expected output.

Fixes: ce2651222911 ("payload: refine payload expr merging")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agodoc: fix non-working example
Florian Westphal [Fri, 25 Jan 2019 14:08:10 +0000 (15:08 +0100)] 
doc: fix non-working example

nft doesn't have the context to translate "dns" or "http" as being
service names here.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agomnl: name is ignored when deleting a table
Florian Westphal [Wed, 16 Jan 2019 12:54:13 +0000 (13:54 +0100)] 
mnl: name is ignored when deleting a table

nlt is reallocated, leaking first allocation and also removing
the table name/handle that was set on nlt object.

Add a test case for this as well, the batch is supposed to fail
when trying to delete a non-existant table, rather than wiping
all tables in the same address family.

Fixes: 12c362e2214a0 ("mnl: remove alloc_nftnl_table()")
Reported-by: Mikhail Morfikov <mmorfikov@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agopayload: refine payload expr merging
Florian Westphal [Tue, 8 Jan 2019 23:15:09 +0000 (00:15 +0100)] 
payload: refine payload expr merging

nf_tables can handle payload exprs for sizes <= sizeof(u32) via a direct
operation from the eval loop, rather than a a call to the payload
expression.  Two loads for four byte quantities are thus faster than a
single load for an 8 byte load.

ip saddr 1.2.3.4 ip daddr 2.3.4.5

is faster with this applied, even though it involves two payload and two
two compare expressions, just because all can be handled from the main
loop without any calls to expression ops.

Keep merging for linklayer and when at least one of the expressions
already exceeded the 4 byte "limit" anyway.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: fix netdev family device name parsing
Florian Westphal [Wed, 9 Jan 2019 22:26:05 +0000 (23:26 +0100)] 
src: fix netdev family device name parsing

Should use accept/use quotes, else you can't use this with a device name
that is shared with a key word, e.g. 'device vm'.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add igmp support
Pablo Neira Ayuso [Wed, 9 Jan 2019 15:26:19 +0000 (16:26 +0100)] 
src: add igmp support

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: shell: remove RETURNCODE_SEPARATOR
Florian Westphal [Fri, 4 Jan 2019 15:25:41 +0000 (16:25 +0100)] 
tests: shell: remove RETURNCODE_SEPARATOR

test files are located via find + a pattern search that looks for
_[0-9].  Previous change makes all test scripts return 0 when the
test case is supposed to pass, so the foo_$retval name is no longer
needed.

Update script to look for all executeables in the 'testcases' directory.
This makes it necessary to make two dump-files non-executeable.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: shell: fix up redefine test case
Florian Westphal [Fri, 4 Jan 2019 15:00:16 +0000 (16:00 +0100)] 
tests: shell: fix up redefine test case

The '$' has to be escaped, else it gets replaced with an empty
value by the shell.  As 'set -e' is used, that caused the first
nft command to fail.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: shell: change all test scripts to return 0
Florian Westphal [Fri, 4 Jan 2019 14:57:00 +0000 (15:57 +0100)] 
tests: shell: change all test scripts to return 0

The shell-based tests currently encode a return value in the
file name, i.e. foo_1 expects that the script should return '1'
for the test case to pass.

This is very error prone, and one test case is even broken (i.e.,
it returns 1, but because of a different, earlier error).

do_something || exit 1
or
'set -e'

are both pretty common patterns, in both cases tests should fail.

In those test-cases that deliberately test for an error,
nft something_should_fail || exit 0
nft something_should_fail && exit 1

or a similar constructs should be used.

This initial commit modififies all '_1' scripts to return 0 on
success, usually via 'nft wrong || exit 0'.

All tests pass, except the one broken test case that hasn't worked
before either, but where 'set -e' use made it pass (the failing command
is supposed to work, and the command that is supposed to fail is never
run).

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: shell: add test case for leaking of stateful object refcount
Florian Westphal [Fri, 4 Jan 2019 11:30:47 +0000 (12:30 +0100)] 
tests: shell: add test case for leaking of stateful object refcount

Taehee Yoo fixed a bug in error path handling for object refcounts.
Quoting patch description:
  |   $nft add table ip filter
  |   $nft add counter ip filter c1
  |   $nft add map ip filter m1 { type ipv4_addr : counter \;}
  |   $nft add element ip filter m1 { 1 : c1 }
  |   $nft add element ip filter m1 { 1 : c1 }
  |   $nft delete element ip filter m1 { 1 }
  |   $nft delete counter ip filter c1
  |Result:
  |   Error: Could not process rule: Device or resource busy
  |   delete counter ip filter c1
  |
  |At the second 'nft add element ip filter m1 { 1 : c1 }', the reference
  |count of the 'c1' is increased then it tries to insert into the 'm1'. but
  |the 'm1' already has same element so it returns -EEXIST.
  |But it doesn't decrease the reference count of the 'c1' in the error path.
  |Due to a leak of the reference count of the 'c1', the 'c1' can't be
  |removed by 'nft delete counter ip filter c1'.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agorule: fix object listing when no table is given
Florian Westphal [Wed, 2 Jan 2019 16:10:36 +0000 (17:10 +0100)] 
rule: fix object listing when no table is given

'nft list quotas' would not print anything at all anymore.

Fixes: 88456a7ef01172 ("rule: list only the table containing object")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxt: fix build with --with-xtables
Florian Westphal [Sat, 29 Dec 2018 20:29:00 +0000 (21:29 +0100)] 
xt: fix build with --with-xtables

The previous change is bonkers, it fixes build when libxtables isn't
even installed, but broke build when --with-xtables is provided to configure.

Reason is that the include guard comes too early, so xtables.h is never
included, causing build to fail because no libxtables function prototypes
and definitions are available.

Fixes: 9e84f3f083bb ("xt: fix build when libxtables is not installed")
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agodoc: refer to meta protocol in icmp and icmpv6
Pablo Neira Ayuso [Sat, 29 Dec 2018 00:23:11 +0000 (01:23 +0100)] 
doc: refer to meta protocol in icmp and icmpv6

Instead of meta nftproto, which is a typo.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: remove deprecated code for export/import commands
Pablo Neira Ayuso [Thu, 27 Dec 2018 20:19:08 +0000 (21:19 +0100)] 
src: remove deprecated code for export/import commands

Update parser to display this error message:

 # nft export json
 Error: JSON export is no longer supported, use 'nft -j list ruleset' instead
 export json
 ^^^^^^^^^^^^

Just like:

 # nft export vm json
 Error: JSON export is no longer supported, use 'nft -j list ruleset' instead
 export vm json
 ^^^^^^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: Reject 'export vm json' command
Phil Sutter [Mon, 17 Dec 2018 15:29:56 +0000 (16:29 +0100)] 
src: Reject 'export vm json' command

Since libnftnl recently dropped JSON output support, this form of JSON
export is not available anymore. Point at 'nft -j list ruleset' command
for a replacement in error message.

Since 'export' command is not useable anymore, remove it from
documentation. Instead point out that 'list ruleset' command serves well
for dumping and later restoring.

To not cause pointless inconvenience for users wishing to store their
ruleset in JSON format, make JSON parser fallback to CMD_ADD if no
recognized command property was found. This allows to feed the output of
'nft -j list ruleset' into 'nft -f' without any modification.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxt: fix build when libxtables is not installed
Florian Westphal [Thu, 29 Nov 2018 13:57:59 +0000 (14:57 +0100)] 
xt: fix build when libxtables is not installed

If libxtables is not even installed, build fails due to to missing
include file.

ifdef LIBXTABLES guard fixes the first error, but results in two
followup failures:
1. missing IFNAMSIZ definition
2. dereference of unknown struct.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoparser: bail out on incorrect burst unit
Pablo Neira Ayuso [Mon, 3 Dec 2018 16:06:21 +0000 (17:06 +0100)] 
parser: bail out on incorrect burst unit

Burst can be either bytes or packets, depending on the rate limit unit.

 # nft add rule x y iif eth0 limit rate 512 kbytes/second burst 5 packets
 Error: syntax error, unexpected packets, expecting string or bytes
 add rule x y iif eth0 limit rate 512 kbytes/second burst 5 packets
                                                            ^^^^^^^

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1306
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: nft: document ct count
Pablo Neira Ayuso [Sat, 1 Dec 2018 16:54:03 +0000 (17:54 +0100)] 
doc: nft: document ct count

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: introduce simple hints on incorrect identifier
Pablo Neira Ayuso [Sat, 1 Dec 2018 11:06:46 +0000 (12:06 +0100)] 
src: introduce simple hints on incorrect identifier

 # cat test.nft
 define test = "1.2.3.4"

 table ip x {
        chain y {
                ip saddr $text
        }
 }
 # nft -f test.nft
 test.nft:5:13-16: Error: unknown identifier 'text'; did you mean identifier ‘test’?
                 ip saddr $text
                           ^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: introduce simple hints on incorrect object
Pablo Neira Ayuso [Sat, 1 Dec 2018 10:33:31 +0000 (11:33 +0100)] 
src: introduce simple hints on incorrect object

 # nft add counter x test
 # nft list counter x test
 Error: No such file or directory; did you mean obj ‘test’ in table ip ‘x’?
 list counter x text
                ^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomisspell: add distance threshold for suggestions
Pablo Neira Ayuso [Fri, 30 Nov 2018 17:04:14 +0000 (18:04 +0100)] 
misspell: add distance threshold for suggestions

Restrict suggestions to threshold, like gcc does.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: provide suggestion for misspelled object name
Pablo Neira Ayuso [Fri, 30 Nov 2018 17:04:10 +0000 (18:04 +0100)] 
src: provide suggestion for misspelled object name

Use this from the lookup path, to check for misspellings:

 # nft add table filter
 # nft add chain filtre test
 Error: No such file or directory; did you mean table ‘filter’ in family ip?
 add chain filtre test
           ^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoutils: remove type checks in min() and max()
Pablo Neira Ayuso [Fri, 30 Nov 2018 17:04:01 +0000 (18:04 +0100)] 
utils: remove type checks in min() and max()

So we can pass functions as parameters, needed by follow up patch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: fix return codes
Arturo Borrero Gonzalez [Wed, 28 Nov 2018 13:31:57 +0000 (14:31 +0100)] 
tests: fix return codes

Try to return != 0 if a testsuite fails.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: add test case for rule replacement expression deactivation
Florian Westphal [Wed, 28 Nov 2018 10:44:59 +0000 (11:44 +0100)] 
tests: add test case for rule replacement expression deactivation

When a rule is replaced, all of the expressions that are in use need to
be deactivated.

Kernel missed to do this on replace.  In this example, this would
result in a leak of the chain use counter ("jump" expression
deactivation is not called).  This then either resulted in a BUG or
WARN, depending on kernel version.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agosrc: introduce simple hints on incorrect set
Pablo Neira Ayuso [Mon, 19 Nov 2018 12:02:03 +0000 (13:02 +0100)] 
src: introduce simple hints on incorrect set

 # nft rule x y ip saddr @y
 Error: No such file or directory; did you mean set ‘y’ in table inet ‘x’?
 rule x y ip saddr @y
                   ^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: introduce simple hints on incorrect chain
Pablo Neira Ayuso [Mon, 19 Nov 2018 11:22:06 +0000 (12:22 +0100)] 
src: introduce simple hints on incorrect chain

 # nft list chain x y
 Error: No such file or directory; did you mean chain ‘y’ in table inet ‘x’?
 list chain x y
              ^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: introduce simple hints on incorrect table
Pablo Neira Ayuso [Mon, 19 Nov 2018 10:41:07 +0000 (11:41 +0100)] 
src: introduce simple hints on incorrect table

This patch adds simple infrastructure to provide a hints to user on
references to incorrect table. While at it, remove "Could not process
rule:" which I think it is implicit in the error.

 # nft rule x y ip saddr @y
 Error: No such file or directory; did you mean table ‘x’ in family inet?

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: grammar fixes
Jan Engelhardt [Tue, 13 Nov 2018 10:53:30 +0000 (11:53 +0100)] 
doc: grammar fixes

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: Spelling and grammar fixes
Ville Skyttä [Tue, 13 Nov 2018 09:46:08 +0000 (11:46 +0200)] 
doc: Spelling and grammar fixes

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoxt: always build with a minimal support for xt match/target decode
Florian Westphal [Tue, 6 Nov 2018 15:06:27 +0000 (16:06 +0100)] 
xt: always build with a minimal support for xt match/target decode

When building without libxtables, nft would just silently omit any presence
of nft_compat in the output.

This adds ifdef-ry to at least print name of target/match involved when
libxtables isn't available for decoding.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoxt: pass octx to translate function
Florian Westphal [Tue, 6 Nov 2018 15:06:26 +0000 (16:06 +0100)] 
xt: pass octx to translate function

We can't use it when no translation is available as libxtables will
use plain printf(), but when translation is available we can.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agonft.8: Clarify 'index' option of add rule command
Phil Sutter [Mon, 12 Nov 2018 14:02:52 +0000 (15:02 +0100)] 
nft.8: Clarify 'index' option of add rule command

Documentation for add rule command might trick readers into believing
the optional 'index' argument does not need to be that of an existing
rule. This false assumption is fueled by the fact that iptables allows
to insert with last rule number + 1 to actually append to a chain.
Change the relevant sentence to clarify that.

While being at it, drop the deprecated 'position' option from
documentation - since this will likely go away at some point, don't
encourage users to use it although they should notice that they
shoudn't.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodocumentation: clarify iif vs. iifname
Florian Westphal [Sun, 4 Nov 2018 19:05:20 +0000 (20:05 +0100)] 
documentation: clarify iif vs. iifname

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agodoc: libnftables.adoc misc cleanups
Duncan Roe [Sun, 4 Nov 2018 03:56:39 +0000 (14:56 +1100)] 
doc: libnftables.adoc misc cleanups

Ensure split-off fragments of long lines start with <TAB>
if the original long line did.

Split 1 remaining long line at sentence boundary.

Fix spelling of "eg." to "e.g."

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: Fix for make distcheck
Phil Sutter [Wed, 31 Oct 2018 22:16:56 +0000 (23:16 +0100)] 
doc: Fix for make distcheck

When building from a separate build directory, a2x did not find the
source file nft.txt. Using '$<' instead fixes this.

Fixes: 3bacae9e4a1e3 ("doc: Review man page building in Makefile.am")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agopy: Adjust Nftables class to output flags changes
Phil Sutter [Wed, 31 Oct 2018 12:53:16 +0000 (13:53 +0100)] 
py: Adjust Nftables class to output flags changes

Introduce setter/getter methods for each introduced output flag. Ignore
NFT_CTX_OUTPUT_NUMERIC_ALL for now since it's main purpose is for
internal use.

Adjust the script in tests/py accordingly: Due to the good defaults,
only numeric proto output has to be selected - this is not a must, but
allows for the test cases to remain unchanged.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: fix json_events_cb() declaration when libjansson is not present
Laura Garcia Liebana [Wed, 31 Oct 2018 11:54:18 +0000 (12:54 +0100)] 
json: fix json_events_cb() declaration when libjansson is not present

When nftables is configured without libjansson support, the following
compilation error is shown:

monitor.c: In function ‘netlink_echo_callback’:
monitor.c:910:10: error: too many arguments to function ‘json_events_cb’
   return json_events_cb(nlh, &echo_monh);
          ^~~~~~~~~~~~~~

This patch makes a declaration of the json_events_cb() function
consistent.

Fixes: bb32d8db9a12 ("JSON: Add support for echo option")
Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: remove unnecessary extra asterisk at the end of option line
Pablo Neira Ayuso [Mon, 29 Oct 2018 21:04:55 +0000 (22:04 +0100)] 
doc: remove unnecessary extra asterisk at the end of option line

For --guid, --numeric-protocol and --numeric-priority.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoexpression: always print range expression numerically
Pablo Neira Ayuso [Mon, 29 Oct 2018 20:50:49 +0000 (21:50 +0100)] 
expression: always print range expression numerically

Otherwise we end up displaying things that we cannot parse as input.
Moreover, in a range, it's relevant to the user the values that are
enclosed in the range, so let's print this numerically.

Fixes: baa4e0e3fa5f ("src: add NFT_CTX_OUTPUT_NUMERIC_PROTO")
Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add -p to print layer 4 protocol numerically
Pablo Neira Ayuso [Mon, 29 Oct 2018 20:43:25 +0000 (21:43 +0100)] 
src: add -p to print layer 4 protocol numerically

We keep printing layer 4 protocols as literals since we do not use
/etc/protocols. Add -p option to print layer 4 protocols numerically.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: get rid of nft_ctx_output_{get,set}_numeric()
Pablo Neira Ayuso [Mon, 29 Oct 2018 15:03:32 +0000 (16:03 +0100)] 
src: get rid of nft_ctx_output_{get,set}_numeric()

This patch adds NFT_CTX_OUTPUT_NUMERIC_SYMBOL, which replaces the last
client of the numeric level approach.

This patch updates `-n' option semantics to display all output
numerically.

Note that monitor code was still using the -n option to skip printing
the process name, this patch updates that path too to print it
inconditionally to simplify things.

Given the numeric levels have no more clients after this patch, remove
that code.

Update several tests/shell not to use -nn.

This patch adds NFT_CTX_OUTPUT_NUMERIC_ALL which enables all flags to
provide a fully numerical output.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add -y to priority base chain nummerically
Pablo Neira Ayuso [Mon, 29 Oct 2018 13:15:14 +0000 (14:15 +0100)] 
src: add -y to priority base chain nummerically

By default base chains are printed using default hook priority
definitions. Add -y option to print them as numbers.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add NFT_CTX_OUTPUT_NUMERIC_PROTO
Pablo Neira Ayuso [Mon, 29 Oct 2018 13:04:07 +0000 (14:04 +0100)] 
src: add NFT_CTX_OUTPUT_NUMERIC_PROTO

We keep printing layer 4 protocols as literals since we do not use
/etc/protocols. This new flag allows us to print it as a number.

libnftables internally uses this to print layer 4 protocol as numbers
when part of a range.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: default to numeric UID and GID listing
Pablo Neira Ayuso [Mon, 29 Oct 2018 11:49:00 +0000 (12:49 +0100)] 
src: default to numeric UID and GID listing

Like iptables-save, print UID and GID as numeric values by default.

Add a new option `-u' to print the UID and GID names as defined by
/etc/passwd and /etc/group.

Note that -n is ignored after this patch, since default are numeric
printing for UID and GID.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add nft_ctx_output_{get,set}_echo() to nft_ctx_output_{get,set}_flags
Pablo Neira Ayuso [Mon, 29 Oct 2018 11:11:09 +0000 (12:11 +0100)] 
src: add nft_ctx_output_{get,set}_echo() to nft_ctx_output_{get,set}_flags

Add NFT_CTX_OUTPUT_ECHO flag and echo the command that has been send to
the kernel.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add nft_ctx_output_{get,set}_json() to nft_ctx_output_{get,set}_flags
Pablo Neira Ayuso [Sat, 27 Oct 2018 10:02:02 +0000 (12:02 +0200)] 
src: add nft_ctx_output_{get,set}_json() to nft_ctx_output_{get,set}_flags

Add NFT_CTX_OUTPUT_JSON flag and display output in json format.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add nft_ctx_output_{get,set}_handle() to nft_ctx_output_{get,set}_flags
Pablo Neira Ayuso [Sat, 27 Oct 2018 09:55:00 +0000 (11:55 +0200)] 
src: add nft_ctx_output_{get,set}_handle() to nft_ctx_output_{get,set}_flags

Add NFT_CTX_OUTPUT_HANDLE flag and print handle that uniquely identify
objects from new output flags interface.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add nft_ctx_output_{get,set}_stateless() to nft_ctx_output_{get,flags}_flags
Pablo Neira Ayuso [Sat, 27 Oct 2018 09:44:09 +0000 (11:44 +0200)] 
src: add nft_ctx_output_{get,set}_stateless() to nft_ctx_output_{get,flags}_flags

Add NFT_CTX_OUTPUT_STATELESS flag and enable stateless printing from new
output flags interface.

This patch adds nft_output_save_flags() and nft_output_restore_flags()
to temporarily disable stateful printing

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: Revert --literal, add -S/--service
Pablo Neira Ayuso [Wed, 24 Oct 2018 15:37:47 +0000 (17:37 +0200)] 
src: Revert --literal, add -S/--service

This is a partial revert of b0f6a45b25dd1 ("src: add --literal option")
which was added during the development cycle before 0.9.1 is released.

After looking at patch: https://patchwork.ozlabs.org/patch/969864/ that
allows to print priority, uid, gid and protocols as numerics, I decided
to revisit this to provide individual options to turn on literal
printing.

What I'm proposing is to provide a good default for everyone, and
provide options to turn on literal/numeric printing.

This patch adds nft_ctx_output_{set,get}_flags() and define two flags to
enable reverse DNS lookups and to print ports as service names.

This patch introduces -S/--services, to print service names as per
/etc/services.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft.8: Document log level audit
Phil Sutter [Sat, 27 Oct 2018 10:15:50 +0000 (12:15 +0200)] 
nft.8: Document log level audit

Since this pseudo log level fundamentally changes behaviour of log
statement, dedicate this mode a separate paragraph.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoJSON: Add support for echo option
Phil Sutter [Fri, 26 Oct 2018 13:01:38 +0000 (15:01 +0200)] 
JSON: Add support for echo option

The basic principle is to not return a JSON object freshly created from
netlink responses, but just update the existing user-provided one to
make sure callers get back exactly what they expect.

To achieve that, keep the parsed JSON object around in a global variable
('cur_root') and provide a custom callback to insert handles into it
from received netlink messages. The tricky bit here is updating rules
since unique identification is problematic. Therefore drop possibly
present handles from input and later assume updates are received in
order so the first rule not having a handle set is the right one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests/shell: Add testcase for cache update problems
Phil Sutter [Fri, 26 Oct 2018 09:42:05 +0000 (11:42 +0200)] 
tests/shell: Add testcase for cache update problems

The first test in there shows how the current cache update strategy
causes trouble. The second test shows that proposed "locking" of cache
when local entries are added is flawed, too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoevaluate: stmt_evaluate_map() needs right hand side evaluation too
Pablo Neira Ayuso [Thu, 25 Oct 2018 17:35:10 +0000 (19:35 +0200)] 
evaluate: stmt_evaluate_map() needs right hand side evaluation too

The data side of the mapping that is dynamically generated needs to be
evaluated as well.

Fixes: 0e90798e9812 ("src: simplify map statement")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoevaluate: do not pass EXPR_SET_ELEM to stmt_evaluate_arg() for set/map evaluation
Pablo Neira Ayuso [Thu, 25 Oct 2018 17:18:28 +0000 (19:18 +0200)] 
evaluate: do not pass EXPR_SET_ELEM to stmt_evaluate_arg() for set/map evaluation

Otherwise, we cannot validate mismatching length size when combining raw
expressions with sets and maps, eg.

 # cat /tmp/test
 table ip nftlb {
       map persistency {
               type ipv4_addr : mark
               size 65535
               timeout 1h
       }

       chain pre {
               type filter hook prerouting priority filter; policy accept;
               ip protocol { tcp, udp } update @persistency { @th,0,16 : numgen inc mod 2 offset 100 }
       }
 }

 # nft -f /tmp/test
 /tmp/test:10:68-75: Error: datatype mismatch: expected IPv4 address, expression has type integer with length 16
                    ip protocol { tcp, udp } update @persistency { @th,0,16 : numgen inc mod 2 offset 100 }
                                             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass inner expression instead, instead of the wrapping set element
expression.

Fixes: 0e90798e9812 ("src: simplify map statement")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Work around segfault when encountering xt stmt
Phil Sutter [Wed, 24 Oct 2018 19:14:37 +0000 (21:14 +0200)] 
json: Work around segfault when encountering xt stmt

When trying to convert an xt stmt into JSON, print() callback was
called. Though the code in src/xt.c does not respect output_fp,
therefore buffer wasn't filled as expected making libjansson to puke:

| # nft -j list ruleset
| warning: stmt ops xt have no json callback
| nft: json.c:169: stmt_print_json: Assertion `__out' failed.
| Aborted (core dumped)

Avoid this by detecting xt stmt ops and returning a stub.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonetlink: remove netlink_batch_send()
Pablo Neira Ayuso [Wed, 24 Oct 2018 16:47:15 +0000 (18:47 +0200)] 
netlink: remove netlink_batch_send()

Replace it by direct call to mnl_batch_talk().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: remove alloc_nftnl_flowtable()
Pablo Neira Ayuso [Wed, 24 Oct 2018 16:37:48 +0000 (18:37 +0200)] 
mnl: remove alloc_nftnl_flowtable()

We can remove alloc_nftnl_flowtable() and consolidate infrastructure in
the src/mnl.c file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: Improve error checking in mnl_nft_event_listener()
Phil Sutter [Wed, 24 Oct 2018 16:05:55 +0000 (18:05 +0200)] 
mnl: Improve error checking in mnl_nft_event_listener()

When trying to adjust receive buffer size, the second call to
setsockopt() was not error-checked.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Fix for recent changes to context structs
Phil Sutter [Wed, 24 Oct 2018 10:35:04 +0000 (12:35 +0200)] 
json: Fix for recent changes to context structs

Commits introducing nft_ctx pointer to netlink and eval contexts did not
update JSON code accordingly.

Fixes: 00f777bfc414a ("src: pass struct nft_ctx through struct eval_ctx")
Fixes: 2dc07bcd7eaa5 ("src: pass struct nft_ctx through struct netlink_ctx")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Fix osf ttl support
Phil Sutter [Wed, 24 Oct 2018 10:35:03 +0000 (12:35 +0200)] 
json: Fix osf ttl support

Having to use numerical values for ttl property in JSON is not
practical as these values are arbitrary and meaningful only in
netfilter. Instead align JSON output/input with standard API, accepting
names for TTL matching strategy.

Also add missing documentation in libnftables-json man page and fix JSON
equivalent in tests/py.

Fixes: 03eafe098d5ee ("osf: add ttl option support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoinclude: Fix comment for struct eval_ctx
Phil Sutter [Wed, 24 Oct 2018 10:35:02 +0000 (12:35 +0200)] 
include: Fix comment for struct eval_ctx

Previous change to that struct missed to update the comment.

Fixes: 00f777bfc414a ("src: pass struct nft_ctx through struct eval_ctx")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: use either name or handle to refer to objects
Pablo Neira Ayuso [Tue, 23 Oct 2018 17:07:23 +0000 (19:07 +0200)] 
mnl: use either name or handle to refer to objects

We can only specify either name or handle to refer to objects.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: remove alloc_nftnl_obj()
Pablo Neira Ayuso [Tue, 23 Oct 2018 16:59:07 +0000 (18:59 +0200)] 
mnl: remove alloc_nftnl_obj()

We can remove alloc_nftnl_obj() and consolidate infrastructure in the
src/mnl.c file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: move socket open and reopen to mnl.c
Pablo Neira Ayuso [Tue, 23 Oct 2018 16:24:31 +0000 (18:24 +0200)] 
src: move socket open and reopen to mnl.c

These functions are part of the mnl backend, move them there. Remove
netlink_close_sock(), use direct call to mnl_socket_close().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: osf: add ttl option to man page
Fernando Fernandez Mancera [Mon, 22 Oct 2018 20:46:19 +0000 (22:46 +0200)] 
doc: osf: add ttl option to man page

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoosf: add ttl option support
Fernando Fernandez Mancera [Tue, 23 Oct 2018 15:06:22 +0000 (17:06 +0200)] 
osf: add ttl option support

Add support for ttl option in "osf" expression. Example:

table ip foo {
chain bar {
type filter hook input priority filter; policy accept;
osf ttl skip name "Linux"
}
}

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonetlink: reset mnl_socket field in struct nft_ctx on EINTR
Pablo Neira Ayuso [Mon, 22 Oct 2018 19:20:44 +0000 (21:20 +0200)] 
netlink: reset mnl_socket field in struct nft_ctx on EINTR

Otherwise we keep using the old netlink socket if we hit EINTR.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: pass struct nft_ctx through struct netlink_ctx
Pablo Neira Ayuso [Mon, 22 Oct 2018 19:18:19 +0000 (21:18 +0200)] 
src: pass struct nft_ctx through struct netlink_ctx

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: pass struct nft_ctx through struct eval_ctx
Pablo Neira Ayuso [Mon, 22 Oct 2018 10:38:35 +0000 (12:38 +0200)] 
src: pass struct nft_ctx through struct eval_ctx

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: shell: Extend get element test
Phil Sutter [Mon, 22 Oct 2018 13:45:09 +0000 (15:45 +0200)] 
tests: shell: Extend get element test

Despite the recent fixes, the test still fails. While trying to address
the remaining issues, I found more potentially problematic inputs so
extend the test by those.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: Document ct timeout support
Harsha Sharma [Thu, 18 Oct 2018 18:12:20 +0000 (23:42 +0530)] 
doc: Document ct timeout support

Add documentation for creating ct timeout objects and assigning timeout
policies via rules.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoevaluate: bogus bail out with raw expression from dynamic sets
Pablo Neira Ayuso [Wed, 17 Oct 2018 10:31:22 +0000 (12:31 +0200)] 
evaluate: bogus bail out with raw expression from dynamic sets

The following ruleset that uses raw expressions:

 table ip nftlb {
        map persistency {
                type inet_service : mark
                size 65535
                timeout 1h
                elements = { 53 expires 59m55s864ms : 0x00000064, 80 expires 59m58s924ms : 0x00000065, 443 expires 59m56s220ms : 0x00000064 }
        }

        chain pre {
                type filter hook prerouting priority filter; policy accept;
                ip protocol { tcp, udp } update @persistencia { @th,0,16 : numgen inc mod 2 offset 100 }
        }
 }

bogusly bails out with:

 /tmp/test:9:57-64: Error: datatype mismatch: expected internet network service, expression has type integer
         ip protocol { tcp, udp } update @persistencia { @th,0,16 : numgen inc mod 2 offset 100 }
                                  ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix the problem by evaluating expression basetype and length in this case.

Reported-by: Laura Garcia <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>