]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
12 years agoutils: nft_str2family sets errno
Pablo Neira Ayuso [Thu, 25 Jul 2013 20:39:29 +0000 (22:39 +0200)] 
utils: nft_str2family sets errno

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: utils: add verdict2str and use it
Arturo Borrero [Thu, 25 Jul 2013 20:20:33 +0000 (22:20 +0200)] 
src: utils: add verdict2str and use it

Add verdict2str() and str2verdict() helper functions and use in XML.

While at it, I've fixed a small style issue in the data_reg JSON output and
a bug in the data_reg XML parser: The parser walked the top level tree,
instead of single <data_reg> node. Introduced in (51370f0 src: add support
for XML parsing).

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: don't override errno value if nft_mxml_num_parse is used
Pablo Neira Ayuso [Thu, 25 Jul 2013 20:08:15 +0000 (22:08 +0200)] 
expr: don't override errno value if nft_mxml_num_parse is used

That function already sets errno for us.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agomxml: nft_mxml_str_parse returns copy of the string
Pablo Neira Ayuso [Thu, 25 Jul 2013 19:58:33 +0000 (21:58 +0200)] 
mxml: nft_mxml_str_parse returns copy of the string

Otherwise, the string points to an invalid memory position
somewhere in the XML tree that is released after the parsing.

This problem was there before the conversion to the new helper
function nft_mxml_str_parse.

Reported-by: Arturo Borrero <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: ct: use nft_mxml_str_parse
Pablo Neira Ayuso [Thu, 25 Jul 2013 19:46:46 +0000 (21:46 +0200)] 
expr: ct: use nft_mxml_str_parse

Replace existing code to use this function.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: payload: use nft_mxml_num_parse
Pablo Neira Ayuso [Thu, 25 Jul 2013 19:36:55 +0000 (21:36 +0200)] 
expr: payload: use nft_mxml_num_parse

Replace existing code to use this function.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: xml: consolidate common XML code via nft_mxml_str_parse
Pablo Neira Ayuso [Thu, 25 Jul 2013 19:21:51 +0000 (21:21 +0200)] 
src: xml: consolidate common XML code via nft_mxml_str_parse

This patch moves common XML string parsing code to nft_mxml_str_parse().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: cmp: cmpdata is mandatory node
Pablo Neira Ayuso [Thu, 25 Jul 2013 18:44:13 +0000 (20:44 +0200)] 
expr: cmp: cmpdata is mandatory node

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: counter: use nft_mxml_num_parse
Pablo Neira Ayuso [Thu, 25 Jul 2013 18:34:24 +0000 (20:34 +0200)] 
expr: counter: use nft_mxml_num_parse

Put this code on a diet by using the new helper function nft_mxml_num_parse.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: xml: consolidate common XML code via nft_mxml_num_parse
Arturo Borrero [Thu, 25 Jul 2013 16:46:35 +0000 (18:46 +0200)] 
src: xml: consolidate common XML code via nft_mxml_num_parse

This patch moves common XML parsing code to nft_mxml_num_parse().
To handle this, the nft_strtoi() helper fuction is included.

I've changed some MXML_DESCEND[_FIRST] flags to avoid match a nested node under
some circumstances, ie, matching two nodes with the same name that are descendant.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: refactor nft_rule_expr_get
Pablo Neira Ayuso [Sun, 21 Jul 2013 13:32:21 +0000 (15:32 +0200)] 
expr: refactor nft_rule_expr_get

Merge common checking for attribute set in nft_rule_expr_get.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: remove default case from nft_*_attr_unset
Pablo Neira Ayuso [Sun, 21 Jul 2013 13:26:02 +0000 (15:26 +0200)] 
src: remove default case from nft_*_attr_unset

This patch removes the default case in nft_*_attr_unset, thus, the
compiler will spot a warning if we add a new attribute in the future
and you forget to handle it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: constify parameter of nft_*_is_set
Eric Leblond [Sat, 6 Jul 2013 15:33:16 +0000 (17:33 +0200)] 
src: constify parameter of nft_*_is_set

