]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
11 years agoset: add support for set mechanism selection
Arturo Borrero [Mon, 14 Jul 2014 08:41:26 +0000 (10:41 +0200)] 
set: add support for set mechanism selection

This patch adds support to select the set mechanism.
The kernel support was added in commit:

 c50b960 netfilter: nf_tables: implement proper set selection

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: stricter netlink attribute length validation
Pablo Neira Ayuso [Sun, 20 Jul 2014 12:09:34 +0000 (14:09 +0200)] 
src: stricter netlink attribute length validation

If the kernel sends us different data length for a given attribute,
stop further processing and indicate that an ABI breakage has ocurred.
This is an example of the (hypothetical) message that is shown in that
case:

 nf_tables kernel ABI is broken, contact your vendor.
 table.c:214 reason: Numerical result out of range

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: log: define variable flags in xml parser
Álvaro Neira Ayuso [Mon, 14 Jul 2014 19:04:31 +0000 (21:04 +0200)] 
expr: log: define variable flags in xml parser

In the xml parser, we have used a variable flags for parsing it
but we have forgot define it. This patch solves a compile error
like:

expr/log.c:263:12: error: 'flags' undeclared (first use in this function)

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: log: add support for level and flags
Pablo Neira Ayuso [Thu, 19 Jun 2014 18:28:29 +0000 (20:28 +0200)] 
expr: log: add support for level and flags

This is required by changes scheduled for Linux kernel 3.17.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agochain: Do not print unset attributes in json
Ana Rey [Mon, 30 Jun 2014 11:50:08 +0000 (13:50 +0200)] 
chain: Do not print unset attributes in json

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agochain: Rename variables in nft_jansson_parse_chain functions
Ana Rey [Mon, 30 Jun 2014 11:50:07 +0000 (13:50 +0200)] 
chain: Rename variables in nft_jansson_parse_chain functions

Renames some variables for code readability reasons.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agochain: Do not print unset attributes in xml
Ana Rey [Mon, 30 Jun 2014 11:50:06 +0000 (13:50 +0200)] 
chain: Do not print unset attributes in xml

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agochain: Add all support of use attribute
Ana Rey [Mon, 30 Jun 2014 11:50:05 +0000 (13:50 +0200)] 
chain: Add all support of use attribute

Add set, unset, get, parse and build payload implementation for use value.

These changes are neeeded for a correct import/export of xml/json file

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotable: Do not print unset values in json file
Ana Rey [Thu, 26 Jun 2014 17:08:41 +0000 (19:08 +0200)] 
table: Do not print unset values in json file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotable: Do not print unset values in xml file
Ana Rey [Thu, 26 Jun 2014 17:08:40 +0000 (19:08 +0200)] 
table: Do not print unset values in xml file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotable: Add set, unset and parse implementation for the use attribute
Ana Rey [Thu, 26 Jun 2014 17:08:39 +0000 (19:08 +0200)] 
table: Add set, unset and parse implementation for the use attribute

Add some parts of the implemention of 'use' vualue in table that miss it.

These changes are neeeded for a correct import/export of xml/json file

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotable: Use nft_table_attr_set_* in the xml functions
Ana Rey [Thu, 26 Jun 2014 17:08:38 +0000 (19:08 +0200)] 
table: Use nft_table_attr_set_* in the xml functions

Code refactoring to use nft_table_attr_set_* in parse xml functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotable: Free memory in the same function that is reserved
Ana Rey [Thu, 26 Jun 2014 17:08:37 +0000 (19:08 +0200)] 
table: Free memory in the same function that is reserved

Free memory in the same function that is reserved.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agochain: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Thu, 26 Jun 2014 16:38:56 +0000 (18:38 +0200)] 
chain: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agochain: Free memory in the same function that is reserved
Ana Rey [Thu, 26 Jun 2014 16:38:55 +0000 (18:38 +0200)] 
chain: Free memory in the same function that is reserved

