]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
12 years agoexpr: log: fix wrong attribute type in nft_rule_expr_log_parse
Ana Rey [Tue, 19 Nov 2013 12:01:16 +0000 (13:01 +0100)] 
expr: log: fix wrong attribute type in nft_rule_expr_log_parse

I fixed it by using the correct value.

Signed-off-by: Ana Rey <anarey@gmail.com>
Acked-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: target: fix wrong info length in nft_rule_expr_target_parse
Ana Rey [Tue, 19 Nov 2013 17:54:14 +0000 (18:54 +0100)] 
expr: target: fix wrong info length in nft_rule_expr_target_parse

If I run my automatic unit test of libnftable, It shows:

ERROR: Expr NFT_EXPR_TG_INFO size mismatches size a: 32 b: 36

The problem was in nft_rule_expr_target_parse function. With the
attached patch, we use mnl_attr_get_payload_len() in instead of
mnl_attr_get_len().

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: log: fix missing \0 when sending log prefix to kernel
Ana Rey [Tue, 19 Nov 2013 16:56:18 +0000 (17:56 +0100)] 
expr: log: fix missing \0 when sending log prefix to kernel

If I run my automatic unit test for libnftables, It shows:
"ERROR: Expr NFT_EXPR_LOG_PREFIX mismatches"
a: test
b: test\ 6
       ^^
       garbage

The problem was in nft_rule_expr_log_build function. With
the attached patch, we use mnl_attr_put_strz() instead of
mnl_attr_put_str() as in other functions in the library.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: log: release prefix
Pablo Neira Ayuso [Mon, 18 Nov 2013 13:18:04 +0000 (14:18 +0100)] 
expr: log: release prefix

Ana Rey reported a leak in the log expression. Fix it by using
the new .free interface added in (3cf788a expr: fix leak in target
and match expressions).

Reported-by: Ana Rey Botello <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: match: fix wrong flag setting in nft_rule_expr_match_parse
Pablo Neira Ayuso [Fri, 15 Nov 2013 13:55:21 +0000 (14:55 +0100)] 
expr: match: fix wrong flag setting in nft_rule_expr_match_parse

Expression flags were incorrectly set.

Reported-by: Ana Rey Botello <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: fix make distcheck
Pablo Neira Ayuso [Thu, 14 Nov 2013 00:12:39 +0000 (01:12 +0100)] 
build: fix make distcheck

Fix missing files that were not included in the tarball
that distcheck generates.

This also includes AC_EXEEXT, otherwise configure complains about
undefined CHECK_GCC_FVISIBILITY.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: fix leak in target and match expressions
Pablo Neira Ayuso [Thu, 14 Nov 2013 14:19:03 +0000 (15:19 +0100)] 
expr: fix leak in target and match expressions

Release internal data area for match and target expressions.

==30104== 68 bytes in 1 blocks are definitely lost in loss record 1 of 1
==30104==    at 0x4C2B514: calloc (vg_replace_malloc.c:593)
==30104==    by 0x400C2F: main (nft-expr_match-test.c:65)

Reported-by: Ana Rey Botello <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: unify parse and output types
Álvaro Neira Ayuso [Mon, 11 Nov 2013 20:09:35 +0000 (21:09 +0100)] 
src: unify parse and output types

Unify parse and output types that are redundant to all
existing nftables objects. Thus, all NFT_*_O_[XML|JSON|DEFAULT]
are merged into NFT_OUTPUT_[JSON|XML] and NFT_PARSE_[JSON|XML].

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: json: remove rule flags in ruleset test file
Álvaro Neira Ayuso [Mon, 11 Nov 2013 20:09:21 +0000 (21:09 +0100)] 
tests: json: remove rule flags in ruleset test file

It should have been done in (2cba099 rule: remove
NFT_RULE_ATTR_FLAGS).

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: fix reference to undefined symbol
Arturo Borrero [Thu, 7 Nov 2013 09:39:55 +0000 (10:39 +0100)] 
tests: fix reference to undefined symbol

Kill reference to undefined symbol.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: resolve build errors in dependent programs
Jan Engelhardt [Mon, 28 Oct 2013 12:27:18 +0000 (13:27 +0100)] 
build: resolve build errors in dependent programs

