]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
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>
9 years agoexpr: add number generation expression
Laura Garcia Liebana [Sun, 14 Aug 2016 14:48:48 +0000 (16:48 +0200)] 
expr: add number generation expression

Support for the nft ng expression within libnftnl.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: add quota expression
Pablo Neira Ayuso [Thu, 18 Aug 2016 16:51:28 +0000 (18:51 +0200)] 
expr: add quota expression

This patch adds support for the new quota expression.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agorule: Fix comparison between rules if number of expressions differ
Carlos Falgueras García [Thu, 18 Aug 2016 15:12:36 +0000 (17:12 +0200)] 
rule: Fix comparison between rules if number of expressions differ

Before this patch, comparison between rules with distinct number of
expressions indicate that they are equals, however, they are not.
Example:

r1[e1, e2] == r2[e1, e2, e3]

Fix this by checking that the number of expression is the same.

Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: Implement rule comparison
Carlos Falgueras García [Wed, 17 Aug 2016 14:07:09 +0000 (16:07 +0200)] 
src: Implement rule comparison

This patch implements the function:

bool nftnl_rule_cmp(const struct nftnl_rule *r1,
    const struct nftnl_rule *r2)

for rule comparison.

Expressions within rules need to be compared, so also has been created the
function:

bool nftnl_expr_cmp(const struct nftnl_expr *e1,
    const struct nftnl_expr *e2);

Also includes all expression comparators.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: add hash expression
Laura Garcia Liebana [Fri, 12 Aug 2016 23:02:03 +0000 (01:02 +0200)] 
expr: add hash expression

Support for the nft hash expression in libnftnl.

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: cmp: Use cmp2str() instead of directly access to array
Carlos Falgueras García [Mon, 15 Aug 2016 10:51:03 +0000 (12:51 +0200)] 
expr: cmp: Use cmp2str() instead of directly access to array

Uses cmp2str() which checks array bounds.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoutils: Fix out of bound access in nftnl_family2str
Carlos Falgueras García [Mon, 15 Aug 2016 10:51:02 +0000 (12:51 +0200)] 
utils: Fix out of bound access in nftnl_family2str

Checks array limits before access it and adds a missed translation.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agotests: masq: Fix wrong expression creation
Carlos Falgueras García [Fri, 12 Aug 2016 20:17:20 +0000 (22:17 +0200)] 
tests: masq: Fix wrong expression creation

The expression should be "masq" not "nat.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoutils: Don't return directly from SNPRINTF_BUFFER_SIZE
Phil Sutter [Fri, 12 Aug 2016 12:39:50 +0000 (14:39 +0200)] 
utils: Don't return directly from SNPRINTF_BUFFER_SIZE

Apart from being a bad idea in general, the return statement contained
in that macro in some cases leads to returning from functions without
properly cleaning up, thereby causing memory leaks.

Instead, just sanitize the value in 'ret' to not harm further calls of
snprintf() (as 'len' will eventually just become zero).

Cc: Arturo Borrero <arturo.borrero.glez@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoRevert "common: Avoid integer overflow in nftnl_batch_is_supported()"
Pablo Neira Ayuso [Fri, 12 Aug 2016 08:39:12 +0000 (10:39 +0200)] 
Revert "common: Avoid integer overflow in nftnl_batch_is_supported()"

This patch accidentally slipped through. The sequence number
(uint32_t)-1 is fine in case time() fails.

So this reverts commit d26feca2c9c19b650b5a7554b5a412ceca990b7a.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoruleset: Initialize ctx.flags before calling nftnl_ruleset_ctx_set()
Phil Sutter [Thu, 11 Aug 2016 23:33:39 +0000 (01:33 +0200)] 
ruleset: Initialize ctx.flags before calling nftnl_ruleset_ctx_set()

The called function otherwise accesses uninitialized data.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: Avoid returning uninitialized data
Phil Sutter [Thu, 11 Aug 2016 23:33:38 +0000 (01:33 +0200)] 
src: Avoid returning uninitialized data

Although the 'err' pointer should be interesting for users only if the
parser returned non-zero, having it point to uninitialized data is
generally a bad thing.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agocommon: Avoid integer overflow in nftnl_batch_is_supported()
Phil Sutter [Thu, 11 Aug 2016 23:33:37 +0000 (01:33 +0200)] 
common: Avoid integer overflow in nftnl_batch_is_supported()

time() may return -1 which is then assigned to an unsigned integer type
and used as sequence number. The following code increments that number
multiple times, so it may overflow and get libmnl confused. To avoid
this, fall back to a starting sequence number of zero in case the call
to time() failed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr/limit: Drop unreachable code in limit_to_type()
Phil Sutter [Thu, 11 Aug 2016 23:33:36 +0000 (01:33 +0200)] 
expr/limit: Drop unreachable code in limit_to_type()