Free memory in the same function that is reserved.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agobump version to 1.0.2 libnftnl-1.0.2
Pablo Neira Ayuso [Wed, 25 Jun 2014 14:42:47 +0000 (16:42 +0200)] 
bump version to 1.0.2

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: match: Do not print unset values in json file
Ana Rey [Tue, 24 Jun 2014 17:15:04 +0000 (19:15 +0200)] 
expr: match: Do not print unset values in json file

It changes the parse and snprintf functions json to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: match: Do not print unset values in xml file
Ana Rey [Tue, 24 Jun 2014 17:15:03 +0000 (19:15 +0200)] 
expr: match: Do not print unset values in xml file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: match: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Tue, 24 Jun 2014 17:15:02 +0000 (19:15 +0200)] 
expr: match: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: match: get a nft_rule_expr type in nft_rule_expr_match_snprintf_* functions
Ana Rey [Tue, 24 Jun 2014 17:15:01 +0000 (19:15 +0200)] 
expr: match: get a nft_rule_expr type in nft_rule_expr_match_snprintf_* functions

Code refactoring in nft_rule_expr_match_snprintf_* functions to get a
nft_rule_expr type instead of nft_expr_match type.

The nft_rule_expr type is needed to check information into flags variables.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: lookup: Do not print unset values in json file
Ana Rey [Tue, 24 Jun 2014 17:14:17 +0000 (19:14 +0200)] 
expr: lookup: Do not print unset values in json file

It changes the parse functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: lookup: Do not print unset values in xml file
Ana Rey [Tue, 24 Jun 2014 17:14:16 +0000 (19:14 +0200)] 
expr: lookup: Do not print unset values in xml file

It changes the parse functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: lookup: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Tue, 24 Jun 2014 17:14:15 +0000 (19:14 +0200)] 
expr: lookup: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: exthdr: Do not print unset values in json
Ana Rey [Tue, 24 Jun 2014 12:33:47 +0000 (14:33 +0200)] 
expr: exthdr: Do not print unset values in json

It changes the parse and the snprint functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: exthdr: Do not print unset values in xml
Ana Rey [Tue, 24 Jun 2014 12:33:46 +0000 (14:33 +0200)] 
expr: exthdr: Do not print unset values in xml

It changes the parse and the snprint functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: exthdr: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Tue, 24 Jun 2014 12:33:45 +0000 (14:33 +0200)] 
expr: exthdr: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: exthdr: Add nft_rule_expr_exthdr_snprinf_* functions
Ana Rey [Tue, 24 Jun 2014 12:33:44 +0000 (14:33 +0200)] 
expr: exthdr: Add nft_rule_expr_exthdr_snprinf_* functions

Code refactoring in nft_rule_expr_exthdr functions.

This patch adds three new functions:
* nft_rule_expr_exthdr_snprinf_default
* nft_rule_expr_exthdr_snprinf_xml
* nft_rule_expr_exthdr_snprinf_json

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: counter: Do not print unset values in json
Ana Rey [Tue, 24 Jun 2014 07:15:38 +0000 (09:15 +0200)] 
expr: counter: Do not print unset values in json

It changes the parse and the snprint functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: counter: Do not print unset values in xml
Ana Rey [Tue, 24 Jun 2014 07:15:37 +0000 (09:15 +0200)] 
expr: counter: Do not print unset values in xml

It changes the parse and the snprint functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: counter: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Tue, 24 Jun 2014 07:15:36 +0000 (09:15 +0200)] 
expr: counter: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: counter: Add nft_rule_expr_counter_snprinf_* functions
Ana Rey [Tue, 24 Jun 2014 07:15:35 +0000 (09:15 +0200)] 
expr: counter: Add nft_rule_expr_counter_snprinf_* functions

Code refactoring in nft_rule_expr_counter_snprinf functions.

This patch adds three new functions:
 * nft_rule_expr_counter_snprinf_default
 * nft_rule_expr_counter_snprinf_xml
 * nft_rule_expr_counter_snprinf_json

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: ct: Do not parse unset values in json
Ana Rey [Tue, 24 Jun 2014 06:46:41 +0000 (08:46 +0200)] 
expr: ct: Do not parse unset values in json

