]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
6 years agoobj/ct_timeout: Avoid array overrun in timeout_parse_attr_data()
Phil Sutter [Fri, 4 Oct 2019 19:44:14 +0000 (21:44 +0200)] 
obj/ct_timeout: Avoid array overrun in timeout_parse_attr_data()

Array 'tb' has only 'attr_max' elements, the loop overstepped its
boundary by one. Copy array_size() macro from include/utils.h in
nftables.git to make sure code does the right thing.

Fixes: 0adceeab1597a ("src: add ct timeout support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoset: Don't bypass checks in nftnl_set_set_u{32,64}()
Phil Sutter [Fri, 4 Oct 2019 19:33:48 +0000 (21:33 +0200)] 
set: Don't bypass checks in nftnl_set_set_u{32,64}()

By calling nftnl_set_set(), any data size checks are effectively
bypassed. Better call nftnl_set_set_data() directly, passing the real
size for validation.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoobj/tunnel: Fix for undefined behaviour
Phil Sutter [Fri, 4 Oct 2019 19:53:53 +0000 (21:53 +0200)] 
obj/tunnel: Fix for undefined behaviour

Cppcheck complains: Shifting signed 32-bit value by 31 bits is undefined
behaviour.

Indeed, NFTNL_OBJ_TUNNEL_ERSPAN_V2_DIR enum value is 31. Make sure
behaviour is as intended by shifting unsigned 1.

Fixes: ea63a05272f54 ("obj: add tunnel support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoset_elem: Fix return code of nftnl_set_elem_set()
Phil Sutter [Fri, 4 Oct 2019 19:18:43 +0000 (21:18 +0200)] 
set_elem: Fix return code of nftnl_set_elem_set()

The function returned -1 on success.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoobj: ct_timeout: Check return code of mnl_attr_parse_nested()
Phil Sutter [Fri, 4 Oct 2019 19:05:44 +0000 (21:05 +0200)] 
obj: ct_timeout: Check return code of mnl_attr_parse_nested()

Don't ignore nested attribute parsing errors, this may hide bugs in
users' code.

Fixes: 0adceeab1597a ("src: add ct timeout support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoset: Export nftnl_set_list_lookup_byname()
Phil Sutter [Fri, 27 Sep 2019 12:24:40 +0000 (14:24 +0200)] 
set: Export nftnl_set_list_lookup_byname()

Rename and optimize internal function nftnl_set_lookup() for external
use. Just like with nftnl_chain_list, use a hash table for fast set name
lookups.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: synproxy stateful object support
Fernando Fernandez Mancera [Sat, 7 Sep 2019 16:05:01 +0000 (18:05 +0200)] 
src: synproxy stateful object support

This patch adds synproxy stateful object support.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoexpr: meta: Make NFT_DYNSET_OP_DELETE known
Ander Juaristi [Sat, 17 Aug 2019 11:32:48 +0000 (13:32 +0200)] 
expr: meta: Make NFT_DYNSET_OP_DELETE known

Signed-off-by: Ander Juaristi <a@juaristi.eus>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoexpr: meta: Make NFT_META_TIME_{NS, DAY, HOUR} known
Ander Juaristi [Sat, 17 Aug 2019 11:32:47 +0000 (13:32 +0200)] 
expr: meta: Make NFT_META_TIME_{NS, DAY, HOUR} known

Signed-off-by: Ander Juaristi <a@juaristi.eus>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agobuild: libnftnl 1.1.4 release libnftnl-1.1.4
Pablo Neira Ayuso [Mon, 19 Aug 2019 09:15:45 +0000 (11:15 +0200)] 
build: libnftnl 1.1.4 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoexpr: meta: Make NFT_META_BRI_IIF{VPROTO, PVID} known
wenxu [Wed, 14 Aug 2019 07:12:07 +0000 (15:12 +0800)] 
expr: meta: Make NFT_META_BRI_IIF{VPROTO, PVID} known

This only affects debug output, the key was properly handled in
productive code paths already.

Signed-off-by: wenxu <wenxu@ucloud.cn>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoinclude: resync nf_tables.h cache copy
Pablo Neira Ayuso [Tue, 13 Aug 2019 19:41:45 +0000 (21:41 +0200)] 
include: resync nf_tables.h cache copy

Get this header in sync with 5.3-rc1.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoexpr: meta: Make NFT_META_{I,O}IFKIND known
Phil Sutter [Thu, 18 Jul 2019 03:38:29 +0000 (05:38 +0200)] 
expr: meta: Make NFT_META_{I,O}IFKIND known

This only affects debug output, the key was properly handled in
productive code paths already.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoudata: fix sigbus crash on sparc
Florian Westphal [Sat, 13 Jul 2019 19:34:43 +0000 (21:34 +0200)] 
udata: fix sigbus crash on sparc

Anatoly Pugachev reported crash on 'nft list tables' on sparc
and provided following gdb backtrace:

 Starting program: /opt/nft/sbin/nft list tables
 Program received signal SIGBUS, Bus error.
 0xfff8000100946490 in nftnl_udata_get_u32 (attr=0x10000106e30) at udata.c:127
 127             return *data;

We can't deref attr->value directly, it causes unaligned access.

Reported-by: Anatoly Pugachev <matorola@gmail.com>
Tested-by: Anatoly Pugachev <matorola@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agosrc: add synproxy support
Fernando Fernandez Mancera [Wed, 19 Jun 2019 17:53:50 +0000 (19:53 +0200)] 
src: add synproxy support

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoAdd Requires.private field to libnftnl.pc
Thomas Petazzoni [Fri, 5 Jul 2019 08:34:19 +0000 (11:34 +0300)] 
Add Requires.private field to libnftnl.pc

Static linking userspace programs such as nftables against libnftnl
currently doesn't work out of the box, because libnftnl is linked
against libmnl, but this isn't expressed in libnftnl pkg-config
file:

  CCLD   nft
[...]/bfin-buildroot-uclinux-uclibc/sysroot/usr/lib/libnftnl.a(table.o): In function `_nft_table_nlmsg_parse':
table.c:(.text+0x480): undefined reference to `_mnl_attr_parse'
table.c:(.text+0x492): undefined reference to `_mnl_attr_get_str'
table.c:(.text+0x4a8): undefined reference to `_mnl_attr_get_u32'
table.c:(.text+0x4ca): undefined reference to `_mnl_attr_get_u32'
[...]

The Libs.private field is specifically designed for such usage:

>From pkg-config documentation:

  Requires.private:

    A list of packages required by this package. The difference from
    Requires is that the packages listed under Requires.private are not
    taken into account when a flag list is computed for dynamically
    linked executable (i.e., when --static was not specified). In the
    situation where each .pc file corresponds to a library,
    Requires.private shall be used exclusively to specify the
    dependencies between the libraries.

Therefore, this patch adds a reference to libmnl in the Requires.private
field of libnftnl pkg-config file.

[baruch: use Requires.private; update commit log]

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add support for matching IPv4 options
Stephen Suryaputra [Thu, 20 Jun 2019 11:54:29 +0000 (07:54 -0400)] 
src: add support for matching IPv4 options

Add capability to have rules matching IPv4 options. This is developed
mainly to support dropping of IP packets with loose and/or strict source
route route options.

Signed-off-by: Stephen Suryaputra <ssuryaextr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: Add ct id support
Brett Mastbergen [Tue, 23 Apr 2019 20:18:17 +0000 (16:18 -0400)] 
src: Add ct id support

The 'id' key returns the id of the connection entry

Signed-off-by: Brett Mastbergen <bmastbergen@untangle.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: enable set expiration date for set elements
Laura Garcia Liebana [Mon, 17 Jun 2019 16:15:05 +0000 (18:15 +0200)] 
src: enable set expiration date for set elements

Currently, the expiration of every element in a set or map
is a read-only parameter generated at kernel side.

This change will permit to set a certain expiration date
per element that will be required, for example, during
stateful replication among several nodes.

This patch allows to propagate NFTA_SET_ELEM_EXPIRATION
from userspace to the kernel in order to set the
configured value.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoexamples: add ct expectation examples
Stéphane Veyret [Fri, 31 May 2019 16:51:45 +0000 (18:51 +0200)] 
examples: add ct expectation examples

Add examples for ct expectations.

Add, list and delete ct expectation objects from specified table.
Add expectation object to rule.

Signed-off-by: Stéphane Veyret <sveyret@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add ct expectation support
Stéphane Veyret [Fri, 31 May 2019 16:51:44 +0000 (18:51 +0200)] 
src: add ct expectation support

Add support for ct expectation objects, used to define specific
expectations.

Signed-off-by: Stéphane Veyret <sveyret@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agobuild: libnftnl 1.1.3 release libnftnl-1.1.3
Pablo Neira Ayuso [Mon, 27 May 2019 11:27:31 +0000 (13:27 +0200)] 
build: libnftnl 1.1.3 release

Moreover, add missing include/rule.h file to Makefile.am.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoinclude: Remove redundant declaration of nftnl_gen_nlmsg_parse()
Phil Sutter [Mon, 13 May 2019 17:11:59 +0000 (19:11 +0200)] 
include: Remove redundant declaration of nftnl_gen_nlmsg_parse()

The duplicated declaration was there since the functions initial
introduction as 'nft_gen_nlmsg_parse()'.

Fixes: 2e66fb09d6936 ("src: add ruleset generation class")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoexpr: osf: add version option support
Fernando Fernandez Mancera [Wed, 27 Mar 2019 10:36:58 +0000 (11:36 +0100)] 
expr: osf: add version option support

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: libnftnl: export genid functions again
Florian Westphal [Thu, 7 Mar 2019 11:15:40 +0000 (12:15 +0100)] 
src: libnftnl: export genid functions again

Can't use them currently: they are exported only under their old names.

Fixes: 44d11498479a08 ("src: get rid of _attr_ infix in new nftnl_ definitions")
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoudata: add NFTNL_UDATA_* definitions
Pablo Neira Ayuso [Fri, 8 Feb 2019 16:13:28 +0000 (17:13 +0100)] 
udata: add NFTNL_UDATA_* definitions

Place them in the library, so iptables and nftables do not need to
redefine them.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Phil Sutter <phil@nwl.cc>
6 years agoset_elem: close a padding hole
Florian Westphal [Fri, 18 Jan 2019 16:46:31 +0000 (17:46 +0100)] 
set_elem: close a padding hole

224 -> 216 bytes on x86_64.

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agosrc: rule: Support NFTA_RULE_POSITION_ID attribute
Phil Sutter [Tue, 15 Jan 2019 19:59:04 +0000 (20:59 +0100)] 
src: rule: Support NFTA_RULE_POSITION_ID attribute

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoRevert "expr: add map lookups for hash statements"
Laura Garcia Liebana [Mon, 21 Jan 2019 11:38:03 +0000 (12:38 +0100)] 
Revert "expr: add map lookups for hash statements"

A better way to implement this from userspace has been found without
specific code in the kernel side, revert this.

Fixes: bb4b75aea5c0 ("expr: add map lookups for hash statements")
Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoRevert "expr: add map lookups for numgen statements"
Laura Garcia Liebana [Mon, 21 Jan 2019 11:37:34 +0000 (12:37 +0100)] 
Revert "expr: add map lookups for numgen statements"

A better way to implement this from userspace has been found without
specific code in the kernel side, revert this.

Fixes: b97f45c2ebaa ("expr: add map lookups for numgen statements")
Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: chain: Fix nftnl_chain_rule_insert_at()
Phil Sutter [Mon, 14 Jan 2019 16:42:50 +0000 (17:42 +0100)] 
src: chain: Fix nftnl_chain_rule_insert_at()

Extrapolating from iptables nomenclature, one would expect that "insert"
means to prepend the new item to the referenced one, not append. Change
nftnl_chain_rule_insert_at() to do just that and introduce
nftnl_chain_rule_append_at() to insert a rule after the referenced one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: chain: Add missing nftnl_chain_rule_del()
Phil Sutter [Sun, 30 Dec 2018 16:02:13 +0000 (17:02 +0100)] 
src: chain: Add missing nftnl_chain_rule_del()

Although identical to nftnl_rule_list_del(), this function adheres to
the common naming style of per chain rule list routines introduced
earlier, therefore helps with deprecating the global rule list API at a
later point.

Fixes: e33798478176f ("chain: Support per chain rules list")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoflowtable: Fix for reading garbage
Phil Sutter [Thu, 20 Dec 2018 20:03:31 +0000 (21:03 +0100)] 
flowtable: Fix for reading garbage

nftnl_flowtable_get_data() doesn't assign to passt data_len pointer
destination in all cases, so initialize it to 0.

Fixes: eb58f53372e74 ("src: add flowtable support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoflowtable: Fix memleak in nftnl_flowtable_parse_devs()
Phil Sutter [Thu, 20 Dec 2018 20:03:30 +0000 (21:03 +0100)] 
flowtable: Fix memleak in nftnl_flowtable_parse_devs()

Allocated strings in dev_array were not freed. Fix this by freeing them
on error path and assigning them to c->dev_array directly in regular
path.

Fixes: eb58f53372e74 ("src: add flowtable support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoflowtable: Fix use after free in two spots
Phil Sutter [Thu, 20 Dec 2018 20:03:29 +0000 (21:03 +0100)] 
flowtable: Fix use after free in two spots

When freeing flowtable devices array, the loop freeing each device
string incorrectly included the call to free the device array itself.

Fixes: eb58f53372e74 ("src: add flowtable support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoflowtable: Add missing break
Phil Sutter [Thu, 20 Dec 2018 20:03:28 +0000 (21:03 +0100)] 
flowtable: Add missing break

In nftnl_flowtable_set_data(), when setting flowtable size, the switch()
case fell through and the same value was copied into ft_flags field.
This can't be right.

Fixes: 41fe3d38ba34b ("flowtable: support for flags")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoobject: Avoid obj_ops array overrun
Phil Sutter [Thu, 20 Dec 2018 20:03:27 +0000 (21:03 +0100)] 
object: Avoid obj_ops array overrun

In version 1.1.1, obj_ops array was smaller than __NFT_OBJECT_MAX since
there are no ops for NFT_OBJECT_CONNLIMIT. Avoid this potential issue in
the future by defining the array size.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agochain: Hash chain list by name
Phil Sutter [Tue, 11 Dec 2018 17:44:00 +0000 (18:44 +0100)] 
chain: Hash chain list by name

Introduce a hash table to speedup nftnl_chain_list_lookup_byname(). In
theory this could replace the linked list completely but has been left
in place so that nftnl_chain_list_add_tail() still does what it's
supposed to and iterators return chains in original order.

Speed was tested using a simple script which creates a dump file
containing a number of custom chains and for each of them two rules in
INPUT chain jumping to it. The following table compares run-time of
iptables-legacy-restore with iptables-nft-restore before and after this
patch:

count      legacy       nft-old        nft-new
----------------------------------------------
10000         26s           38s            31s
50000        137s          339s           149s

So while it is still not as quick, it now scales nicely (at least in
this very primitive test).

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agochain: Add lookup functions for chain list and rules in chain
Phil Sutter [Thu, 6 Dec 2018 16:17:52 +0000 (17:17 +0100)] 
chain: Add lookup functions for chain list and rules in chain

For now, these lookup functions simply iterate over the linked list
until they find the right entry. In future, they may make use of more
optimized data structures behind the curtains.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agochain: Support per chain rules list
Phil Sutter [Thu, 6 Dec 2018 16:17:51 +0000 (17:17 +0100)] 
chain: Support per chain rules list

The implementation basically copies expr_list in struct nftnl_rule.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agobuild: libnftnl 1.1.2 release libnftnl-1.1.2
Pablo Neira Ayuso [Tue, 13 Nov 2018 11:01:46 +0000 (12:01 +0100)] 
build: libnftnl 1.1.2 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: remove nftnl_rule_cmp() and nftnl_expr_cmp()
Pablo Neira Ayuso [Wed, 24 Oct 2018 17:18:50 +0000 (19:18 +0200)] 
src: remove nftnl_rule_cmp() and nftnl_expr_cmp()

These functions are not very useful, rule comparison from this layer
does not work well with implicit set definitions.

This infrastructure was added as an attempt to support for deletion by
name from this layer, which should be done from higher level libnftables
library. Finally, we never had a client for this code in
git.netfilter.org.

Let's remove it and bump libversion for safety reasons.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Use memcpy() to handle potentially unaligned data
Matt Turner [Wed, 17 Oct 2018 19:32:54 +0000 (12:32 -0700)] 
src: Use memcpy() to handle potentially unaligned data

Rolf Eike Beer <eike@sf-mail.de> reported that nft-expr_quota-test fails
with a SIGBUS on SPARC due to unaligned accesses. This patch resolves
that and fixes additional sources of unaligned accesses matching the
same pattern. Both nft-expr_quota-test and nft-expr_objref-test
generated unaligned accesses on DEC Alpha.

Bug: https://bugs.gentoo.org/666448
Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: Remove test-script.sh
Matt Turner [Wed, 17 Oct 2018 19:32:53 +0000 (12:32 -0700)] 
tests: Remove test-script.sh

All tests are now run with make check.

Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: Run regression tests from make check
Matt Turner [Wed, 17 Oct 2018 19:32:52 +0000 (12:32 -0700)] 
tests: Run regression tests from make check

The existing test-script.sh does not check the return values of the
tests so it is not very good for automated testing.

Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: Execute nft-flowtable-test in test-script.sh
Matt Turner [Wed, 17 Oct 2018 19:32:51 +0000 (12:32 -0700)] 
tests: Execute nft-flowtable-test in test-script.sh

Seems to have been forgotten in commit 4d472c225ba0 ("tests: add
flowtable regression test")

Signed-off-by: Matt Turner <mattst88@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoobj: secmark: remove json stub
Pablo Neira Ayuso [Mon, 15 Oct 2018 12:05:48 +0000 (14:05 +0200)] 
obj: secmark: remove json stub

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: osf: add ttl option support
Fernando Fernandez Mancera [Sat, 29 Sep 2018 10:16:37 +0000 (12:16 +0200)] 
expr: osf: add ttl option support

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: remove json support
Pablo Neira Ayuso [Mon, 8 Oct 2018 22:03:28 +0000 (00:03 +0200)] 
src: remove json support

We have better json support in libnftables these days.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add support for new secmark object
Christian Göttsche [Fri, 28 Sep 2018 16:21:15 +0000 (18:21 +0200)] 
src: add support for new secmark object

The new object will hold security context strings.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: add xfrm support
Florian Westphal [Wed, 5 Sep 2018 09:16:41 +0000 (11:16 +0200)] 
expr: add xfrm support

Joint work with Máté Eckl.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: rt: ipsec match support
Florian Westphal [Wed, 5 Sep 2018 09:16:40 +0000 (11:16 +0200)] 
expr: rt: ipsec match support

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoobj: ct_timeout: fix error in building tests
Harsha Sharma [Wed, 19 Sep 2018 05:10:39 +0000 (10:40 +0530)] 
obj: ct_timeout: fix error in building tests

Add include header for NFTNL_CTTIMEOUT_ARRAY_MAX. Fixes compilation error
"../include/obj.h:43:21: error: ‘NFTNL_CTTIMEOUT_ARRAY_MAX’
undeclared here (not in a function);

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoobj: ct_timeout: don't skip zero value timeout
Pablo Neira Ayuso [Fri, 31 Aug 2018 15:32:16 +0000 (17:32 +0200)] 
obj: ct_timeout: don't skip zero value timeout

It's a valid configuration, don't assume this means timeout is unset.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoobj: ct_timeout: use fixed size array
Pablo Neira Ayuso [Fri, 31 Aug 2018 14:16:40 +0000 (16:16 +0200)] 
obj: ct_timeout: use fixed size array

Use an internal array and expose maximum size so we can just use the
same array size for all protocol timeouts. This simplifies handling
a bit and we don't need to set NFTNL_OBJ_CT_TIMEOUT_L4PROTO in first
place.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoobj: ct_timeout: fix gcc4 build error
Florian Westphal [Tue, 21 Aug 2018 14:56:36 +0000 (16:56 +0200)] 
obj: ct_timeout: fix gcc4 build error

gcc 4.9 only allows for-loop initialisation declarations in C99 or C11 modes.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: remove cttimeout.h leftover
Pablo Neira Ayuso [Tue, 14 Aug 2018 09:30:00 +0000 (11:30 +0200)] 
src: remove cttimeout.h leftover

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexamples: Add test for assigning timeout objects via rule
Harsha Sharma [Fri, 10 Aug 2018 14:57:56 +0000 (20:27 +0530)] 
examples: Add test for assigning timeout objects via rule

Usage:
./nft-rule-ct-timeout-add ip filter input some-name
./nft-rule-get ip filter
ip filter input 4
  [ objref type 7 name some-name ]

nft list ruleset

...
chain input {
       ct timeout set "some-name"
}

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexamples: add nft-ct-timeout-{add,del,get}
Harsha Sharma [Fri, 10 Aug 2018 14:57:07 +0000 (20:27 +0530)] 
examples: add nft-ct-timeout-{add,del,get}

Add, list and delete ct timeout objects from specified table

Usage e.g.:

% ./nft-ct-timeout-add ip filter some-name tcp
% ./nft-ct-timeout-get ip filter
table filter name some-name use 0 [ ct_timeout family 2 protocol 6
policy = {ESTABLISHED = 111,CLOSE_WAIT = 14, CLOSE = 16}]
% ./nft-ct-timeout-del ip filter some-name

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add ct timeout support
Harsha Sharma [Fri, 10 Aug 2018 14:53:39 +0000 (20:23 +0530)] 
src: add ct timeout support

Add support for ct timeout objects, used to assign connection tracking
timeout policies.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: osf: modify _snprintf_default function
Fernando Fernandez Mancera [Tue, 7 Aug 2018 09:42:15 +0000 (11:42 +0200)] 
expr: osf: modify _snprintf_default function

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: add support for matching tunnel metadata
Pablo Neira Ayuso [Mon, 6 Aug 2018 11:35:05 +0000 (13:35 +0200)] 
expr: add support for matching tunnel metadata

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoobj: add tunnel support
Pablo Neira Ayuso [Mon, 6 Aug 2018 11:35:00 +0000 (13:35 +0200)] 
obj: add tunnel support

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: osf: remove json code
Pablo Neira Ayuso [Fri, 3 Aug 2018 10:19:25 +0000 (12:19 +0200)] 
expr: osf: remove json code

This code, which is enabled via --with-json-parsing, doesn't compile.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: add osf support
Fernando Fernandez Mancera [Tue, 24 Jul 2018 23:34:28 +0000 (01:34 +0200)] 
expr: add osf support

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: Add tproxy support
Máté Eckl [Fri, 20 Jul 2018 07:38:24 +0000 (09:38 +0200)] 
expr: Add tproxy support

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosocket: Expose socket mark via socket expression
Máté Eckl [Wed, 11 Jul 2018 22:52:14 +0000 (00:52 +0200)] 
socket: Expose socket mark via socket expression

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoinclude: missing C++ linkage in headers
Pablo Neira Ayuso [Tue, 3 Jul 2018 09:55:18 +0000 (11:55 +0200)] 
include: missing C++ linkage in headers

A few files (batch.h / common.h / set.h / udata.h) are missing the
usual.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1268
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr/exthdr: Fix JSON parsing on big endian
Phil Sutter [Fri, 22 Jun 2018 12:18:59 +0000 (14:18 +0200)] 
expr/exthdr: Fix JSON parsing on big endian

When setting NFTNL_EXPR_EXTHDR_TYPE, one needs to call
nftnl_expr_set_u8() and not nftnl_expr_set_u32(). Otherwise 'type'
variable is assigned to uint32_t parameter before being passed to
nftnl_expr_exthdr_set() as void pointer which casts it to uint8_t.
On big endian systems, the latter would only consider the most
significant byte instead of the least significant one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
7 years agoexpr/data_reg: Fix JSON parsing on big endian
Phil Sutter [Fri, 22 Jun 2018 12:18:58 +0000 (14:18 +0200)] 
expr/data_reg: Fix JSON parsing on big endian

Since reg->len is a 32bit variable, one needs to pass NFTNL_TYPE_U32 to
nftnl_jansson_parse_val(). Otherwise, only the most significant byte in
that variable is being written to.

Since the value could potentially be larger than 255, increase node_name
buffer to avoid a compiler warning.

Signed-off-by: Phil Sutter <phil@nwl.cc>
7 years agoutils: Fix nftnl_get_value() on big endian
Phil Sutter [Fri, 22 Jun 2018 12:18:57 +0000 (14:18 +0200)] 
utils: Fix nftnl_get_value() on big endian

This function basically did:

| memcpy(out, val, <len of requested type>);

which works only for little endian integer types. Fix this by assigning
the 64bit input value to a variable of the right size and use that as
input for above memcpy() call.

Signed-off-by: Phil Sutter <phil@nwl.cc>
7 years agobuild: libnftnl 1.1.1 release libnftnl-1.1.1
Florian Westphal [Fri, 8 Jun 2018 11:03:32 +0000 (13:03 +0200)] 
build: libnftnl 1.1.1 release

Check for libmnl >= 1.0.3 just like nftables does.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoexpr: rt: print tcpmss
Pablo Neira Ayuso [Thu, 7 Jun 2018 15:50:55 +0000 (17:50 +0200)] 
expr: rt: print tcpmss

rt_key2str() should also return the 'tcpmss' case.

Instead of:

  [ rt load unknown => reg 1 ]

print:

  [ rt load tcpmss => reg 1 ]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: extend fwd to support address and protocol
Pablo Neira Ayuso [Wed, 6 Jun 2018 16:44:55 +0000 (18:44 +0200)] 
expr: extend fwd to support address and protocol

To support forwarding through neighbour layer from ingress.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: add connlimit support
Pablo Neira Ayuso [Thu, 31 May 2018 15:46:13 +0000 (17:46 +0200)] 
expr: add connlimit support

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Add support for native socket matching
Máté Eckl [Mon, 28 May 2018 07:15:32 +0000 (09:15 +0200)] 
src: Add support for native socket matching

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoinclude: updated nf_tables.h
Máté Eckl [Mon, 28 May 2018 23:11:44 +0000 (01:11 +0200)] 
include: updated nf_tables.h

Joint work with Pablo.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: add nftnl_rule_list_insert_at()
Pablo Neira Ayuso [Mon, 28 May 2018 15:00:31 +0000 (17:00 +0200)] 
rule: add nftnl_rule_list_insert_at()

Allow to add rule object before any existing rule.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: add map lookups for hash statements
Laura Garcia Liebana [Thu, 10 May 2018 22:15:41 +0000 (00:15 +0200)] 
expr: add map lookups for hash statements

This patch introduces two new attributes for hash expression
to allow map lookups where the hash is the key.

The new attributes are NFTNL_EXPR_HASH_SET_NAME and
NFTNL_EXPR_HASH_SET_ID in order to identify the given map.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexamples: Add test for assigning helper objects via rule
Harsha Sharma [Tue, 8 May 2018 12:51:14 +0000 (18:21 +0530)] 
examples: Add test for assigning helper objects via rule

Usage:
./nft-rule-ct-helper-add ip filter input sip-5060
./nft-rule-get ip filter
ip filter input 7 6
  [ objref type 3 name sip-5060 ]

nft list ruleset

...
chain input {
       ct helper set "sip-5060"
}

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: add map lookups for numgen statements
Laura Garcia Liebana [Sun, 22 Apr 2018 09:04:56 +0000 (11:04 +0200)] 
expr: add map lookups for numgen statements

This patch introduces two new attributes for numgen to allow map
lookups where the number generator will be the key.

Two new attributes needs to be included: NFTNL_EXPR_NG_SET_NAME and
NFTNL_EXPR_NG_SET_ID in order to identify the given map.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agobuild: bump LIBVERSION libnftnl-1.1.0
Florian Westphal [Tue, 1 May 2018 09:10:31 +0000 (11:10 +0200)] 
build: bump LIBVERSION

AC_INIT version was already bumped in 7693a5e293962, not needed.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoudata: refuse to put more than UINT8_MAX bytes
Florian Westphal [Sat, 28 Apr 2018 09:41:23 +0000 (11:41 +0200)] 
udata: refuse to put more than UINT8_MAX bytes

->len is uint8_t, so we can't handle more than this.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoexpr: objref: do not print id
Pablo Neira Ayuso [Wed, 11 Apr 2018 07:52:23 +0000 (09:52 +0200)] 
expr: objref: do not print id

The lookup expression does not do this either, so let's be consistent
and remove it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexamples: nft-flowtable-add: do not use nftnl_flowtable_set_array()
Pablo Neira Ayuso [Tue, 20 Mar 2018 15:32:15 +0000 (16:32 +0100)] 
examples: nft-flowtable-add: do not use nftnl_flowtable_set_array()

Fixes: 62d6fff78b2c ("src: remove set/get array api")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexamples: add nft-ct-helper-{add,get,del}
Yang Zheng [Tue, 20 Mar 2018 14:53:22 +0000 (22:53 +0800)] 
examples: add nft-ct-helper-{add,get,del}

nft-ct-helper-{add,get,del}: add, get, or delete ct helper objects from the specified table.

Examples:
  % ./nft-ct-helper-get ip filter
  <nothing>
  % ./nft-ct-helper-add ip filter sip-5060 sip udp
  % ./nft-ct-helper-get ip filter
  table filter name sip-5060 use 0 [ ct_helper name sip family 2 protocol 17 ]
  % ./nft-ct-helper-del ip filter sip-5060
  % ./nft-ct-helper-get ip filter
  <nothing>

Signed-off-by: Yang Zheng <tomsun.0.7@gmail.com>
Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: remove set/get array api
Florian Westphal [Mon, 12 Mar 2018 11:55:32 +0000 (12:55 +0100)] 
src: remove set/get array api

one-line wrapper, callers can use nftnl_flowtable_get/set instead.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: support for NFT_CT_{SRC,DST}_{IP,IP6}
Pablo Neira Ayuso [Fri, 9 Mar 2018 11:41:43 +0000 (12:41 +0100)] 
src: support for NFT_CT_{SRC,DST}_{IP,IP6}

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoset: fix parsing for set handle attributes
Harsha Sharma [Sun, 11 Mar 2018 13:18:00 +0000 (18:48 +0530)] 
set: fix parsing for set handle attributes

Correct one typo for parsing set handles.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoconfigure: bump library version to 1.1.0
Pablo Neira Ayuso [Tue, 6 Mar 2018 11:02:20 +0000 (12:02 +0100)] 
configure: bump library version to 1.1.0

So new nftables doesn't break compilation with old libnftnl versions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: parse new handle attribute for objects
Harsha Sharma [Thu, 18 Jan 2018 18:51:32 +0000 (00:21 +0530)] 
src: parse new handle attribute for objects

This patch add code to allocate object handles and delete objects via
object handles.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: parse new handle attribute for sets
Harsha Sharma [Sun, 14 Jan 2018 16:43:52 +0000 (22:13 +0530)] 
src: parse new handle attribute for sets

This patch adds code to allocate set handles and delete sets via set
handle.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
7 years agosrc: parse new handle attribute for tables
Harsha Sharma [Sat, 23 Dec 2017 19:44:52 +0000 (11:44 -0800)] 
src: parse new handle attribute for tables

This patch adds code to parse new handle attribute for tables.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: add flowtable regression test
Pablo Neira Ayuso [Mon, 19 Feb 2018 09:34:55 +0000 (10:34 +0100)] 
tests: add flowtable regression test

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoflowtable: support for flags
Pablo Neira Ayuso [Mon, 19 Feb 2018 08:20:23 +0000 (09:20 +0100)] 
flowtable: support for flags

This new attribute allows you to specify the flowtable flags.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoflowtable: allow to specify size
Pablo Neira Ayuso [Mon, 19 Feb 2018 16:20:23 +0000 (17:20 +0100)] 
flowtable: allow to specify size

This new attribute allows you to specify the flowtable size.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexpr: add flow offload expression
Pablo Neira Ayuso [Sun, 3 Dec 2017 20:05:54 +0000 (21:05 +0100)] 
expr: add flow offload expression

This patch adds the new "flow_offload" expression to select what flows
are offloaded to an existing flowtable.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add flowtable support
Pablo Neira Ayuso [Wed, 29 Nov 2017 12:07:02 +0000 (13:07 +0100)] 
src: add flowtable support

This patch allows you to add, delete and list flowtable through the
existing netlink interface.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoset_elem: nftnl_set_elems_parse() returns 0 if set is empty
Pablo Neira Ayuso [Wed, 14 Feb 2018 19:11:18 +0000 (20:11 +0100)] 
set_elem: nftnl_set_elems_parse() returns 0 if set is empty

Instead of -1, which results n misleading error propagate to the caller
with errno == 0 (success).

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoexamples: nft-set-del: fix set deletion
Pablo Neira Ayuso [Wed, 14 Feb 2018 19:03:53 +0000 (20:03 +0100)] 
examples: nft-set-del: fix set deletion

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