]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
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>
11 years agodata_reg: fix bad buffer size bounds
Arturo Borrero [Tue, 6 May 2014 17:19:46 +0000 (19:19 +0200)] 
data_reg: fix bad buffer size bounds

These calls need to use the new buffer size, instead of the
size that the buffer originally had.

Bugs introduced by myself at dec68741 [data_reg: fix verdict format approach].

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoruleset: fix erroneous call to snprintf
Arturo Borrero [Tue, 6 May 2014 15:09:33 +0000 (17:09 +0200)] 
ruleset: fix erroneous call to snprintf

This snprintf call is taking an erroneous value for size.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
11 years agocommon: fix unconditional output of event wrapping stuff
Arturo Borrero [Mon, 28 Apr 2014 10:58:38 +0000 (12:58 +0200)] 
common: fix unconditional output of event wrapping stuff

We can't unconditionally print out these strings.

Before this patch, objects being printed will be treated as an 'unkown' event.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexamples: nft-events: add option how to format the printed events
Pablo Neira Ayuso [Sat, 26 Apr 2014 11:49:23 +0000 (13:49 +0200)] 
examples: nft-events: add option how to format the printed events

 # ./nft-events xml
 <event><type>new</type><chain><name>xxx</name><handle>9</handle><bytes>0</bytes><packets>0</packets><table>test</table><family>ip</family></chain></event>

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: include xml and json test files via make distcheck
Pablo Neira Ayuso [Sat, 26 Apr 2014 10:35:56 +0000 (12:35 +0200)] 
tests: include xml and json test files via make distcheck

Reported-by: Kevin Fenzi <kevin@scrye.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexamples: nft-events: use new events wrappers
Arturo Borrero [Tue, 15 Apr 2014 18:13:31 +0000 (20:13 +0200)] 
examples: nft-events: use new events wrappers

Let's use the new event wrappers in the events example.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: add flag to add event wrapping in output functions
Arturo Borrero [Tue, 15 Apr 2014 18:12:58 +0000 (20:12 +0200)] 
src: add flag to add event wrapping in output functions

This patch uses the flag option of each output function to print an
event wrapper string in each object.

In order to use this functionality, the caller must pass the
corresponding flags: NFT_OF_EVENT_NEW / NFT_OF_EVENT_DEL.

(I have slightly refactorized the original code to add the xml/json
 header and footer --pablo).

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: include test-script.sh via make distcheck
Pablo Neira Ayuso [Fri, 25 Apr 2014 08:53:44 +0000 (10:53 +0200)] 
tests: include test-script.sh via make distcheck

Reported-by: Kevin Fenzi <kevin@scrye.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: Add support for input and output bridge interface name
Tomasz Bursztyka [Mon, 14 Apr 2014 12:41:29 +0000 (15:41 +0300)] 
meta: Add support for input and output bridge interface name

Add support for dedicated bridge meta key, related to device names:
- NFT_META_BRI_IIFNAME
- NFT_META_BRI_OIFNAME

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agobump version to 1.0.1 libnftnl-1.0.1
Pablo Neira Ayuso [Thu, 17 Apr 2014 10:51:02 +0000 (12:51 +0200)] 
bump version to 1.0.1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoinclude: add missing netfilter.h
Pablo Neira Ayuso [Thu, 17 Apr 2014 10:53:18 +0000 (12:53 +0200)] 
include: add missing netfilter.h

  CC     chain.lo