The functions nft_*_attr_is_set() is doing no modification
so it is possible to type it to const.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: display position in default printf
Eric Leblond [Sat, 6 Jul 2013 15:33:15 +0000 (17:33 +0200)] 
rule: display position in default printf

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: add insert rule example
Eric Leblond [Sat, 6 Jul 2013 15:33:14 +0000 (17:33 +0200)] 
examples: add insert rule example

This program can insert a rule after a rule given by
its handle.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: add support for position attribute
Eric Leblond [Sat, 6 Jul 2013 15:33:13 +0000 (17:33 +0200)] 
rule: add support for position attribute

This patch adds support for position attribute which can be used
to insert a rule at a given position.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: simplify getter logic
Pablo Neira Ayuso [Thu, 18 Jul 2013 18:01:27 +0000 (20:01 +0200)] 
src: simplify getter logic

This patch refactors the getter code to simplify it. The default
cases have been removed so gcc will spot a warning if an attribute
is not handled appropriately.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-chain-add: allow to create custom chains
Pablo Neira Ayuso [Thu, 18 Jul 2013 17:25:16 +0000 (19:25 +0200)] 
examples: nft-chain-add: allow to create custom chains

So far, it was only possible to create base chains. This patch
allows you to create custom chains as well.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-chain-get: allow to list chain from all families
Pablo Neira Ayuso [Thu, 18 Jul 2013 17:24:14 +0000 (19:24 +0200)] 
examples: nft-chain-get: allow to list chain from all families

So far, it was restricted to AF_INET.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: add arp support
Pablo Neira Ayuso [Thu, 18 Jul 2013 17:08:02 +0000 (19:08 +0200)] 
examples: add arp support

While at it, convert all examples to use NFPROTO_*.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoutils: ARP family is number 3
Pablo Neira Ayuso [Thu, 18 Jul 2013 16:43:53 +0000 (18:43 +0200)] 
utils: ARP family is number 3

Netfilter uses family number 3 for ARP since AF_ARP does not
exists.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: json: fix wrong display of table and family
Álvaro Neira Ayuso [Thu, 18 Jul 2013 11:36:01 +0000 (13:36 +0200)] 
chain: json: fix wrong display of table and family

In (74ccff7 chain: json: use string to identify policy), the
json support for chain was unintentionally swapping the table
name and the family.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add nft_*_list_add_tail
Pablo Neira Ayuso [Tue, 16 Jul 2013 20:30:18 +0000 (22:30 +0200)] 
src: add nft_*_list_add_tail

This redefines the meaning of nft_*_list_add to prepend, before this
patch it was appending, which was semantically wrong.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: json: use string to identify policy
Álvaro Neira Ayuso [Mon, 15 Jul 2013 19:31:00 +0000 (21:31 +0200)] 
chain: json: use string to identify policy

* if we don't have hooknum we don't need to print the policy tag
* If we have hooknum, i have used the policy2str function for printing the policy with
"accept" string or "drop" string

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: json: fix incomplete output
Álvaro Neira Ayuso [Mon, 15 Jul 2013 19:30:52 +0000 (21:30 +0200)] 
set: json: fix incomplete output

In (bf39c53 set: add json output), the json support for sets was
incomplete:

* version, family, key_type, key_len, data_type, data_len were not included.
* Now I use nft_data_reg_snprintf for printing the key and data

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: limit: fix getter
Pablo Neira Ayuso [Mon, 15 Jul 2013 17:52:25 +0000 (19:52 +0200)] 
expr: limit: fix getter

Set missing data length via getter, otherwise it returns zero.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add nft_*_list_is_empty() functions
Arturo Borrero [Thu, 11 Jul 2013 08:44:13 +0000 (10:44 +0200)] 
src: add nft_*_list_is_empty() functions

This functions check if a given nft_*_list is empty or not.

