]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
7 years agosrc: add support for new secmark object
Christian Göttsche [Fri, 28 Sep 2018 16:21:15 +0000 (18:21 +0200)] 
src: add support for new secmark object

The new object will hold security context strings.

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

Joint work with Máté Eckl.

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

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

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

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

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

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

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

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

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

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

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

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

nft list ruleset

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

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

Add, list and delete ct timeout objects from specified table

Usage e.g.:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

This function basically did:

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

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

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

Check for libmnl >= 1.0.3 just like nftables does.

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

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

Instead of:

  [ rt load unknown => reg 1 ]

print:

  [ rt load tcpmss => reg 1 ]

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

To support forwarding through neighbour layer from ingress.

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

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

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

Joint work with Pablo.

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

Allow to add rule object before any existing rule.

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

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

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

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

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

nft list ruleset

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Correct one typo for parsing set handles.

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

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

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

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

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

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

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

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

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

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

This new attribute allows you to specify the flowtable flags.

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

This new attribute allows you to specify the flowtable size.

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

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

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

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

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

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

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

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
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>
8 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>
8 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>
8 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>
8 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>
9 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>