The function returns from inside the switch() in any case, so the final
return statement is never reached.

Fixes: 7769cbd9dfe69 ("expr: limit: add per-byte limiting support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr/ct: prevent array index overrun in ctkey2str()
Phil Sutter [Thu, 11 Aug 2016 23:33:35 +0000 (01:33 +0200)] 
expr/ct: prevent array index overrun in ctkey2str()

The array has NFT_CT_MAX fields, so indices must be less than that
number.

Fixes: 977b7a1dbe1bd ("ct: xml: use key names instead of numbers")
Cc: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset: prevent memleak in nftnl_jansson_parse_set_info()
Phil Sutter [Thu, 11 Aug 2016 23:33:33 +0000 (01:33 +0200)] 
set: prevent memleak in nftnl_jansson_parse_set_info()

During list populating, in error case the function returns without
freeing the newly allocated 'elem' object, thereby losing any references
to it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agotests: Fix tests for immediate and lookup expressions
Carlos Falgueras García [Wed, 10 Aug 2016 12:07:06 +0000 (14:07 +0200)] 
tests: Fix tests for immediate and lookup expressions

An error at Makefile.am has caused that the tests
'nft-expr_immediate-test.c' and 'nft-expr_lookup-tests.c' have not been
compiled since they were created. This patch fix that error and some errors
in both tests.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: Fix lookup builder
Carlos Falgueras García [Wed, 10 Aug 2016 12:07:05 +0000 (14:07 +0200)] 
expr: Fix lookup builder

Deleted wrong braces that cause unwanted behaviour.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
9 years agotests: Add missing tests to test-script.sh
Carlos Falgueras García [Wed, 10 Aug 2016 12:07:04 +0000 (14:07 +0200)] 
tests: Add missing tests to test-script.sh

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agorule: Implement internal iterator for expressions
Carlos Falgueras García [Wed, 10 Aug 2016 09:48:54 +0000 (11:48 +0200)] 
rule: Implement internal iterator for expressions

Introduce nftnl_expr_iter_init() to allow stack allocated iterators for
internal use.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
9 years agosrc: Constify iterators
Carlos Falgueras García [Tue, 9 Aug 2016 11:42:17 +0000 (13:42 +0200)] 
src: Constify iterators

Iterators do not modify objects which they iterate, so input pointer must
be const.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: don't set data_len to zero when returning pointers
Pablo Neira Ayuso [Sun, 31 Jul 2016 20:05:52 +0000 (22:05 +0200)] 
src: don't set data_len to zero when returning pointers

nft already assumes that passing NULL as data_len is valid, otherwise
it crashes. Fix this by leave data_len unset in this specific case.

Fixes: bda7102 ("src: Fix nftnl_*_get_data() to return the real attribute length")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexamples: nft-rule-get: selective rule dumping
Josue Alvarez [Thu, 21 Jul 2016 14:59:41 +0000 (16:59 +0200)] 
examples: nft-rule-get: selective rule dumping

Improve nft-rule-get example to demonstrate selective rule dumping when
table and / or chain attributes are set in a rule dump request.

Usage is now as follows:

nft-rule-get <family> [<table> <chain>] [<xml|json>]

Signed-off-by: Josue Alvarez <jalvarez@toulouse.viveris.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: lookup: print flags only if they are available
Pablo Neira Ayuso [Thu, 21 Jul 2016 17:14:13 +0000 (19:14 +0200)] 
expr: lookup: print flags only if they are available

Follow same approach as with other objects, print what it is set only.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: Fix nftnl_*_get_data() to return the real attribute length
Carlos Falgueras García [Mon, 11 Jul 2016 16:07:40 +0000 (18:07 +0200)] 
src: Fix nftnl_*_get_data() to return the real attribute length

All getters must set the memory size of the attributes, ie. this
includes the nul-termination in strings.

For references to opaque objects hidden behind the curtain, report
a zero size.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: Fix missing nul-termination in nftnl_*_set_str()
Carlos Falgueras García [Tue, 5 Jul 2016 17:15:16 +0000 (19:15 +0200)] 
src: Fix missing nul-termination in nftnl_*_set_str()

The string length must be one character longer to include the
nul-termination.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agotests: Check set user data
Carlos Falgueras García [Mon, 27 Jun 2016 17:05:23 +0000 (19:05 +0200)] 
tests: Check set user data

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset: Add new attribute into 'set' to store user data
Carlos Falgueras García [Mon, 27 Jun 2016 17:05:22 +0000 (19:05 +0200)] 
set: Add new attribute into 'set' to store user data

The new structure 'user' holds a pointer to user data and its length. The
kernel must have the flag NFTA_SET_USERDATA to support this feature.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: lookup: give support for inverted matching
Arturo Borrero [Fri, 24 Jun 2016 07:07:02 +0000 (09:07 +0200)] 
expr: lookup: give support for inverted matching

Inverted matching support was included in the kernel, let's give support here
as well.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset_elem: fix return in several error paths of nftnl_set_elems_parse2()
Pablo Neira Ayuso [Wed, 22 Jun 2016 17:30:21 +0000 (19:30 +0200)] 
set_elem: fix return in several error paths of nftnl_set_elems_parse2()

They don't set ret to anything, and ret is not initialized, so we return
garbage.

Fixes: 59cb13b ("src: fix missing error checking in parser functions")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: fix missing error checking in parser functions
Carlos Falgueras García [Mon, 20 Jun 2016 10:29:19 +0000 (12:29 +0200)] 
src: fix missing error checking in parser functions

Bail out on errors in several nftnl_*_nlmsg_parse() functions. We can
overwrite the previous error value, and may execute code which should
not.

Bad way:
int f() {
int ret;

ret = g();
ret = h();

return ret;
}

Good way:
int f() {
int ret;

ret = g();
if (ret < 0)
return ret;

ret = h();
if (ret < 0)
return ret;

return 0;
}

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agochain: Check correct attribute
Carlos Falgueras García [Thu, 16 Jun 2016 10:20:10 +0000 (12:20 +0200)] 
chain: Check correct attribute

Fix nftnl_chain_set_data() with NFTNL_CHAIN_DEV.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agotests: stricter string attribute validation
Pablo Neira Ayuso [Wed, 15 Jun 2016 11:41:06 +0000 (13:41 +0200)] 
tests: stricter string attribute validation

In nft-expr_lookup-test.c, check for the strings instead of size.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agochain: dynamically allocate name
Pablo Neira Ayuso [Fri, 10 Jun 2016 12:34:10 +0000 (14:34 +0200)] 
chain: dynamically allocate name

Just in case we ever support chain with larger names in the future,
this will ensure the library doesn't break. Although I don't expect
allocating more bytes for this anytime soon, but let's be conservative
here.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agotests: shuffle values that are injected
Pablo Neira Ayuso [Fri, 10 Jun 2016 14:56:46 +0000 (16:56 +0200)] 
tests: shuffle values that are injected

Shuffle value that are used to set attributes, this variability should
help us catch more problems in the future.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: check for flags before releasing attributes
Pablo Neira Ayuso [Fri, 10 Jun 2016 14:45:48 +0000 (16:45 +0200)] 
src: check for flags before releasing attributes

Now that unsetters don't set pointers to NULL, check if the attribute is
set before trying to release it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: simplify unsetters
Pablo Neira Ayuso [Fri, 10 Jun 2016 13:07:13 +0000 (15:07 +0200)] 
src: simplify unsetters

If the attribute is set as we already check at the beginning of this
function, then we can release the object.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: data_reg: get rid of leftover perror() calls
Pablo Neira Ayuso [Fri, 10 Jun 2016 12:49:01 +0000 (14:49 +0200)] 
expr: data_reg: get rid of leftover perror() calls

Let the client of this library decide when to display error messages.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: check for strdup() errors from setters and parsers
Pablo Neira Ayuso [Fri, 10 Jun 2016 12:47:53 +0000 (14:47 +0200)] 
src: check for strdup() errors from setters and parsers

And pass up an error to the caller.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: return value on setters that internally allocate memory
Pablo Neira Ayuso [Fri, 10 Jun 2016 12:30:56 +0000 (14:30 +0200)] 
src: return value on setters that internally allocate memory

So the client can bail out of memory allocation errors. Or in case of
daemon, make sure things are left in consistent state before bailing
out.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: assert when setting unknown attributes
Pablo Neira Ayuso [Fri, 10 Jun 2016 12:13:00 +0000 (14:13 +0200)] 
src: assert when setting unknown attributes

If this attribute is not supported by the library, we should rise an
assertion so the client knows something is wrong, instead of silently
going through.

The only case I can think may hit this problem is version mismatch
between library and tools. This should not ever really happen, so better
bail out from the library itself in this case.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agosrc: Fix leak in nftnl_*_unset()
Carlos Falgueras García [Fri, 10 Jun 2016 12:22:45 +0000 (14:22 +0200)] 
src: Fix leak in nftnl_*_unset()

Fix leak of NFTNL_*_USERDATA from unset() functions.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexpr: payload: don't use deprecated definition NFT_EXPR_PAYLOAD_SREG
Pablo Neira Ayuso [Fri, 10 Jun 2016 12:08:27 +0000 (14:08 +0200)] 
expr: payload: don't use deprecated definition NFT_EXPR_PAYLOAD_SREG

Use NFTNL_EXPR_PAYLOAD_SREG instead.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoexamples: nft-table-upd: don't use deprecated aliases
Pablo Neira Ayuso [Tue, 7 Jun 2016 14:47:38 +0000 (16:47 +0200)] 
examples: nft-table-upd: don't use deprecated aliases

Convert this example not to use the deprecated aliases anymore.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agobuild: update LIBVERSION to prepare a new release libnftnl-1.0.6
Pablo Neira Ayuso [Thu, 26 May 2016 14:35:03 +0000 (16:35 +0200)] 
build: update LIBVERSION to prepare a new release

Bump Current and Age accordingly, given that we got new interfaces.
This git repository shows these changes in the map file since previous
release:

$ git diff libnftnl-1.0.5..HEAD src/libnftnl.map
--- a/src/libnftnl.map
+++ b/src/libnftnl.map
@@ -498,3 +498,33 @@ global:

 local: *;
 };