The headers do not compile standalone which may cause compilation
problems to third party programs.

$ gcc -x c -Wall -c *.h
chain.h:62:35: error: unknown type name ‘size_t’
expr.h:40:39: error: unknown type name ‘size_t’
rule.h:60:34: error: unknown type name ‘size_t’
ruleset.h:20:1: error: unknown type name ‘bool’
ruleset.h:20:59: error: unknown type name ‘uint16_t’
ruleset.h:21:52: error: unknown type name ‘uint16_t’
ruleset.h:22:50: error: unknown type name ‘uint16_t’
ruleset.h:23:63: error: unknown type name ‘uint16_t’
ruleset.h:39:37: error: unknown type name ‘size_t’
ruleset.h:39:80: error: unknown type name ‘uint32_t’
ruleset.h:39:95: error: unknown type name ‘uint32_t’
set.h:40:33: error: unknown type name ‘size_t’
set.h:110:38: error: unknown type name ‘size_t’
table.h:50:35: error: unknown type name ‘size_t’

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: resolve automake 1.12 warning
Jan Engelhardt [Mon, 28 Oct 2013 12:27:17 +0000 (13:27 +0100)] 
build: resolve automake 1.12 warning

ltlibrary.am: archiver requires 'AM_PROG_AR' in 'configure.ac'

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: Fix a build issue on header inclusion in internal.h
Tomasz Bursztyka [Tue, 5 Nov 2013 08:03:39 +0000 (10:03 +0200)] 
src: Fix a build issue on header inclusion in internal.h

Fixes:
In file included from utils.c:11:0:
./internal.h:93:17: error: unknown type name 'FILE'
 int nft_fprintf(FILE *fp, void *obj, uint32_t type, uint32_t flags, int
 (*snprintf_cb)(char *buf, size_t bufsiz, void *obj, uint32_t type,
 uint32_t flags));

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotest: report compilation without support
Arturo Borrero [Thu, 31 Oct 2013 12:36:44 +0000 (13:36 +0100)] 
test: report compilation without support

Print a message when there is no support for some parser.

Remove those EOPNOTSUPPs because they are unused.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotest: report errors building XML tree
Arturo Borrero [Thu, 31 Oct 2013 12:36:34 +0000 (13:36 +0100)] 
test: report errors building XML tree

Report error when building XML tree.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotest: fix memleak in XML testing
Arturo Borrero [Thu, 31 Oct 2013 12:36:23 +0000 (13:36 +0100)] 
test: fix memleak in XML testing

Ensure the tree is freed when done.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotest: return EXIT_FAILURE if some error was found
Arturo Borrero [Thu, 31 Oct 2013 12:36:18 +0000 (13:36 +0100)] 
test: return EXIT_FAILURE if some error was found

Before this patch, 0 was returned unconditionally.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add fprintf API functions
Arturo Borrero [Tue, 29 Oct 2013 22:44:25 +0000 (23:44 +0100)] 
src: add fprintf API functions

Now it's possible to print directly from libnftables to a file or
other stream. The caller must explicitly print the trailing '\n'
in this call.

The error reporting of fprintf (< 0) is respected. However, we have
already print some information in case that the default (plain text)
output is used, that output is mostly intended for debugging so it
should not be a problem.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoruleset: refactorize json/xml tagging
Arturo Borrero [Mon, 28 Oct 2013 10:57:47 +0000 (11:57 +0100)] 
ruleset: refactorize json/xml tagging

This factorization of JSON/XML open & close tag allows reutilice
code in future patches (for example, the fprintf API functions).

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: xml: fix truncated ruleset testfile
Arturo Borrero [Mon, 28 Oct 2013 13:28:27 +0000 (14:28 +0100)] 
tests: xml: fix truncated ruleset testfile

Give a new XML ruleset testfile. For some reason patchwork has truncated
the file?

This should have been fixed in (b7c39a7 test: xml: fix malformed ruleset
testfile).

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoinclude: fix missing struct nlmsghdr without definition
Pablo Neira Ayuso [Sun, 27 Oct 2013 20:50:35 +0000 (21:50 +0100)] 
include: fix missing struct nlmsghdr without definition