I found this quite useful while working with a full ruleset.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoinclude: update include/linux/netfilter/nf_tables.h
Pablo Neira Ayuso [Sat, 13 Jul 2013 19:35:33 +0000 (21:35 +0200)] 
include: update include/linux/netfilter/nf_tables.h

Get it in sync with the current kernel tree.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add nft_expr_data to replace explicit casting to obtain expression data
Pablo Neira Ayuso [Sat, 13 Jul 2013 19:56:06 +0000 (21:56 +0200)] 
expr: add nft_expr_data to replace explicit casting to obtain expression data

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: use __attribute__((constructor)) to register expression
Pablo Neira Ayuso [Sat, 13 Jul 2013 19:21:27 +0000 (21:21 +0200)] 
expr: use __attribute__((constructor)) to register expression

Instead of manual array registration.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-{table,chain,rule}-xml-add: fix missing NLM_F_CREATE
Pablo Neira Ayuso [Wed, 10 Jul 2013 16:34:57 +0000 (18:34 +0200)] 
examples: nft-{table,chain,rule}-xml-add: fix missing NLM_F_CREATE

Thus, automodule loading was not working.

While at it, apply not so relevant comestic cleanups and fix some
inconsistencies between examples.

* Fix copyright header, this is code heavily based on existing
  nft-*-add examples.
* Remove unrequired extern struct nft_table definition.
* Make sure we close file descriptor once we don't need it anymore.
* Remove unrequired casting.
* Remove comment that provides nothing interesting.

I considered a patch to address each on those was too much burden.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: payload: fix incorrect length and base in default output
Eric Leblond [Wed, 10 Jul 2013 16:22:53 +0000 (18:22 +0200)] 
expr: payload: fix incorrect length and base in default output

This patch fixes an accidental swapping of the dreg and length
payload fields.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: remove LIBXML_LIBS from LDADD
Pablo Neira Ayuso [Tue, 9 Jul 2013 19:13:11 +0000 (21:13 +0200)] 
examples: remove LIBXML_LIBS from LDADD

Remove it from the example files, we don't need it. There is no explicit
reference to any of the libmxml functions in those files, so the linker
does not need that library.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: payload: fix printing of base
Pablo Neira Ayuso [Tue, 9 Jul 2013 18:42:58 +0000 (20:42 +0200)] 
expr: payload: fix printing of base

In (f95e859 src: improve default text output), it assumes all bases
are network, but we may have link and transport as well.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobitwise: xml: export len node
Arturo Borrero [Mon, 8 Jul 2013 11:52:31 +0000 (13:52 +0200)] 
bitwise: xml: export len node

Fix missing length, it was not being exported in XML.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@soleta.eu>
12 years agoset: add xml output
Arturo Borrero [Sat, 6 Jul 2013 00:39:52 +0000 (02:39 +0200)] 
set: add xml output

This patch adds XML output for sets.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: xml: consolidate parsing of data_reg via nft_mxml_data_reg_parse
Arturo Borrero [Fri, 5 Jul 2013 14:28:06 +0000 (16:28 +0200)] 
src: xml: consolidate parsing of data_reg via nft_mxml_data_reg_parse

Move common code for XML parsing of data_reg to the new
nft_mxml_data_reg_parse function.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-table-get: add json support
Álvaro Neira Ayuso [Fri, 5 Jul 2013 12:41:35 +0000 (14:41 +0200)] 
examples: nft-table-get: add json support

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: add json output
Álvaro Neira Ayuso [Fri, 5 Jul 2013 12:41:28 +0000 (14:41 +0200)] 
set: add json output

This patch allows you to dump set and their content in json format.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: fix printing of key and data registers
Pablo Neira Ayuso [Fri, 5 Jul 2013 21:38:40 +0000 (23:38 +0200)] 
set: fix printing of key and data registers

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: expr: data_reg: fix printing data register content
Pablo Neira Ayuso [Fri, 5 Jul 2013 12:00:08 +0000 (14:00 +0200)] 
src: expr: data_reg: fix printing data register content