+
+LIBNFTNL_4.1 {
+       nftnl_trace_alloc;
+       nftnl_trace_free;
+
+       nftnl_trace_is_set;
+
+       nftnl_trace_get_u16;
+       nftnl_trace_get_u32;
+       nftnl_trace_get_u64;
+       nftnl_trace_get_str;
+       nftnl_trace_get_data;
+
+       nftnl_trace_nlmsg_parse;
+
+       nftnl_udata_buf_alloc;
+       nftnl_udata_buf_free;
+       nftnl_udata_buf_len;
+       nftnl_udata_buf_data;
+       nftnl_udata_buf_put;
+       nftnl_udata_start;
+       nftnl_udata_end;
+       nftnl_udata_put;
+       nftnl_udata_put_strz;
+       nftnl_udata_type;
+       nftnl_udata_len;
+       nftnl_udata_get;
+       nftnl_udata_next;
+       nftnl_udata_parse;
+} LIBNFTNL_4;

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset_elem: Copy user data memory
Carlos Falgueras García [Fri, 27 May 2016 14:56:54 +0000 (16:56 +0200)] 
set_elem: Copy user data memory

All attributes are passed by copy, so user data should be copied too.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoset_elem: Fix memory leak
Carlos Falgueras García [Tue, 24 May 2016 15:17:07 +0000 (17:17 +0200)] 
set_elem: Fix memory leak

