]>
git.ipfire.org Git - thirdparty/libnftnl.git/log
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Pablo Neira Ayuso [Fri, 13 May 2016 10:51:22 +0000 (12:51 +0200)]
chain: missing constification of _get() functions
These functions don't modify the chain object.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Pablo Neira Ayuso [Mon, 9 May 2016 21:05:53 +0000 (23:05 +0200)]
src: missing static in several array definitions
They are not used out of the scope of the C file where they are defined,
so we can statify them.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Pablo Neira Ayuso [Mon, 9 May 2016 21:03:25 +0000 (23:03 +0200)]
src: remove unnecessary inline in _snprintf functions
These functions are passed as parameter, so we basically get nothing
with this.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Patrick McHardy [Tue, 26 Apr 2016 13:16:58 +0000 (14:16 +0100)]
libnftnl: constify object arguments to various functions
flow table support needs constant object arguments to printing functions
to avoid ugly casts. While at it, also constify object arguments to message
construction, destructor and a few helper functions.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Pablo Neira Ayuso [Thu, 5 May 2016 12:05:56 +0000 (14:05 +0200)]
libnftnl: allow any set name length
Unfortunately libnftnl restricts the set names in the lookup and dynset
expressions to 16 bytes. Remove this restriction so this can work with
the upcoming 4.7 Linux kernel.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Daniel Wagner [Fri, 29 Apr 2016 10:07:34 +0000 (12:07 +0200)]
examples: load modules when adding chains or tables
Tell the kernel to load the necessary modules by adding
the NLM_F_CREATE flag.
Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Arturo Borrero [Tue, 19 Apr 2016 12:54:46 +0000 (14:54 +0200)]
expr: ct: fix typo unknow vs unknown
Reported by Debian's lintian tool.
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Pablo Neira Ayuso [Fri, 15 Apr 2016 10:29:42 +0000 (12:29 +0200)]
rule: fix leaks in NFTNL_RULE_USERDATA
Fix leaks in nftnl_rule_free() and nftnl_rule_set_data().
Reported-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Shivani Bhardwaj [Fri, 15 Apr 2016 08:12:57 +0000 (13:42 +0530)]
tests: expr-nat: Use different values to test
Tests are more effective if different values are set so, use different
values for every expression.
Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Carlos Falgueras García [Tue, 22 Mar 2016 19:46:26 +0000 (20:46 +0100)]
tests: nft-rule-test: check for NFTNL_RULE_USERDATA
Modify nft-rule-test.c to check TLV attribute inclusion in nftnl_rule.
Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Carlos Falgueras García [Tue, 22 Mar 2016 19:46:24 +0000 (20:46 +0100)]
udata: add TLV user data infrastructure
These functions allow to create a buffer (struct nftnl_udata_buf) of
user data attributes in TLV format (struct nftnl_udata). It is inspired
by libmnl/src/attr.c. It can be used to store several TLVs sequentially
into an object.
Example:
struct nftnl_udata_buf *buf;
struct nftnl_udata *attr;
const char *str = "Hello World!";
buf = nftnl_udata_buf_alloc(UDATA_SIZE);
if (!buf) {
perror("OOM");
exit(EXIT_FAILURE);
}
if (!nftnl_udata_put_strz(buf, MY_TYPE, str)) {
perror("Can't put attribute \"%s\"", str);
exit(EXIT_FAILURE);
}
nftnl_udata_for_each(buf, attr)
printf("%s\n", (char *)nftnl_udata_attr_value(attr));
nftnl_udata_buf_free(buf);
Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Patrick McHardy [Thu, 10 Mar 2016 12:16:05 +0000 (13:16 +0100)]
trace: fix missing NFTNL_TRACE_JUMP_TARGET in nftnl_trace_get_str()
Signed-off-by: Patrick McHardy <kaber@trash.net>
Patrick McHardy [Fri, 4 Mar 2016 11:26:30 +0000 (12:26 +0100)]
trace: fix multiple copy and paste errors
Fix duplicated and incorrect assignments.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Shivani Bhardwaj [Fri, 22 Jan 2016 19:36:06 +0000 (01:06 +0530)]
expr: masq: Add support for port selection
Complete masquerading support by allowing port range selection.
Signed-off-by: Shivani Bhardwaj <shivanib134@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Florian Westphal [Mon, 1 Feb 2016 23:19:44 +0000 (00:19 +0100)]
src: meta: add prandom support
Signed-off-by: Florian Westphal <fw@strlen.de>
Pablo Neira Ayuso [Mon, 11 Jan 2016 18:43:01 +0000 (19:43 +0100)]
expr: add forward expression
Add forward expression for the netdev family.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Florian Westphal [Thu, 14 Jan 2016 03:53:31 +0000 (04:53 +0100)]
src: ct: add packet and byte counter support
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Pablo Neira Ayuso [Mon, 11 Jan 2016 18:38:24 +0000 (19:38 +0100)]
expr: limit: add support for flags
This patch adds the limit flags, the first client of this is the
inversion flag that allows us to match overlimit.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Florian Westphal [Wed, 11 Nov 2015 00:54:01 +0000 (01:54 +0100)]
src: add trace infrastructure support
parses trace monitor netlink messages from the kernel and builds
nftnl_trace struct that contains the dissected information.
Provides getters to access these attributes.
Signed-off-by: Florian Westphal <fw@strlen.de>
Patrick McHardy [Wed, 25 Nov 2015 16:48:34 +0000 (16:48 +0000)]
payload: add payload mangling support
Signed-off-by: Patrick McHardy <kaber@trash.net>
Florian Westphal [Tue, 24 Nov 2015 10:02:09 +0000 (11:02 +0100)]
src: rename EXPORT_SYMBOL to EXPORT_SYMBOL_ALIAS
Future symbols don't need backwards-compat aliases.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Vijay Subramanian [Sun, 25 Oct 2015 02:50:33 +0000 (19:50 -0700)]
Add support to print netdev family
When we lookup the family, return "netdev" for NFPROTO_NETDEV instead of
"unknown".
Signed-off-by: Vijay Subramanian <subramanian.vijay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Arturo Borrero [Tue, 13 Oct 2015 07:39:10 +0000 (09:39 +0200)]
chain: fix segfault in 'device' XML parsing
Reported by valgrind:
[...]
==14065== Process terminating with default action of signal 11 (SIGSEGV)
==14065== Access not within mapped region at address 0x0
==14065== at 0x4C2C022: strlen (vg_replace_strmem.c:454)
==14065== by 0x4E41A93: nftnl_chain_set_str (chain.c:259)
==14065== by 0x4E427F7: nftnl_mxml_chain_parse (chain.c:770)
==14065== by 0x4E48F96: nftnl_ruleset_parse_chains (ruleset.c:314)
==14065== by 0x4E4959A: nftnl_ruleset_xml_parse_ruleset (ruleset.c:625)
==14065== by 0x4E4959A: nftnl_ruleset_xml_parse_cmd (ruleset.c:668)
==14065== by 0x4E4959A: nftnl_ruleset_xml_parse (ruleset.c:706)
==14065== by 0x4E4959A: nftnl_ruleset_do_parse (ruleset.c:734)
==14065== by 0x4013C9: test_xml (nft-parsing-test.c:166)
==14065== by 0x4016F4: execute_test (nft-parsing-test.c:214)
==14065== by 0x400EBA: main (nft-parsing-test.c:330)
[...]
While at it, fix a bit the coding style.
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Vijay Subramanian [Fri, 9 Oct 2015 21:24:18 +0000 (14:24 -0700)]
examples: Fix nft-table-upd example
examples/nft-table-upd does not work currently since NFT_MSG_NEWTABLE
needs to use batching mode of netlink message delivery.
This patch adds batching to nft-table-upd example.
While here, also add support for netdev family.
Signed-off-by: Vijay Subramanian <subramanian.vijay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Vijay Subramanian [Fri, 9 Oct 2015 19:21:07 +0000 (12:21 -0700)]
expr: Fix compilation with JSON and XML parsing enabled
Fix missing/incorrect variables.
Also remove unsed variables to avoid warnings.
Signed-off-by: Vijay Subramanian <subramanian.vijay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Pablo Neira Ayuso [Tue, 29 Sep 2015 18:07:03 +0000 (20:07 +0200)]
expr: dup: fix missing space in text output
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>