../../src/chain.c: In function 'nft_hooknum2str':
../../src/chain.c:53:7: error: 'NFPROTO_INET' undeclared (first use in this function)
../../src/chain.c:53:7: note: each undeclared identifier is reported only once for each function it appears in
make[3]: *** [chain.lo] Error 1
make[3]: se sale del directorio `/home/pablo/devel/scm/git-netfilter/libnftnl/libnftnl-1.0.1/_build/src'
make[2]: *** [all-recursive] Error 1
make[2]: se sale del directorio `/home/pablo/devel/scm/git-netfilter/libnftnl/libnftnl-1.0.1/_build'
make[1]: *** [all] Error 2
make[1]: se sale del directorio `/home/pablo/devel/scm/git-netfilter/libnftnl/libnftnl-1.0.1/_build'
make: *** [distcheck] Error 1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agolookup: Fix an invalid read
Ana Rey [Tue, 15 Apr 2014 10:13:46 +0000 (12:13 +0200)] 
lookup: Fix an invalid read

Valgrind reports the following invalid read:

$ sudo valgrind ./nft-parsing-test -f ../jsonfiles/30-rule-lookup.json
==26664== Memcheck, a memory error detector
==26664== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==26664== Using Valgrind-3.9.0 and LibVEX; rerun with -h for copyright info
==26664== Command: ./nft-parsing-test -f ../jsonfiles/30-rule-lookup.json
==26664==
==26664== Invalid read of size 8
==26664==    at 0x4E45490: nft_rule_expr_lookup_set (lookup.c:50)
==26664==    by 0x4E40B04: nft_rule_expr_set (expr.c:73)
==26664==    by 0x4E44FFF: nft_rule_expr_lookup_json_parse (lookup.c:157)
==26664==    by 0x4E408CD: nft_jansson_expr_parse (jansson.c:206)
==26664==    by 0x4E3B719: nft_jansson_parse_rule (rule.c:606)
==26664==    by 0x4E3F005: nft_ruleset_do_parse (ruleset.c:312)
==26664==    by 0x401479: test_json (nft-parsing-test.c:129)
==26664==    by 0x4017C2: execute_test_file (nft-parsing-test.c:270)
==26664==    by 0x400EBB: main (nft-parsing-test.c:332)
==26664==  Address 0x5c34d40 is 0 bytes inside a block of size 5 alloc'd
==26664==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==26664==    by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==
==26664== Invalid read of size 8
==26664==    at 0x4E45497: nft_rule_expr_lookup_set (lookup.c:50)
==26664==    by 0x4E40B04: nft_rule_expr_set (expr.c:73)
==26664==    by 0x4E44FFF: nft_rule_expr_lookup_json_parse (lookup.c:157)
==26664==    by 0x4E408CD: nft_jansson_expr_parse (jansson.c:206)
==26664==    by 0x4E3B719: nft_jansson_parse_rule (rule.c:606)
==26664==    by 0x4E3F005: nft_ruleset_do_parse (ruleset.c:312)
==26664==    by 0x401479: test_json (nft-parsing-test.c:129)
==26664==    by 0x4017C2: execute_test_file (nft-parsing-test.c:270)
==26664==    by 0x400EBB: main (nft-parsing-test.c:332)
==26664==  Address 0x5c34d48 is 3 bytes after a block of size 5 alloc'd
==26664==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==26664==    by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26664==    by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)

Signed-off-by: Ana Rey <anarey@gmail.com>
11 years agoset-elem: fix a memory leak
Ana Rey [Tue, 15 Apr 2014 10:13:47 +0000 (12:13 +0200)] 
set-elem: fix a memory leak

Valgrind reports the following memory leak:

valgrind  --leak-check=full ./nft-parsing-test -f jsonfiles/63-set.json
==7131== HEAP SUMMARY:
==7131==     in use at exit: 2 bytes in 1 blocks
==7131==   total heap usage: 155 allocs, 154 frees, 6,497 bytes allocated
==7131==
==7131== 2 bytes in 1 blocks are definitely lost in loss record 1 of 1
==7131==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==7131==    by 0x590B829: strdup (strdup.c:42)
==7131==    by 0x4E4341A: nft_data_reg_json_parse (data_reg.c:55)
==7131==    by 0x4E4093A: nft_jansson_data_reg_parse (jansson.c:231)
==7131==    by 0x4E40A1B: nft_jansson_et_elem_parse (jansson.c:257)
==7131==    by 0x4E3CECA: nft_jansson_parse_set (set.c:398)
==7131==    by 0x4E3EC65: nft_ruleset_do_parse (ruleset.c:263)
==7131==    by 0x401479: test_json (nft-parsing-test.c:129)
==7131==    by 0x4017C2: execute_test_file (nft-parsing-test.c:270)
==7131==    by 0x400EBB: main (nft-parsing-test.c:332)

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotarget, match: Fix an invalid read
Ana Rey [Mon, 14 Apr 2014 09:50:37 +0000 (11:50 +0200)] 
target, match: Fix an invalid read

Valgrind reports the following invalid read:

$ sudo valgrind --leak-check=full ./nft-parsing-test -f ../jsonfiles/35-rule-target.json
( and similar result with jsonfiles/29-rule-match.json file)

==26018== Invalid read of size 8
==26018==    at 0x4E484E3: nft_rule_expr_target_set (target.c:46)
==26018==    by 0x4E40B54: nft_rule_expr_set (expr.c:73)
==26018==    by 0x4E48167: nft_rule_expr_target_json_parse (target.c:185)
==26018==    by 0x4E4091D: nft_jansson_expr_parse (jansson.c:206)
==26018==    by 0x4E3B769: nft_jansson_parse_rule (rule.c:606)
==26018==    by 0x4E3F055: nft_ruleset_do_parse (ruleset.c:312)
==26018==    by 0x401479: test_json (nft-parsing-test.c:129)
==26018==    by 0x4017C2: execute_test_file (nft-parsing-test.c:270)
==26018==    by 0x400EBB: main (nft-parsing-test.c:332)
==26018==  Address 0x5c34a60 is 0 bytes inside a block of size 4 alloc'd
==26018==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==26018==    by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==
==26018== Invalid read of size 8
==26018==    at 0x4E484ED: nft_rule_expr_target_set (target.c:46)
==26018==    by 0x4E40B54: nft_rule_expr_set (expr.c:73)
==26018==    by 0x4E48167: nft_rule_expr_target_json_parse (target.c:185)
==26018==    by 0x4E4091D: nft_jansson_expr_parse (jansson.c:206)
==26018==    by 0x4E3B769: nft_jansson_parse_rule (rule.c:606)
==26018==    by 0x4E3F055: nft_ruleset_do_parse (ruleset.c:312)
==26018==    by 0x401479: test_json (nft-parsing-test.c:129)
==26018==    by 0x4017C2: execute_test_file (nft-parsing-test.c:270)
==26018==    by 0x400EBB: main (nft-parsing-test.c:332)
==26018==  Address 0x5c34a68 is 4 bytes after a block of size 4 alloc'd
==26018==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==26018==    by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==
==26018== Invalid read of size 8
==26018==    at 0x4E484F5: nft_rule_expr_target_set (target.c:46)
==26018==    by 0x4E40B54: nft_rule_expr_set (expr.c:73)
==26018==    by 0x4E48167: nft_rule_expr_target_json_parse (target.c:185)
==26018==    by 0x4E4091D: nft_jansson_expr_parse (jansson.c:206)
==26018==    by 0x4E3B769: nft_jansson_parse_rule (rule.c:606)
==26018==    by 0x4E3F055: nft_ruleset_do_parse (ruleset.c:312)
==26018==    by 0x401479: test_json (nft-parsing-test.c:129)
==26018==    by 0x4017C2: execute_test_file (nft-parsing-test.c:270)
==26018==    by 0x400EBB: main (nft-parsing-test.c:332)
==26018==  Address 0x5c34a70 is 12 bytes after a block of size 4 alloc'd
==26018==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==26018==    by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==
==26018== Invalid read of size 4
==26018==    at 0x4E484FD: nft_rule_expr_target_set (target.c:46)
==26018==    by 0x4E40B54: nft_rule_expr_set (expr.c:73)
==26018==    by 0x4E48167: nft_rule_expr_target_json_parse (target.c:185)
==26018==    by 0x4E4091D: nft_jansson_expr_parse (jansson.c:206)
==26018==    by 0x4E3B769: nft_jansson_parse_rule (rule.c:606)
==26018==    by 0x4E3F055: nft_ruleset_do_parse (ruleset.c:312)
==26018==    by 0x401479: test_json (nft-parsing-test.c:129)
==26018==    by 0x4017C2: execute_test_file (nft-parsing-test.c:270)
==26018==    by 0x400EBB: main (nft-parsing-test.c:332)
==26018==  Address 0x5c34a78 is 20 bytes after a block of size 4 alloc'd
==26018==    at 0x4C274A0: malloc (vg_replace_malloc.c:291)
==26018==    by 0x56834FF: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5685825: json_string_nocheck (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682A3F: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682C5D: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682ADE: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5682EDD: ??? (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)
==26018==    by 0x5683295: json_loadf (in /usr/lib/x86_64-linux-gnu/libjansson.so.4.6.0)

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: Fix a memory leak
Ana Rey [Sun, 13 Apr 2014 18:08:34 +0000 (20:08 +0200)] 
tests: Fix a memory leak

Free nft_parse_err struct when there is an error in execute_test function.

It solves the following memory leak shown by valgrind.

==7845== 24 bytes in 1 blocks are still reachable in loss record 1 of 2
==7845==    at 0x4C29590: calloc (vg_replace_malloc.c:618)
==7845==    by 0x401740: execute_test_file (nft-parsing-test.c:249)
==7845==    by 0x400EBB: main (nft-parsing-test.c:330)

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: Add support to check a json or xml testfile
Ana Rey [Wed, 9 Apr 2014 15:03:45 +0000 (17:03 +0200)] 
tests: Add support to check a json or xml testfile

Add new command-line argument "-f <file>" to check a json or xml
testfile.

./nft-parsing-test -f <file>  Check this testfile.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: New tools to update xml and json testfiles
Ana Rey [Wed, 9 Apr 2014 15:03:44 +0000 (17:03 +0200)] 
tests: New tools to update xml and json testfiles

New tools to updata testfiles when the structure of xml or json files
are changed.

It adds a new command-line argument in nft-parsing-test.

With nft-parsing-test -u <directory>, you can update test files in
<directory> with a new structure of xml or json file.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxml, json: Delete an immediatedate label in xml and json file
Ana Rey [Wed, 9 Apr 2014 09:16:54 +0000 (11:16 +0200)] 
xml, json: Delete an immediatedate label in xml and json file

It deletes the immediatedata label in the structure of json and xml file.

Example of the old structure of xmlfile:
<nftables>
<rule>
<family>ip</family>
<table>filter</table>
<chain>input</chain>
<handle>32</handle>
<expr type="immediate">
<dreg>0</dreg>
<immediatedata>
<data_reg type="verdict">
<verdict>accept</verdict>
</data_reg>
</immediatedata>
</expr>
</rule>
</nftables>

Example of the new structure of xmlfile:
<nftables>
<rule>
<family>ip</family>
<table>filter</table>
<chain>input</chain>
<handle>32</handle>
<expr type="immediate">
<dreg>0</dreg>
<data_reg type="verdict">
<verdict>accept</verdict>
</data_reg>
</expr>
</rule>
</nftables>

To generate the new testfiles, It use the option -u of nft-parsing-test
script.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoxml, json: Delete a cmpdata label in xml and json file
Ana Rey [Wed, 9 Apr 2014 09:16:19 +0000 (11:16 +0200)] 
xml, json: Delete a cmpdata label in xml and json file

It delete the cmpdata label in the structure of json and xml file.

Example of xmlfile:

The old structure of xml file:
[...]
<expr type="cmp">
<sreg>1</sreg>
<op>eq</op>
<cmpdata>
<data_reg type="value">
<len>4</len>
<data0>0x0100a8c0</data0>
</data_reg>
</cmpdata>
</expr>

The new structure of json file:
[...]
<expr type="cmp">
<sreg>1</sreg>
<op>eq</op>
<data_reg type="value">
<len>4</len>
<data0>0x0100a8c0</data0>
</data_reg>
</expr>
[...]

To generate the new testfiles, It use the option -u of nft-parsing-test
script.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: complete nft-events example
Arturo Borrero [Tue, 1 Apr 2014 12:06:44 +0000 (14:06 +0200)] 
examples: complete nft-events example

Complete nft-events example by adding a basic set & set_elem event
notification.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: fix bogus assertion for unset attributes
Pablo Neira Ayuso [Sat, 5 Apr 2014 18:31:37 +0000 (20:31 +0200)] 
src: fix bogus assertion for unset attributes

If you try to obtain an unset attribute, you hit an assertion error
that should not happen. Fix this by checking if the attribute is
unset, otherwise skip the assertion checking.

Now that we have that nft_assert takes the data parameter, we can also
validate if someone is using the setter passing NULL, which is illegal.
So let's add an assertion for that as well.

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