]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
7 years agotests/shell: add tests for deletion of objects via object handle
Harsha Sharma [Thu, 18 Jan 2018 20:45:14 +0000 (02:15 +0530)] 
tests/shell: add tests for deletion of objects via object handle

Delete objects with given object handle

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc/nft.xml: Add deletion for objects via handles
Harsha Sharma [Tue, 23 Jan 2018 22:03:10 +0000 (03:33 +0530)] 
doc/nft.xml: Add deletion for objects via handles

Add documentation for deletion of tables, chains, sets and objects
via unique handles.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: extend nft to list object handle and delete objects via handle
Harsha Sharma [Thu, 18 Jan 2018 18:52:56 +0000 (00:22 +0530)] 
src: extend nft to list object handle and delete objects via handle

Print handle attributes in objects when listing via '-a' option and
delete objects via their unique object handles.
For e.g.

nft delete [<object-type>] [<family>] <table-name> [handle <handle>]

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: print object handle with --echo --handle
Pablo Neira Ayuso [Mon, 5 Mar 2018 16:25:45 +0000 (17:25 +0100)] 
rule: print object handle with --echo --handle

 # nft --echo --handle add counter x y
 add counter ip x y { packets 0 bytes 0 }  # handle 0

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonetlink: print table handle with --echo --handle
Pablo Neira Ayuso [Mon, 5 Mar 2018 16:06:51 +0000 (17:06 +0100)] 
netlink: print table handle with --echo --handle

 # nft --echo --handle add table x
 add table ip x # handle 80

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonetlink: print chain handle with --echo --handle
Pablo Neira Ayuso [Mon, 5 Mar 2018 16:01:19 +0000 (17:01 +0100)] 
netlink: print chain handle with --echo --handle

 # nft add --echo --handle chain x y
 add chain ip x y # handle 1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/shell: add tests for deletion of sets via set handle
Harsha Sharma [Mon, 15 Jan 2018 11:51:33 +0000 (17:21 +0530)] 
tests/shell: add tests for deletion of sets via set handle

Delete set with given unique set handle.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/shell: add tests for deletion of chains via chain handle
Harsha Sharma [Sun, 14 Jan 2018 19:33:07 +0000 (01:03 +0530)] 
tests/shell: add tests for deletion of chains via chain handle

Delete chain with given unique handle for a table.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: list set handle and delete set via set handle
Harsha Sharma [Sun, 14 Jan 2018 16:18:46 +0000 (21:48 +0530)] 
src: list set handle and delete set via set handle

Print 'handle' attribute in sets when listing via '-a' option and
delete sets via their unique set handles listed with '-a' option.
For e.g.

nft delete set [<family>] <table-name> [handle <handle>]

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser_bison: delete chain via chain handle
Harsha Sharma [Tue, 9 Jan 2018 18:59:42 +0000 (00:29 +0530)] 
parser_bison: delete chain via chain handle

This patch allows deletion of chains via unique chain handles which
can be listed with '-a' option and table name and family.
For eg.

nft delete chain [<family>] <table-name> [handle <handle>]

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Print handle attribute in chains
Harsha Sharma [Tue, 9 Jan 2018 18:59:01 +0000 (00:29 +0530)] 
src: Print handle attribute in chains

Print handle attribute in chains when listing via '-a' option.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser_bison: delete table via table handle
Harsha Sharma [Mon, 8 Jan 2018 17:57:07 +0000 (23:27 +0530)] 
parser_bison: delete table via table handle

This patch allows deletion of table via unique table handles and table
family which can be listed with '-a' option.
For.eg.
nft delete table [<family>] [handle <handle>]

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: print 'handle' attribute in tables
Harsha Sharma [Sat, 23 Dec 2017 19:45:25 +0000 (11:45 -0800)] 
src: print 'handle' attribute in tables

Print 'handle' attribute in tables, when listing via '-a' option

For eg.
nft list ruleset -a