The definition of this structure belongs to the scope of
linux/netlink.h.

Based on patch from Jan Engelhardt.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: fix possible null pointer dereference in nft_*_attr_get_*
Phil Oester [Fri, 25 Oct 2013 16:55:31 +0000 (09:55 -0700)] 
src: fix possible null pointer dereference in nft_*_attr_get_*

As reported by John Sager, nft_set_attr_get_u32 can cause a
segfault because nft_set_attr_get can return NULL. Check for
a non-NULL pointer before dereferencing.

This closes netfilter bugzilla #868.

[ I have mangled this patch to solve possible null pointer
  dereference with get operations with rule objects --pablo ]

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: update to fit latest limit changes
Arturo Borrero [Tue, 22 Oct 2013 16:25:45 +0000 (18:25 +0200)] 
tests: update to fit latest limit changes

Update tests to fit the latest limit changes in
commit [e91ea14] (expr: limit: operational limit match)

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add reject
Pablo Neira Ayuso [Fri, 25 Oct 2013 14:48:36 +0000 (16:48 +0200)] 
expr: add reject

This patch adds support for the reject expression.

Tested-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: remove NFT_RULE_ATTR_FLAGS
Pablo Neira Ayuso [Thu, 24 Oct 2013 22:00:07 +0000 (00:00 +0200)] 
rule: remove NFT_RULE_ATTR_FLAGS

This is a leftover from the time we had per rule flags, obsoleted
by the new rule batching approach. Kill it as it is unused.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotest: xml: fix malformed ruleset testfile
Arturo Borrero [Thu, 24 Oct 2013 15:00:58 +0000 (17:00 +0200)] 
test: xml: fix malformed ruleset testfile

Give a new XML ruleset testfile. For some reason, the previous was truncated.
This passed silently as nft-parsing-test is not reporting some errors properly.

This new file provides:
 * 2 tables
 * 3 chains
 * 2 sets, with and without maps
 * 3 rules with mixed exprs

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: limit: s/seconds/second/
Florian Westphal [Tue, 22 Oct 2013 13:33:41 +0000 (15:33 +0200)] 
expr: limit: s/seconds/second/

my fault, spotted by Phil Oester.

Signed-off-by: Florian Westphal <fw@strlen.de>
12 years agoexpr: limit: avoid huge rodata array
Pablo Neira Ayuso [Tue, 22 Oct 2013 13:11:02 +0000 (15:11 +0200)] 
expr: limit: avoid huge rodata array

commit 10e0890e ('src: operational limit match') creates huge
array, increasing libnftables binary size. Use switch statement
instead.

Based on patch from Florian Westphal, for nft.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: limit: operational limit match
Phil Oester [Tue, 22 Oct 2013 08:48:22 +0000 (10:48 +0200)] 
expr: limit: operational limit match

The nft limit match currently does not work at all.  Below patches to
nftables, libnftables, and kernel address the issue.  A few notes on
the implementation:

- Removed support for nano/micro/milli second limits.  These seem pointless,
  given we are using jiffies in the limit match, not a hpet.  And who really
  needs to limit items down to sub-second level??

- 'depth' member is removed as unnecessary.  All we need in the kernel is the
  rate and the unit.

- 'stamp' member becomes the time we need to next refresh the token bucket,
  instead of being updated on every packet which goes through the match.

This closes netfilter bugzilla #827, reported by Eric Leblond.

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset_elem: fix access after free in case of parsing errors
Pablo Neira Ayuso [Mon, 21 Oct 2013 12:42:33 +0000 (14:42 +0200)] 
set_elem: fix access after free in case of parsing errors

If this fails to parse a set element, stop the processing.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: json: remove spaces
Álvaro Neira Ayuso [Sun, 13 Oct 2013 19:52:34 +0000 (21:52 +0200)] 
src: json: remove spaces

Remove all the spaces from the JSON output to reduce the size
of the output string, this also provides a consistent output
in table, chain, rule and set.

