]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
7 years agosrc: add --literal option
Pablo Neira Ayuso [Tue, 3 Jul 2018 15:24:05 +0000 (17:24 +0200)] 
src: add --literal option

Default not to print the service name as we discussed during the NFWS.

 # nft list ruleset
 table ip x {
        chain y {
                tcp dport 22
                ip saddr 1.1.1.1
        }
 }

 # nft -l list ruleset
 table ip x {
        chain y {
                tcp dport ssh
                ip saddr 1.1.1.1
        }
 }

 # nft -ll list ruleset
 table ip x {
        chain y {
                tcp dport 22
                ip saddr 1dot1dot1dot1.cloudflare-dns.com
        }
 }

Then, -ll displays FQDN. just like the (now deprecated) --ip2name (-N)
option.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: limit: don't print default burst value
Florian Westphal [Wed, 4 Jul 2018 13:10:12 +0000 (15:10 +0200)] 
rule: limit: don't print default burst value

limit http-traffic { rate 1/second } gets printed as
limit http-traffic { rate 1/second burst 5 packets }

caused tests/shell/run-tests.sh tests/shell/testcases/sets/0026named_limit_0

to return 'DUMP FAIL'.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Add socket expression to man page
Máté Eckl [Tue, 3 Jul 2018 14:20:10 +0000 (16:20 +0200)] 
doc: Add socket expression to man page

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
7 years agonftables: tests: shell: Replace "%" with "#" or "$"
Arushi Singhal [Sun, 1 Jul 2018 06:06:09 +0000 (11:36 +0530)] 
nftables: tests: shell: Replace "%" with "#" or "$"

Shell prompt ends with:
"%", indicates a C shell.
"$", indicates shell that's compatible with the Bash.
"#", indicates shell is running as the system's root.
So, "%" is replaced with "$" or "#".

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonetlink_delinearize: Refactor meta_may_dependency_kill()
Phil Sutter [Thu, 21 Jun 2018 12:01:13 +0000 (14:01 +0200)] 
netlink_delinearize: Refactor meta_may_dependency_kill()

The original intent was to fix a bug: The following rule in inet table:

| meta nfproto ipv4 icmpv6 type echo-reply