table ip test-ip4 {
chain input {
ip saddr 8.8.8.8 counter packets 0 bytes 0 # handle 3
}
 # handle 1}
table ip filter {
chain output {
tcp dport ssh counter packets 0 bytes 0 # handle 4
}
 # handle 2}
table ip xyz {
 # handle 3}

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: nft: document flowtable
Pablo Neira Ayuso [Tue, 23 Jan 2018 11:58:30 +0000 (12:58 +0100)] 
doc: nft: document flowtable

Document the new flowtable objects available since Linux kernel 4.16-rc.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: add flowtable tests
Pablo Neira Ayuso [Mon, 22 Jan 2018 18:54:36 +0000 (19:54 +0100)] 
tests: shell: add flowtable tests

Add basic flowtable tests.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: flow offload support
Pablo Neira Ayuso [Sun, 3 Dec 2017 20:27:03 +0000 (21:27 +0100)] 
src: flow offload support

This patch allows us to refer to existing flowtables:

 # nft add rule x x flow offload @m

Packets matching this rule create an entry in the flow table 'm', hence,
follow up packets that get to the flowtable at ingress bypass the
classic forwarding path.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: delete flowtable
Pablo Neira Ayuso [Fri, 19 Jan 2018 00:41:38 +0000 (01:41 +0100)] 
src: delete flowtable

This patch allows you to delete an existing flowtable:

 # nft delete flowtable x m

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add support to add flowtables
Pablo Neira Ayuso [Thu, 18 Jan 2018 07:43:23 +0000 (08:43 +0100)] 
src: add support to add flowtables

This patch allows you to create flowtable:

 # nft add table x
 # nft add flowtable x m { hook ingress priority 10\; devices = { eth0, wlan0 }\; }

You have to specify hook and priority. So far, only the ingress hook is
supported. The priority represents where this flowtable is placed in the
ingress hook, which is registered to the devices that the user
specifies.

You can also use the 'create' command instead to bail out in case that
there is an existing flowtable with this name.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: support for flowtable listing
Pablo Neira Ayuso [Mon, 4 Dec 2017 12:28:25 +0000 (13:28 +0100)] 
src: support for flowtable listing

This patch allows you to dump existing flowtable.

 # nft list ruleset
 table ip x {
        flowtable x {
                hook ingress priority 10
                devices = { eth0, tap0 }
        }
 }

You can also list existing flowtables via:

 # nft list flowtables
 table ip x {
        flowtable x {
                hook ingress priority 10
                devices = { eth0, tap0 }
        }
 }

 You need a Linux kernel >= 4.16-rc to test this new feature.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: set timeout and size combination coverage
Pablo Neira Ayuso [Mon, 5 Mar 2018 15:19:02 +0000 (16:19 +0100)] 
tests: shell: set timeout and size combination coverage

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: redefine and undefine
Pablo Neira Ayuso [Sat, 3 Mar 2018 22:45:11 +0000 (23:45 +0100)] 
tests: shell: redefine and undefine

This tests cover the new redefine and undefine scripting feature.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add variable expression and use it to allow redefinitions
Pablo Neira Ayuso [Sat, 3 Mar 2018 21:52:35 +0000 (22:52 +0100)] 
src: add variable expression and use it to allow redefinitions

Add new variable expression that we can use to attach symbols in
runtime, this allows us to redefine variables via new keyword, eg.

 table ip x {
        chain y {
                define address = { 1.1.1.1, 2.2.2.2 }
                ip saddr $address
                redefine address = { 3.3.3.3 }
                ip saddr $address
        }
 }

 # nft list ruleset
 table ip x {
        chain y {
                ip saddr { 1.1.1.1, 2.2.2.2 }
                ip saddr { 3.3.3.3 }
        }
 }

Note that redefinition just places a new symbol version before the
existing one, so symbol lookups always find the latest version. The
undefine keyword decrements the reference counter and removes the symbol
from the list, so it cannot be used anymore. Still, previous references
to this symbol via variable expression are still valid.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agobuild: Bump version to v0.8.3 v0.8.3
Florian Westphal [Sat, 3 Mar 2018 10:50:23 +0000 (11:50 +0100)] 
build: Bump version to v0.8.3

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: datatype: prefer sscanf, avoid strncpy
Florian Westphal [Sat, 3 Mar 2018 09:57:54 +0000 (10:57 +0100)] 
src: datatype: prefer sscanf, avoid strncpy

similar to previous patch, but replace strncpy+atoi by sscanf.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: Use snprintf() over strncpy()
Harsha Sharma [Sun, 8 Oct 2017 19:23:43 +0000 (00:53 +0530)] 
src: Use snprintf() over strncpy()

Use snprintf() over strncpy() functions as the buffer is not null
terminated in strncpy().

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
7 years agonetlink: remove non-batching routines
Pablo Neira Ayuso [Sat, 3 Mar 2018 09:18:33 +0000 (10:18 +0100)] 
netlink: remove non-batching routines

This is only needed by 3.16, which was released 8 months after nftables
was merged upstream. That kernel version supports a reduced featureset.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoconfigure: misc updates
Pablo Neira Ayuso [Sat, 3 Mar 2018 09:02:31 +0000 (10:02 +0100)] 
configure: misc updates

This patch removes the following macros:

* AC_PREREQ checks for 2.61, which is not supported any contemporary
  distribution.

* AC_COPYRIGHT, autoconf documentation states "in addition to the Free
  Software Foundation's copyright on the Autoconf macros, parts of your
  configure are covered by the copyright-notice.".

  This only refers to the autoconf infrastructure: we are doing simple
  and standard usage of autoconf infrastructure, we also don't use this
  macro in other existing userspace software available at netfilter.org.
  The comment above at the beginning of this file shows text that is
  available in many configure.ac templates on the Internet.

* AC_CANONICAL_HOST, we don't need the canonical host-system type to
  build this software.

* AC_CONFIG_SRCDIR is not used in other userspace software in the tree.

* AC_DEFINE _GNU_SOURCE, define this where it's needed instead.

* AC_DEFINE _STDC_FORMAT_MACROS is not used in this codebase.

* AC_HEADER_STDC checks for ANSI C89 headers, however, we need more than
  just this C standard, so this doesn't guarantee anything at all.

* Remove "Checks for libraries" comment, it's obvious.

* AC_HEADER_ASSERT allows us to disable assertions, this is bad because
  this is helping us to diagnose bugs and incomplete features.

* AC_CHECK_HEADERS is checking for an arbitrary list of headers,
  this still doesn't even guarantee that we can actually do a successful
  compilation in a broken system.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoparser: use nf_key_proto
Florian Westphal [Sat, 18 Nov 2017 20:00:58 +0000 (21:00 +0100)] 
parser: use nf_key_proto

Consolidate into one so it can be reused by new users.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agolibnftables: don't crash when no commands are specified
Harsha Sharma [Sat, 3 Mar 2018 08:03:58 +0000 (13:33 +0530)] 
libnftables: don't crash when no commands are specified

For e.g.  nft -c "  "
Without this patch it segfaults.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoparser: support of maps with timeout
Laura Garcia Liebana [Fri, 2 Mar 2018 09:50:18 +0000 (10:50 +0100)] 
parser: support of maps with timeout

Support of key and value association with a certain timeout.

Example:

nft add map nftlb mapa { type inet_service: ipv4_addr\;
 timeout 5s\; }

Results in:

table ip nftlb {
map mapa {
type inet_service : ipv4_addr
timeout 5s
}
}

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonetlink_delinearize: Fix resource leaks
Phil Sutter [Thu, 1 Mar 2018 14:00:32 +0000 (15:00 +0100)] 
netlink_delinearize: Fix resource leaks

Most of the cases are basically the same: Error path fails to free the
previously allocated statement or expression. A few cases received
special treatment though:

- In netlink_parse_payload_stmt(), the leak is easily avoided by code
  reordering.

- In netlink_parse_exthdr(), there's no point in introducing a goto
  label since there is but a single affected error check.

- In netlink_parse_hash() non-error path leaked as well if sreg
  contained a concatenated expression.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonetlink: Complain if setting O_NONBLOCK fails
Phil Sutter [Thu, 1 Mar 2018 14:00:31 +0000 (15:00 +0100)] 
netlink: Complain if setting O_NONBLOCK fails

Assuming that code is not aware that reads from netlink socket may
block, treat inability to set O_NONBLOCK flag as fatal initialization
error aborting program execution.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agohash: Fix potential null-pointer dereference in hash_expr_cmp()
Phil Sutter [Thu, 1 Mar 2018 14:00:30 +0000 (15:00 +0100)] 
hash: Fix potential null-pointer dereference in hash_expr_cmp()

The first part of the conditional:

| (e1->hash.expr || expr_cmp(e1->hash.expr, e2->hash.expr))

will call expr_cmp() in case e1->hash.expr is NULL, causing null-pointer
dereference. This is probably a typo, the intention when introducing
this was to avoid the call to expr_cmp() for symmetric hash expressions
which don't use expr->hash.expr. Inverting the existence check should
fix this.

Fixes: 3a86406729782 ("src: hash: support of symmetric hash")
Cc: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoevaluate: Fix memleak in stmt_reject_gen_dependency()
Phil Sutter [Thu, 1 Mar 2018 14:00:29 +0000 (15:00 +0100)] 
evaluate: Fix memleak in stmt_reject_gen_dependency()

The allocated payload expression is not used after returning from that
function, so it needs to be freed again.

Simple test case:

| nft add rule inet t c reject with tcp reset

Valgrind reports definitely lost 144 bytes.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoerec: Avoid passing negative offset to fseek()
Phil Sutter [Thu, 1 Mar 2018 14:00:28 +0000 (15:00 +0100)] 
erec: Avoid passing negative offset to fseek()

If the initial call to ftell() fails, variable orig_offset is set to -1.
Avoid passing this to fseek() later on.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agocli: Drop pointless check in cli_append_multiline()
Phil Sutter [Thu, 1 Mar 2018 14:00:27 +0000 (15:00 +0100)] 
cli: Drop pointless check in cli_append_multiline()

The function is called from cli_complete after it has checked for line
to be != NULL. The other part of the conditional, namely multiline being
NULL, is perfectly valid (if the last read line didn't end with
backslash. Hence drop the conditional completely.

Since variable eof is not used anywhere outside of the dropped
conditional, get rid of it completely.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: regression test for bugzilla 1228
Pablo Neira Ayuso [Tue, 27 Feb 2018 16:00:41 +0000 (17:00 +0100)] 
tests: shell: regression test for bugzilla 1228

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomonitor: Make JSON/XML output respect output_fp
Phil Sutter [Wed, 28 Feb 2018 15:04:28 +0000 (16:04 +0100)] 
monitor: Make JSON/XML output respect output_fp

Make sure events callbacks print to output_ctx-defined stream for any
type of output format.

Since all of them use nft_print() as last call (if anything is printed
at all), the final call to fflush() in netlink_events_cb() can be
dropped.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agomonitor: Make trace events respect output_fp
Phil Sutter [Wed, 28 Feb 2018 15:04:27 +0000 (16:04 +0100)] 
monitor: Make trace events respect output_fp

Seems like this was incompletely converted, part of the output went to
output_fp already.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: add example for rule add/delete
Florian Westphal [Wed, 28 Feb 2018 14:32:11 +0000 (15:32 +0100)] 
doc: add example for rule add/delete

also mention that 'ip' is used when the family gets omitted.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: remove ipv6 address FIXME
Florian Westphal [Wed, 28 Feb 2018 08:34:07 +0000 (09:34 +0100)] 
doc: remove ipv6 address FIXME

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoReview switch statements for unmarked fall through cases
Phil Sutter [Wed, 28 Feb 2018 15:06:16 +0000 (16:06 +0100)] 
Review switch statements for unmarked fall through cases

While revisiting all of them, clear a few oddities as well:

- There's no point in marking empty fall through cases: They are easy to
  spot and a common concept when using switch().

- Fix indenting of break statement in one occasion.

- Drop needless braces around one case which doesn't declare variables.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: mention meta l4proto and ipv6 nexthdr issue wrt. extension headers
Florian Westphal [Tue, 27 Feb 2018 11:48:16 +0000 (12:48 +0100)] 
doc: mention meta l4proto and ipv6 nexthdr issue wrt. extension headers

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoAdded undefine/redefine keywords
David Fabian [Mon, 22 Jan 2018 13:02:11 +0000 (14:02 +0100)] 
Added undefine/redefine keywords

This is a small patch to nft which adds two new keywords - undefine and
redefine. undefine simply undefines a variable from the current scope.
redefine allows one to change a variable definition. We have a firewall
written in bash (using iptables) that is organized by customer VLANs.
Each VLAN has its own set of bash variables holding things like uplink
iface names, gateway IPs, etc. We want to rewrite the firewall to
nftables but are stuck on the fact that nft variables cannot be
overridden in the same scope. We have each VLAN configuration in a
separate file containing pre/post-routing, input, output and forward
rules,and we include those files to a master firewall configuration. One
solution is to rename all the variables with some VLAN specific
(pre/su)ffix. But that is cumbersome.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: add raw payload test cases.
Florian Westphal [Sat, 24 Feb 2018 09:45:32 +0000 (10:45 +0100)] 
tests: add raw payload test cases.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: document raw protocol expression
Florian Westphal [Sat, 24 Feb 2018 13:43:16 +0000 (14:43 +0100)] 
doc: document raw protocol expression

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: make raw payloads work
Florian Westphal [Sun, 25 Feb 2018 18:46:04 +0000 (19:46 +0100)] 
src: make raw payloads work

make syntax consistent between print and parse.
No dependency handling -- once you use raw expression, you need
to make sure the raw expression only sees the packets that you'd
want it to see.

based on an earlier patch from Laurent Fasnacht <l@libres.ch>.
Laurents patch added a different syntax:
   @<protocol>,<base>,<data type>,<offset>,<length>

data_type is useful to make nftables not err when
asking for "@payload,32,32 192.168.0.1", this patch still requires
manual convsersion to an integer type (hex or decimal notation).

data_type should probably be added later by adding an explicit
cast expression, independent of the raw payload syntax.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agopayload: don't resolve expressions using the inet pseudoheader
Florian Westphal [Sat, 24 Feb 2018 10:10:27 +0000 (11:10 +0100)] 
payload: don't resolve expressions using the inet pseudoheader

Else, '@ll,0,8' will be mapped to 'inet nfproto', but thats
not correct (inet is a pseudo header).

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agopayload: use integer_type when initializing a raw expression
Florian Westphal [Sat, 24 Feb 2018 11:51:45 +0000 (12:51 +0100)] 
payload: use integer_type when initializing a raw expression

The invalid type prints prominent "[invalid]", so prefer integer type
in raw expressions.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agometa: introduce datatype ifname_type
Arturo Borrero Gonzalez [Sun, 25 Feb 2018 17:30:24 +0000 (18:30 +0100)] 
meta: introduce datatype ifname_type

This new datatype is a string subtype.
It will allow us to build named maps/sets using meta keys like 'iifname',
'oifname', 'ibriport' or 'obriport'.

Example:

table inet t {
set s {
type ifname
elements = { "eth0",
     "eth1" }
}

chain c {
iifname @s accept
oifname @s accept
}
}

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agofiles: add load balance example
Arturo Borrero Gonzalez [Sat, 24 Feb 2018 21:06:49 +0000 (22:06 +0100)] 
files: add load balance example

Include this example file in the tarball on how to do load balancing with
nftables, inspired from https://wiki.nftables.org

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexamples: add ct helper examples
Arturo Borrero Gonzalez [Sun, 25 Feb 2018 17:36:16 +0000 (18:36 +0100)] 
examples: add ct helper examples

Include some examples in the nftables tarball on using the ct helper
infraestructure, inspired from wiki.nftables.org.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonftables: rearrange files and examples
Arturo Borrero Gonzalez [Sat, 24 Feb 2018 21:06:19 +0000 (22:06 +0100)] 
nftables: rearrange files and examples

Concatenate all family/hook examples into a single one by means of includes.

Put all example files under examples/. Use the '.nft' prefix and mark
them as executable files. Use a static shebang declaration, since these
are examples meant for final systems and users.

While at it, refresh also the sets_and_maps.nft example file and also
add the 'netdev-ingress.nft' example file.

Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosegtree: check for overlapping elements at insertion
Pablo Neira Ayuso [Fri, 23 Feb 2018 09:36:27 +0000 (10:36 +0100)] 
segtree: check for overlapping elements at insertion

This speeds up element overlap checks quite a bit.

Fixes: https://bugzilla.netfilter.org/show_bug.cgi?id=1228
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: meta.t: fix test case for anonymous set automerge
Florian Westphal [Sat, 24 Feb 2018 11:28:30 +0000 (12:28 +0100)] 
tests: meta.t: fix test case for anonymous set automerge

commit fb16c8b7f795e0d
("evaluate: Enable automerge feature for anonymous sets") re-enabled
merging of adjacent ranges, so 33-55, 56-88 turns into 33-88.

Update test case to reflect this.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc/nft.xml: fix typo
Duncan Roe [Sun, 18 Feb 2018 22:54:11 +0000 (09:54 +1100)] 
doc/nft.xml: fix typo

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoinclude: fix build failure
Florian Westphal [Sat, 17 Feb 2018 22:21:14 +0000 (23:21 +0100)] 
include: fix build failure

on older machine of mine:
../include/nftables.h:130:30: error: 'UINT_MAX' undeclared (first use in this function)

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: bail out when exporting ruleset with unsupported output
Pablo Neira Ayuso [Thu, 15 Feb 2018 16:22:16 +0000 (17:22 +0100)] 
src: bail out when exporting ruleset with unsupported output

Display error message and propagate error to shell when running command
with unsupported output:

 # nft export ruleset json
 Error: this output type is not supported
 export ruleset json
 ^^^^^^^^^^^^^^^^^^^^
 # echo $?
 1

When displaying the output in json using the low-level VM
representation, it shows:

 # nft export ruleset vm json
 ... low-level VM json output
 # echo $?
 0

While at it, do the same with obsoleted XML output.

Fixes: https://bugzilla.netfilter.org/show_bug.cgi?id=1224
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agopayload: don't decode past last valid template
Florian Westphal [Thu, 15 Feb 2018 14:26:31 +0000 (15:26 +0100)] 
payload: don't decode past last valid template

When trying to decode payload header fields, be sure to bail out
when having exhausted all available templates.

Otherwise, we allocate invalid payload expressions (no dataype,
header length of 0) and then crash when trying to print them.

Fixes: https://bugzilla.netfilter.org/show_bug.cgi?id=1226
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Spelling fixes
Ville Skyttä [Wed, 7 Feb 2018 09:34:31 +0000 (11:34 +0200)] 
src: Spelling fixes

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonetlink_delinearize: add meta_may_dependency_kill()
Pablo Neira Ayuso [Wed, 14 Feb 2018 15:27:10 +0000 (16:27 +0100)] 
netlink_delinearize: add meta_may_dependency_kill()

Do not exercise dependency removal for protocol key network payload
expressions in bridge, netdev and inet families from meta expressions,
more specifically:

* inet: nfproto and ether type.
* netdev and bridge: meta protocol and ether type.

need to be left in place.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agopayload: add payload_may_dependency_kill()
Pablo Neira Ayuso [Wed, 14 Feb 2018 15:27:01 +0000 (16:27 +0100)] 
payload: add payload_may_dependency_kill()

Payload protocol key expressions at network base are meaningful in the
netdev, bridge and inet families, do not exercise the redundant
dependency removal in those cases since it breaks rule semantics.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: get rid of __payload_dependency_kill()
Pablo Neira Ayuso [Wed, 14 Feb 2018 15:26:57 +0000 (16:26 +0100)] 
src: get rid of __payload_dependency_kill()

Use payload_dependency_release() instead.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add payload_dependency_exists()
Pablo Neira Ayuso [Wed, 14 Feb 2018 15:26:50 +0000 (16:26 +0100)] 
src: add payload_dependency_exists()

This helper function tells us if there is already a protocol key payload
expression, ie. those with EXPR_F_PROTOCOL flag set on, that we might
want to remove since we can infer from another expression in the upper
protocol base, eg.

ip protocol tcp tcp dport 22

'ip protocol tcp' can be removed in the ip family since it is redundant,
but not in the netdev, bridge and inet families, where we cannot make
assumptions on the layer 3 protocol.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agopayload: add payload_dependency_release() helper function
Pablo Neira Ayuso [Wed, 14 Feb 2018 15:26:46 +0000 (16:26 +0100)] 
payload: add payload_dependency_release() helper function

Wrap code that releases existing dependencies that we have just
annotated in the context structure.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: pass family to payload_dependency_kill()
Pablo Neira Ayuso [Wed, 14 Feb 2018 15:26:31 +0000 (16:26 +0100)] 
src: pass family to payload_dependency_kill()

This context information is very relevant when deciding if a redundant
dependency needs to be removed or not, specifically for the inet, bridge
and netdev families. This new parameter is used by follow up patch
entitled ("payload: add payload_may_dependency_kill()").

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoevaluate: Enable automerge feature for anonymous sets
Phil Sutter [Tue, 6 Feb 2018 18:18:47 +0000 (19:18 +0100)] 
evaluate: Enable automerge feature for anonymous sets

Automatic merging of adjacent/overlapping ranges upon insertion has
clear benefits performance- and readability-wise. The drawbacks which
led to disabling it by default don't apply to anonymous sets since they
are read-only anyway, so enable this feature for them again.

Cc: Jeff Kletsky <netfilter@allycomm.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoconfigure: Make missing docbook2man an error if man build requested
Ville Skyttä [Wed, 7 Feb 2018 09:40:00 +0000 (11:40 +0200)] 
configure: Make missing docbook2man an error if man build requested

Previously, if man page build was enabled but no suitable docbook2man or
the like tool was found, build failed at a later stage with
undescriptive error message. Fail early and explicitly at configure
stage instead.

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: add test case for sets updated from packet path
Florian Westphal [Tue, 13 Feb 2018 14:28:00 +0000 (15:28 +0100)] 
tests: add test case for sets updated from packet path

currently kernel may pick a set implementation that doesn't provide
a ->update() function. This causes an error when user attempts to
add the nftables rule that is supposed to add entries to the set.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: enable sets test case 27
Florian Westphal [Tue, 13 Feb 2018 14:27:13 +0000 (15:27 +0100)] 
tests: enable sets test case 27

needs +x, else run-tests.sh won't run it.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: fix build with older glibc
Baruch Siach [Fri, 9 Feb 2018 12:49:50 +0000 (14:49 +0200)] 
src: fix build with older glibc

glibc before 2.19 missed the definition of IPPROTO_MH. This leads to
build failure:

parser_bison.y: In function 'nft_parse':
parser_bison.y:3793:21: error: 'IPPROTO_MH' undeclared (first use in this function)
    | MH { $$ = IPPROTO_MH; }
                     ^

Since we have a local definition of IPPROTO_MH in headers.h use that to
fix the build.

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agobuild: Bump version to v0.8.2 v0.8.2
Pablo Neira Ayuso [Fri, 2 Feb 2018 15:58:55 +0000 (16:58 +0100)] 
build: Bump version to v0.8.2

This release includes incremental fixes since last release plus meta
secpath support. libnftnl 1.0.9 is still OK as dependency, actually it
just prints meta secpath as unknown with --debug=netlink but I don't
think that is worth a libnftnl library release.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonetlink_delinearize: add assertion to prevent infinite loop
Pablo Neira Ayuso [Fri, 2 Feb 2018 12:26:55 +0000 (13:26 +0100)] 
netlink_delinearize: add assertion to prevent infinite loop

The following configuration:

 table inet filter {
chain input {
ct original ip daddr {1.2.3.4} accept
}
 }

is triggering an infinite loop.

This problem also exists with concatenations and ct ip {s,d}addr. Until
we have a solution for this, let's just prevent infinite loops.

Now we hit this:

 # nft list ruleset
 nft: netlink_delinearize.c:124: netlink_parse_concat_expr: Assertion `consumed > 0' failed.
 Abort

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: dup and fwd statements
Florian Westphal [Fri, 26 Jan 2018 13:27:12 +0000 (14:27 +0100)] 
doc: dup and fwd statements

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/shell: Add back named_interval_automerging_0
Phil Sutter [Sat, 20 Jan 2018 13:21:01 +0000 (14:21 +0100)] 
tests/shell: Add back named_interval_automerging_0

Change the test to expect no automerging since it was disabled recently.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: fetch rule handle with '-a' option and then delete rule
Harsha Sharma [Tue, 23 Jan 2018 23:46:01 +0000 (05:16 +0530)] 
tests: shell: fetch rule handle with '-a' option and then delete rule

Fetch rule handle and then delete rule via that rule handle.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: build: Add enable man page option.
Varsha Rao [Thu, 25 Jan 2018 15:18:52 +0000 (20:48 +0530)] 
tests: build: Add enable man page option.

Add test for man page compile option.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoconfigure: Remove macro AC_CHECK_FUNCS
Varsha Rao [Thu, 25 Jan 2018 15:18:53 +0000 (20:48 +0530)] 
configure: Remove macro AC_CHECK_FUNCS

Functions memmove, strchr, strerror and strdup are defined in string.h
header file. Also, strtoull is defined in stdlib.h header file. These
header files are checked by AC_CHECK_HEADERS macro. AC_CHECK_FUNCS macro
is not required, so remove it.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoupdate gitignore
Pablo M. Bermudo Garay [Wed, 24 Jan 2018 10:09:43 +0000 (11:09 +0100)] 
update gitignore

Add new internal libraries generated since [1] to the .gitignore file.

[1]: 0b3ccd27e12d ("build: Restore per object CFLAGS")

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add 'auto-merge' option to sets
Pablo Neira Ayuso [Mon, 22 Jan 2018 10:17:10 +0000 (11:17 +0100)] 
src: add 'auto-merge' option to sets

After discussions with Karel here:

https://bugzilla.netfilter.org/show_bug.cgi?id=1184

And later on with Phil Sutter, we decided to disable the automatic merge
feature in sets with intervals. This feature is problematic because it
introduces an inconsistency between what we add and what we later on
get. This is going to get worse with the upcoming timeout support for
intervals. Therefore, we turned off this by default.

However, Jeff Kletsky and folks like this feature, so let's restore this
behaviour on demand with this new 'auto-merge' statement, that you can
place on the set definition, eg.

 # nft list ruleset
 table ip x {
...
        set y {
                type ipv4_addr
                flags interval
                auto-merge
        }
 }
 # nft add element x z { 1.1.1.1-2.2.2.2, 1.1.1.2 }

Regarding implementation details: Given this feature only makes sense
from userspace, let's store this in the set user data area, so nft knows
it has to do automatic merge of adjacent/overlapping elements as per
user request.

 # nft add set x z { type ipv4_addr\; auto-merge\; }
 Error: auto-merge only works with interval sets
 add set x z { type ipv4_addr; auto-merge; }
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Fixes: https://bugzilla.netfilter.org/show_bug.cgi?id=1216
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoRevert ("src: Remove xt_stmt_() functions").
Pablo Neira Ayuso [Sat, 20 Jan 2018 12:38:55 +0000 (13:38 +0100)] 
Revert ("src: Remove xt_stmt_() functions").

Revert commit bce55916b51ec1a4c23322781e3b0c698ecc9561, we need this
code in place to properly make translation when iptables-compat loads
rules.

Reported-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc/nft.xml: mention nftables earlier
Arturo Borrero Gonzalez [Fri, 19 Jan 2018 12:17:47 +0000 (13:17 +0100)] 
doc/nft.xml: mention nftables earlier

Mention nftables earlier in the documentation, so users have more context on what
we are talking about.

This is Debian bug #887718, which contains:

<<<
Currently one must read down 100 lines before it is even mentioned.
You might want to make the connection between "nft" and "nftables" as
early as the NAME or DESCRIPTION.
>>>

Requested-by: Dan Jacobson <jidanni@jidanni.org>
Signed-off-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: build: Add README.
Varsha Rao [Wed, 17 Jan 2018 18:58:33 +0000 (00:28 +0530)] 
tests: build: Add README.

Add readme for compile options test script.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoconfigure: Allow to disable man page building
Phil Sutter [Tue, 16 Jan 2018 16:38:07 +0000 (17:38 +0100)] 
configure: Allow to disable man page building

Aparently there are distributions which come with incompatible docbook
implementations. On those, forced man page creating if required binaries
are found leads to build failure.

Allow them to conveniently disable man page output instead of having to
pass undocumented variables to configure.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoconfigure: Fix help text regarding --enable-debug
Phil Sutter [Tue, 16 Jan 2018 16:38:06 +0000 (17:38 +0100)] 
configure: Fix help text regarding --enable-debug

Debugging symbols are enabled by default, so list '--disable-debug' in
help output rather than '--enable-debug'. This way it is also consistent
with the parameter's description.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agobuild: Eliminate forgotten traces of libnftables exporting
Phil Sutter [Tue, 16 Jan 2018 16:19:57 +0000 (17:19 +0100)] 
build: Eliminate forgotten traces of libnftables exporting

This removes libnftables pkg-config file along with the few lines of
code to adjust and install it.

Fixes: d572d59788143 ("Make libnftables a local static library")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoconfigure: Remove AC_HEADER_STDBOOL, AC_C_ and AC_TYPE_ macros
Varsha Rao [Fri, 19 Jan 2018 03:00:17 +0000 (08:30 +0530)] 
configure: Remove AC_HEADER_STDBOOL, AC_C_ and AC_TYPE_ macros

The following macros check if particular C types in specific header file
exists, these header files defines them and are already included in the
source code. So, remove them.

AC_HEADER_STDBOOL - stdbool.h
AC_TYPE_INT and AC_TYPE_UINT - stdint.h or inttypes.h
AC_TYPE_OFF_T and AC_TYPE_UID_T - sys/types.h
AC_TYPE_SIZE_T - stddef.h, string.h, stdlib.h or stdio.h

Remove AC_C_CONST and AC_C_INLINE as gcc supports inline and const
keywords.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: Add tests for low level json import
Shyam Saini [Tue, 5 Dec 2017 14:07:35 +0000 (19:37 +0530)] 
tests: shell: Add tests for low level json import

Test "nft import vm json".

Basically it loads same set of rules by "nft -f" and "nft import vm json"
and prints differences (if any) in the ruleset listed by "nft list
ruleset" in each case.

For Example:
$ ./run-tests.sh testcases/import/vm_json_import_0

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Add import command for low level json
Shyam Saini [Tue, 5 Dec 2017 14:07:34 +0000 (19:37 +0530)] 
src: Add import command for low level json

This new operation allows to import low level virtual machine ruleset in
json to make incremental changes using the parse functions of libnftnl.

A basic way to test this new functionality is:

 $ cat file.json | nft import vm json

where the file.json is a ruleset exported in low level json format.

To export json rules in low level virtual machine format
we need to specify "vm" token before json. See below
        $ nft export vm json

and
        $ nft export/import json

will do no operations.
Same goes with  "$nft monitor"

Highly based on work from  Alvaro Neira <alvaroneay@gmail.com>
and Arturo Borrero <arturo@netfilter.org>

Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: Add test for compile options.
Varsha Rao [Tue, 16 Jan 2018 02:30:36 +0000 (08:00 +0530)] 
tests: Add test for compile options.

This patch adds a script to test available compile options.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agometa: add secpath support
Florian Westphal [Fri, 1 Dec 2017 12:40:21 +0000 (13:40 +0100)] 
meta: add secpath support

This can be used to check if a packet has a secpath attached to it, i.e.
was subject to ipsec processing.  Example:

add rule inet raw prerouting meta secpath exists accept

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agobuild: Bump version to v0.8.1 v0.8.1
Pablo Neira Ayuso [Tue, 9 Jan 2018 15:26:39 +0000 (16:26 +0100)] 
build: Bump version to v0.8.1

A release including incremental fixes since last release. Still it needs
libnftnl 1.0.9 because of nftnl_expr_fprint().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Don't merge adjacent/overlapping ranges
Phil Sutter [Wed, 10 Jan 2018 20:32:04 +0000 (21:32 +0100)] 
src: Don't merge adjacent/overlapping ranges

Previously, when adding multiple ranges to a set they were merged if
overlapping or adjacent. This might cause inconvenience though since it
is afterwards not easily possible anymore to remove one of the merged
ranges again while keeping the others in place.

Since it is not possible to have overlapping ranges, this patch adds a
check for newly added ranges to make sure they don't overlap if merging
is turned off.

Note that it is not possible (yet?) to enable range merging using nft
tool.

Testsuite had to be adjusted as well: One test in tests/py changed avoid
adding overlapping ranges and the test in tests/shell which explicitly
tests for this feature dropped.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agobuild: Restore per object CFLAGS
Phil Sutter [Wed, 10 Jan 2018 12:43:21 +0000 (13:43 +0100)] 
build: Restore per object CFLAGS

As per the automake manual, create internal libraries for parser and
mini-gmp sources so per-object flags can be set.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoinclude: refresh nf_tables.h cached copy
Pablo Neira Ayuso [Mon, 8 Jan 2018 21:15:20 +0000 (22:15 +0100)] 
include: refresh nf_tables.h cached copy

Refresh it to fetch what we have in 4.15-rc.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: do not print limit keyword inside object definition
Pablo M. Bermudo Garay [Fri, 22 Dec 2017 17:26:10 +0000 (18:26 +0100)] 
src: do not print limit keyword inside object definition

table ip limits {
    limit foo {
        limit rate 5/second
        ^^^^^
    }
}

This behaviour is inconsistent and breaks the restoration of saved
rule-sets with "nft -f".

Fixes: c0697eabe832 ("src: add stateful object support for limit")
Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: fix protocol context update on big-endian systems
Phil Sutter [Sat, 9 Dec 2017 15:52:29 +0000 (16:52 +0100)] 
src: fix protocol context update on big-endian systems

There is an obscure bug on big-endian systems when trying to list a rule
containing the expression 'ct helper tftp' which triggers the assert()
call in mpz_get_type().

Florian identified the cause: ct_expr_pctx_update() is called for the
relational expression which calls mpz_get_uint32() to get RHS value
(assuming it is a protocol number). On big-endian systems, the
misinterpreted value exceeds UINT_MAX.

Expressions' pctx_update() callback should only be called for protocol
matches, so ct_meta_common_postprocess() lacked a check for 'left->flags
& EXPR_F_PROTOCOL' like the one already present in
payload_expr_pctx_update().

In order to fix this in a clean way, this patch introduces a wrapper
relational_expr_pctx_update() to be used instead of directly calling
LHS's pctx_update() callback which unifies the necessary checks (and
adds one more assert):

- assert(expr->ops->type == EXPR_RELATIONAL)
  -> This is new, just to ensure the wrapper is called properly.
- assert(expr->op == OP_EQ)
  -> This was moved from {ct,meta,payload}_expr_pctx_update().
- left->ops->pctx_update != NULL
  -> This was taken from expr_evaluate_relational(), a necessary
     requirement for the introduced wrapper to function at all.
- (left->flags & EXPR_F_PROTOCOL) != 0
  -> The crucial missing check which led to the problem.

Suggested-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonetlink_linearize: exthdr op must be u32
Florian Westphal [Mon, 11 Dec 2017 09:06:55 +0000 (10:06 +0100)] 
netlink_linearize: exthdr op must be u32

libnftnl casts this to u32. Broke exthdr expressions on bigendian.

Reported-by: Li Shuang <shuali@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: trivial: Fix error message
Phil Sutter [Sat, 9 Dec 2017 15:53:10 +0000 (16:53 +0100)] 
tests/py: trivial: Fix error message

The error message for failed chain creation quotes the chain's name but
lacked the closing tick.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoMake libnftables a local static library
Phil Sutter [Thu, 30 Nov 2017 18:36:23 +0000 (19:36 +0100)] 
Make libnftables a local static library

This changes Makefiles so that libnftables is built into a static
library which is not installed. This allows for incompatible changes
while still providing a library to link to for testing purposes.

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