As Stephen Hemminger suggested, better to squash the output to
consume as less bytes as possible.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoruleset: fix compilation warning
Pablo Neira Ayuso [Wed, 2 Oct 2013 08:27:29 +0000 (10:27 +0200)] 
ruleset: fix compilation warning

Due to missing calloc definition in stdlib.h, spotted by gcc-4.8.

Reported-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add low-level ruleset API
Arturo Borrero [Mon, 30 Sep 2013 22:33:18 +0000 (00:33 +0200)] 
src: add low-level ruleset API

This patch adds a low level ruleset API for libnftables.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: json: fix returned string length
Pablo Neira Ayuso [Fri, 27 Sep 2013 14:03:37 +0000 (16:03 +0200)] 
set: json: fix returned string length

Similar to (e7c068d rule: json: fix returned string length).

Based on patch from Arturo.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: snprintf: fix buffer lengths
Arturo Borrero [Wed, 25 Sep 2013 22:13:08 +0000 (00:13 +0200)] 
src: snprintf: fix buffer lengths

Use 'len' instead of 'size' since we need the remaining unused bytes
in the buffer, not its total size.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset_elem: xml: avoid code duplication
Arturo Borrero [Wed, 25 Sep 2013 22:13:02 +0000 (00:13 +0200)] 
set_elem: xml: avoid code duplication

This patch removes 3x code duplication in the XML snprintf function.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: json: fix returned string length
Alvaro Neira Ayuso [Wed, 25 Sep 2013 20:06:34 +0000 (22:06 +0200)] 
rule: json: fix returned string length

It was returning one byte more than the real string length.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-set-get: retrieve all sets per family
Pablo Neira Ayuso [Tue, 24 Sep 2013 16:29:33 +0000 (18:29 +0200)] 
examples: nft-set-get: retrieve all sets per family

Likewise other nftables objects, this patch allows you to dump
the sets per family.

This is possible since kernel changes (netfilter: nf_tables: allow
to dump all existing sets), we can get the full list of sets per
family.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: json: fix wrong indentation in nft_rule_snprintf_json
Pablo Neira Ayuso [Tue, 24 Sep 2013 14:56:59 +0000 (16:56 +0200)] 
rule: json: fix wrong indentation in nft_rule_snprintf_json

Comestic cleanup.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: get rid of NFTA_RULE_FLAGS
Pablo Neira Ayuso [Tue, 24 Sep 2013 10:30:39 +0000 (12:30 +0200)] 
rule: get rid of NFTA_RULE_FLAGS

It has been removed after (netfilter: nf_tables: all rule
updates are transactional).

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: replace size_t by uint32_t in set/get interfaces
Pablo Neira Ayuso [Thu, 19 Sep 2013 18:11:27 +0000 (20:11 +0200)] 
src: replace size_t by uint32_t in set/get interfaces

This patch breaks the ABI to shrink the size parameter from 8
to 4 bytes in x86_64. The maximum length of netlink attributes
is 2 bytes, so 4 bytes as attribute payload length should be
enough.

After this patch, size_t is only used in the nft_*_snprintf
interfaces.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: don't put NFTA_RULE_EXPRESSION into messages
Pablo Neira Ayuso [Tue, 17 Sep 2013 16:24:30 +0000 (18:24 +0200)] 
rule: don't put NFTA_RULE_EXPRESSION into messages

If there are no expressions in this rule, skip the
NFTA_RULE_EXPRESSION attribute, otherwise it will be
empty.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add nft_*_list_del
Pablo Neira Ayuso [Tue, 17 Sep 2013 14:16:22 +0000 (16:16 +0200)] 
src: add nft_*_list_del

This allows us to delete object from the list, note that
nft_chain_list_del already existed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: fix build error
Arturo Borrero Gonzalez [Mon, 16 Sep 2013 18:20:34 +0000 (20:20 +0200)] 
build: fix build error

This declaration was missing and is needed in case you compile libnftables
without XML parsing support.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: xml: refactor XML parsing code
Arturo Borrero Gonzalez [Mon, 16 Sep 2013 18:24:51 +0000 (20:24 +0200)] 
src: xml: refactor XML parsing code