Before:

ip filter output 41
  [ payload load 1b @ network header + 9 => reg 1 ]
  [ cmp eq reg 1 ]

Now:

ip filter output 41
  [ payload load 1b @ network header + 9 => reg 1 ]
  [ cmp eq reg 1 0x00000006 ]
                 ^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: improve default text output
Giuseppe Longo [Fri, 5 Jul 2013 08:06:28 +0000 (10:06 +0200)] 
src: improve default text output

This patch improves default plain text output by mimicing the
default output of libnl-nft.

While at it, several %lu has been translated to use %"PRIu64"
for correctness.

[ I have added the policy to string translation --pablo ]

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: xml: fix compilation without XML parsing enabled
Pablo Neira Ayuso [Thu, 4 Jul 2013 14:51:57 +0000 (16:51 +0200)] 
src: xml: fix compilation without XML parsing enabled

Since (d844fa0 src: consolidate XML parsing of expressions via
nft_mxml_expr_parse), the library was not compiling with XML support
anymore.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: consolidate XML parsing of expressions via nft_mxml_reg_parse
Pablo Neira Ayuso [Thu, 4 Jul 2013 14:10:24 +0000 (16:10 +0200)] 
src: consolidate XML parsing of expressions via nft_mxml_reg_parse

This patch reduces the XML code in 100 LOC.

12 years agosrc: consolidate XML parsing of expressions via nft_mxml_expr_parse
Pablo Neira Ayuso [Thu, 4 Jul 2013 12:50:22 +0000 (14:50 +0200)] 
src: consolidate XML parsing of expressions via nft_mxml_expr_parse

Move common code for XML parsing of expressions to the new
nft_mxml_expr_parse function.

This patch reduces the XML parsing code in 300 LOC.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: ct: fix setting of NFT_EXPR_CT_DIR
Arturo Borrero Gonzalez [Thu, 4 Jul 2013 10:34:07 +0000 (12:34 +0200)] 
expr: ct: fix setting of NFT_EXPR_CT_DIR

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: Fix header inclusion for integer types
Tomasz Bursztyka [Wed, 3 Jul 2013 09:42:20 +0000 (12:42 +0300)] 
expr: Fix header inclusion for integer types

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: add JSON support
Álvaro Neira Ayuso [Thu, 27 Jun 2013 19:56:26 +0000 (21:56 +0200)] 
examples: add JSON support

By specifying 'json' as first parameter.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: support JSON format in chain, rule and expressions
Álvaro Neira Ayuso [Thu, 27 Jun 2013 19:56:18 +0000 (21:56 +0200)] 
src: support JSON format in chain, rule and expressions

While at it, order possible switch cases of _snprintf.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: nft-parsing-test: restore default terminal color after test
Pablo Neira Ayuso [Thu, 27 Jun 2013 19:26:34 +0000 (21:26 +0200)] 
tests: nft-parsing-test: restore default terminal color after test

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: remove several wrong XML nodes in tests
Pablo Neira Ayuso [Thu, 27 Jun 2013 19:25:03 +0000 (21:25 +0200)] 
tests: remove several wrong XML nodes in tests

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotest: add testbench for XML
Arturo Borrero Gonzalez [Thu, 27 Jun 2013 18:09:34 +0000 (20:09 +0200)] 
test: add testbench for XML

This patch add a testbench for XML parsing, which may be extended
to test JSON as well.

To use it:
 $ cd test/
 $ make nft-parsing-test
 $ ./nft-parsing-test xmlfiles/

This testbench supersedes old .sh test scripts, so they are deleted.

[ I have mangled this patch to rename/mangle files, to colorize the
  test output and not to compile XML inconditionally --pablo ]

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexthdr: xml: rename type node to exthdr_type
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:21 +0000 (13:37 +0200)] 
exthdr: xml: rename type node to exthdr_type