It changes the parse functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: ct: Delete the last comma character in json text
Ana Rey [Tue, 24 Jun 2014 06:46:39 +0000 (08:46 +0200)] 
expr: ct: Delete the last comma character in json text

Code refactoring to delete correctly the last comma character in json text.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: ct: Do not print unset values in xml file
Ana Rey [Tue, 24 Jun 2014 06:46:38 +0000 (08:46 +0200)] 
expr: ct: Do not print unset values in xml file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: ct: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Tue, 24 Jun 2014 06:46:37 +0000 (08:46 +0200)] 
expr: ct: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: nat: add helper function to translate nat types to string
Arturo Borrero [Fri, 20 Jun 2014 08:55:08 +0000 (10:55 +0200)] 
expr: nat: add helper function to translate nat types to string

This patch adds a helper functon to translate nat types to string.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: cmp: Do not print unset values in json file
Ana Rey [Thu, 19 Jun 2014 17:34:24 +0000 (19:34 +0200)] 
expr: cmp: Do not print unset values in json file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: cmp: Do not print unset values in xml file
Ana Rey [Thu, 19 Jun 2014 17:34:23 +0000 (19:34 +0200)] 
expr: cmp: Do not print unset values in xml file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: cmp: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Thu, 19 Jun 2014 17:34:22 +0000 (19:34 +0200)] 
expr: cmp: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_cmp_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: cmp: Get a nft_rule_expr type in nft_rule_expr_cmp_snprintf_* functions
Ana Rey [Thu, 19 Jun 2014 17:34:21 +0000 (19:34 +0200)] 
expr: cmp: Get a nft_rule_expr type in nft_rule_expr_cmp_snprintf_* functions

Code refactoring in nft_rule_expr_cmp_snprintf_* functions to get a
nft_rule_expr type instead of nft_expr_cmp type.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: byteorder: Do not print unset values in json
Ana Rey [Thu, 19 Jun 2014 15:07:10 +0000 (17:07 +0200)] 
expr: byteorder: Do not print unset values in json

It changes the parse and the snprint functions to omit unset values.

Now, This part of a json file is gotten without unset elements.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: byteorder: Rename variables in nft_rule_expr_byteorder_json_parse functions
Ana Rey [Thu, 19 Jun 2014 15:07:09 +0000 (17:07 +0200)] 
expr: byteorder: Rename variables in nft_rule_expr_byteorder_json_parse functions

Renames some variables for code readability reasons.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: byteorder: Do not print unset values in xml file
Ana Rey [Thu, 19 Jun 2014 15:07:08 +0000 (17:07 +0200)] 
expr: byteorder: Do not print unset values in xml file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: byteorder: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Thu, 19 Jun 2014 15:07:07 +0000 (17:07 +0200)] 
expr: byteorder: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: byteorder: Get a nft_rule_expr type in nft_rule_expr_byteorder_snprintf_* functions
Ana Rey [Thu, 19 Jun 2014 15:07:06 +0000 (17:07 +0200)] 
expr: byteorder: Get a nft_rule_expr type in nft_rule_expr_byteorder_snprintf_* functions

Code refactoring in nft_rule_expr_byteorder_snprintf_* functions to get a
nft_rule_expr type instead of nft_expr_byorder type.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: target: Do not print unset values in json file
Ana Rey [Mon, 23 Jun 2014 09:38:20 +0000 (11:38 +0200)] 
expr: target: Do not print unset values in json file

It changes the parse and snrintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: target: Do not print unset values in xml file
Ana Rey [Mon, 23 Jun 2014 09:38:19 +0000 (11:38 +0200)] 
expr: target: Do not print unset values in xml file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: target: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Mon, 23 Jun 2014 09:38:18 +0000 (11:38 +0200)] 
expr: target: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: target: get a nft_rule_expr type in nft_rule_expr_target_snprintf_* functions
Ana Rey [Mon, 23 Jun 2014 09:38:17 +0000 (11:38 +0200)] 
expr: target: get a nft_rule_expr type in nft_rule_expr_target_snprintf_* functions

Code refactoring in nft_rule_expr_target_snprintf_* functions to get a
nft_rule_expr type instead of nft_expr_target type. The nft_rule_expr is
needed to check information into flags variables.