This patch refactors nft_*_xml_parse to provide a new intermediate function
nft_mxml_parse_* which will allow us to navigate an entire XML tree
containing a ruleset without xml2text2xml conversions.

While at it, I added a helper to build the XML tree and validate the top node
name.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
12 years agosrc: xml: avoid unecessary tree to text to tree conversions
Arturo Borrero Gonzalez [Fri, 13 Sep 2013 12:45:21 +0000 (14:45 +0200)] 
src: xml: avoid unecessary tree to text to tree conversions

This patch avoid several tree to text to tree conversions in the XML
parsing helpers.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: xml: add parsing optional/mandatory flag
Arturo Borrero Gonzalez [Fri, 13 Sep 2013 12:05:51 +0000 (14:05 +0200)] 
src: xml: add parsing optional/mandatory flag

Add an optional/mandatory flag to XML parsing.

In some elements (ie regs), no flag is used because is always mandatory.

DATA_NONE is created to indicate a non-parsed data_reg.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: fix compilation warning
Álvaro Neira Ayuso [Thu, 12 Sep 2013 17:16:19 +0000 (19:16 +0200)] 
set: fix compilation warning

Signed-off-by: Álvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: log: use real length when fetching attributes
Florian Westphal [Fri, 13 Sep 2013 14:44:47 +0000 (16:44 +0200)] 
expr: log: use real length when fetching attributes

NFTA_LOG_SNAPLEN is u32 and NFTA_LOG_QTHRESHOLD is u16.
Without this, netlink messages from kernel fail mnl_validate step when
QTHRESH or SNAPLEN was set.

Also, nft_rule_expr_log_get must update data_length, else 'nft list' doesn't
show log arguments (prefix, group ..) because the netlink message
decoding uses nft_rule_expr_get_u16/32 etc. which validate the length, too.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: json: refactor json parsing to allow tree based navigation
Álvaro Neira Ayuso [Thu, 12 Sep 2013 17:16:37 +0000 (19:16 +0200)] 
src: json: refactor json parsing to allow tree based navigation

This patch refactors nft_*_json_parse to provide a new
intermediate function nft_jansson_parse_chain which will
allows us to navigate the entire json tree containing the
ruleset.

Signed-off-by: Álvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: use helper function nft_jansson_free_root
Álvaro Neira Ayuso [Thu, 12 Sep 2013 17:16:28 +0000 (19:16 +0200)] 
rule: use helper function nft_jansson_free_root

Signed-off-by: Álvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: use human readable netfilter hook
Pablo Neira Ayuso [Thu, 5 Sep 2013 19:54:56 +0000 (21:54 +0200)] 
chain: use human readable netfilter hook

Since (108d9f6 src: Wrap netfilter hooks around human readable strings)
in nft, we have to use human readable netfilter hooks.

This patch also adapts the XML and JSON tests.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-{chain,rule,table}-get allows unspec family
Pablo Neira Ayuso [Thu, 5 Sep 2013 19:10:50 +0000 (21:10 +0200)] 
examples: nft-{chain,rule,table}-get allows unspec family

To obtain any table, chain and rule.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: display configuration after ./configure
Pablo Neira Ayuso [Thu, 5 Sep 2013 17:03:23 +0000 (19:03 +0200)] 
build: display configuration after ./configure

libnftables configuration:
  XML support:                          no
  JSON support:                         no

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: xml: fix key_type parsing
Arturo Borrero [Wed, 4 Sep 2013 16:03:25 +0000 (18:03 +0200)] 
set: xml: fix key_type parsing

Bug introduced by myself at 44928cd5 [set: add XML parsing]

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: xml: fix parsing of optional attributes
Arturo Borrero [Sun, 1 Sep 2013 23:32:31 +0000 (01:32 +0200)] 
chain: xml: fix parsing of optional attributes

This patch fixes the parsing of custom chains in XML.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: Add nft-set-json-add
Álvaro Neira Ayuso [Tue, 27 Aug 2013 18:11:02 +0000 (20:11 +0200)] 
examples: Add nft-set-json-add

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: set: add json parsing support
Álvaro Neira Ayuso [Tue, 27 Aug 2013 18:10:55 +0000 (20:10 +0200)] 
tests: set: add json parsing support