This patch renames the <type> node in the exthdr expr to <exthdr_type>.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonat: xml: rename node type to nat_type
Arturo Borrero Gonzalez [Thu, 27 Jun 2013 17:35:21 +0000 (19:35 +0200)] 
nat: xml: rename node type to nat_type

This patch renames the node <type> to a more explicit <nat_type>.

This will prevent in the future from confusing other <type> nodes from other exprs.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonat: snprintf: fix buffer offset
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:19 +0000 (13:37 +0200)] 
nat: snprintf: fix buffer offset

This patch fix the buffer offset necesary to print correctly the nat expr in a default output mode.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agometa: xml: use string to represent key attribute
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:18 +0000 (13:37 +0200)] 
meta: xml: use string to represent key attribute

Use a string for <key> node instead of a number.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexthdr: xml: use string for type node
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:17 +0000 (13:37 +0200)] 
exthdr: xml: use string for type node

This patch implements using a string for the <type> node.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agopayload: xml: use string for base attribute
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:15 +0000 (13:37 +0200)] 
payload: xml: use string for base attribute

This patch implements using a string instead of a number for the <base> node.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotarget&match: xml: don't print rev number
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:14 +0000 (13:37 +0200)] 
target&match: xml: don't print rev number

The <rev> node is not printed/parsed anymore. It should not be exported,
this is negotiated with the kernel.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodata_reg: xml: display register in big endian
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:13 +0000 (13:37 +0200)] 
data_reg: xml: display register in big endian

Display registers in big endian, so the output will be the same in
different endianness CPU.

<data>0xaabbccdd</data>

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodata_reg: xml: fix len node, it should show byte length
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:12 +0000 (13:37 +0200)] 
data_reg: xml: fix len node, it should show byte length

Previous to this patch, the <len> node was 'how many <dataN> nodes we have'.
However, the <len> node means 'how many bytes are in <dataN> nodes'.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: xml: use string for policy
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:10 +0000 (13:37 +0200)] 
chain: xml: use string for policy

Now the <policy> node is using "accept" or "drop".

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexthdr: xml: fix mandatory elements
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:09 +0000 (13:37 +0200)] 
exthdr: xml: fix mandatory elements

According to net/netfilter/nft_exthdr.c: nft_exthdr_init(),
all of dreg, type, offset and len are mandatory:

if (tb[NFTA_EXTHDR_DREG] == NULL ||
    tb[NFTA_EXTHDR_TYPE] == NULL ||
    tb[NFTA_EXTHDR_OFFSET] == NULL ||
    tb[NFTA_EXTHDR_LEN] == NULL)
return -EINVAL;

So the XML parser must make sure the equivalent nodes exists.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoct: xml: use key names instead of numbers
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:08 +0000 (13:37 +0200)] 
ct: xml: use key names instead of numbers

ct expr uses a string instead of a numerical one in the <key> node.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoct: xml: add extra dir check
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:07 +0000 (13:37 +0200)] 
ct: xml: add extra dir check

This patch adds an extra dir check.

0 means original.
1 means a reply.

Pablo decided not to include nf_conntrack_tuple_common.h, instead internally
defined them.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonat: xml: fix node names for sreg_addr_{min|max}
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:04 +0000 (13:37 +0200)] 
nat: xml: fix node names for sreg_addr_{min|max}

This patch changes the name of XML nodes from <sreg_addr_min_v4> to
<sreg_addr_min>, and <sreg_addr_max_v4> to <sreg_addr_max>, as they
are register numbers, not addresses, so they are protocol independent.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonat: xml: change nat types string to dnat/snat
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:03 +0000 (13:37 +0200)] 
nat: xml: change nat types string to dnat/snat

This patch replaces the string NFT_NAT_{S|D}NAT with {s|d}nat in
the <type> node.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: xml: convert family values to string
Arturo Borrero [Thu, 27 Jun 2013 16:56:38 +0000 (18:56 +0200)] 
src: xml: convert family values to string