Moreover, It remanes some variables like 'tg' to 'target' for code
readability reasons.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: payload: Do not print unset values in json file
Ana Rey [Sun, 22 Jun 2014 18:32:21 +0000 (20:32 +0200)] 
expr: payload: Do not print unset values in json file

It changes the parse functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
11 years agoexpr: payload: Do not print unset values in xml file
Ana Rey [Sun, 22 Jun 2014 18:32:20 +0000 (20:32 +0200)] 
expr: payload: Do not print unset values in xml file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: payload: get a nft_rule_expr type in nft_rule_expr_payload_snprintf_* functions.
Ana Rey [Sun, 22 Jun 2014 18:32:19 +0000 (20:32 +0200)] 
expr: payload: get a nft_rule_expr type in nft_rule_expr_payload_snprintf_* functions.

Code refactoring in nft_rule_expr_payload_snprintf_* functions to get a
nft_rule_expr type instead of nft_expr_payload type. The nft_rule_expr is
needed to check information into flags variables.

Moreover, It remanes a variable from 'p' to 'payload' for code
readability reasons.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: payload: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Sun, 22 Jun 2014 18:32:18 +0000 (20:32 +0200)] 
expr: payload: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: meta: Do not print unset values in json file
Ana Rey [Sat, 21 Jun 2014 16:30:00 +0000 (18:30 +0200)] 
expr: meta: Do not print unset values in json file

It changes the parse and snprintf functions to omit unset values.
Moreover, It adds some whitespaces arount '+' caracter, as the CodingStyle
recommends.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: meta: Do not print unset values in xml file
Ana Rey [Sat, 21 Jun 2014 16:29:58 +0000 (18:29 +0200)] 
expr: meta: Do not print unset values in xml file

It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: meta: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Sat, 21 Jun 2014 16:29:57 +0000 (18:29 +0200)] 
expr: meta: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: immediate: Do not print unset values in xml file
Ana Rey [Sat, 21 Jun 2014 15:53:43 +0000 (17:53 +0200)] 
expr: immediate: Do not print unset values in xml file

It changes the parse functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: immediate: Do not print unset values in json file
Ana Rey [Sat, 21 Jun 2014 15:53:42 +0000 (17:53 +0200)] 
expr: immediate: Do not print unset values in json file

It changes the parse functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: immediate: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Sat, 21 Jun 2014 15:53:41 +0000 (17:53 +0200)] 
expr: immediate: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: bitwise: Do not print unset values in json
Ana Rey [Thu, 19 Jun 2014 10:05:39 +0000 (12:05 +0200)] 
expr: bitwise: Do not print unset values in json

It changes the parse and the snprint functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: bitwise: Do not print unset values in xml
Ana Rey [Thu, 19 Jun 2014 10:05:38 +0000 (12:05 +0200)] 
expr: bitwise: Do not print unset values in xml

It changes the parse and the snprint functions to omit unset values.

Now, This part of a xml file is gotten without unset elements.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: bitwise: Get a nft_rule_expr type in nft_rule_expr_bitwise_snprintf_* functions
Ana Rey [Thu, 19 Jun 2014 10:05:37 +0000 (12:05 +0200)] 
expr: bitwise: Get a nft_rule_expr type in nft_rule_expr_bitwise_snprintf_* functions

Code refactoring in nft_rule_expr_bitwise_snprintf_* functions to get a
nft_rule_expr type instead of nft_expr_bitwise type.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: remove alignment through XT_ALIGN in match and target
Pablo Neira Ayuso [Tue, 17 Jun 2014 20:05:20 +0000 (22:05 +0200)] 
expr: remove alignment through XT_ALIGN in match and target

The info area that this gets via the setter should be already
aligned. The caller has to care of this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: limit: Do not print unset values in xml
Ana Rey [Mon, 16 Jun 2014 09:10:17 +0000 (11:10 +0200)] 
expr: limit: Do not print unset values in xml

It changes the parse and the snprint functions to omit unset values.

Now, This part of a xml file is gotten without unset elements.