Was added correctly but when printing the meta match was falsely
removed. The fix is to deny dependency killing if RHS family of nfproto
match doesn't match RHS family of l4proto match. Adding this to the
already large conditional led to even more unreadable code, therefore
this patch tries to clean that up (and also removes the partial code
duplication.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: trace: fix policy printing
Florian Westphal [Wed, 20 Jun 2018 21:06:04 +0000 (23:06 +0200)] 
src: trace: fix policy printing

policy type is erronously handled via verdict, this is wrong.
It is a different event type and needs to be handled as such.

before:
trace id 42b54e71 inet filter input packet: iif "lo" ip saddr 127.0.0.1 ..
trace id 42b54e71 inet filter input rule ip protocol icmp nftrace set 1 (verdict continue)
trace id 42b54e71 inet filter input verdict continue
trace id 42b54e71 inet filter input

after:
trace id 9f40c5c7 inet filter input packet: iif "lo" ip saddr 127.0.0.1 ..
trace id 9f40c5c7 inet filter input rule ip protocol icmp nftrace set 1 (verdict continue)
trace id 9f40c5c7 inet filter input verdict continue
trace id 9f40c5c7 inet filter input policy drop

Reported-by: vtol@gmx.net
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests/py: fix import when run from other directory
Eric Leblond [Thu, 21 Jun 2018 14:47:47 +0000 (16:47 +0200)] 
tests/py: fix import when run from other directory

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: minor cleaning
Eric Leblond [Tue, 19 Jun 2018 21:46:56 +0000 (23:46 +0200)] 
tests/py: minor cleaning

Move import and use explicit parameter in object creation.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: fix make distcheck
Eric Leblond [Tue, 19 Jun 2018 21:46:55 +0000 (23:46 +0200)] 
doc: fix make distcheck

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agopython: set license and author in nftables.py
Eric Leblond [Tue, 19 Jun 2018 21:46:54 +0000 (23:46 +0200)] 
python: set license and author in nftables.py

It will be distributed separately so this worth setting things
correctly.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agopython: installation of binding via make install
Eric Leblond [Tue, 19 Jun 2018 21:46:53 +0000 (23:46 +0200)] 
python: installation of binding via make install

setup.py is used to build and install the python binding. Call
to setup.py are done in Makefile to proceed to build and
installation.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoconfigure.ac: docbook2man invalid syntax error
Eric Leblond [Tue, 19 Jun 2018 21:46:52 +0000 (23:46 +0200)] 
configure.ac: docbook2man invalid syntax error

docbook2man can not be used with the same option so let's remove
it from the alternative. Fedora and debian seems to be fine with
that.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoconfigure.ac: remove useless braces in messages
Eric Leblond [Tue, 19 Jun 2018 21:46:51 +0000 (23:46 +0200)] 
configure.ac: remove useless braces in messages

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoconfigure.ac: better message when a2x is missing
Eric Leblond [Tue, 19 Jun 2018 21:46:50 +0000 (23:46 +0200)] 
configure.ac: better message when a2x is missing

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonftables: Fix typos/Grammatical Errors
Arushi Singhal [Tue, 19 Jun 2018 03:04:51 +0000 (08:34 +0530)] 
nftables: Fix typos/Grammatical Errors

typos/Grammatical errors are corrected.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Acked-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoMakefile: Introduce Make_global.am
Phil Sutter [Mon, 18 Jun 2018 08:43:37 +0000 (10:43 +0200)] 
Makefile: Introduce Make_global.am

Analogous to libnftnl's build system, define libnftables interface
version in a variable in Make_global.am.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: libnftables-json: Review asciidoc syntax
Phil Sutter [Mon, 18 Jun 2018 08:23:23 +0000 (10:23 +0200)] 
doc: libnftables-json: Review asciidoc syntax

This changes asciidoc markup according to a few best practices
recommended in [1] and a quick review of html output:

* Use atx-style headings everywhere apart from the document title.
  This requires to explicitly disable compat-mode after the latter.

* Use only the minimum number of dashes for listings.

* Enclose verses with empty lines in a verse block instead of having
  multiple verses for it.

* Indent continued lines in synopsis for added readability.

[1] https://asciidoctor.org/docs/asciidoc-recommended-practices/

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoscanner: Do not convert tabs into spaces
Phil Sutter [Mon, 18 Jun 2018 08:23:22 +0000 (10:23 +0200)] 
scanner: Do not convert tabs into spaces

Commit 2f86dd5a43baf ("erec: Review erec_print()") changed erec_print()
function to expect tabs in input by replacing the whitespace character
in the marker line at the same offset with a tab character so that the
marker aligns with the offending part of input.

The need for that came from JSON input not having its tabs converted to
spaces, which erec_print() didn't expect.

Above change though has a shortcoming: When reading standard syntax
input from a file, Flex code converts tabs into spaces. Location
information is taken from this converted input, but when printing an
error message, the offending input line is read from the input file
directly (which still contains tabs).

The solution is to simply drop said tab conversion from scanner.l.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agolibnftables: Simplify nft_run_cmd_from_buffer footprint
Phil Sutter [Mon, 18 Jun 2018 08:11:46 +0000 (10:11 +0200)] 
libnftables: Simplify nft_run_cmd_from_buffer footprint

With libnftables documentation being upstream and one confirmed external
user (nftlb), time to break the API!

First of all, the command buffer passed to nft_run_cmd_from_buffer may
(and should) be const. One should consider it a bug if that function
ever changed it's content.

On the other hand, there is no point in passing the buffer's length as
separate argument: NULL bytes are not expected to occur in the input, so
it is safe to rely upon strlen(). Also, the actual parsers don't require
a buffer length passed to them, either. The only use-case for it is when
reallocating the buffer to append a final newline character, there
strlen() is perfectly sufficient.

Suggested-by: Harald Welte <laforge@gnumonks.org>
Cc: Laura Garcia Liebana <nevola@gmail.com>
Cc: Eric Leblond <eric@regit.org>
Cc: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agolibnftables: Fix exit_cookie()
Phil Sutter [Wed, 13 Jun 2018 17:18:24 +0000 (19:18 +0200)] 
libnftables: Fix exit_cookie()

The output and error buffer feature depends on cookie->orig_fp to
indicate the current status of buffering: If it is set, a prior call to
init_cookie() is assumed. Though exit_cookie() missed to reset that
pointer to NULL. causing weird behaviour in applications if they do:

| nft = nft_ctx_new(0);
| nft_ctx_buffer_output(nft);
| nft_ctx_unbuffer_output(nft);
| nft_ctx_buffer_output(nft);

While being at it, apply the same fix to error path in init_cookie() as
well.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Fix typo in Makefile.am
Phil Sutter [Sat, 16 Jun 2018 13:51:17 +0000 (15:51 +0200)] 
doc: Fix typo in Makefile.am

Previous patch adding libnftables man page missed a backslash.

Fixes: 3c57ff87b1b2b ("doc: Add libnftables man page")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: Add libnftables man page
Phil Sutter [Thu, 14 Jun 2018 12:02:11 +0000 (14:02 +0200)] 
doc: Add libnftables man page

For now, use a single man page to describe all the functions exported by
libnftables.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add dynamic flag and use it
Pablo Neira Ayuso [Mon, 11 Jun 2018 15:19:20 +0000 (17:19 +0200)] 
src: add dynamic flag and use it

We need to signal the kernel to use a set backend that supports dynamic
updates.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodatatype: add stolen verdict
Florian Westphal [Tue, 12 Jun 2018 16:39:13 +0000 (18:39 +0200)] 
datatype: add stolen verdict

using fwd statement causes crash when using nft trace:

 trace id ddbbaae2 netdev vpn ingress_out packet: iif "enp2s0" ether saddr 78:54:00:29:bb:aa ether daddr 52:54:00:01:53:9f ip saddr 85.14.236.41 ip daddr 17.25.63.98 ip dscp cs0 ip ecn not-ect ip ttl 64 ip id 49036 ip length 84 icmp type echo-reply icmp code 0 icmp id 16947 icmp sequence 4
 trace id ddbbaae2 netdev vpn ingress_out rule ip saddr 85.14.236.41 nftrace set 1 (verdict continue)
 trace id ddbbaae2 netdev vpn ingress_out rule ip saddr 85.14.236.41 ether saddr set aa:bb:00:18:cc:dd ether daddr set 00:00:5e:00:00:11 fwd to "enp1s0"
 BUG: invalid verdict value 2
 nft: datatype.c:282: verdict_type_print: Assertion `0' failed.

ADd stolen verdict (2) and remove the BUG statement.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1261
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: Add JSON schema documentation
Phil Sutter [Fri, 8 Jun 2018 15:27:19 +0000 (17:27 +0200)] 
doc: Add JSON schema documentation

The document is written as man page in asciidoc which means this adds
another dependency to the build system. Though since the (long-term)
plan is to replace the docbook-based nft man page with an asciidoc one
anyway, we might ultimately get rid of docbook dependency in exchange.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Support latest enhancements of fwd statement
Phil Sutter [Fri, 8 Jun 2018 15:27:18 +0000 (17:27 +0200)] 
JSON: Support latest enhancements of fwd statement

JSON equivalent of fwd statement was too primitive to support the added
address and family parameters, so make its value an object and accept
the device expression as value of a "dev" property in there. Then add
optional "addr" and "family" properties to it.

While being at it, add a testcase to make sure the extended syntax works
right.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Add support for connlimit statement
Phil Sutter [Fri, 8 Jun 2018 15:27:17 +0000 (17:27 +0200)] 
JSON: Add support for connlimit statement

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Add support for socket expression
Phil Sutter [Fri, 8 Jun 2018 15:27:16 +0000 (17:27 +0200)] 
JSON: Add support for socket expression

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Don't print burst if equal to 5
Phil Sutter [Fri, 8 Jun 2018 15:27:15 +0000 (17:27 +0200)] 
JSON: Don't print burst if equal to 5

Analogous to commit 3dddef928d80d ("statement: don't print burst if
equals 5"), don't print the default burst value.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: Fix JSON for flowtable tests
Phil Sutter [Fri, 8 Jun 2018 15:27:14 +0000 (17:27 +0200)] 
tests/py: Fix JSON for flowtable tests

Changing the reference lines is not enough, the actual JSON has to be
adjusted as well. Since after the changes output for ip/flowtable.t is
now symmetric, ip/flowtable.t.json.output can be removed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Call verdict maps 'vmap' in JSON as well
Phil Sutter [Fri, 8 Jun 2018 15:27:13 +0000 (17:27 +0200)] 
JSON: Call verdict maps 'vmap' in JSON as well

This way JSON format is more consistent with the standard one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: build: cover --with-json too
Pablo Neira Ayuso [Sun, 10 Jun 2018 18:39:31 +0000 (20:39 +0200)] 
tests: build: cover --with-json too

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: timeout: fix output for HZ=250 v0.9.0
Florian Westphal [Fri, 8 Jun 2018 12:46:00 +0000 (14:46 +0200)] 
tests: shell: timeout: fix output for HZ=250

4s5ms gets rounded to 4s8ms with HZ=250, which is a common setting.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: shell: add quotes when using <<<-style here document
Florian Westphal [Fri, 8 Jun 2018 12:41:08 +0000 (14:41 +0200)] 
tests: shell: add quotes when using <<<-style here document

bash 4.3.30 removes newlines in RULESET when "" are omitted, which
then causes nft -f to complain about invalid syntax.

As a result, all test cases that use this here-doc style fail.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agobuild: missing headers file in Makefile.am
Florian Westphal [Fri, 8 Jun 2018 11:16:07 +0000 (13:16 +0200)] 
build: missing headers file in Makefile.am

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agobuild: Bump version to v0.9.0
Florian Westphal [Fri, 8 Jun 2018 11:00:30 +0000 (13:00 +0200)] 
build: Bump version to v0.9.0

Update dependency on libnftnl.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agobuild: update release name
Pablo Neira Ayuso [Fri, 8 Jun 2018 10:56:03 +0000 (12:56 +0200)] 
build: update release name

Dedicated to Al Capp cartoonist:

https://en.wikipedia.org/wiki/Fearless_Fosdick

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: use 100ms for set timeout
Florian Westphal [Thu, 7 Jun 2018 16:31:59 +0000 (18:31 +0200)] 
tests: use 100ms for set timeout

Pablo reports set test fails with HZ=250, as it lists "324ms" instead
of "321".  This is because of rounding errors that occur when converting
from user-side millisecond scale to kernel-internal jiffies one.

use 100ms for now to avoid this error.
Alternatives would be to store use-provided value in kernel or to avoid
the conversions; this would require a change to make timeout independent from
jiffies on kernel side.

Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: netlink_delinarize: don't stop when encountering unsupported expression
Florian Westphal [Wed, 23 May 2018 21:30:24 +0000 (23:30 +0200)] 
src: netlink_delinarize: don't stop when encountering unsupported expression

The error message is still shown, but try to make sense of further
expressions (if any).

I tried to replace the expression by a textual representation.

Two variants I tested are:
1. append as comment:
   ip saddr 127.0.0.2 drop comment "unknown expression 'foo'"
   This allows nft -f, but it adds/alters a comment.

2. substitute in-place (i.e., add a constant expression
   with the error message instead of 'unkown' message:

   unknown expression "foo" ip saddr 127.0.0.2 drop

This won't allow 'nft -f' however.
I'm not sure this is a problem, in any case we lose information
if we can't find an expression (e.g. added by newer version).

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: shell: add crash reproducer
Florian Westphal [Tue, 29 May 2018 14:16:44 +0000 (16:16 +0200)] 
tests: shell: add crash reproducer

Two reports point to a crash in nft when 'flush' is provided
on existing ruleset.  In that case, nft will crash with a null-ptr
dereference.

"evaluate: do not inconditionally update cache from flush command"
causes the commit to fail due to a cache inconsistency, we then trip
over NULL location->indesc.  Cause of 2nd bug not known yet, not sure
how to fix cache issue either, so only adding reproducer so this can be
fixed later.

Without erec bug, the (errnoeous) error message would be
Could not process rule: File exists

Reported-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Reported-by: Timothy Redaelli <tredaelli@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: do not reset generation ID on ruleset flush
Pablo Neira Ayuso [Thu, 7 Jun 2018 11:35:52 +0000 (13:35 +0200)] 
src: do not reset generation ID on ruleset flush

If 'flush ruleset' command is done, release the cache but still keep the
generation ID around. Hence, follow up calls to cache_update() will
assume that cache is updated and will not perform a netlink dump.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotest: py: Add test cases for socket matching
Máté Eckl [Mon, 4 Jun 2018 07:36:32 +0000 (09:36 +0200)] 
test: py: Add test cases for socket matching

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoinclude: update linux/netfilter_ipv4.h
Máté Eckl [Mon, 4 Jun 2018 09:58:17 +0000 (11:58 +0200)] 
include: update linux/netfilter_ipv4.h

Update file from <kerneldir>/usr/include/linux/netfilter_ipv4.h.

Reasons:
 - New values have been introduced in nf_ip_hook_priorities.
 - include limits.h was missing

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Introduce socket matching
Máté Eckl [Thu, 31 May 2018 18:06:16 +0000 (20:06 +0200)] 
src: Introduce socket matching

For now it can only match sockets with IP(V6)_TRANSPARENT socket option
set. Example:

 table inet sockin {
chain sockchain {
type filter hook prerouting priority -150; policy accept;
socket transparent 1 mark set 0x00000001 nftrace set 1 counter packets 9 bytes 504 accept

}
 }

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: extend fwd statement to support address and family
Pablo Neira Ayuso [Thu, 9 Nov 2017 02:42:55 +0000 (03:42 +0100)] 
expr: extend fwd statement to support address and family

Allow to forward packets through to explicit destination and interface.

  nft add rule netdev x y fwd ip to 192.168.2.200 device eth0

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: connlimit support
Pablo Neira Ayuso [Thu, 31 May 2018 16:08:06 +0000 (18:08 +0200)] 
src: connlimit support

This patch adds support for the new connlimit stateful expression, that
provides a mapping with the connlimit iptables extension through meters.
eg.

  nft add rule filter input tcp dport 22 \
meter test { ip saddr ct count over 2 } counter reject

This limits the maximum amount incoming of SSH connections per source
address up to 2 simultaneous connections.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonat: Eliminate misuse of AF_*
Máté Eckl [Wed, 6 Jun 2018 09:13:35 +0000 (11:13 +0200)] 
nat: Eliminate misuse of AF_*

Although the value of AF_INET and NFPROTO_IPV4 is the same, the use of
AF_INET was misleading when checking the proto family.
Same with AF_INET6.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoevaluate: explicitly deny concatenated types in interval sets
Phil Sutter [Wed, 6 Jun 2018 11:21:49 +0000 (13:21 +0200)] 
evaluate: explicitly deny concatenated types in interval sets

Previously, this triggered a program abort:

| # nft add table ip t
| # nft add set ip t my_set '{ type ipv4_addr . inet_service ; flags interval ; }'
| # nft add element ip t my_set '{10.0.0.1 . tcp }'
| BUG: invalid range expression type concat
| nft: expression.c:1085: range_expr_value_low: Assertion `0' failed.

With this patch in place, the 'add set' command above gives an error
message:

| # nft add set ip t my_set3 '{ type ipv4_addr . inet_service ; flags interval ; }'
| Error: concatenated types not supported in interval sets
| add set ip t my_set3 { type ipv4_addr . inet_service ; flags interval ; }
|                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft.8: Fix reject statement documentation
Phil Sutter [Wed, 6 Jun 2018 08:56:26 +0000 (10:56 +0200)] 
nft.8: Fix reject statement documentation

First of all, 'with icmp6' is invalid, expected is 'with icmpv6'. In
addition to that, parameter 'type' expects an icmp*_code type, not
icmp*_type. The respective table column was already correct, but in
synopsis it was wrong.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoconfigure.ac: fix typo in docbook2x error message
Fernando Fernandez Mancera [Tue, 5 Jun 2018 13:15:45 +0000 (15:15 +0200)] 
configure.ac: fix typo in docbook2x error message

The correct name is "docbook2x-man" not "docbookx2-man".

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agolog: Add support for audit logging
Phil Sutter [Fri, 1 Jun 2018 15:15:07 +0000 (17:15 +0200)] 
log: Add support for audit logging

This is implemented via a pseudo log level. The kernel ignores any other
parameter, so reject those at evaluation stage. Audit logging is
therefore simply a matter of:

| log level audit

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: ip6/flowtable.t: Add missing JSON expected output
Phil Sutter [Fri, 1 Jun 2018 15:32:12 +0000 (17:32 +0200)] 
tests/py: ip6/flowtable.t: Add missing JSON expected output

The output differs from input in added size property.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Review large number parsing/printing
Phil Sutter [Fri, 1 Jun 2018 15:32:11 +0000 (17:32 +0200)] 
JSON: Review large number parsing/printing

When parsing large (uint64_t) values, capital 'I' has to be used in
format string. While being at it, make sure JSON output code handles
those variables correctly, too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Fix replace command parser
Phil Sutter [Fri, 1 Jun 2018 15:32:10 +0000 (17:32 +0200)] 
JSON: Fix replace command parser

This was completely broken. Yet another indicator the JSON API part of
testsuite is insufficient.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Fix add rule with index
Phil Sutter [Fri, 1 Jun 2018 15:32:09 +0000 (17:32 +0200)] 
JSON: Fix add rule with index

This was missed by commit fb557b5546084 ("JSON: Sort out rule position
and handles in general"): When adding a rule, the parser would still
expect "pos" property instead of "index".

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Simplify verdict statement parsing
Phil Sutter [Fri, 1 Jun 2018 15:32:08 +0000 (17:32 +0200)] 
JSON: Simplify verdict statement parsing

Reuse verdict expression parsing routine. Since the statement simply
wraps an expression, this change is an obvious one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Simplify wildcard expression
Phil Sutter [Fri, 1 Jun 2018 15:32:07 +0000 (17:32 +0200)] 
JSON: Simplify wildcard expression

Instead of dedicating an object for it ('{ "*": null }'), just use a
string consisting of an asterisk as sole character.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser_bison: Merge wildcard_rhs_expr and wildcard_stmt_expr
Phil Sutter [Fri, 1 Jun 2018 15:32:06 +0000 (17:32 +0200)] 
parser_bison: Merge wildcard_rhs_expr and wildcard_stmt_expr

The two are absolutely identical, just referenced at different places.
Since there is no need for the distinction, just merge them into one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: Add missing JSON equivalent for rule in inet/tcp.t
Phil Sutter [Mon, 28 May 2018 16:51:09 +0000 (18:51 +0200)] 
tests/py: Add missing JSON equivalent for rule in inet/tcp.t

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: Add missing JSON equivalent for inet/sets.t
Phil Sutter [Mon, 28 May 2018 16:51:08 +0000 (18:51 +0200)] 
tests/py: Add missing JSON equivalent for inet/sets.t

This adds the missing JSON variant for the two rules which are supposed
to work.

Fixes: 2efbdf7b8fcf7 ("tests: py: allow to specify sets with a timeout")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: Adjust JSON for changes in any/ct.t
Phil Sutter [Mon, 28 May 2018 16:51:07 +0000 (18:51 +0200)] 
tests/py: Adjust JSON for changes in any/ct.t

Commit 71624f25f22b1 ("tests: py: add expires tests with different time
bases") removed two testcases and added five other ones, adjust JSON
equivalent and recorded output to those changes.

Fixes: 71624f25f22b1 ("tests: py: add expires tests with different time bases")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Simplify immediate value parsing
Phil Sutter [Mon, 28 May 2018 16:51:06 +0000 (18:51 +0200)] 
JSON: Simplify immediate value parsing

Since an explicit "immediate" expression doesn't exist in JSON (the
values are represented as plain JSON string/integer/boolean types),
there is no need for json_parse_immediate_expr() to comply to the common
expression parser parameter format.

Apart from that:

* Drop CTX_F_RHS checks - caller assures sane context already.
* Improve error message a bit for denied JSON types.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Fix parsing of meter statement key
Phil Sutter [Mon, 28 May 2018 16:51:05 +0000 (18:51 +0200)] 
JSON: Fix parsing of meter statement key

The key must be a set elem expression, but if a "regular" expression was
provided (which should be commonly accepted in case no set elem specific
properties are required), the resulting object tree crashed libnftables.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Improve prefix expression parsing error message a bit
Phil Sutter [Mon, 28 May 2018 16:51:04 +0000 (18:51 +0200)] 
JSON: Improve prefix expression parsing error message a bit

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Simplify tcp option expression parsing a bit
Phil Sutter [Mon, 28 May 2018 16:51:03 +0000 (18:51 +0200)] 
JSON: Simplify tcp option expression parsing a bit

When parsing the optional "field" property, use return code of
json_unpack() directly to check if it was present or not.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Fix parsing and printing of limit objects
Phil Sutter [Mon, 28 May 2018 16:51:02 +0000 (18:51 +0200)] 
JSON: Fix parsing and printing of limit objects

Fix parsing and printing of named limit objects by aligning the code
with parser/printer of anonymous ones.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Review set elem expressions
Phil Sutter [Mon, 28 May 2018 16:51:01 +0000 (18:51 +0200)] 
JSON: Review set elem expressions

* There is no need to prefix element-specific properties with 'elem_',
  they can't conflict.
* In json_parse_set_stmt(), searching for above properties is pointless
  since that's already done by called function.
* Fix potential NULL-pointer deref in json_parse_set_elem_expr_stmt():
  json_parse_flagged_expr() may return NULL.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Review meter statement support
Phil Sutter [Mon, 28 May 2018 16:51:00 +0000 (18:51 +0200)] 
JSON: Review meter statement support

Meter name being optional seems to come from old flow statement, so
don't support this. Also add size support as was recently added to
standard syntax.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Sort out rule position and handles in general
Phil Sutter [Mon, 28 May 2018 16:50:59 +0000 (18:50 +0200)] 
JSON: Sort out rule position and handles in general

First of all, don't print the position property when listing rules. This
was there only because libnftnl JSON output has it too, but since the
preferred way to *add* a rule at some location is via 'handle' keyword,
keeping "position" in output would be non-intuitive. Changing "position"
property name to "handle" instead is also a no-go since that would clash
with the real rule handle.

Secondly, turn all handle output on regardless of octx->handle setting.
For a programmatic API like JSON, this should be fine.

Thirdly, fix rule locations when parsing JSON: Respect "handle" property
for CMD_INSERT and CMD_ADD and ignore "pos" at all (actually even a
typo, should have read "position"). Also support "index" property
recently added to standard syntax.

Finally, adjust nft-test.py for the above changes: There is no
"position" property to drop from rule output, and "handle" property will
always be present.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Disallow non-array concat expression values
Phil Sutter [Mon, 28 May 2018 16:50:58 +0000 (18:50 +0200)] 
JSON: Disallow non-array concat expression values

Concat expressions with just a single element don't make sense, so
there's no point in supporting a shorter syntax for this.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Use "type" for CT helper object
Phil Sutter [Mon, 28 May 2018 16:50:57 +0000 (18:50 +0200)] 
JSON: Use "type" for CT helper object

Property name "helper" was a bit unclear, "type" is better.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoobjref: Use "ct helper" for NFT_OBJECT_CT_HELPER
Phil Sutter [Mon, 28 May 2018 16:50:56 +0000 (18:50 +0200)] 
objref: Use "ct helper" for NFT_OBJECT_CT_HELPER

Change name of NFT_OBJECT_CT_HELPER in objref_type table to "ct helper"
for consistency. Note that this is not used in regular nft output since
objref_stmt_print() treats this object type separately.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agostatement: old kernels are allowing burst zero, don't print it
Pablo Neira Ayuso [Wed, 30 May 2018 10:40:32 +0000 (12:40 +0200)] 
statement: old kernels are allowing burst zero, don't print it

Don't print limit burst zero which was the default value in old kernels,
this is not allowed in more recent kernels that now operate like
iptables xt_limit which is what users are expecting.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: remove nft_objref module on cleanup
Pablo Neira Ayuso [Wed, 30 May 2018 10:34:46 +0000 (12:34 +0200)] 
tests: shell: remove nft_objref module on cleanup

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agostatement: don't print burst if equals 5
Pablo Neira Ayuso [Tue, 29 May 2018 11:52:08 +0000 (13:52 +0200)] 
statement: don't print burst if equals 5

This is the default value we use if not specified, don't print it just
like we do in iptables.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agometers: do not set a defaut meter size from userspace
Florian Westphal [Tue, 29 May 2018 11:47:11 +0000 (13:47 +0200)] 
meters: do not set a defaut meter size from userspace

doing this breaks with older kernels as it will pick a set without
and update callback.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoinclude: update nf_tables.h
Máté Eckl [Mon, 28 May 2018 23:17:42 +0000 (01:17 +0200)] 
include: update nf_tables.h

It seems tracing ABI got broken because the header file has been
manually updated.

Joint work with Pablo.

Fixes: 0f8302635ad3 ("src: print 'handle' attribute in tables")
Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: py: fix race in deleting element
Pablo Neira Ayuso [Fri, 25 May 2018 08:43:00 +0000 (10:43 +0200)] 
tests: py: fix race in deleting element

Sometimes we may hit this because script is too slow to remove the
element with timeout from the set.

inet/sets.t: ERROR: line 18: I cannot delete element  dead::beef timeout 1s from the set set2

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosegtree: incorrect handling of comments and timeouts with mapping
Pablo Neira Ayuso [Fri, 25 May 2018 10:30:57 +0000 (12:30 +0200)] 
segtree: incorrect handling of comments and timeouts with mapping

Check if expression is a mapping to do the right handling.

Fixes: 35fedcf540bf ("segtree: missing comments in range and prefix expressions in sets")
Fixes: be90e03dd1fa ("segtree: add timeout for range and prefix expressions in sets")
Reported-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agofix printing of "tcp flags syn" and "tcp flags == syn" expressions
Sabrina Dubroca [Fri, 25 May 2018 13:23:16 +0000 (15:23 +0200)] 
fix printing of "tcp flags syn" and "tcp flags == syn" expressions

Commit 6979625686ec ("relational: Eliminate meta OPs") introduced some
bugs when printing bitmask types.

First, during the post-processing phase of delinearization, the
expression for "tcp flags syn" (PAYLOAD & flag != 0) gets converted to
PAYLOAD == flag, which is not equivalent. This should be
PAYLOAD (IMPL) flag.

Then, during output, the "==" sign from "tcp flags == syn" is dropped,
because the bitmask condition in must_print_eq_op() was removed. Let's
restore it, so that "tcp flags == syn" doesn't get printed as
"tcp flags syn". An extra check for value types is added, so that we
don't start printing "==" for sets such as "tcp flags {syn,ack}"

Finally, add a regression test for this particular case.

Fixes: 6979625686ec ("relational: Eliminate meta OPs")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosegtree: add timeout for range and prefix expressions in sets
Pablo Neira Ayuso [Wed, 16 May 2018 21:03:51 +0000 (23:03 +0200)] 
segtree: add timeout for range and prefix expressions in sets

# nft add table x
 # nft add set x y { type ipv4_addr\; flags timeout,interval\; }
 # nft add element x y { 7.4.4.5-8.8.8.8 comment "good guy" timeout 30s}
 # nft list ruleset
 table ip x {
       set y {
                type ipv4_addr
                flags interval,timeout
                elements = { 7.4.4.5-8.8.8.8 timeout 30s expires 27s956ms comment "good guy" }
        }
 }

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: chain dependency validation with maps
Pablo Neira Ayuso [Wed, 23 May 2018 10:46:05 +0000 (12:46 +0200)] 
tests: shell: chain dependency validation with maps

Just like 4b6fb07de07a ("tests: shell: more chain dependency
validation") but test chain dependency in jumps from maps.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: non-base chain loops
Pablo Neira Ayuso [Wed, 23 May 2018 10:45:06 +0000 (12:45 +0200)] 
tests: shell: non-base chain loops

Detect more non-base chain loops.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: more chain dependency validation
Pablo Neira Ayuso [Wed, 23 May 2018 10:08:02 +0000 (12:08 +0200)] 
tests: shell: more chain dependency validation

More exercising for the chain dependency validation.

Reported-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonft.8: Document limitation of reject statement in bridge family
Phil Sutter [Tue, 15 May 2018 15:34:30 +0000 (17:34 +0200)] 
nft.8: Document limitation of reject statement in bridge family

Bridge family allows reject statement in prerouting and input chains
only. Users can't know without looking at kernel code.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: py: Make diff functions use print_* functions
Máté Eckl [Thu, 17 May 2018 07:37:02 +0000 (09:37 +0200)] 
tests: py: Make diff functions use print_* functions

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: py: Added paylad file description to README
Máté Eckl [Thu, 17 May 2018 07:37:01 +0000 (09:37 +0200)] 
tests: py: Added paylad file description to README

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: py: print path of the logfile
Máté Eckl [Thu, 17 May 2018 07:37:00 +0000 (09:37 +0200)] 
tests: py: print path of the logfile

It is good to know that a log is generated even without browsing the
nft-test.py source code.

Also print_info function is introduced.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: py: print_msg refactor
Máté Eckl [Thu, 17 May 2018 07:36:59 +0000 (09:36 +0200)] 
tests: py: print_msg refactor

The errstr attribute was hard-coded to "ERROR:"

errstr has been moved in the parameter list. As print_msg is only
used from the other print_* this is not an issue, and as there is a
print_error function, I don't think that strerr should default to
"ERROR:".

Also this kind of messages now get written to stderr. This can be
beneficial if someone wants to redirect output to a file.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: py: updated test file structure descripion in README
Máté Eckl [Thu, 17 May 2018 07:36:58 +0000 (09:36 +0200)] 
tests: py: updated test file structure descripion in README

The order of the table and chain definitions have changed in test files.
Now the name of the chain has to be specified in the definition of the
table, so their order is reverted.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: py: small typo fixes in the python tests README
Máté Eckl [Thu, 17 May 2018 07:36:57 +0000 (09:36 +0200)] 
tests: py: small typo fixes in the python tests README

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: py: specify python version in nft-test.py
Máté Eckl [Thu, 17 May 2018 07:36:55 +0000 (09:36 +0200)] 
tests: py: specify python version in nft-test.py

/usr/bin/python is linked to different main version of python in
different distributions (eg. 2 on debian, 3 on arch linux).

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosegtree: missing comments in range and prefix expressions in sets
Pablo Neira Ayuso [Wed, 16 May 2018 19:59:12 +0000 (21:59 +0200)] 
segtree: missing comments in range and prefix expressions in sets

 table inet filter {
        set spamhaus {
                type ipv4_addr
                flags interval
                elements = { 1.2.3.8/31 comment "evil people", 3.3.3.16-3.3.3.20 comment "more than evil" }
        }
 }

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agolibnftables: Move scanner object into struct nft_ctx
Phil Sutter [Tue, 15 May 2018 09:37:56 +0000 (11:37 +0200)] 
libnftables: Move scanner object into struct nft_ctx

The initial approach of keeping as much of lex/yacc-specific data
local to the relevant parsing routines was flawed in that input
descriptors which parsed commands' location information points at were
freed after parsing (in scanner_destroy()) although they were required
later for error reporting in case a command was rejected by the kernel.

To overcome this, keep the scanner pointer in struct nft_ctx so that it
can be kept in place until kernel communication has finished.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonftables: xt: don't use hard-coded AF_INET
Florian Westphal [Fri, 11 May 2018 21:17:16 +0000 (23:17 +0200)] 
nftables: xt: don't use hard-coded AF_INET

We need to check which revision type is requested (match, target)
and wheter its ipv4 or ipv6, then set family based on that.

This allows nft ipv6 family to display compat entries if a translation
is available.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft.8: Drop misleading adjective 'absolute'
Phil Sutter [Fri, 11 May 2018 12:20:35 +0000 (14:20 +0200)] 
nft.8: Drop misleading adjective 'absolute'

Discussion showed that rule index may be interpreted as being absolute
or relative, so just drop this adjective without replacement.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoevaluate: Return ENOENT if rule index is too large
Phil Sutter [Fri, 11 May 2018 10:33:46 +0000 (12:33 +0200)] 
evaluate: Return ENOENT if rule index is too large

Since EINVAL usually indicates errors from kernel, avoid using it here
too. Instead return ENOENT to indicate there's no entry to append or
prepend the rule to.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: Support testing JSON input and output as well
Phil Sutter [Tue, 8 May 2018 11:08:45 +0000 (13:08 +0200)] 
tests/py: Support testing JSON input and output as well

This extends nft-test.py by optional JSON testing capabilities,
activated via '-j'/'--enable-json' parameter).

JSON testing happens for all rules which are supposed to work: After a
rule has been added and the existing tests (payload, ruleset listing
output) have been performed, basically the same test is done again using
a recorded JSON equivalent and (if necessary) a recorded listing output.

The code tries to ease new test case creation overhead by
auto-generating JSON equivalent input via listing the (non-JSON) rule in
JSON format. Also, differing netlink debug and listing output are stored
in *.got files to assist in analyzing/fixing failing test cases.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: Highlight offending parts in differences warnings
Phil Sutter [Tue, 8 May 2018 11:08:44 +0000 (13:08 +0200)] 
tests/py: Highlight offending parts in differences warnings

Print the non-equal parts of the two rules in yellow when printing the
differences warning.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: Don't read expected payload for each table
Phil Sutter [Tue, 8 May 2018 11:08:43 +0000 (13:08 +0200)] 
tests/py: Don't read expected payload for each table

When testing rule adding to different table families, expected payload
was read for each tested family again. Instead, read it just once and
just try to read a family-specific payload for each tested family.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>