]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
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>
7 years agoexamples: do not call nftnl_batch_is_supported()
Pablo Neira Ayuso [Thu, 1 Feb 2018 18:33:52 +0000 (19:33 +0100)] 
examples: do not call nftnl_batch_is_supported()

This is only required by Linux kernel <= 3.16.x, that's too old and at
that time nft was very limited in term of features, so let's remove this
check from example files.

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

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agobuild: libnftnl 1.0.9 release libnftnl-1.0.9
Pablo Neira Ayuso [Thu, 28 Dec 2017 18:28:54 +0000 (19:28 +0100)] 
build: libnftnl 1.0.9 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: change char * pointer to constant (const char *)
Harsha Sharma [Fri, 29 Dec 2017 06:49:39 +0000 (12:19 +0530)] 
tests: change char * pointer to constant (const char *)

As the parameter for function is pointer to constant, change it to
constant. This fix gcc compilation warning in libnftnl with make check.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Fix exporting symbols with clang
Armin K [Sat, 23 Dec 2017 20:12:04 +0000 (21:12 +0100)] 
src: Fix exporting symbols with clang

When EXPORT_SYMBOL is located after function definition, clang won't
properly export the function, resulting in a library with no symbols
when built with clang.

Based on libmnl commit dcdb47373a37 ("Move declaration of visibility
attributes before definition.")

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1205
Signed-off-by: Armin K <krejzi@email.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodata_reg: calm down compilation warning in nftnl_data_reg_value_json_parse()
Pablo Neira Ayuso [Thu, 28 Dec 2017 18:17:34 +0000 (19:17 +0100)] 
data_reg: calm down compilation warning in nftnl_data_reg_value_json_parse()

expr/data_reg.c: In function 'nftnl_data_reg_json_parse':
expr/data_reg.c:69:27: warning: '%d' directive writing between 1 and 10 bytes into a region of size 2 [-Wformat-overflow=]
   sprintf(node_name, "data%d", i);
                           ^~
expr/data_reg.c:69:22: note: directive argument in the range [0, 2147483647]
   sprintf(node_name, "data%d", i);

Buffer overflow is triggerable when reg->len > 396, but len never goes
over 128 due to type validation just a bit before.

Use snprintf() and make sure buffer is large enough to store the
"data256" string.

Reported-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agotrace: Check return value of mnl_attr_parse_nested()
Phil Sutter [Thu, 14 Dec 2017 19:40:25 +0000 (20:40 +0100)] 
trace: Check return value of mnl_attr_parse_nested()

This is done everywhere else as well, so certainly not a bad thing here
either.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoset_elem: Don't return garbage in nftnl_set_elems_parse()
Phil Sutter [Thu, 14 Dec 2017 19:40:24 +0000 (20:40 +0100)] 
set_elem: Don't return garbage in nftnl_set_elems_parse()

This might happen if netlink message is malformed (no nested attributes
are present), so treat this as an error and return -1 instead of
garbage to caller.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoruleset: Avoid reading garbage in nftnl_ruleset_cb()
Phil Sutter [Thu, 14 Dec 2017 19:40:23 +0000 (20:40 +0100)] 
ruleset: Avoid reading garbage in nftnl_ruleset_cb()

If nftnl_ruleset_json_parse() is called with arg == NULL, ctx.data is
left uninitialized and will later be used in nftnl_ruleset_cb(). Avoid
this by using a C99-style initializer for 'ctx' which sets all omitted
fields to zero.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoobject: Avoid returning garbage in nftnl_obj_do_parse()
Phil Sutter [Thu, 14 Dec 2017 19:40:22 +0000 (20:40 +0100)] 
object: Avoid returning garbage in nftnl_obj_do_parse()

It may happen that 'perr' variable does not get initialized, so making
parameter 'err' point to it in any case is error-prone. Avoid this by
initializing 'perr' upon declaration.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agogen: Remove a pointless call to mnl_nlmsg_get_payload()
Phil Sutter [Thu, 14 Dec 2017 19:40:21 +0000 (20:40 +0100)] 
gen: Remove a pointless call to mnl_nlmsg_get_payload()

It is a common idiom in all *_nlmsg_parse() functions, but
nftnl_gen_nlmsg_parse() doesn't make use of the data pointer and the
compiler probably can't eliminate it since there could be a side-effect.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agodata_reg: Add a missing break in nftnl_data_reg_snprintf
Phil Sutter [Thu, 14 Dec 2017 19:40:20 +0000 (20:40 +0100)] 
data_reg: Add a missing break in nftnl_data_reg_snprintf

The code works fine as-is, but if reg_type == DATA_VALUE &&
output_format == NFTNL_OUTPUT_XML, we fall through to DATA_CHAIN case
and therefore pointlessly check output_format again.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoexpr: Introduce nftnl_expr_fprintf()
Phil Sutter [Tue, 17 Oct 2017 13:17:41 +0000 (15:17 +0200)] 
expr: Introduce nftnl_expr_fprintf()

Implement expression printing into a FILE pointer analogous to
nftnl_rule_fprintf().

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agobuild: libnftnl 1.0.8 release libnftnl-1.0.8
Pablo Neira Ayuso [Wed, 4 Oct 2017 13:22:00 +0000 (15:22 +0200)] 
build: libnftnl 1.0.8 release

907a9f8e5a93 ("src: get rid of aliases and compat") already updated
LIBVERSION when symbol aliases have been dropped.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: do not nul-terminate internal helper functions
Pablo Neira Ayuso [Wed, 4 Oct 2017 12:11:43 +0000 (14:11 +0200)] 
src: do not nul-terminate internal helper functions

Public API already does this for us, no need to do this again from
internal helper functions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: no need to nul-terminate buffer for nftnl_fprintf() calls
Pablo Neira Ayuso [Wed, 4 Oct 2017 11:58:53 +0000 (13:58 +0200)] 
src: no need to nul-terminate buffer for nftnl_fprintf() calls

This function bails out with -1 if we cannot print, and this buffer is
internally allocated. No need for this overly deffensive initialization.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoexpr: no need to nul-terminate buffer from expression ->snprintf indirection
Pablo Neira Ayuso [Wed, 4 Oct 2017 11:19:10 +0000 (13:19 +0200)] 
expr: no need to nul-terminate buffer from expression ->snprintf indirection

->snprintf() is always called via nftnl_expr_snprintf() wrapper, which
is already dealing with this corner case for us.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agobuffer: use nftnl_expr_snprintf() from nftnl_buf_expr()
Pablo Neira Ayuso [Wed, 4 Oct 2017 11:24:02 +0000 (13:24 +0200)] 
buffer: use nftnl_expr_snprintf() from nftnl_buf_expr()

This helper function deals with no ->snprintf() indirection in
expression and safe buffer nul-termination, use it.

Fixes: 059b9bf6fb31 ("src: Use nftnl_buf to export XML/JSON rules")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: Buffer is null terminated.
Varsha Rao [Wed, 20 Sep 2017 16:23:09 +0000 (21:53 +0530)] 
src: Buffer is null terminated.

In _snprintf() functions definition the buffer is null terminated.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: Change parameters of SNPRINTF_BUFFER_SIZE macro.
Varsha Rao [Wed, 20 Sep 2017 16:23:08 +0000 (21:53 +0530)] 
src: Change parameters of SNPRINTF_BUFFER_SIZE macro.

SNPRINTF_BUFFER_SIZE() macro declaration and definition is changed so
that it accepts three arguments ret, remain and offset. Parameters size
and len are not required instead parameter remain keeps track of
available space in the buffer.

Signed-off-by: Varsha Rao <rvarsha016@gmail.com>
8 years agochain: Don't print unset policy value in netlink debug
Phil Sutter [Thu, 7 Sep 2017 17:41:27 +0000 (19:41 +0200)] 
chain: Don't print unset policy value in netlink debug

The policy field was printed unconditionally, but if it wasn't set the
default value 0 was printed as 'policy drop' which is not correct.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoexamples: Fix memory leaks detected by Valgrind
Shyam Saini [Tue, 29 Aug 2017 12:49:36 +0000 (18:19 +0530)] 
examples: Fix memory leaks detected by Valgrind

==11688== HEAP SUMMARY:
==11688==     in use at exit: 40 bytes in 1 blocks
==11688==   total heap usage: 7 allocs, 6 frees, 220 bytes allocated
==11688==
==11688== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
==11688==    at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11688==    by 0x5068955: mnl_nlmsg_batch_start (nlmsg.c:441)
==11688==    by 0x40133B: main (nft-chain-add.c:103)
==11688==
==11688== LEAK SUMMARY:
==11688==    definitely lost: 40 bytes in 1 blocks
==11688==    indirectly lost: 0 bytes in 0 blocks
==11688==      possibly lost: 0 bytes in 0 blocks
==11688==    still reachable: 0 bytes in 0 blocks
==11688==         suppressed: 0 bytes in 0 blocks

==11831== HEAP SUMMARY:
==11831==     in use at exit: 40 bytes in 1 blocks
==11831==   total heap usage: 7 allocs, 6 frees, 220 bytes allocated
==11831==
==11831== 40 bytes in 1 blocks are definitely lost in loss record 1 of 1
==11831==    at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11831==    by 0x5068955: mnl_nlmsg_batch_start (nlmsg.c:441)
==11831==    by 0x401154: main (nft-chain-del.c:79)
==11831==
==11831== LEAK SUMMARY:
==11831==    definitely lost: 40 bytes in 1 blocks
==11831==    indirectly lost: 0 bytes in 0 blocks
==11831==      possibly lost: 0 bytes in 0 blocks
==11831==    still reachable: 0 bytes in 0 blocks
==11831==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: limit stateful object support
Pablo M. Bermudo Garay [Wed, 23 Aug 2017 20:42:24 +0000 (22:42 +0200)] 
src: limit stateful object support

This patch adds support for a new type of stateful object: limit.

Signed-off-by: Pablo M. Bermudo Garay <pablombg@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agort: tcpmss get support
Florian Westphal [Fri, 28 Jul 2017 10:29:35 +0000 (12:29 +0200)] 
rt: tcpmss get support

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoexthdr: tcp option set support
Florian Westphal [Wed, 7 Jun 2017 10:40:16 +0000 (12:40 +0200)] 
exthdr: tcp option set support

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoset: free user data
Eric Leblond [Thu, 6 Jul 2017 12:58:27 +0000 (13:58 +0100)] 
set: free user data

This was causing a memory leak when using set.

Catched by an ASAN run:

==21004==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 12 byte(s) in 2 object(s) allocated from:
    #0 0x4cde58 in malloc (/usr/local/sbin/nft+0x4cde58)
    #1 0x7ffff79b8c19 in nftnl_set_set_data /home/eric/git/netfilter/libnftnl/src/set.c:179

8 years agoct: rename eventmask to event
Florian Westphal [Wed, 7 Jun 2017 10:40:45 +0000 (12:40 +0200)] 
ct: rename eventmask to event

Pablo suggested this for consistency; ct status isn't named statusmask either.

Signed-off-by: Florian Westphal <fw@strlen.de>
8 years agosrc: ct eventmask support
Florian Westphal [Wed, 15 Mar 2017 13:49:00 +0000 (14:49 +0100)] 
src: ct eventmask support

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: ct helper support
Florian Westphal [Sun, 19 Feb 2017 21:49:51 +0000 (22:49 +0100)] 
src: ct helper support

add support for ct helper objects, these are used to assign helpers to
connections, similar to iptables -j CT --set-helper target.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoobject: extend set/get api for u8/u16 types
Florian Westphal [Mon, 20 Feb 2017 15:14:42 +0000 (16:14 +0100)] 
object: extend set/get api for u8/u16 types

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoexpr: exthdr: Display NFT_EXTHDR_F_PRESENT in debug output
Phil Sutter [Sat, 11 Mar 2017 13:27:23 +0000 (14:27 +0100)] 
expr: exthdr: Display NFT_EXTHDR_F_PRESENT in debug output

This allows to assert it in testsuite also.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agofib: Add support for NFTA_FIB_F_PRESENT flag
Phil Sutter [Sat, 11 Mar 2017 13:27:16 +0000 (14:27 +0100)] 
fib: Add support for NFTA_FIB_F_PRESENT flag

Reflect existence of flag in debug output so testsuite can check for it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoudata: add nftnl_udata_put_u32() and nftnl_udata_get_u32()
Pablo Neira Ayuso [Mon, 6 Mar 2017 13:27:24 +0000 (14:27 +0100)] 
udata: add nftnl_udata_put_u32() and nftnl_udata_get_u32()

Add new helper function to put and to fetch tlv that comes with u32
payload.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoexpr: hash: support of symmetric hash
Laura Garcia Liebana [Thu, 23 Feb 2017 11:11:08 +0000 (12:11 +0100)] 
expr: hash: support of symmetric hash

This patch provides symmetric hash support according to source
ip address and port, and destination ip address and port.

The new attribute NFTA_HASH_TYPE has been included to support
different types of hashing functions. Currently supported
NFT_HASH_JENKINS through jhash and NFT_HASH_SYM through symhash.

The main difference between both types are:
 - jhash requires an expression with sreg, symhash doesn't.
 - symhash supports modulus and offset, but not seed.

Examples:

 nft add rule ip nat prerouting ct mark set jhash ip saddr mod 2
 nft add rule ip nat prerouting ct mark set symhash mod 2

Signed-off-by: Laura Garcia Liebana <laura.garcia@zevenet.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: Use nftnl_buf to export XML/JSON rules
Elise Lennion [Thu, 2 Mar 2017 18:34:13 +0000 (15:34 -0300)] 
src: Use nftnl_buf to export XML/JSON rules

This completes the use of nftnl_buf and its auxiliary functions to
export XML/JSON rules.

Highly based on work from Shivani Bhardwaj <shivanib134@gmail.com>.

Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoobject: fix crash when object ops is null
Florian Westphal [Sun, 19 Feb 2017 21:59:42 +0000 (22:59 +0100)] 
object: fix crash when object ops is null

when debugging nft with invalid object type (during development),
this will crash here with null deref.  Print (unknown) instead
if obj->ops is null.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoobject: don't set NFTNL_OBJ_TYPE unless obj->ops is non-null
Florian Westphal [Sun, 19 Feb 2017 17:19:03 +0000 (18:19 +0100)] 
object: don't set NFTNL_OBJ_TYPE unless obj->ops is non-null

If nft sets an invalid type, nftnl_obj_ops_lookup will return NULL.
In this case we must not set NFTNL_OBJ_TYPE flag, else we later get
crash in nftnl_obj_nlmsg_build_payload as it dereferences obj->ops.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoexthdr: remove unused variable uval8
Alexander Alemayhu [Thu, 23 Feb 2017 22:33:06 +0000 (23:33 +0100)] 
exthdr: remove unused variable uval8

Was added but not used in d7b451fe1a45 (src: add TCP option matching
requirements, 2017-02-07). Fixes the following warning:

expr/exthdr.c: In function ‘nftnl_expr_exthdr_json_parse’:
expr/exthdr.c:244:10: warning: unused variable ‘uval8’ [-Wunused-variable]
  uint8_t uval8;
          ^~~~~

Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
8 years agosrc: ct: add zone support
Florian Westphal [Tue, 17 Jan 2017 13:54:12 +0000 (14:54 +0100)] 
src: ct: add zone support

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agorule: add NFTA_RULE_ID attribute
Pablo Neira Ayuso [Thu, 16 Feb 2017 13:27:57 +0000 (14:27 +0100)] 
rule: add NFTA_RULE_ID attribute

This patch adds the new NFTA_RULE_ID attribute.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agocommon: return nlmsghdr in nftnl_batch_{begin,end}()
Pablo Neira Ayuso [Thu, 16 Feb 2017 13:27:53 +0000 (14:27 +0100)] 
common: return nlmsghdr in nftnl_batch_{begin,end}()

Useful to append netlink attributes after the batch headers.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agocommon: get rid of nftnl_batch_build_hdr()
Pablo Neira Ayuso [Thu, 16 Feb 2017 13:27:45 +0000 (14:27 +0100)] 
common: get rid of nftnl_batch_build_hdr()

Add __nftnl_nlmsg_build_hdr() so nftnl_batch_build_hdr() and
nftnl_nlmsg_build_hdr() share the same code.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoexthdr: Add missing exthdr flags cases
Phil Sutter [Thu, 16 Feb 2017 11:32:24 +0000 (12:32 +0100)] 
exthdr: Add missing exthdr flags cases

Looks like some chunks went by the board while merging with exthdr->op
patch.

Fixes: 4196376330468 ("exthdr: Add support for exthdr flags")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
8 years agoexthdr: Add support for exthdr flags
Phil Sutter [Tue, 17 Jan 2017 21:55:00 +0000 (22:55 +0100)] 
exthdr: Add support for exthdr flags

Along with the actual support for exthdr expression specific flags, this
also declares NFT_EXTHDR_F_PRESENT used for exthdr existence match.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoinclude: refresh nf_tables.h copy
Pablo Neira Ayuso [Wed, 15 Feb 2017 10:37:58 +0000 (11:37 +0100)] 
include: refresh nf_tables.h copy

Fetch what we have in the kernel tree.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: add TCP option matching requirements
Manuel Messner [Tue, 7 Feb 2017 02:15:18 +0000 (03:15 +0100)] 
src: add TCP option matching requirements

This patch is a requirement of the TCP option patch.

Signed-off-by: Manuel Messner <mm@skelett.io>
Signed-off-by: Florian Westphal <fw@strlen.de>
8 years agoexamples: Remove the use of nftnl_mnl_batch_put()
Elise Lennion [Thu, 12 Jan 2017 19:22:55 +0000 (17:22 -0200)] 
examples: Remove the use of nftnl_mnl_batch_put()

use nftnl_batch_begin() and nftnl_batch_end() instead, to keep examples
consistent and avoid code duplication.

Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agoexpr: Add const qualifiers to *2str translation arrays
Tobias Klauser [Fri, 13 Jan 2017 10:50:09 +0000 (11:50 +0100)] 
expr: Add const qualifiers to *2str translation arrays

Add const qualifiers to the "to string" translation arrays used by
various *2str() functions.

This fixes GCC warnings such as the following when compiling with
-Wwrite-strings:

  expr/byteorder.c:176:25: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

In order to catch these in the future, also add -Wwrite-strings to
default CFLAGS.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
8 years agosrc: ct: add average bytes per packet counter support
Liping Zhang [Sun, 25 Dec 2016 12:02:20 +0000 (20:02 +0800)] 
src: ct: add average bytes per packet counter support

Similar to ct packets/bytes ...

Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: get rid of aliases and compat
Pablo Neira Ayuso [Tue, 20 Dec 2016 12:47:11 +0000 (13:47 +0100)] 
src: get rid of aliases and compat

This machinery was introduced to avoid sudden compilation breakage of
old nftables releases. With the upcoming release of 0.7 (and 0.6 which
is now 6 months old) this is not required anymore. Moreover, users gain
nothing from older releases since they are half-boiled and buggy.

So let's get rid of aliases now. Bump LIBVERSION and update map file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoinclude: Missing nf_log.h in Makefile libnftnl-1.0.7
Pablo Neira Ayuso [Mon, 19 Dec 2016 22:08:36 +0000 (23:08 +0100)] 
include: Missing nf_log.h in Makefile

Otherwise, make distcheck breaks.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agobuild: update LIBVERSION to prepare a new release
Pablo Neira Ayuso [Mon, 19 Dec 2016 18:08:32 +0000 (19:08 +0100)] 
build: update LIBVERSION to prepare a new release

New interfaces has been added (bump revision), and no interfaces were
removed (bump age). Update version: 1.0.7.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoquota: support for consumed bytes
Pablo Neira Ayuso [Fri, 2 Dec 2016 13:41:36 +0000 (14:41 +0100)] 
quota: support for consumed bytes

This patch extends the quota support to account for consumed bytes.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: objref: add support for stateful object maps
Pablo Neira Ayuso [Sun, 27 Nov 2016 22:27:11 +0000 (23:27 +0100)] 
expr: objref: add support for stateful object maps

If the NFT_SET_OBJECT flag is set, then this set stores a mapping
between any random user-defined arbitrary key and one stateful object.
Very useful for performance lookups.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset_elem: add NFTNL_SET_ELEM_OBJREF attribute
Pablo Neira Ayuso [Sun, 27 Nov 2016 22:27:07 +0000 (23:27 +0100)] 
set_elem: add NFTNL_SET_ELEM_OBJREF attribute

This new attribute allows us to attach stateful objects to elements for
map lookups. This new attribute identifies the object through its name.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset: add NFTNL_SET_OBJ_TYPE attribute
Pablo Neira Ayuso [Sun, 27 Nov 2016 22:27:04 +0000 (23:27 +0100)] 
set: add NFTNL_SET_OBJ_TYPE attribute

This new attribute specifies the stateful object type this set stores.
Similar to data type, but specific to store objects. You must set the
NFT_SET_OBJECT flag to use this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: add stateful object reference expression
Pablo Neira Ayuso [Sun, 27 Nov 2016 22:27:00 +0000 (23:27 +0100)] 
expr: add stateful object reference expression

This patch adds a new "objref" expression that you can use to refer to
stateful objects from rules.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: support for stateful objects
Pablo Neira Ayuso [Sun, 27 Nov 2016 22:26:56 +0000 (23:26 +0100)] 
src: support for stateful objects

This patch allows you to add, to delete and to get stateful objects,
this support two object types: counter and quota.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoinclude: fetch stateful object updates for nf_tables.h cache copy
Pablo Neira Ayuso [Tue, 29 Nov 2016 20:52:57 +0000 (21:52 +0100)] 
include: fetch stateful object updates for nf_tables.h cache copy

This patch includes updates for the stateful objects.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset_elem: nftnl_set_elems_nlmsg_build_payload_iter()
Pablo Neira Ayuso [Mon, 5 Dec 2016 22:00:45 +0000 (23:00 +0100)] 
set_elem: nftnl_set_elems_nlmsg_build_payload_iter()

Similar to a24e4b21ee33 ("set_elem: don't add NFTA_SET_ELEM_LIST_ELEMENTS
attribute if set is empty"). This is required by the set flush support.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: payload: add NFTNL_EXPR_PAYLOAD_FLAGS
Pablo Neira Ayuso [Thu, 24 Nov 2016 11:08:52 +0000 (12:08 +0100)] 
expr: payload: add NFTNL_EXPR_PAYLOAD_FLAGS

So we can include the new NFT_PAYLOAD_L4CSUM_PSEUDOHDR flag.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexamples: nft-set-elem-add: add missing batch logic
Pablo Neira Ayuso [Wed, 30 Nov 2016 21:07:32 +0000 (22:07 +0100)] 
examples: nft-set-elem-add: add missing batch logic

This example is broken since batch logic in missing. Update it to add
element of 2 bytes so this works with nft-set-add.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexamples: nft-set-add: update it to add a set that stores port numbers
Pablo Neira Ayuso [Wed, 30 Nov 2016 21:05:54 +0000 (22:05 +0100)] 
examples: nft-set-add: update it to add a set that stores port numbers

This patch updates the existing example to add a set that stores port
numbers. In order to interoperate with the nft tool, we use the datatype
numbers defined there.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexamples: add nft-map-add
Pablo Neira Ayuso [Wed, 30 Nov 2016 19:32:32 +0000 (20:32 +0100)] 
examples: add nft-map-add

Place an example to add a map in the libnftnl tree.

Reported-by: Khawar Shehzad <shehzad.khawar@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: call expr->ops->snprintf only if defined
Pablo Neira Ayuso [Tue, 29 Nov 2016 20:34:31 +0000 (21:34 +0100)] 
expr: call expr->ops->snprintf only if defined

The notrack expression comes with no ->ops->snprintf, so skip this from
nftnl_expr_snprintf() if not set.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoinclude: refresh nf_tables.h cache copy
Pablo Neira Ayuso [Thu, 24 Nov 2016 11:06:25 +0000 (12:06 +0100)] 
include: refresh nf_tables.h cache copy

Fetch what we have at 4.9-rc6.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: missing offset handling for snprintf() in hash and numgen
Pablo Neira Ayuso [Mon, 31 Oct 2016 12:30:31 +0000 (13:30 +0100)] 
expr: missing offset handling for snprintf() in hash and numgen

Fix incorrect output when offset attribute is unset.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: add fib expression
Florian Westphal [Wed, 14 Sep 2016 09:41:26 +0000 (11:41 +0200)] 
expr: add fib expression

Allows to query fib for output interface and route type of a packets
source or destination address.

Scheduled for Linux 4.10.

Signed-off-by: Florian Westphal <fw@strlen.de>
9 years agosrc: introduce rt expression
Anders K. Pedersen [Fri, 28 Oct 2016 05:55:33 +0000 (05:55 +0000)] 
src: introduce rt expression

Introduce support for rt expression for routing related data as implemented
in kernel.

Signed-off-by: Anders K. Pedersen <akp@cohaesio.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: add notrack expression
Pablo Neira Ayuso [Thu, 20 Oct 2016 15:43:26 +0000 (17:43 +0200)] 
src: add notrack expression

Register this simple expression with no attributes. Make sure libnftnl
doesn't crash when no build and parse indirections are defined, as it
is the case for this expression.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: update Arturo Borrero Gonzalez email
Arturo Borrero Gonzalez [Mon, 10 Oct 2016 10:26:34 +0000 (12:26 +0200)] 
src: update Arturo Borrero Gonzalez email

Update Arturo Borrero Gonzalez email address.

Signed-off-by: Arturo Borrero Gonzalez <arturo@debian.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset_elem: don't add NFTA_SET_ELEM_LIST_ELEMENTS attribute if set is empty
Pablo Neira Ayuso [Tue, 4 Oct 2016 06:48:37 +0000 (08:48 +0200)] 
set_elem: don't add NFTA_SET_ELEM_LIST_ELEMENTS attribute if set is empty

If the set is empty, don't send an empty NFTA_SET_ELEM_LIST_ELEMENTS
netlink attributes with no elements.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: add range expression
Pablo Neira Ayuso [Tue, 20 Sep 2016 15:53:21 +0000 (17:53 +0200)] 
src: add range expression

Add range expression available that is scheduled for linux kernel 4.9.
This range expression allows us to check if a given value placed in a
register is within/outside a specified interval.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: log: complete log flags support
Liping Zhang [Sun, 25 Sep 2016 08:54:35 +0000 (16:54 +0800)] 
expr: log: complete log flags support

If NFTNL_EXPR_LOG_FLAGS is not set, it's unnecessary to print out the
flags value. Furthermore, it's better to print out string message
instead of the hex value.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: log: do not print prefix if it is not set
Liping Zhang [Sun, 25 Sep 2016 08:54:34 +0000 (16:54 +0800)] 
expr: log: do not print prefix if it is not set

This will avoid the following ugly display output:
  [ log prefix (null) ]

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: log: fix typo in nftnl_expr_log_export
Liping Zhang [Sun, 25 Sep 2016 08:54:33 +0000 (16:54 +0800)] 
expr: log: fix typo in nftnl_expr_log_export

After test NFTNL_EXPR_LOG_FLAGS is set, we should put "log->flags"
instead of "log->level".

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: display offset only if present in hash and numgen expressions
Pablo Neira Ayuso [Fri, 23 Sep 2016 08:16:53 +0000 (10:16 +0200)] 
src: display offset only if present in hash and numgen expressions

So nft payload python tests don't break.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: remove libmxml support
Arturo Borrero [Thu, 22 Sep 2016 14:58:13 +0000 (16:58 +0200)] 
src: remove libmxml support

This patch removes the libmxml integration in libnftnl, since we have
JSON in place and there is no need to support two at the same time.

The JSON support is much better, for example libjansson has a better
parsing error reporting.

Moreover, libmxml 2.10 breaks the integration with libnftnl somehow,
as reported in Debian bug #83870 [0].

Also, the XML support inside libnftnl has never been in good shape, with
several tiny inconsitencies.

[0] https://bugs.debian.org/838370

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: queue: add NFTA_QUEUE_SREG_QNUM attr support
Liping Zhang [Wed, 14 Sep 2016 15:45:44 +0000 (23:45 +0800)] 
expr: queue: add NFTA_QUEUE_SREG_QNUM attr support

After adding _SREG_QNUM attr, queuenum is not must option anymore,
so we must test NFTNL_EXPR_QUEUE_NUM first before dumpping queue num
in snprintf_default. Also add a tailing space in snprintf_default,
this is consistent with other expressions.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: numgen: add number generation offset
Laura Garcia Liebana [Tue, 13 Sep 2016 11:50:41 +0000 (13:50 +0200)] 
expr: numgen: add number generation offset

Add support to pass through an offset value to the counter
initialization. With this feature, the sysadmin is able to apply a value
to be added to the generated number.

Example:

meta mark set numgen inc mod 2 offset 100

This will generate marks with series 100, 101, 100, 101, ...

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: hash: Add offset to hash value
Laura Garcia Liebana [Mon, 5 Sep 2016 08:55:03 +0000 (10:55 +0200)] 
expr: hash: Add offset to hash value

Add support to pass through an offset to the hash value. With this
feature, the sysadmin is able to generate a hash with a given
started value.

Example:

meta mark set jhash ip saddr mod 2 seed 0xabcd offset 100

This option generates marks according to the source address from 100 to
101.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agotests: queue: add missing NFTNL_EXPR_QUEUE_FLAGS compare test
Liping Zhang [Sun, 11 Sep 2016 14:11:23 +0000 (22:11 +0800)] 
tests: queue: add missing NFTNL_EXPR_QUEUE_FLAGS compare test

We forgot to compare NFTNL_EXPR_QUEUE_FLAGS between two exprs,
now add it.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: queue: remove redundant NFTNL_EXPR_QUEUE_NUM set in json parse
Liping Zhang [Sun, 11 Sep 2016 14:11:22 +0000 (22:11 +0800)] 
expr: queue: remove redundant NFTNL_EXPR_QUEUE_NUM set in json parse

We have already set NFTNL_EXPR_QUEUE_NUM when parse "num" successfully,
here is wrong and redundant, remove it.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: numgen: Rename until attribute by modulus
Laura Garcia Liebana [Wed, 7 Sep 2016 12:29:45 +0000 (14:29 +0200)] 
expr: numgen: Rename until attribute by modulus

The _modulus_ attribute will be reused as _until_, as it's similar to
other expressions with value limits (ex. hash).

Renaming is possible according to the kernel module ntf_numgen that has
not been released yet.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agotrace: use get_u32 to parse NFPROTO and POLICY attribute
Liping Zhang [Fri, 2 Sep 2016 12:51:26 +0000 (20:51 +0800)] 
trace: use get_u32 to parse NFPROTO and POLICY attribute

NFTA_TRACE_NFPROTO and NFTA_TRACE_POLICY attribute is 32-bit
value, so we should use mnl_attr_get_u32 and htonl here.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
9 years agoinclude: resync nf_tables.h cache copy
Pablo Neira Ayuso [Wed, 31 Aug 2016 15:07:01 +0000 (17:07 +0200)] 
include: resync nf_tables.h cache copy

Sync this with the kernel header file we currently have in tree.

This patch addresses the compilation warning and breakage as result of
this header update, specifically the "attibute" typo in trace and
missing default case in expr/numgen.c.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset: fix incorrect maximum set description attribute
Pablo Neira Ayuso [Tue, 30 Aug 2016 15:24:46 +0000 (17:24 +0200)] 
set: fix incorrect maximum set description attribute

Maximum set description attribute is NFTA_SET_DESC_MAX, instead of
NFTA_SET_MAX.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: numgen: add missing nftnl_expr_ng_cmp()
Pablo Neira Ayuso [Tue, 30 Aug 2016 14:15:46 +0000 (16:15 +0200)] 
expr: numgen: add missing nftnl_expr_ng_cmp()

This patch adds the missing comparator interface, most likely due to
race between the patchset that has added this and the introduction of
numgen.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: hash: missing trailing space and modulus in hexadecimal in snprintf
Pablo Neira Ayuso [Tue, 30 Aug 2016 10:18:20 +0000 (12:18 +0200)] 
expr: hash: missing trailing space and modulus in hexadecimal in snprintf

Before patch:

[ hash reg 1 = jhash(reg 2, 8, 3735928559) % modulus 2]

After patch:

[ hash reg 1 = jhash(reg 2, 8, 0xdeadbeef) % mod 2 ]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: numgen: add missing trailing whitespace
Pablo Neira Ayuso [Tue, 30 Aug 2016 10:16:29 +0000 (12:16 +0200)] 
expr: numgen: add missing trailing whitespace

Before patch:

  [ numgen reg 1 = inc(2)]

After patch:

  [ numgen reg 1 = inc(2) ]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: numgen: use switch to handle numgen types from snprintf
Pablo Neira Ayuso [Tue, 30 Aug 2016 10:14:05 +0000 (12:14 +0200)] 
expr: numgen: use switch to handle numgen types from snprintf

Use switch instead of if branch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: immediate: Fix verdict comparison
Carlos Falgueras García [Fri, 26 Aug 2016 13:49:22 +0000 (15:49 +0200)] 
expr: immediate: Fix verdict comparison

An immediate expression of type 'DATA_VERDICT' can have set a chain (jump
or goto), in this cases we must compare its 'union nftnl_data_reg' using
'DATA_CHAIN' flag instead of 'DATA_VERDICT'

Before this patch compare expressions "jump -> chain_a" and
"jump -> chain_b" returns they are equals.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: data_reg: Fix DATA_CHAIN comparison
Carlos Falgueras García [Wed, 24 Aug 2016 12:22:16 +0000 (14:22 +0200)] 
expr: data_reg: Fix DATA_CHAIN comparison

Split DATA_VERDICT and DATA_CHAIN comparison. A verdict can have a NULL
chain (accept, drop, etc) so segfault will happen when strcmp is called.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>