<expr type="limit">
<rate>400</rate>
<unit>60</unit>
</expr>

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: limit: Do not print unset values in json
Ana Rey [Mon, 16 Jun 2014 09:10:16 +0000 (11:10 +0200)] 
expr: limit: Do not print unset values in json

It changes the parse and the snprint functions to omit unset values.

Now, This part of a json file is gotten without unset elements.

{"expr":[{"type":"limit","rate":400,"unit":60}]}

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: limit: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Mon, 16 Jun 2014 09:10:15 +0000 (11:10 +0200)] 
expr: limit: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: limit: Add nft_rule_expr_limit_snprinf_* functions
Ana Rey [Mon, 16 Jun 2014 09:10:14 +0000 (11:10 +0200)] 
expr: limit: Add nft_rule_expr_limit_snprinf_* functions

Code refactoring in nft_rule_expr_limit_snprinf functions.
This process adds three new functions:

* nft_rule_expr_limit_snprinf_default
* nft_rule_expr_limit_snprinf_xml
* nft_rule_expr_limit_snprinf_json

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: nat: Do not print unset values in json file
Ana Rey [Fri, 13 Jun 2014 12:08:29 +0000 (14:08 +0200)] 
expr: nat: Do not print unset values in json file

It changes the parse functions to omit unset values.

Now, It possible to use a xml file like this:
[...]
      {
        "type": "nat",
        "nat_type": "snat",
        "family": "ip",
        "sreg_addr_min": 1,
        "sreg_addr_max": 1,
      }

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: nat: Do not print unset values in xml file
Ana Rey [Fri, 13 Jun 2014 12:08:28 +0000 (14:08 +0200)] 
expr: nat: Do not print unset values in xml file

It changes the parse functions to omit unset values.

Now, It possible to use a xml file like this:
[...]
<expr type="nat">
        <type>snat</type>
        <family>ip</family>
        <sreg_addr_min>1</sreg_addr_min>
        <sreg_addr_max>1</sreg_addr_max>
</expr></rule>

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: nat: Use nft_rule_expr_set_* in the xml
Ana Rey [Fri, 13 Jun 2014 12:08:27 +0000 (14:08 +0200)] 
expr: nat: Use nft_rule_expr_set_* in the xml

Code refactoring to use nft_rule_expr_set_* in parse xml functions. Also,
It renames some variables for code readability reasons and It converts some
variables from int to uint32_t.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: Add json and xml test file for queue
Ana Rey [Mon, 16 Jun 2014 09:06:38 +0000 (11:06 +0200)] 
tests: Add json and xml test file for queue

New xml and json test files.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: queue: Use snprintf and SNPRINTF_BUFFER_SIZE in snprintf_default function
Ana Rey [Mon, 16 Jun 2014 09:06:37 +0000 (11:06 +0200)] 
expr: queue: Use snprintf and SNPRINTF_BUFFER_SIZE in snprintf_default function

Code refactoring to use snprintf and SNPRINTF_BUFFER_SIZE in
snprintf_default functions. Also, It adapts to the next syntax in queue.
Added in:

http://git.netfilter.org/nftables/commit/?id=27619ffbe503ed4d9e59a02e81db9a7ac49d37af

Here, some examples:

ip test input 31
  [ queue num 3-5 bypass fanout]

ip test input 32 31
  [ queue num 0]

ip test input 33 32
  [ queue num 4]

ip test input 34 33
  [ queue num 2-6 bypass]

table ip test {
chain input {
 type filter hook input priority 0;
 queue num 3-5 bypass fanout
 queue num 0
 queue num 4
 queue num 2-6 bypass
}
}

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: queue: Use the correct data type
Ana Rey [Fri, 13 Jun 2014 09:31:53 +0000 (11:31 +0200)] 
expr: queue: Use the correct data type

Fix wrong data types, eg. queue num is u16.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: queue: Do not print unset values in json
Ana Rey [Fri, 13 Jun 2014 09:31:52 +0000 (11:31 +0200)] 
expr: queue: Do not print unset values in json

It changes the parse and the snprint functions to omit unset values.

This json file is gotten for a queue:

{"expr":[{"type":"queue","num":0,"total":1,"flags":0}]}

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: queue: Do not print unset values in xml
Ana Rey [Fri, 13 Jun 2014 09:31:51 +0000 (11:31 +0200)] 
expr: queue: Do not print unset values in xml

It changes the parse and the snprint functions to omit unset values.

This xml file is gotten for a queue:

[...]
<expr type="queue">
<num>0</num>
<total>1</total>
<flags>0</flags>
</expr>
[...]

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: queue: Use nft_rule_expr_* in the xml
Ana Rey [Fri, 13 Jun 2014 09:31:50 +0000 (11:31 +0200)] 
expr: queue: Use nft_rule_expr_* in the xml

Code refactoring to use nft_rule_expr_* in parse xml functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: queue: Add nft_rule_expr_queue_snprinf_* functions
Ana Rey [Fri, 13 Jun 2014 09:31:49 +0000 (11:31 +0200)] 
expr: queue: Add nft_rule_expr_queue_snprinf_* functions

Code refactoring in nft_rule_expr_queue_snprinf functions. This patch
adds three new functions:

* nft_rule_expr_queue_snprinf_default
* nft_rule_expr_queue_snprinf_xml
* nft_rule_expr_queue_snprinf_json

Moreover, I have deleted an unnecesary whitespace as the CodingStyle
recommends.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: xmlfiles: Test files without unset child elements in set elements
Ana Rey [Wed, 11 Jun 2014 15:50:51 +0000 (17:50 +0200)] 
tests: xmlfiles: Test files without unset child elements in set elements

Test files without unset child element in set elements.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoset: Free memory in the same function that is reserved
Ana Rey [Wed, 11 Jun 2014 17:37:35 +0000 (19:37 +0200)] 
set: Free memory in the same function that is reserved

Free memory in the same function that is reserved.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: set: Do not print unset values in json
Ana Rey [Wed, 11 Jun 2014 15:50:49 +0000 (17:50 +0200)] 
src: set: Do not print unset values in json

It changes the parse and the snprint functions to omit unset values.

