]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
3 years agorule, set_elem: remove trailing \n in userdata snprintf
Pablo Neira Ayuso [Wed, 31 Aug 2022 14:52:51 +0000 (16:52 +0200)] 
rule, set_elem: remove trailing \n in userdata snprintf

212479ad2c92 ("rule, set_elem: fix printing of user data") uncovered
another an extra line break in the userdata printing, remove it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agorule, set_elem: fix printing of user data
Jeremy Sowden [Sat, 27 Aug 2022 17:17:17 +0000 (18:17 +0100)] 
rule, set_elem: fix printing of user data

Hitherto, alphanumeric characters have been printed as-is, but anything
else was replaced by '\0'.  However, this effectively truncates the
output.  Instead, print any printable character as-is and print anything
else as a hexadecimal escape sequence:

  userdata = { \x01\x04\x01\x00\x00\x00 }

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: libnftnl 1.2.3 release libnftnl-1.2.3
Pablo Neira Ayuso [Tue, 9 Aug 2022 18:23:55 +0000 (20:23 +0200)] 
build: libnftnl 1.2.3 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agobuild: fix clang+glibc snprintf substitution error
Nicholas Vinson [Wed, 15 Jun 2022 11:35:28 +0000 (07:35 -0400)] 
build: fix clang+glibc snprintf substitution error

When building with clang and glibc and -D_FORTIFY_SOURCE=2 is passed to
clang, the snprintf member of the expr_ops and obj_ops structures will
be incorrectly replaced with __builtin_snprintf_chk() which results in
"error: no member named '__builtin___snprintf_chk'" errors at build
time.

This patch changes the member name from 'snprintf' to 'output' to
prevent the replacement.

This bug can be emulated using GCC by undefining the __va_arg_pack macro
before stdio.h is included.

This patch is based on the notes provided in
https://bugs.gentoo.org/807766.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agobuild: libnftnl 1.2.2 release libnftnl-1.2.2
Pablo Neira Ayuso [Tue, 7 Jun 2022 14:10:40 +0000 (16:10 +0200)] 
build: libnftnl 1.2.2 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoset_elem: missing export symbol
Pablo Neira Ayuso [Wed, 18 May 2022 21:54:03 +0000 (23:54 +0200)] 
set_elem: missing export symbol

nftnl_set_elem_nlmsg_build_payload() is already available through .map
file and headers, add missing EXPORT_SYMBOL.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoexthdr: tcp option reset support
Florian Westphal [Sat, 19 Feb 2022 13:39:04 +0000 (14:39 +0100)] 
exthdr: tcp option reset support

Adds print debug support for tcp reset feature.

Signed-off-by: Florian Westphal <fw@strlen.de>
4 years agobuild: libnftnl 1.2.1 release libnftnl-1.2.1
Pablo Neira Ayuso [Wed, 17 Nov 2021 14:08:46 +0000 (15:08 +0100)] 
build: libnftnl 1.2.1 release

Bump libversion, because this release adds new API:
nftnl_set_elem_nlmsg_build().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoexpr: payload: print inner header base offset
Pablo Neira Ayuso [Wed, 17 Nov 2021 10:05:11 +0000 (11:05 +0100)] 
expr: payload: print inner header base offset

Update string array to print the "inner" header string, instead of
printing "unknown".

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoset: use NFTNL_SET_ELEM_VERDICT to print verdict
Pablo Neira Ayuso [Thu, 4 Nov 2021 14:30:48 +0000 (15:30 +0100)] 
set: use NFTNL_SET_ELEM_VERDICT to print verdict