This patch translates family values to display a string:

 * ip if AF_INET
 * ip6 if AF_INET6
 * bridge if AF_BRIDGE
 * arp if 0

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: add hooknum2str
Arturo Borrero Gonzalez [Thu, 27 Jun 2013 16:55:47 +0000 (18:55 +0200)] 
chain: add hooknum2str

This patch translates the Netfilter hooknumber to a readable string.

Useful for printing and parsing in XML and JSON formats.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobyteorder: xml: op as string
Arturo Borrero [Wed, 26 Jun 2013 11:37:05 +0000 (13:37 +0200)] 
byteorder: xml: op as string

This patch changes the numerical value of the XML byteorder's <op> node to a string representation.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
12 years agoexpr: xml: registers must be <= NFT_REG_MAX
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:02 +0000 (13:37 +0200)] 
expr: xml: registers must be <= NFT_REG_MAX

With this patch, all expressions validate that registers are <= NFT_REG_MAX.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobitwise: xml: mask and xor use same number of data registers
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:37:00 +0000 (13:37 +0200)] 
bitwise: xml: mask and xor use same number of data registers

The mask and xor must use the same number of data registers.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: xml: conditional display of compat info
Arturo Borrero Gonzalez [Wed, 26 Jun 2013 11:36:59 +0000 (13:36 +0200)] 
rule: xml: conditional display of compat info

The compat XML info is now conditional both when printing and parsing.
It is only used by iptables-nftables.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset_elem: add nft_set_elem_attr_set_str
Pablo Neira Ayuso [Fri, 21 Jun 2013 12:46:47 +0000 (14:46 +0200)] 
set_elem: add nft_set_elem_attr_set_str

It was not implemented, it was defined in the header anf map files
though.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add nft_rule_expr_snprintf
Pablo Neira Ayuso [Wed, 19 Jun 2013 15:53:25 +0000 (17:53 +0200)] 
expr: add nft_rule_expr_snprintf

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset_elem: fix nft_set_elem_attr_get with NFT_SET_ELEM_ATTR_CHAIN
Pablo Neira Ayuso [Wed, 19 Jun 2013 15:06:57 +0000 (17:06 +0200)] 
set_elem: fix nft_set_elem_attr_get with NFT_SET_ELEM_ATTR_CHAIN

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset_elem: fix wrong flags setting in nft_set_elems_parse2
Pablo Neira Ayuso [Wed, 19 Jun 2013 15:05:38 +0000 (17:05 +0200)] 
set_elem: fix wrong flags setting in nft_set_elems_parse2

Set element object flags instead of set flags.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: add missing set/unset support for NFT_SET_ATTR_DATA_[TYPE|LEN]
Pablo Neira Ayuso [Wed, 19 Jun 2013 09:46:37 +0000 (11:46 +0200)] 
set: add missing set/unset support for NFT_SET_ATTR_DATA_[TYPE|LEN]

While at it, use fixed length uint32_t instead of size_t.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: xml: don't print target and match info
Arturo Borrero [Mon, 3 Jun 2013 20:44:55 +0000 (22:44 +0200)] 
expr: xml: don't print target and match info

This is binary layout of the iptables target/match, we can do nothing
with it at this moment. Let's get rid of it.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: unset chain & rule handle
Arturo Borrero [Wed, 5 Jun 2013 21:37:18 +0000 (23:37 +0200)] 
examples: unset chain & rule handle

Use _unset functions to delete handle so test don't fail.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: xml: delete trailing space
Arturo Borrero [Sat, 15 Jun 2013 01:16:15 +0000 (03:16 +0200)] 
rule: xml: delete trailing space

This patch fixes a trailing space in rule xml_snprintf.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonat: xml: fix crash during parsing if non-mandatory element is not present
Arturo Borrero Gonzalez [Mon, 17 Jun 2013 19:23:12 +0000 (21:23 +0200)] 
nat: xml: fix crash during parsing if non-mandatory element is not present

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonat: xml: fix wrong offset in snprintf
Arturo Borrero [Sat, 15 Jun 2013 01:16:03 +0000 (03:16 +0200)] 
nat: xml: fix wrong offset in snprintf