Test the functions for parsing set in JSON.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: Add json parser support
Álvaro Neira Ayuso [Tue, 27 Aug 2013 18:10:47 +0000 (20:10 +0200)] 
set: Add json parser support

Add function for parsing set in format JSON.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: remove unnecessary variable initialization
Álvaro Neira Ayuso [Tue, 27 Aug 2013 18:10:37 +0000 (20:10 +0200)] 
tests: remove unnecessary variable initialization

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: json: s/nft_jansson_value_parse_reg/nft_jansson_parse_reg/g
Pablo Neira Ayuso [Sat, 24 Aug 2013 16:27:58 +0000 (18:27 +0200)] 
src: json: s/nft_jansson_value_parse_reg/nft_jansson_parse_reg/g

This patch is a cleanup to save LOC.

I have also changed it to use < 0 to check for error conditions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: json: s/nft_jansson_value_parse_val/nft_jansson_parse_val/g
Pablo Neira Ayuso [Sat, 24 Aug 2013 16:08:17 +0000 (18:08 +0200)] 
src: json: s/nft_jansson_value_parse_val/nft_jansson_parse_val/g

This patch is a cleanup to save LOC.

I have also changed it to use < 0 to check for error conditions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: json: s/nft_jansson_value_parse_str/nft_jansson_parse_str/g
Pablo Neira Ayuso [Sat, 24 Aug 2013 15:57:16 +0000 (17:57 +0200)] 
src: json: s/nft_jansson_value_parse_str/nft_jansson_parse_str/g

Remove _value_ infix to make the function name smaller.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: xml/json: support rule position attribute
Arturo Borrero [Fri, 23 Aug 2013 11:35:35 +0000 (13:35 +0200)] 
rule: xml/json: support rule position attribute

Note that the position attr is optional as stated in
net/netfilter/nf_tables_api.c

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: constify nft_*_parse input data
Arturo Borrero Gonzalez [Wed, 21 Aug 2013 19:21:29 +0000 (21:21 +0200)] 
src: constify nft_*_parse input data

Since the input string is not changing, let's make it constant.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: Add nft-rule-json-add
Álvaro Neira Ayuso [Tue, 20 Aug 2013 15:59:03 +0000 (17:59 +0200)] 
examples: Add nft-rule-json-add

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
12 years agotests: rule: add json parsing support
Álvaro Neira Ayuso [Tue, 20 Aug 2013 15:58:56 +0000 (17:58 +0200)] 
tests: rule: add json parsing support

Test the functions for parsing rules in JSON.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
12 years agorule: Add json parser support
Álvaro Neira Ayuso [Tue, 20 Aug 2013 15:58:46 +0000 (17:58 +0200)] 
rule: Add json parser support

Add function for parsing rules in JSON format

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoutils: fix error path for nft_strtoi
Arturo Borrero [Mon, 19 Aug 2013 12:37:30 +0000 (14:37 +0200)] 
utils: fix error path for nft_strtoi

If the return of nft_get_value() is not evaluated, we don't know if
the parsed value is between the limits of its type.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: fix memory leaks in jansson test
Álvaro Neira Ayuso [Wed, 14 Aug 2013 10:19:31 +0000 (12:19 +0200)] 
tests: fix memory leaks in jansson test

Fixed a string leak and a jansson leak.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agojson: fixed some leaks in the json parsing function
Álvaro Neira Ayuso [Wed, 14 Aug 2013 10:19:19 +0000 (12:19 +0200)] 
json: fixed some leaks in the json parsing function

This patch fixes some leaks in the json parsing function. After this patch,
we use nft_jansson_free_root. This function uses json_decref and it
decrements the reference count and it releases the node if needed.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add nft_rule_expr_get_u16 and nft_rule_expr_set_u16
Pablo Neira Ayuso [Sat, 17 Aug 2013 10:40:32 +0000 (12:40 +0200)] 
expr: add nft_rule_expr_get_u16 and nft_rule_expr_set_u16

Now required since log has two u16 fields.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: log: group and qthreshold are 16 bits long
Pablo Neira Ayuso [Wed, 14 Aug 2013 22:08:58 +0000 (00:08 +0200)] 
expr: log: group and qthreshold are 16 bits long