This patch reworks 228e8b174627 ("set_elem: Fix printing of verdict map
elements"), check if NFTNL_SET_ELEM_VERDICT is set then print the set
element verdict.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoset: expose nftnl_set_elem_nlmsg_build()
Pablo Neira Ayuso [Thu, 4 Nov 2021 13:09:44 +0000 (14:09 +0100)] 
set: expose nftnl_set_elem_nlmsg_build()

Expose a function to build one single set element netlink message.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoexpr: last: add NFTNL_EXPR_LAST_SET
Pablo Neira Ayuso [Mon, 5 Jul 2021 17:56:24 +0000 (19:56 +0200)] 
expr: last: add NFTNL_EXPR_LAST_SET

Honor NFTA_LAST_SET netlink attribute, it tells us if a packet has ever
updated this expression.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoexpr: missing netlink attribute in last expression
Pablo Neira Ayuso [Thu, 10 Jun 2021 18:46:09 +0000 (20:46 +0200)] 
expr: missing netlink attribute in last expression

NFTA_LAST_SET is missing, add it.

Fixes: ed7c442c2d04 ("expr: add last match time support")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoexpr: add last match time support
Pablo Neira Ayuso [Tue, 8 Jun 2021 18:00:05 +0000 (20:00 +0200)] 
expr: add last match time support

This new expression displays when last matching has happened.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoinclude: update nf_tables.h
Pablo Neira Ayuso [Tue, 8 Jun 2021 17:58:58 +0000 (19:58 +0200)] 
include: update nf_tables.h

Get header in sync with 5.13.0-rc.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agobuild: libnftnl 1.2.0 release libnftnl-1.2.0
Pablo Neira Ayuso [Tue, 25 May 2021 11:13:15 +0000 (13:13 +0200)] 
build: libnftnl 1.2.0 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoexpr: socket: add cgroups v2 support
Pablo Neira Ayuso [Tue, 20 Apr 2021 23:25:49 +0000 (01:25 +0200)] 
expr: socket: add cgroups v2 support

Add NFT_SOCKET_CGROUPSV2 key type and NFTA_SOCKET_LEVEL attribute.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agosrc: incorrect header refers to GPLv2 only
Pablo Neira Ayuso [Mon, 19 Apr 2021 23:57:20 +0000 (01:57 +0200)] 
src: incorrect header refers to GPLv2 only

libnftnl is GPLv2+, fix incorrect headers.

Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agoruleset: Eliminate tag and separator helpers
Phil Sutter [Tue, 9 Mar 2021 15:03:58 +0000 (16:03 +0100)] 
ruleset: Eliminate tag and separator helpers

Those were used for JSON and XML output only with the exception of
separator helper which at the same time served as conditional nop if no
"previous" object as passed. Replace it by a string variable updated at
the end of each loop iteration and just drop the other helpers.

Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoGet rid of single option switch statements
Phil Sutter [Tue, 9 Mar 2021 12:41:44 +0000 (13:41 +0100)] 
Get rid of single option switch statements

Replace each by a conditional testing the only valid case.

There is one odd example, namely src/set.c: When printing a set with
type NFTNL_OUTPUT_XML, the relevant function would return 0 instead of
-1 like all others. Just drop it assuming nothing depends on that
(faulty) behaviour.

Cc: Arturo Borrero <arturo.borrero.glez@gmail.com>
Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoDrop pointless local variable in snprintf callbacks
Phil Sutter [Tue, 9 Mar 2021 10:26:47 +0000 (11:26 +0100)] 
Drop pointless local variable in snprintf callbacks

A common idiom among snprintf callbacks was to copy the unsigned
parameter 'size' (or 'len') into a signed variable for further use.
Though since snprintf() itself casts it to unsigned and
SNPRINTF_BUFFER_SIZE() does not allow it to become negative, this is not
needed. Drop the local variable and rename the parameter accordingly.

Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoobj: Drop type parameter from snprintf callback
Phil Sutter [Tue, 9 Mar 2021 11:01:19 +0000 (12:01 +0100)] 
obj: Drop type parameter from snprintf callback

Objects don't support any other output type than NFTNL_OUTPUT_DEFAULT,
so just drop the parameter.

Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoexpr/data_reg: Drop output_format parameter
Phil Sutter [Tue, 9 Mar 2021 10:36:03 +0000 (11:36 +0100)] 
expr/data_reg: Drop output_format parameter

The function nftnl_data_reg_snprintf is exclusively called with
NFTNL_OUTPUT_DEFAULT as parameter, others are not supported - just drop
it.

Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoexpr: Check output type once and for all
Phil Sutter [Tue, 9 Mar 2021 09:40:16 +0000 (10:40 +0100)] 
expr: Check output type once and for all

There is but a single supported output type left, so check it in expr.c
and drop all the single option switch statements in individual
expressions.

Since the parameter is now unused (and to ensure code correctness), drop
'type' parameter from struct expr_ops' snprintf callback.

Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoobject: Fix for wrong parameter passed to snprintf callback
Phil Sutter [Tue, 9 Mar 2021 12:29:30 +0000 (13:29 +0100)] 
object: Fix for wrong parameter passed to snprintf callback

Instead of the remaining buffer length, the used buffer length was
passed to object's snprintf callback (and the final snprintf call).

Fixes: 5573d0146c1ae ("src: support for stateful objects")
Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoobj/ct_timeout: Fix snprintf buffer length updates
Phil Sutter [Tue, 9 Mar 2021 11:16:12 +0000 (12:16 +0100)] 
obj/ct_timeout: Fix snprintf buffer length updates

Have to pass shrinking 'remain' variable to consecutive snprintf calls
instead of the unchanged 'len' parameter.

Fixes: 0adceeab1597a ("src: add ct timeout support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoobj/ct_expect: Fix snprintf buffer length updates
Phil Sutter [Tue, 9 Mar 2021 11:13:23 +0000 (12:13 +0100)] 
obj/ct_expect: Fix snprintf buffer length updates

Have to pass shrinking 'remain' variable to consecutive snprintf calls
instead of the unchanged 'len' parameter.

Fixes: c4b6aa09b85d2 ("src: add ct expectation support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoexpr: Fix snprintf buffer length updates
Phil Sutter [Tue, 9 Mar 2021 10:14:29 +0000 (11:14 +0100)] 
expr: Fix snprintf buffer length updates

Subsequent calls to snprintf() sometimes reuse 'len' variable although
they should refer to the updated value in 'remain' instead.

Fixes: 676ea569bbe5a ("src: Change parameters of SNPRINTF_BUFFER_SIZE macro.")
Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoset_elem: Fix printing of verdict map elements
Phil Sutter [Sat, 26 Dec 2020 18:44:48 +0000 (19:44 +0100)] 
set_elem: Fix printing of verdict map elements

Elements' data was printed as type DATA_VALUE no matter the actual type.
For verdicts, this meant no printing at all (because reg->len is either
zero or garbage).

To fix this, nftnl_set_elem_snprintf_default() needs type info held in
struct nftnl_set. Pass it via parameter to that function, make it
non-static and call it from nftnl_set_snprintf_default() instead of the
generic nftnl_set_elem_snprintf(). This way no changes have to be done
to exported functions, also the output type is already defined when
nftnl_set_snprintf_default() runs so checking type value again is
pointless.

Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoexpr/{masq,nat}: Don't print unused regs
Phil Sutter [Sat, 19 Dec 2020 01:01:23 +0000 (02:01 +0100)] 
expr/{masq,nat}: Don't print unused regs

No point in printing the unset register value (which is zero then).

Fixes: af0c182670837 ("expr: masq: Add support for port selection")
Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agorule: Avoid printing trailing spaces
Phil Sutter [Sat, 19 Dec 2020 01:24:16 +0000 (02:24 +0100)] 
rule: Avoid printing trailing spaces

Introduce 'sep' variable to track whether something was printed already.
While being at it, introduce PRIu64 for 'handle' and 'position'
attributes.

Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoexpr/xfrm: Kill dead code
Phil Sutter [Sat, 19 Dec 2020 01:22:56 +0000 (02:22 +0100)] 
expr/xfrm: Kill dead code

These functions were used by removed JSON parser only.

Fixes: 80077787f8f21 ("src: remove json support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoexpr/tunnel: Kill dead code
Phil Sutter [Sat, 19 Dec 2020 01:21:44 +0000 (02:21 +0100)] 
expr/tunnel: Kill dead code

Function str2tunnel_key() was never used.

Fixes: 42468fb6df61a ("expr: add support for matching tunnel metadata")
Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agoexpr/socket: Kill dead code
Phil Sutter [Sat, 19 Dec 2020 01:20:40 +0000 (02:20 +0100)] 
expr/socket: Kill dead code

Function str2socket_key() was never used.

Fixes: 038d226f2e6cc ("src: Add support for native socket matching")
Signed-off-by: Phil Sutter <phil@nwl.cc>
4 years agotable: add table owner support
Pablo Neira Ayuso [Sat, 20 Feb 2021 15:18:13 +0000 (16:18 +0100)] 
table: add table owner support

Add support for NFTA_TABLE_OWNER.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agobuild: libnftnl 1.1.9 release libnftnl-1.1.9
Pablo Neira Ayuso [Wed, 13 Jan 2021 15:30:48 +0000 (16:30 +0100)] 
build: libnftnl 1.1.9 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agodynset: add NFTNL_EXPR_DYNSET_FLAGS
Pablo Neira Ayuso [Wed, 13 Jan 2021 15:27:50 +0000 (16:27 +0100)] 
dynset: add NFTNL_EXPR_DYNSET_FLAGS

This patch adds support for the dynset flags.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agosrc: add NFTNL_EXPR_DYNSET_EXPRESSIONS
Pablo Neira Ayuso [Sat, 12 Dec 2020 19:17:31 +0000 (20:17 +0100)] 
src: add NFTNL_EXPR_DYNSET_EXPRESSIONS

NFTNL_EXPR_DYNSET_EXPR defines the stateful expression type that
an element stores when added from the packet path.

This patch adds support for the set expression list, which generalizes
NFTNL_EXPR_DYNSET_EXPR.

This patch also adds nftnl_expr_add_expr() to add new expressions to
elements and nftnl_set_expr_expr_foreach() to iterate over the list of
expressions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agosrc: add NFTNL_SET_EXPRESSIONS
Pablo Neira Ayuso [Sat, 12 Dec 2020 19:16:53 +0000 (20:16 +0100)] 
src: add NFTNL_SET_EXPRESSIONS

NFTNL_SET_EXPR defines the stateful expression type that this set stores
in each element. This provides the set definition in terms of stateful
expressions. The expression that is passed via NFNTL_SET_ELEM_EXPR must
equal to this set stateful expression type, otherwise the kernel bails
out.

This patch adds support for the set expression list, which generalizes
NFTNL_SET_EXPR.

This patch also adds nftnl_set_add_expr() to add new expressions to a set
and nftnl_set_elem_expr_foreach() to iterate over the list of expressions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
4 years agosrc: add NFTNL_SET_ELEM_EXPRESSIONS
Pablo Neira Ayuso [Sat, 12 Dec 2020 19:13:07 +0000 (20:13 +0100)] 
src: add NFTNL_SET_ELEM_EXPRESSIONS

NFTNL_SET_ELEM_EXPR defines the stateful expression type that this
element stores. This is useful to restore runtime set element stateful
expressions (when saving, then reboot and restore).

This patch adds support for the set element expression list, which
generalizes NFTNL_SET_ELEM_EXPR.

This patch also adds nftnl_set_elem_add_expr() to add new expressions to
set elements and nftnl_set_elem_expr_foreach() to iterate over the list
of expressions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoset_elem: Include key_end data reg in print output
Phil Sutter [Mon, 14 Dec 2020 17:52:07 +0000 (18:52 +0100)] 
set_elem: Include key_end data reg in print output

Elements of concatenated range sets hold the upper boundary in an extra
data_reg, print it using dash as a somewhat intuitive separator.

Fixes: 04cc28d8d6923 ("set_elem: Introduce support for NFTNL_SET_ELEM_KEY_END")
Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agoset_elem: Use nftnl_data_reg_snprintf()
Phil Sutter [Mon, 14 Dec 2020 16:53:47 +0000 (17:53 +0100)] 
set_elem: Use nftnl_data_reg_snprintf()

Introduce a flag to allow toggling the '0x' prefix when printing data
values, then use the existing routines to print data registers from
set_elem code.

Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agobitwise: improve formatting of registers in bitwise dumps.
Jeremy Sowden [Sat, 14 Nov 2020 17:36:05 +0000 (17:36 +0000)] 
bitwise: improve formatting of registers in bitwise dumps.

Registers are formatted as 'reg %u' everywhere apart from in bitwise
expressions where they are formatted as 'reg=%u'.  Change bitwise to
match.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agobuild: libnftnl 1.1.8 release libnftnl-1.1.8
Pablo Neira Ayuso [Mon, 26 Oct 2020 12:54:19 +0000 (13:54 +0100)] 
build: libnftnl 1.1.8 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexpr: add nftnl_rule_del_expr()
Pablo Neira Ayuso [Mon, 19 Oct 2020 11:24:37 +0000 (13:24 +0200)] 
expr: add nftnl_rule_del_expr()

Add a function to remove expression from the rule list.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexpr: expose nftnl_expr_build_payload()
Pablo Neira Ayuso [Fri, 16 Oct 2020 16:53:37 +0000 (18:53 +0200)] 
expr: expose nftnl_expr_build_payload()

This function allows you to build the netlink attributes for
expressions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexpr: socket: add wildcard support
Pablo Neira Ayuso [Mon, 12 Oct 2020 01:21:34 +0000 (03:21 +0200)] 
expr: socket: add wildcard support

Add missing NFT_SOCKET_WILDCARD definition.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agochain: add userdata and comment support
Jose M. Guisado Gomez [Mon, 21 Sep 2020 13:28:22 +0000 (15:28 +0200)] 
chain: add userdata and comment support

Adds NFTNL_CHAIN_USERDATA, in order to support userdata for chains.

Adds NFTNL_UDATA_CHAIN_COMMENT chain userdata type to support storing a
comment.

Relies on NFTA_CHAIN_USERDATA.

Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoobject: add userdata and comment support
Jose M. Guisado Gomez [Wed, 2 Sep 2020 09:12:40 +0000 (11:12 +0200)] 
object: add userdata and comment support

This patch adds NFTNL_OBJ_USERDATA to support userdata for objects.

Also adds NFTNL_UDATA_OBJ_COMMENT to support comments for objects,
stored in userdata space.

Bumps libnftnl.map to 15 as nftnl_obj_get_data needs to be exported to
enable getting object attributes/data.

Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotable: add userdata support
Jose M. Guisado Gomez [Thu, 20 Aug 2020 08:19:02 +0000 (10:19 +0200)] 
table: add userdata support

This patch adds NFT_TABLE_USERDATA and NFTNL_UDATA_TABLE_COMMENT to
support for table comments.

Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agolibnftnl: export nftnl_set_elem_fprintf
Florian Westphal [Thu, 20 Aug 2020 15:15:05 +0000 (17:15 +0200)] 
libnftnl: export nftnl_set_elem_fprintf

Was not exported so far due to a typo.  While at it, add const qualifier
to element structure.

Will be used to optionally dump set contents / elements from nft
frontend.

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoudata: add NFTNL_UDATA_SET_COMMENT
Jose M. Guisado Gomez [Tue, 11 Aug 2020 14:27:19 +0000 (16:27 +0200)] 
udata: add NFTNL_UDATA_SET_COMMENT

This field is used to store an optional comment of a set.

Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexamples: add support for NF_PROTO_INET family
Jose M. Guisado Gomez [Mon, 27 Jul 2020 10:31:08 +0000 (12:31 +0200)] 
examples: add support for NF_PROTO_INET family

Add missing support for "inet" family for a handful of examples where
applicable.

Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexamples: unbreak nft-set-elem-del
Pablo Neira Ayuso [Fri, 24 Jul 2020 13:48:29 +0000 (15:48 +0200)] 
examples: unbreak nft-set-elem-del

This code is missing the batch netlink routines. There was another bug,
the set element key size was not correct.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: add support for chain ID attribute
Pablo Neira Ayuso [Wed, 24 Jun 2020 14:27:00 +0000 (16:27 +0200)] 
src: add support for chain ID attribute

his patch allows you to refer to chains via the chain ID. The semantics
are similar to the NFTA_RULE_ID attribute.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agobuild: libnftnl 1.1.7 release libnftnl-1.1.7
Pablo Neira Ayuso [Fri, 5 Jun 2020 11:14:40 +0000 (13:14 +0200)] 
build: libnftnl 1.1.7 release

bump libmnl dependency too.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoflowtable: relax logic to build NFTA_FLOWTABLE_HOOK
Pablo Neira Ayuso [Mon, 25 May 2020 15:57:15 +0000 (17:57 +0200)] 
flowtable: relax logic to build NFTA_FLOWTABLE_HOOK

The logic to build NFTA_FLOWTABLE_HOOK enforces the presence of the hook
number and priority to include the devices. Relax this to allow for
incremental device updates.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexpr: dynset: release stateful expression from .free path
Pablo Neira Ayuso [Wed, 6 May 2020 18:45:35 +0000 (20:45 +0200)] 
expr: dynset: release stateful expression from .free path

==22778==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f3212406518 in calloc (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xe9518)
    #1 0x7f321041703e in nftnl_expr_alloc /home/pablo/devel/scm/git-netfilter/libnftnl/src/expr.c:37
    #2 0x7f3211d51c16 in netlink_gen_limit_stmt /home/pablo/devel/scm/git-netfilter/nftables/src/netlink_linearize.c:859
    #3 0x7f3211d5220c in netlink_gen_stmt_stateful /home/pablo/devel/scm/git-netfilter/nftables/src/netlink_linearize.c:891
    #4 0x7f3211d58630 in netlink_gen_meter_stmt /home/pablo/devel/scm/git-netfilter/nftables/src/netlink_linearize.c:1441
[...]

SUMMARY: AddressSanitizer: 64 byte(s) leaked in 1 allocation(s).

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexpr: objref: add nftnl_expr_objref_free() to release object name
Pablo Neira Ayuso [Tue, 5 May 2020 18:49:51 +0000 (20:49 +0200)] 
expr: objref: add nftnl_expr_objref_free() to release object name

==4876==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 9 byte(s) in 1 object(s) allocated from:
    #0 0x7f4e2c16b810 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x3a810)
    #1 0x7f4e2a39906f in nftnl_expr_objref_set expr/objref.c:45
    #2 0x7f4e2a39906f in nftnl_expr_objref_set expr/objref.c:35

Direct leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x7f4018aa0810 in strdup (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x3a810)
    #1 0x7f4016b660af in nftnl_expr_objref_set expr/objref.c:53

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoudata: add NFTNL_UDATA_SET_DATA_INTERVAL
Pablo Neira Ayuso [Mon, 27 Apr 2020 17:23:20 +0000 (19:23 +0200)] 
udata: add NFTNL_UDATA_SET_DATA_INTERVAL

Use this field to specify that set element data specifies an interval.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agobuild: libnftnl 1.1.6 release libnftnl-1.1.6
Pablo Neira Ayuso [Tue, 31 Mar 2020 19:05:04 +0000 (21:05 +0200)] 
build: libnftnl 1.1.6 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoinclude: update nf_tables.h.
Pablo Neira Ayuso [Tue, 31 Mar 2020 18:52:36 +0000 (20:52 +0200)] 
include: update nf_tables.h.

Get header in sync with 5.7.0-rc.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoRevert "bitwise: add support for passing mask and xor via registers."
Pablo Neira Ayuso [Tue, 31 Mar 2020 18:49:54 +0000 (20:49 +0200)] 
Revert "bitwise: add support for passing mask and xor via registers."

This reverts commit 75b8778e5bf630a3fc13e5d76bc64838135f02a9. Kernel
support for this new feature might be reworked, keep this back.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexpr: nat: snprint flags in hexadecimal
Pablo Neira Ayuso [Fri, 20 Mar 2020 12:41:35 +0000 (13:41 +0100)] 
expr: nat: snprint flags in hexadecimal

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexpr: masq: revisit _snprintf()
Pablo Neira Ayuso [Fri, 20 Mar 2020 12:40:57 +0000 (13:40 +0100)] 
expr: masq: revisit _snprintf()

Print combination of registers and flags.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoset: support for NFTNL_SET_EXPR
Pablo Neira Ayuso [Tue, 17 Mar 2020 13:14:05 +0000 (14:14 +0100)] 
set: support for NFTNL_SET_EXPR

This patch adds support for the NFTA_SET_EXPR netlink attribute.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoset_elem: missing set and build for NFTNL_SET_ELEM_EXPR
Pablo Neira Ayuso [Wed, 11 Mar 2020 13:23:33 +0000 (14:23 +0100)] 
set_elem: missing set and build for NFTNL_SET_ELEM_EXPR

Extend nftnl_set_elem_set() and nftnl_set_elem_nlmsg_build_payload() to
support for the NFTNL_SET_ELEM_EXPR attribute.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agochain: add NFTNL_CHAIN_FLAGS
Pablo Neira Ayuso [Tue, 3 Mar 2020 11:58:20 +0000 (12:58 +0100)] 
chain: add NFTNL_CHAIN_FLAGS

This patch adds support for chain flags.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agobitwise: add support for passing mask and xor via registers.
Jeremy Sowden [Mon, 24 Feb 2020 13:12:01 +0000 (13:12 +0000)] 
bitwise: add support for passing mask and xor via registers.

The kernel supports passing mask and xor values for bitwise boolean
operations via registers.  These are mutually exclusive with the
existing data attributes: e.g., setting both NFTA_EXPR_BITWISE_MASK and
NFTA_EXPR_BITWISE_MREG is an error.  Add support to libnftnl.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoinclude: update nf_tables.h.
Jeremy Sowden [Mon, 24 Feb 2020 13:12:00 +0000 (13:12 +0000)] 
include: update nf_tables.h.

Pick up a couple of new bitwise netlink attributes.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: bitwise: fix error message.
Jeremy Sowden [Mon, 24 Feb 2020 13:11:59 +0000 (13:11 +0000)] 
tests: bitwise: fix error message.

In one case, the boolean test was reporting the wrong mismatched
attribute.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: add nftnl_*_{get,set}_array()
Pablo Neira Ayuso [Tue, 18 Feb 2020 13:09:23 +0000 (14:09 +0100)] 
src: add nftnl_*_{get,set}_array()

The original intention in eb58f53372e7 ("src: add flowtable support")
was to introduce this helper function. Add helper to set and to get
array of strings.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Phil Sutter <phil@nwl.cc>
5 years agosrc: Fix for reading garbage in nftnl_chain getters
Phil Sutter [Fri, 14 Feb 2020 17:20:29 +0000 (18:20 +0100)] 
src: Fix for reading garbage in nftnl_chain getters

In {s,u}{32,64} type getters nftnl_assert() is called to make sure
returned data length matches expectations. Therefore all attributes must
set data_len, which NFTNL_CHAIN_DEVICES didn't.

While being at it, do the same change for NFTNL_FLOWTABLE_DEVICES as
well to make code a bit more consistent although the problem was fixed
for flowtables with commit f8eed54150fd4 ("flowtable: Fix for reading
garbage") already (but in the other direction).

Fixes: e3ac19b5ec162 ("chain: multi-device support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agoset_elem: Introduce support for NFTNL_SET_ELEM_KEY_END
Stefano Brivio [Thu, 30 Jan 2020 00:16:34 +0000 (01:16 +0100)] 
set_elem: Introduce support for NFTNL_SET_ELEM_KEY_END

The new set element attribute maps to the netlink attribute
NFTA_SET_ELEM_KEY_END in the same way as NFTNL_SET_ELEM_KEY
maps to NFTA_SET_ELEM_KEY, and represents the key data used
to express the upper bound of a range, in concatenations.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoset: Add support for NFTA_SET_DESC_CONCAT attributes
Stefano Brivio [Thu, 30 Jan 2020 00:16:33 +0000 (01:16 +0100)] 
set: Add support for NFTA_SET_DESC_CONCAT attributes

If NFTNL_SET_DESC_CONCAT data is passed, pass that to the kernel
as NFTA_SET_DESC_CONCAT attributes: it describes the length of
single concatenated fields, in bytes.

Similarly, parse NFTA_SET_DESC_CONCAT attributes if received
from the kernel.

This is the libnftnl counterpart for nftables patch:
  src: Add support for NFTNL_SET_DESC_CONCAT

v4:
 - move NFTNL_SET_DESC_CONCAT to the end of enum nftnl_set_attr
   to avoid ABI breakage (Pablo Neira Ayuso)
v3:
 - use NFTNL_SET_DESC_CONCAT and NFTA_SET_DESC_CONCAT instead of a
   stand-alone NFTA_SET_SUBKEY attribute (Pablo Neira Ayuso)
 - pass field length in bytes instead of bits, fields would get
   unnecessarily big otherwise
v2:
 - fixed grammar in commit message
 - removed copy of array bytes in nftnl_set_nlmsg_build_subkey_payload(),
   we're simply passing values to htonl() (Phil Sutter)

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoinclude: resync nf_tables.h cache copy
Stefano Brivio [Thu, 30 Jan 2020 00:16:32 +0000 (01:16 +0100)] 
include: resync nf_tables.h cache copy

Get this header in sync with nf-next as of merge commit
b3a608222336 (5.6-rc1-ish).

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agobitwise: add support for left- and right-shifts.
Jeremy Sowden [Fri, 17 Jan 2020 20:58:08 +0000 (20:58 +0000)] 
bitwise: add support for left- and right-shifts.

The kernel supports bitwise shifts.  Add support to libnftnl.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agobitwise: add support for new netlink attributes.
Jeremy Sowden [Fri, 17 Jan 2020 20:58:07 +0000 (20:58 +0000)] 
bitwise: add support for new netlink attributes.

Add code to set and get the new op and data attributes.  The existing
boolean bitwise expressions will only use the op attribute.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoinclude: update nf_tables.h.
Jeremy Sowden [Fri, 17 Jan 2020 20:58:06 +0000 (20:58 +0000)] 
include: update nf_tables.h.

The kernel UAPI header includes a couple of new bitwise netlink
attributes and an enum.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agobitwise: add helper to print boolean expressions.
Jeremy Sowden [Fri, 17 Jan 2020 20:58:05 +0000 (20:58 +0000)] 
bitwise: add helper to print boolean expressions.

Move the code for printing boolean expressions into a separate function.
Another function will be added for shifts later.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agobitwise: fix some incorrect indentation.
Jeremy Sowden [Fri, 17 Jan 2020 20:58:04 +0000 (20:58 +0000)] 
bitwise: fix some incorrect indentation.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoUpdate gitignore.
Jeremy Sowden [Fri, 17 Jan 2020 20:58:03 +0000 (20:58 +0000)] 
Update gitignore.

Add ctags and etags tag files, and Emacs back-up files.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoinclude: Remove buffer.h
Brett Mastbergen [Fri, 3 Jan 2020 19:36:40 +0000 (14:36 -0500)] 
include: Remove buffer.h

Almost everything in this header is unused.  The command defines
used in utils.c don't seem to be justified and have just been
replaced by their strings

Signed-off-by: Brett Mastbergen <bmastbergen@untangle.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexpr: meta: add slave device matching
Florian Westphal [Wed, 18 Dec 2019 11:10:40 +0000 (12:10 +0100)] 
expr: meta: add slave device matching

Cc: Martin Willi <martin@strongswan.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoudata: support for TLV attribute nesting
Pablo Neira Ayuso [Mon, 16 Dec 2019 12:44:46 +0000 (13:44 +0100)] 
udata: support for TLV attribute nesting

This patch adds nftnl_udata_nest_start() and nftnl_udata_nest_end()
to build attribute nests.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoudata: add NFTNL_UDATA_SET_*TYPEOF* definitions
Pablo Neira Ayuso [Mon, 16 Dec 2019 12:43:42 +0000 (13:43 +0100)] 
udata: add NFTNL_UDATA_SET_*TYPEOF* definitions

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoinclude: typo in object.h C++ wrapper
Pablo Neira Ayuso [Wed, 11 Dec 2019 17:30:04 +0000 (18:30 +0100)] 
include: typo in object.h C++ wrapper

s/__cplusplusg/__cplusplus/

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1389
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoexamples: Replace use of deprecated symbols
Phil Sutter [Wed, 4 Dec 2019 14:45:43 +0000 (15:45 +0100)] 
examples: Replace use of deprecated symbols

Do not use unqualified setters to avoid the warnings. Pass a (false)
zero length value to nftnl_flowtable_set_data() when assigning to
NFTNL_FLOWTABLE_DEVICES as the length value is unused and not even
usable. Maybe one should introduce a dedicated
nftnl_flowtable_set_devices() at a later point.

Fixes: 7349a70634fa0 ("Deprecate untyped data setters")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Arturo Borrero Gonzalez <arturo@netfilter.org>
6 years agochain: Correctly check realloc() call
Phil Sutter [Mon, 2 Dec 2019 22:12:34 +0000 (23:12 +0100)] 
chain: Correctly check realloc() call

If realloc() fails, it returns NULL but the original pointer is
untouchted and therefore still has to be freed. Unconditionally
overwriting the old pointer is therefore a bad idea, use a temporary
variable instead.

Fixes: e3ac19b5ec162 ("chain: multi-device support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoflowtable: Correctly check realloc() call
Phil Sutter [Mon, 2 Dec 2019 22:08:07 +0000 (23:08 +0100)] 
flowtable: Correctly check realloc() call

If realloc() fails, it returns NULL but the original pointer is
untouchted and therefore still has to be freed. Unconditionally
overwriting the old pointer is therefore a bad idea, use a temporary
variable instead.

Fixes: 7f99639dd9217 ("flowtable: device array dynamic allocation")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agochain: Fix memleak in error path of nftnl_chain_parse_devs()
Phil Sutter [Mon, 2 Dec 2019 22:00:20 +0000 (23:00 +0100)] 
chain: Fix memleak in error path of nftnl_chain_parse_devs()

In error case, dev_array is not freed when it should.

Fixes: e3ac19b5ec162 ("chain: multi-device support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoflowtable: Fix memleak in error path of nftnl_flowtable_parse_devs()
Phil Sutter [Mon, 2 Dec 2019 21:57:40 +0000 (22:57 +0100)] 
flowtable: Fix memleak in error path of nftnl_flowtable_parse_devs()

In error case, allocated dev_array is not freed.

Fixes: 7f99639dd9217 ("flowtable: device array dynamic allocation")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: flowtable: Don't check NFTNL_FLOWTABLE_SIZE
Phil Sutter [Mon, 2 Dec 2019 17:29:56 +0000 (18:29 +0100)] 
tests: flowtable: Don't check NFTNL_FLOWTABLE_SIZE

Marshalling code around that attribute has been dropped by commit
d1c4b98c733a5 ("flowtable: remove NFTA_FLOWTABLE_SIZE") so it's value is
lost during the test.

Assuming that NFTNL_FLOWTABLE_SIZE will receive kernel support at a
later point, leave the test code in place but just comment it out.

Fixes: d1c4b98c733a5 ("flowtable: remove NFTA_FLOWTABLE_SIZE")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agobuild: libnftnl 1.1.5 release libnftnl-1.1.5
Pablo Neira Ayuso [Mon, 2 Dec 2019 13:44:29 +0000 (14:44 +0100)] 
build: libnftnl 1.1.5 release

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoutils: Define __visible even if not supported by compiler
Phil Sutter [Wed, 6 Nov 2019 13:26:36 +0000 (14:26 +0100)] 
utils: Define __visible even if not supported by compiler

Since __visible is now used directly, provide a fallback empty
definition if HAVE_VISIBILITY_HIDDEN is not defined.

Fixes: 7349a70634fa0 ("Deprecate untyped data setters")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoflowtable: remove NFTA_FLOWTABLE_SIZE
Pablo Neira Ayuso [Fri, 15 Nov 2019 21:49:44 +0000 (22:49 +0100)] 
flowtable: remove NFTA_FLOWTABLE_SIZE

Never defined in upstream Linux kernel uAPI, remove it.

Reported-by: Eric Garver <eric@garver.life>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Eric Garver <eric@garver.life>
6 years agoflowtable: add support for handle attribute
Eric Jallot [Mon, 4 Nov 2019 20:19:58 +0000 (21:19 +0100)] 
flowtable: add support for handle attribute

Add code to implement NFTA_FLOWTABLE_HANDLE

Signed-off-by: Eric Jallot <ejallot@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoDeprecate untyped data setters
Phil Sutter [Wed, 30 Oct 2019 17:31:59 +0000 (18:31 +0100)] 
Deprecate untyped data setters

These functions make assumptions on size of passed data pointer and
therefore tend to hide programming mistakes. Instead either one of the
type-specific setters or the generic *_set_data() setter should be used.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoflowtable: Fix symbol export for clang
Manuel Messner [Thu, 31 Oct 2019 08:37:07 +0000 (09:37 +0100)] 
flowtable: Fix symbol export for clang

clang does not allow attribute declarations after definitions:

  flowtable.c:41:1: warning: attribute declaration must precede definition [-Wignored-attributes]
  EXPORT_SYMBOL(nftnl_flowtable_alloc);
  ^
  ../include/utils.h:13:41: note: expanded from macro 'EXPORT_SYMBOL'
  #       define EXPORT_SYMBOL(x) typeof(x) (x) __visible;
                                                ^
  ../include/utils.h:12:35: note: expanded from macro '__visible'
  #       define __visible        __attribute__((visibility("default")))
                                                 ^
  flowtable.c:37:25: note: previous definition is here
  struct nftnl_flowtable *nftnl_flowtable_alloc(void)

Move attribute declarations before the symbol definitions just like
it's done in other source files

Signed-off-by: Marvin Schmidt <marvin_schmidt@gmx.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agolibnftnl.map: Export nftnl_{obj,flowtable}_set_data()
Phil Sutter [Wed, 30 Oct 2019 17:37:10 +0000 (18:37 +0100)] 
libnftnl.map: Export nftnl_{obj,flowtable}_set_data()

In order to deprecate nftnl_{obj,flowtable}_set() functions, these must
to be made available.

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