This patch fixes the buffer offset of the nat snprintf function
so elements are properly printed.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: bitwise: xml: fix wrong casting
Arturo Borrero [Sat, 15 Jun 2013 00:36:13 +0000 (02:36 +0200)] 
expr: bitwise: xml: fix wrong casting

Introduced in (51370f0 src: add support for XML parsing)

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: fix nft_set_attr_get with NFT_SET_ATTR_KEY_FLAGS
Pablo Neira Ayuso [Mon, 17 Jun 2013 18:51:35 +0000 (20:51 +0200)] 
set: fix nft_set_attr_get with NFT_SET_ATTR_KEY_FLAGS

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset_elem: fix wrong flags set for NFT_SET_ELEM_ATTR_FLAGS
Pablo Neira Ayuso [Mon, 17 Jun 2013 18:15:13 +0000 (20:15 +0200)] 
set_elem: fix wrong flags set for NFT_SET_ELEM_ATTR_FLAGS

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: set NFT_*_ATTR_FAMILY in nft_*_parse function
Pablo Neira Ayuso [Mon, 17 Jun 2013 15:45:07 +0000 (17:45 +0200)] 
src: set NFT_*_ATTR_FAMILY in nft_*_parse function

This attribute was not approapriately set in most cases.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: fix nft_chain_attr_set_str
Pablo Neira Ayuso [Mon, 17 Jun 2013 00:39:35 +0000 (02:39 +0200)] 
chain: fix nft_chain_attr_set_str

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoinclude: add stdbool.h to libnftables/expr.h
Pablo Neira Ayuso [Sun, 16 Jun 2013 22:37:07 +0000 (00:37 +0200)] 
include: add stdbool.h to libnftables/expr.h

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: constify first parameter of all nft_*_get
Pablo Neira Ayuso [Sat, 15 Jun 2013 20:19:23 +0000 (22:19 +0200)] 
src: constify first parameter of all nft_*_get

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: add NFT_SET_ATTR_FAMILY
Pablo Neira Ayuso [Fri, 14 Jun 2013 14:43:05 +0000 (16:43 +0200)] 
set: add NFT_SET_ATTR_FAMILY

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add nft_*_attr_is_set
Pablo Neira Ayuso [Sun, 16 Jun 2013 22:39:38 +0000 (00:39 +0200)] 
src: add nft_*_attr_is_set

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add nft_*_list_foreach
Pablo Neira Ayuso [Thu, 13 Jun 2013 19:15:05 +0000 (21:15 +0200)] 
src: add nft_*_list_foreach

This patch adds a simplied iterator interface.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add limit
Pablo Neira Ayuso [Thu, 13 Jun 2013 11:33:08 +0000 (13:33 +0200)] 
expr: add limit

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add byteorder
Pablo Neira Ayuso [Wed, 12 Jun 2013 12:16:41 +0000 (14:16 +0200)] 
expr: add byteorder

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add ct
Pablo Neira Ayuso [Wed, 12 Jun 2013 10:21:10 +0000 (12:21 +0200)] 
expr: add ct

This patch adds the ct expression.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add exthdr
Pablo Neira Ayuso [Tue, 11 Jun 2013 12:20:15 +0000 (14:20 +0200)] 
expr: add exthdr

This patch adds support for the exthdr expression of nftables that
is implemented in linux/net/netfilter/nft_exthdr.c

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: fix missing interlibrary dependency
Pablo Neira Ayuso [Tue, 11 Jun 2013 00:37:24 +0000 (02:37 +0200)] 
build: fix missing interlibrary dependency

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add log expression
Pablo Neira Ayuso [Mon, 10 Jun 2013 17:23:03 +0000 (19:23 +0200)] 
expr: add log expression

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-chain-get: export in JSON format
Alvaro Neira Ayuso [Sat, 8 Jun 2013 03:36:12 +0000 (03:36 +0000)] 
examples: nft-chain-get: export in JSON format

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>