This json file is gotten for a set:
{
  "set": {
    "name": "mi6set3",
    "table": "test6",
    "flags": "0",
    "family": "unknown",
    "key_type": "0",
    "key_len": "0",
    "set_elem": [
      {
        "flags": "0",
        "key": {
          "data_reg": {
            "type": "value",
            "len": "16",
            "data0": "0x000080fe",
            "data1": "0x00000000",
            "data2": "0xffb30202",
            "data3": "0x89001efe"

Now, This json file is gotten for a set without unset elements.
{
  "set": {
    "name": "mi6set3",
    "table": "test6",
    "family": "unknown",
    "set_elem": [
      {
        "key": {
          "data_reg": {
            "type": "value",
            "len": "16",
            "data0": "0x000080fe",
            "data1": "0x00000000",
            "data2": "0xffb30202",
            "data3": "0x89001efe"

[ Note: These fields are unset when they are obtained from the set element
  information --pablo. ]

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: set: Do not print unset values in xml
Ana Rey [Wed, 11 Jun 2014 15:50:48 +0000 (17:50 +0200)] 
src: set: Do not print unset values in xml

It changes the parse and the snprint functions to omit unset values.

This xml file is gotten for a set:

<set>
<family>unknown</family>
<table>test</table>
<name>miset</name>
<flags>0</flags>
<key_type>0</key_type>
<key_len>0</key_len>
<set_elem>
<flags>0</flags>
<key>
<data_reg type="value">
<len>4</len>
<data0>0x0401a8c0</data0>
</data_reg>
</key>
</set_elem>
<set_elem>
<flags>0</flags>
<key>
<data_reg type="value">
<len>4</len>
<data0>0x0501a8c0</data0>
</data_reg>
</key>
</set_elem>
</set>

Now, this xml file is gotten without unset values:

<set>
<family>unknown</family>
<table>test</table>
<name>miset</name>
<set_elem>
<key>
<data_reg type="value">
<len>4</len>
<data0>0x00000002</data0>
</data_reg>
</key>
</set_elem>
<set_elem>
<key>
<data_reg type="value">
<len>4</len>
<data0>0x0401a8c0</data0>
</data_reg>
</key>
</set_elem>
</set>

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agocommon: homogeneous error message in nft_parse_perror()
Pablo Neira Ayuso [Wed, 11 Jun 2014 17:10:01 +0000 (19:10 +0200)] 
common: homogeneous error message in nft_parse_perror()

The user-specified message should be used even if the error type
is unspecified. Moreover, make the output error message homogeneous.
Sometimes is was including a space before the ':' separator.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: nft-parsing-test: Display error reason when testing XML
Ana Rey [Wed, 11 Jun 2014 15:50:47 +0000 (17:50 +0200)] 
tests: nft-parsing-test: Display error reason when testing XML

Add the use of system errors (nft_parse_perror) in test_xml to know which
node is not found.

Example:
parsing xmlfiles/75-ruleset.xml: FAILED (Invalid argument)
Reason : Node "flags" not found

[ I have mangled this patch to rename this the current 'fail' message
  to 'Reason' --pablo ]

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: set: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Wed, 11 Jun 2014 15:50:46 +0000 (17:50 +0200)] 
src: set: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: xmlfile: Remove unset child elements in the log expression
Ana Rey [Thu, 29 May 2014 12:42:11 +0000 (14:42 +0200)] 
tests: xmlfile: Remove unset child elements in the log expression

Test files without unset child element in the log expression.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoconfigure: uclinux is also linux (nommu)
Gustavo Zacarias [Tue, 3 Jun 2014 20:10:19 +0000 (17:10 -0300)] 
configure: uclinux is also linux (nommu)

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: reject: Do not print unset values in json
Ana Rey [Wed, 4 Jun 2014 11:38:11 +0000 (13:38 +0200)] 
expr: reject: Do not print unset values in json

It changes the parse and the snprint functions to omit unset values.

If It uses this rule:
nft add rule ip test output input

It gets this json file:
[...] "expr":[{"type":"reject","type":0,"code":0}]}

Now, That rule creates this json file without null values:
[...] "expr":[{"type":"reject"}]}

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: reject: Convert the type of a variable
Ana Rey [Wed, 4 Jun 2014 11:38:10 +0000 (13:38 +0200)] 
expr: reject: Convert the type of a variable

Convert the type of a variable from uint16_t to uint8_t.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: reject: Do not print unset values in xml
Ana Rey [Wed, 4 Jun 2014 11:38:09 +0000 (13:38 +0200)] 
expr: reject: Do not print unset values in xml

It changes the parse and the snprint functions to omit unset values.

If we used this rule:
nft add rule ip test output reject

It gets this xml file:
[...]
<expr type="reject">
<type>0</type>
<code>0</code>
</expr>
</rule></nftables>

Now, That rule creates this xml file without null values:

[...]
<expr type="reject">
</expr>
</rule></nftables>

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: reject: Use nft_rule_expr_set_* in the xml
Ana Rey [Wed, 4 Jun 2014 11:38:08 +0000 (13:38 +0200)] 
expr: reject: Use nft_rule_expr_set_* in the xml

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
11 years agoexpr: reject: Add nft_rule_expr_reject_snprinf_* functions
Ana Rey [Wed, 4 Jun 2014 11:38:07 +0000 (13:38 +0200)] 
expr: reject: Add nft_rule_expr_reject_snprinf_* functions

Code refactoring in nft_rule_expr_reject_snprinf functions. This process
adds three new functions:

* nft_rule_expr_reject_snprinf_default
* nft_rule_expr_reject_snprinf_xml
* nft_rule_expr_reject_snprinf_json

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: log: Do not print unset values in json
Ana Rey [Wed, 4 Jun 2014 11:03:31 +0000 (13:03 +0200)] 
expr: log: Do not print unset values in json

It changes the parse and the snprint functions to omit unset values.

Also, It fixes an unnecessary comma after key-value pair type.
This comma is not necessary if there is not more key-value pairs in this expr.

Example:
"expr":[{"type":"log"}]

If It uses this rule:
nft add rule ip test output log

It gets this json file:

[...]
{"expr":[{"type":"log","prefix":"(null)","group":0,"snaplen":0,"qthreshold":0}]}
[...]

Now, That rule creates this json file without null values:

{"expr":[{"type":"log"}]}

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: log: Do not print unset values in xml
Ana Rey [Tue, 3 Jun 2014 10:41:56 +0000 (12:41 +0200)] 
expr: log: Do not print unset values in xml

It changes the parse and the snprint functions to omit unset values.

If we used this rule:
nft add rule ip test output log

We got this xml file:
<rule><family>ip</family>
<table>test</table>
<chain>output</chain>
<handle>88</handle>
<expr type="log">
        <prefix>(null)</prefix>
        <group>0</group>
        <snaplen>0</snaplen>
        <qthreshold>0</qthreshold>
</expr>
</rule>

And It was imposible import this file.

Now, That rule creates this xml file without null values:

<rule><family>ip</family>
<table>test</table>
<chain>output</chain>
<handle>88</handle>
<expr type="log">
</expr>
</rule>

and It's possible import this xml file.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: log: Use nft_rule_expr_set_* in the xml parsing code
Ana Rey [Tue, 3 Jun 2014 10:41:55 +0000 (12:41 +0200)] 
expr: log: Use nft_rule_expr_set_* in the xml parsing code

Code refactoring to use nft_rule_expr_set_* in parse functions.

Signed-off-by: Ana Rey <anarey@gmail.com>
Suggested-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: log: Rename variables in nft_rule_expr_log_json_parse functions
Ana Rey [Tue, 3 Jun 2014 10:41:54 +0000 (12:41 +0200)] 
expr: log: Rename variables in nft_rule_expr_log_json_parse functions

Renames some variables for code readability reasons.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: log: Code refactoring in nft_rule_expr_log_snprintf
Ana Rey [Thu, 29 May 2014 11:26:39 +0000 (13:26 +0200)] 
expr: log: Code refactoring in nft_rule_expr_log_snprintf

This process adds three new functions:

* nft_rule_expr_log_snprintf_default
* nft_rule_expr_log_snprintf_xml
* nft_rule_expr_log_snprintf_json

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoset: add set ID support
Pablo Neira Ayuso [Tue, 8 Apr 2014 10:32:14 +0000 (12:32 +0200)] 
set: add set ID support

Add the set ID (u32) which allows us to uniquely identify the set
in the batch that is sent to kernel-space.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoinclude: synchronize nf_tables.h with nftables tree
Pablo Neira Ayuso [Fri, 4 Apr 2014 13:50:49 +0000 (15:50 +0200)] 
include: synchronize nf_tables.h with nftables tree

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoutils: fix buffer reallocation of nft_fprinft()
Arturo Borrero [Tue, 13 May 2014 09:17:49 +0000 (11:17 +0200)] 
utils: fix buffer reallocation of nft_fprinft()

When _snprintf() reports it would print n characters, that n doesn't include
the trailing \0 that snprintf adds.

Thus, we need to [re]allocate n+1 characters.

While at it, change the reallocation trigger. If the length of the buffer we
used is equals to the expanded string length, the output has been truncated.
In other words, if ret == bufsiz, then the trailing \0 is missing.

Also, check if _snprintf() returned < 0, which means an error ocurred.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agointernal: fix SNPRINTF_BUFFER_SIZE macro
Arturo Borrero [Tue, 13 May 2014 07:08:15 +0000 (09:08 +0200)] 
internal: fix SNPRINTF_BUFFER_SIZE macro

We need to store in 'offset' the complete amount of characters as returned
from _snprintf. The value means how many characters long needs the buffer to be
in order to store the corresponding string expansion.

Before this patch, in cases where the buffer is smaller than the
expansion, then ret > len, and therefore ret = len.
So when incrementing offset, we do it with a wrong value.

All previous versions of libnftnl are unable to handle this situations: small
buffers (or long string expansion).

BTW, if a caller must reallocate a buffer to the returned value of snprintf, it
should be ret + 1.

While at it, let's add a check to know if the last snprintf call failed.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>