Since kernel patch: netfilter: nft_log: group and qthreshold are 2^16

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: xml: consolidate error path
Pablo Neira Ayuso [Wed, 14 Aug 2013 09:28:47 +0000 (11:28 +0200)] 
rule: xml: consolidate error path

Save a good bunch of lines of code with this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: xml: use nft_mxml_str_parse
Pablo Neira Ayuso [Wed, 14 Aug 2013 09:25:19 +0000 (11:25 +0200)] 
chain: xml: use nft_mxml_str_parse

Replace existing code to use nft_mxml_str_parse.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: xml: don't duplicate string in nft_table_xml_parse
Pablo Neira Ayuso [Wed, 14 Aug 2013 09:10:58 +0000 (11:10 +0200)] 
src: xml: don't duplicate string in nft_table_xml_parse

With this patch, nft_table_xml_parse does not duplicate the string
anymore, which is what most callers seem to need. This fixes memleaks
in several places in the code. Thus, this patch also adapts the code
to duplicate it when needed.

Based on patch from Arturo Borrero.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: release expressions that are part of rules
Pablo Neira Ayuso [Tue, 13 Aug 2013 23:07:13 +0000 (01:07 +0200)] 
rule: release expressions that are part of rules

==11917== 96 bytes in 1 blocks are definitely lost in loss record 1 of 1
==11917==    at 0x4C272B8: calloc (vg_replace_malloc.c:566)
==11917==    by 0x4E3A46F: nft_rule_expr_alloc (expr.c:38)
==11917==    by 0x4E3A331: nft_jansson_expr_parse (jansson.c:165)
==11917==    by 0x4E36F66: nft_rule_json_parse (rule.c:542)
==11917==    by 0x400EA4: main (nft-rule-json-add.c:68)

Reported-by: Álvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonat: xml: fix wrong node name in snprintf
Arturo Borrero [Mon, 12 Aug 2013 07:35:39 +0000 (09:35 +0200)] 
nat: xml: fix wrong node name in snprintf

This patch renames all <nat_type> nodes to <type> in nat expr.
A bug is fixed, since the default option in snprintf was already
<type>.

This follows the pattern of avoid prefixing XML nodes.

Note that this is mostly reverting what was done at:
31e34c3 (nat: xml: rename node type to nat_type).

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: xml: delete <use> node
Arturo Borrero [Mon, 12 Aug 2013 07:35:34 +0000 (09:35 +0200)] 
chain: xml: delete <use> node

Since the 'use' attribute in a chain can't be set, ignore it in the
XML printing.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: xml: reorder XML elements in sets
Arturo Borrero [Mon, 12 Aug 2013 07:35:29 +0000 (09:35 +0200)] 
tests: xml: reorder XML elements in sets

Some node reorganization in order to have an input file equal to
what set_snprintf will output.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoxml: expr: limit: fix wrong assignation when parsing
Arturo Borrero [Mon, 12 Aug 2013 07:35:23 +0000 (09:35 +0200)] 
xml: expr: limit: fix wrong assignation when parsing

This assignation was wrong.

Introduced at commit e13819c
(src: xml: consolidate common XML code via nft_mxml_num_parse).

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: remove superfluous if checking in test_json
Pablo Neira Ayuso [Sun, 11 Aug 2013 07:50:05 +0000 (09:50 +0200)] 
tests: remove superfluous if checking in test_json

It's already done a couple of lines above.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: better parsing validation
Álvaro Neira Ayuso [Sat, 10 Aug 2013 19:40:51 +0000 (21:40 +0200)] 
tests: better parsing validation

Before this patch, the test only verified that we could parse
the file. After this, it also compares what it has parsed with
the original file.

Basically, the idea is that:

file -> buffer -> object -> buffer'
   read               snprintf

So we also compare that buffer = buffer' which should be true
since our tests should be based on the output that the library
generates.

This is an example output for the OK and FAILED cases:

parsing and validating xmlfiles/25-rule-exthdr.xml: OK
validating xmlfiles/27-rule-limit.xml: FAILED
from file:     it"><rate>123123</ra
from snprintf: it"><rate>321321</ra

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: expr: use the function base2str in payload
Álvaro Neira Ayuso [Sat, 10 Aug 2013 19:40:39 +0000 (21:40 +0200)] 
src: expr: use the function base2str in payload

Use base2str instead to consolidate code in the snprintf path.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: xml: remove \t and \n from all the files
Pablo Neira Ayuso [Sat, 10 Aug 2013 10:52:12 +0000 (12:52 +0200)] 
tests: xml: remove \t and \n from all the files

These XML files are intented to be used for automated tests. Thus, it's
important to have exactly the same output that was generated by the library.

The beautified output does not match the real output that the library provides
and it just makes things harder for us to provide a more advanced automated
testing.

If you want to make any of those file human readable, please use:

    xmllint --format file.xml

or open the xml file and any browser, eg. firefox.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: payload: fix missing base setting in XML parser
Pablo Neira Ayuso [Fri, 9 Aug 2013 17:05:22 +0000 (19:05 +0200)] 
expr: payload: fix missing base setting in XML parser

Reported-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agojansson: Add nft_jansson_family function
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:14:46 +0000 (13:14 +0200)] 
jansson: Add nft_jansson_family function

Refactor some existing code with the new function nft_jansson_family.

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexample: nft-rule-get: family parameter added
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:14:31 +0000 (13:14 +0200)] 
example: nft-rule-get: family parameter added

I have added the parameter family in the example nft-rule-get.

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: payload: add nft_str2base function
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:14:16 +0000 (13:14 +0200)] 
expr: payload: add nft_str2base function

Add function that will be use in the JSON parser

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: nat: add nft_str2nat function
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:13:59 +0000 (13:13 +0200)] 
expr: nat: add nft_str2nat function

Add function that will be use in the JSON parser.

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: cmp: add nft_str2cmp function
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:13:45 +0000 (13:13 +0200)] 
expr: cmp: add nft_str2cmp function

Add function that will be use in the JSON parser

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: bytecode: add nft_str2ntoh function
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:13:31 +0000 (13:13 +0200)] 
expr: bytecode: add nft_str2ntoh function

Add function that will be use in the JSON parser.

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: json: delete unneeded JSON prefixes
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:13:14 +0000 (13:13 +0200)] 
src: json: delete unneeded JSON prefixes

This patch adapts JSON nodes to mimic current XML node tags.

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agojson: bitwise: add missing node len
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:13:00 +0000 (13:13 +0200)] 
json: bitwise: add missing node len

I have added the len node in bitwise which was missing

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: ct: optional output in ct
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:12:46 +0000 (13:12 +0200)] 
expr: ct: optional output in ct

Display direction and key if available

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: fix display of compat_flag and compat_proto
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:12:32 +0000 (13:12 +0200)] 
src: fix display of compat_flag and compat_proto

Fixed display compat_proto value and compat_flag if available.

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: expr: fix wrong value in the chain field of data_reg
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:12:19 +0000 (13:12 +0200)] 
src: expr: fix wrong value in the chain field of data_reg

Fixed wrong value in data_reg_chain snprintf.

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: expr: missing curly braces in json output support
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:12:05 +0000 (13:12 +0200)] 
src: expr: missing curly braces in json output support

Added missing curly braces in json output support.

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: expr: missing commas in json output support
Álvaro Neira Ayuso [Fri, 9 Aug 2013 11:11:48 +0000 (13:11 +0200)] 
src: expr: missing commas in json output support

Added missing commas in json output support.

Signed-off-by: Alvaro Neira Ayuso Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: xml: cleanup set element parsing
Pablo Neira Ayuso [Wed, 7 Aug 2013 20:31:52 +0000 (22:31 +0200)] 
src: xml: cleanup set element parsing

Move nft_mxml_set_elem_parse to set_elem.c to improve readability, thus,
we don't need to jump from set_elem.c to mxml.c to see how the parsing
is done.

I have also refactored some common parsing code in the new helper
function nft_mxml_set_elem_parse, that avoids conversions from XML tree
to text and then again back to tree.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>