User data must be freed.

How to reproduce:
    > nft add table t
    > nft add set t s {type ipv4_addr\;}
    > valgrind nft add element t s {1.1.1.1}

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agorule: Fix segfault due to invalid free of rule user data
Carlos Falgueras García [Tue, 17 May 2016 16:00:15 +0000 (18:00 +0200)] 
rule: Fix segfault due to invalid free of rule user data

If the user allocates a nftnl_udata_buf and then passes the TLV data to
nftnl_rule_set_data, the pointer stored in rule.user.data is not the
begining of the allocated block. In this situation, if it calls to
nftnl_rule_free, it tries to free this pointer and segfault is thrown.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agotests: Free nftnl_udata_buf before exit
Carlos Falgueras García [Tue, 17 May 2016 16:00:14 +0000 (18:00 +0200)] 
tests: Free nftnl_udata_buf before exit

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agolibnftnl: gitignore: Fix mistake in gitignore regexp
Carlos Falgueras García [Tue, 17 May 2016 19:11:39 +0000 (21:11 +0200)] 
libnftnl: gitignore: Fix mistake in gitignore regexp

If a whole directory was ignored, files inside it will not be checked.

Fixes: f3d37ef ("libnftnl: Add to .gitignore all auto-generated files")
Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agoinclude: refresh nf_tables.h cache copy
Pablo Neira Ayuso [Tue, 17 May 2016 16:41:33 +0000 (18:41 +0200)] 
include: refresh nf_tables.h cache copy

Refresh the cached header file.

This includes a small fix to avoid this compilation warning after
refreshing the header:

trace.c: In function 'nftnl_trace_parse_attr_cb':
trace.c:87:2: warning: enumeration value 'NFTA_TRACE_PAD' not handled in switch [-Wswitch]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
9 years agolibnftnl: Add to .gitignore all auto-generated files
Carlos Falgueras García [Mon, 16 May 2016 12:39:01 +0000 (14:39 +0200)] 
libnftnl: Add to .gitignore all auto-generated files

It ignores files inside test/ and examples/ except all c code (*.c)
and the Makefile.am.

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