]> git.ipfire.org Git - thirdparty/libnftnl.git/log
thirdparty/libnftnl.git
12 years agoset_elem: parse family from Netlink message
Arturo Borrero [Sat, 5 Apr 2014 16:38:29 +0000 (18:38 +0200)] 
set_elem: parse family from Netlink message

Lets obtain the family from the Netlink message.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: Use getopt_long to parse the command-line arguments.
Ana Rey [Fri, 4 Apr 2014 09:22:37 +0000 (11:22 +0200)] 
tests: Use getopt_long to parse the command-line arguments.

Use getopt_long to parse the command-line arguments and
prepare it to add new arguments in next patches.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: remove nft-rule-insert from Makefile.am
Pablo Neira Ayuso [Fri, 28 Mar 2014 09:52:49 +0000 (10:52 +0100)] 
examples: remove nft-rule-insert from Makefile.am

This example doesn't exist anymore.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset_elems: delete unexisting exported symbol
Arturo Borrero [Wed, 19 Mar 2014 16:53:26 +0000 (17:53 +0100)] 
set_elems: delete unexisting exported symbol

There is no function called 'nft_set_elem_nlmsg_parse()'

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: don't enforce attributes when parsing
Álvaro Neira Ayuso [Thu, 13 Mar 2014 22:12:04 +0000 (23:12 +0100)] 
rule: don't enforce attributes when parsing

This change allow us to parser the rule and the kernel
bail out if the rule is well-formed.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: don't print unset attributes
Álvaro Neira Ayuso [Thu, 13 Mar 2014 21:31:51 +0000 (22:31 +0100)] 
rule: don't print unset attributes

We print some attribute that maybe the user hasn't defined
for printing. We can't assume that the user want to print
some attribute that we have put mandatory in the rules.
Example:

If we have defined family, the output is like that:

{"rule":{"family":"ip","handle":4...
<rule><family>ip</family><handle>4</handle>...

And this if we unset the family.

{"rule":{"handle":4...
<rule><handle>4</handle>...

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-rule-del: removed printf rule function
Álvaro Neira Ayuso [Sat, 8 Mar 2014 15:22:48 +0000 (16:22 +0100)] 
examples: nft-rule-del: removed printf rule function

Removed this code because with that we have a strange
output. Example:

we have a rule with handle 4 and we execute
nft-rule-del ip filter input 4

Output: unknown filter input 4 0

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-rule-insert: fix and merge it to nft-rule-add
Álvaro Neira Ayuso [Sat, 8 Mar 2014 15:22:33 +0000 (16:22 +0100)] 
examples: nft-rule-insert: fix and merge it to nft-rule-add

Merged the example for inserting rules and fixed for using
the correct header.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-rule-del: fix missing batching headers
Álvaro Neira Ayuso [Sat, 8 Mar 2014 15:21:55 +0000 (16:21 +0100)] 
examples: nft-rule-del: fix missing batching headers

Fix the example for deleting rules. Before this patch,
the program tried to delete the rule without using
the correct header.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: add NFT_RULE_ATTR_USERDATA support
Pablo Neira Ayuso [Tue, 25 Feb 2014 23:10:50 +0000 (00:10 +0100)] 
rule: add NFT_RULE_ATTR_USERDATA support

This allows us to manipulate the user data area of the rule.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: check if netlink parsing fails
Arturo Borrero [Wed, 26 Feb 2014 18:13:26 +0000 (19:13 +0100)] 
src: check if netlink parsing fails

We have to check if mnl_attr_parse() returns an error, which means that it
failed to validate and retrieve the attributes.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexample: nft-rule-add: simplify example
Pablo Neira Ayuso [Wed, 19 Feb 2014 17:17:45 +0000 (18:17 +0100)] 
example: nft-rule-add: simplify example

The nft_mnl_batch_talk() is overly complicated for a simple example
that just adds one single rule. Simplify this to prepare the merge
of nft-rule-insert, which looks very similar.

12 years agoinclude: get linux/netfilter/nf_tables.h in sync with kernel header
Pablo Neira Ayuso [Wed, 19 Feb 2014 16:58:45 +0000 (17:58 +0100)] 
include: get linux/netfilter/nf_tables.h in sync with kernel header

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: fix wrong type in NFT_ATTR_*_FAMILY
Pablo Neira Ayuso [Tue, 25 Feb 2014 23:27:36 +0000 (00:27 +0100)] 
src: fix wrong type in NFT_ATTR_*_FAMILY

This fixes assertions in the test files.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add nft_*_attr_{set|get}_data interface
Pablo Neira Ayuso [Tue, 25 Feb 2014 21:30:12 +0000 (22:30 +0100)] 
src: add nft_*_attr_{set|get}_data interface

This patch adds two functions that allows you to validate the size
of the attribute. This new functions provide a replacement for
nft_rule_attr_set and nft_rule_attr_get.

The data_len parameter was already passed to the {_set|_get} funcion
in expressions. For consistency, add nft_rule_expr_{set|get}_data
alias.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add assertion infrastructure to validate attribute types
Pablo Neira Ayuso [Tue, 25 Feb 2014 23:13:30 +0000 (00:13 +0100)] 
src: add assertion infrastructure to validate attribute types

This will be used to validate that the size is correct according
to the expected attribute size.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: early attribute type validation in nft_*_attr_set
Pablo Neira Ayuso [Tue, 25 Feb 2014 21:27:12 +0000 (22:27 +0100)] 
src: early attribute type validation in nft_*_attr_set

This allows us to remove the default case in the switch, which
show help to spot missing attribute support since gcc will spot
a compilation warning.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add conntrack label match support
Florian Westphal [Sun, 16 Feb 2014 19:13:04 +0000 (20:13 +0100)] 
expr: add conntrack label match support

Signed-off-by: Florian Westphal <fw@strlen.de>
12 years agosrc: compile queue expression support
Pablo Neira Ayuso [Mon, 17 Feb 2014 19:59:13 +0000 (20:59 +0100)] 
src: compile queue expression support

This got lost in 29fd6a1df9 when merging major changes in master
to next-3.14.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agochain: print usage counter for base chain via default output as well
Pablo Neira Ayuso [Thu, 6 Feb 2014 12:47:48 +0000 (13:47 +0100)] 
chain: print usage counter for base chain via default output as well

For some reason this was only printed in custom chains. Print it for
any chain, this is useful for debugging purposes.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoMerge branch 'master' into next-3.14
Pablo Neira Ayuso [Mon, 3 Feb 2014 13:04:42 +0000 (14:04 +0100)] 
Merge branch 'master' into next-3.14

This patch includes changes to adapt this branch to the library
rename that happened in the master branch.

Conflicts:
src/Makefile.am
src/expr/cmp.c
src/expr/ct.c
src/expr/data_reg.c
src/expr/meta.c
tests/jsonfiles/01-table.json
tests/jsonfiles/02-table.json
tests/jsonfiles/64-ruleset.json
tests/xmlfiles/01-table.xml
tests/xmlfiles/02-table.xml

12 years agoinclude: add cached copy of linux/kernel.h
Pablo Neira Ayuso [Wed, 22 Jan 2014 11:55:04 +0000 (12:55 +0100)] 
include: add cached copy of linux/kernel.h

This fixes the following compilation warning when compiling with old
kernel headers.

  CC     expr/target.lo
expr/target.c: In function ‘nft_rule_expr_target_build’:
expr/target.c:127: warning: implicit declaration of function ‘__ALIGN_KERNEL’

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoinclude: add stdint.h to common.h
Arturo Borrero [Tue, 21 Jan 2014 12:08:32 +0000 (13:08 +0100)] 
include: add stdint.h to common.h

This fixes:

/usr/local/include/libnftnl/common.h:25:49: error: unknown type name ‘uint16_t’
/usr/local/include/libnftnl/common.h:25:63: error: unknown type name ‘uint16_t’
/usr/local/include/libnftnl/common.h:26:10: error: unknown type name ‘uint16_t’
/usr/local/include/libnftnl/common.h:26:25: error: unknown type name ‘uint32_t’

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: fix final report after configuration
Pablo Neira Ayuso [Tue, 21 Jan 2014 09:39:18 +0000 (10:39 +0100)] 
build: fix final report after configuration

If no xml/json support is explicitly enabled, the final report
does not show "no". This patch fixes this:

libnftnl configuration:
  XML support:                          no
  JSON support:                         no

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: resolve compile error involving XT_EXTENSION_MAXNAMELEN
Jan Engelhardt [Mon, 20 Jan 2014 23:52:02 +0000 (00:52 +0100)] 
build: resolve compile error involving XT_EXTENSION_MAXNAMELEN

2.6.32 headers in /usr/include/linux again.
Ship a copy of x_tables.h from Linux 3.11.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: resolve build failure involving linux/netlink.h
Jan Engelhardt [Mon, 20 Jan 2014 23:52:01 +0000 (00:52 +0100)] 
build: resolve build failure involving linux/netlink.h

This was seen with a sufficiently-old /usr/include/linux
(from Linux 2.6.32).

In file included from common.c:10:
/usr/include/linux/netlink.h:34: error: expected
specifier-qualifier-list before 'sa_family_t'

The solution is to include <linux/*> last of all system headers.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: Ensure pkg-config file provides the right informations
Tomasz Bursztyka [Mon, 20 Jan 2014 15:56:21 +0000 (17:56 +0200)] 
build: Ensure pkg-config file provides the right informations

It's not -lnftables anymore but -lnftnl (among other details)

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorename library to libnftnl libnftnl-1.0.0
Pablo Neira Ayuso [Mon, 20 Jan 2014 09:26:57 +0000 (10:26 +0100)] 
rename library to libnftnl

We plan to use this library name for the higher layer library.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: ct: fix compilation warning when json/xml support is missing
Pablo Neira Ayuso [Mon, 20 Jan 2014 09:18:03 +0000 (10:18 +0100)] 
expr: ct: fix compilation warning when json/xml support is missing

CC     expr/ct.lo
expr/ct.c:194:12: warning: 'str2ctdir' defined but not used [-Wunused-function]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoct: use a string with 'dir' attribute
Arturo Borrero [Sat, 18 Jan 2014 19:01:32 +0000 (20:01 +0100)] 
ct: use a string with 'dir' attribute

This patch implements a string to represent directions in the CT expression:
 * original (0)
 * reply (1)

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodata_reg: fix verdict format approach
Arturo Borrero [Sat, 18 Jan 2014 16:56:45 +0000 (17:56 +0100)] 
data_reg: fix verdict format approach

Patrick reports that the XML/JSON formats of the data_reg object
are not accuarate.

This patch updates these formats, so they are now as follow:

 * <data_reg type=value> with raw data (this doesn't change).
 * <data_reg type=verdict> with a concrete verdict (eg drop accept) and an
  optional <chain>, with destination.

In XML:
<data_reg type="verdict">
<verdict>goto</verdict>
<chain>output</chain>
</data_reg>

In JSON:
"data_reg" : {
"type" : "verdict",
"verdict" : "goto"
"chain" : "output",
}

The default output format is updated to reflect these changes (minor collateral
thing).

When parsing set_elems, to know if we need to add the NFT_SET_ELEM_ATTR_CHAIN
flag, a basic check for the chain not being NULL is done, instead of evaluating
if the result of the parsing was DATA_CHAIN. The DATA_CHAIN symbol is no longer
used in the data_reg XML/JSON parsing zone.

While at it, I updated the error reporting stuff regarding data_reg/verdict, in
order to leave a consistent state in the library.

A JSON testfile is updated as well.

Reported-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoutils: fix nft_str2verdict return value
Arturo Borrero [Sat, 18 Jan 2014 16:01:44 +0000 (17:01 +0100)] 
utils: fix nft_str2verdict return value

Some verdicts have a negative value.

The caller of nft_str2verdict() checking if return was < 0 clash with
enum nft_verdict.

While at it, add error reporting of invalid verdicts.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: meta: statify meta_key2str_array
Pablo Neira Ayuso [Fri, 17 Jan 2014 09:44:56 +0000 (10:44 +0100)] 
expr: meta: statify meta_key2str_array

It's not used out of the scope of expr/meta.c

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: ct: direction is optional
Arturo Borrero [Fri, 17 Jan 2014 01:15:06 +0000 (02:15 +0100)] 
expr: ct: direction is optional

The 'dir' attribute is optional as stated in the kernel sources.

Previous to this patch, using XML/JSON to manage this expr produces some
undefined and erroneous behaviours.

While at it, fix also the default output format.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: ct: fix missing NFT_CT_L3PROTOCOL in ctkey2str_array
Arturo Borrero [Wed, 15 Jan 2014 18:18:46 +0000 (19:18 +0100)] 
expr: ct: fix missing NFT_CT_L3PROTOCOL in ctkey2str_array

Due to missing NFT_CT_L3PROTOCOL key in ctkey2str_array, a segfault is
produced when the str2ctkey() loop reaches that position, since strcmp()
will try to compare a NULL value.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: xml: delete comments
Arturo Borrero [Wed, 15 Jan 2014 11:12:18 +0000 (12:12 +0100)] 
tests: xml: delete comments

When building a XML tree, only one root node can be in place. This is
a "feature" added in libmxml 2.7:

<<<
mxmlLoad... did not error out on XML with multiple root nodes (Bug #403)
>>>

In libmxml 2.6 the second root node was ignored, not because it was a
comment but a bug. Our files had two root nodes, being comments or not.
libmxml accept comments, but inside the root node.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agolookup: xml: conditional output of dreg
Arturo Borrero [Wed, 15 Jan 2014 10:42:22 +0000 (11:42 +0100)] 
lookup: xml: conditional output of dreg

The dreg attribute is optional as stated at:
linux/net/netfilter/nft_lookup.c

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agomxml: add optional/mandatory flag to nft_mxml_reg_parse
Arturo Borrero [Wed, 15 Jan 2014 10:42:17 +0000 (11:42 +0100)] 
mxml: add optional/mandatory flag to nft_mxml_reg_parse

There are some cases where a reg is not mandatory, for example:
 * dreg in lookup
 * dreg/sreg in meta (last version)

So, lets change the function nft_mxml_reg_parse() to add
an optional/mandatory flag.

dreg in lookup is optional as stated at:
 net/netfilter/nft_lookup.c:nft_lookup_init()

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: ct: Add support for setting the mark
Kristian Evensen [Sat, 11 Jan 2014 13:23:35 +0000 (14:23 +0100)] 
expr: ct: Add support for setting the mark

This patch adds userspace support for setting properties of tracked connections.
Currently, the connection mark is supported. This can be used to implemented the
same functionality as iptables -j CONNMARK --save-mark.

Signed-off-by: Kristian Evensen <kristian.evensen@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agometa: Let user specify any combination of sreg/dreg
Kristian Evensen [Sat, 11 Jan 2014 13:03:17 +0000 (14:03 +0100)] 
meta: Let user specify any combination of sreg/dreg

libnftables should not mask kernel errors. Let user specify any combination of
parameters and leave the error-checking to the kernel. The kernel will return
-EINVAL and users will know that they have to fix their code. This patch also a
removes a redundant variable that was passed to the snprintf-functions (flag).

A second iteration might be needed. I was not sure how to deal with
snprintf_default in the case of both sreg and dreg.

Signed-off-by: Kristian Evensen <kristian.evensen@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoset: xml: data_type/data_len are optional
Arturo Borrero [Mon, 13 Jan 2014 12:14:52 +0000 (13:14 +0100)] 
set: xml: data_type/data_len are optional

Don't print data_type and data_len if they aren't set.
Also, they are optional when parsing.

Printing and parsing unconditionally leads to false values and other errors.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoupdate COPYING
Pablo Neira Ayuso [Wed, 15 Jan 2014 09:19:06 +0000 (10:19 +0100)] 
update COPYING

It includes the new FSF office address.

Reported-by: Kevin Fenzi <kevin@scrye.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr/cmp: fix type size
Patrick McHardy [Wed, 15 Jan 2014 07:28:20 +0000 (07:28 +0000)] 
expr/cmp: fix type size

Since nftables now uses nft_rule_expr_get_u32(), the internal size must
also be a uint32_t.

Fixes complete breakage of any cmp or meta expression.

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agolibnftables: replace netfilter.h by sanitized header
Patrick McHardy [Wed, 15 Jan 2014 06:58:06 +0000 (06:58 +0000)] 
libnftables: replace netfilter.h by sanitized header

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoexpr: fix incorrect data type for several expression object fields
Pablo Neira Ayuso [Fri, 10 Jan 2014 12:21:44 +0000 (13:21 +0100)] 
expr: fix incorrect data type for several expression object fields

This patch fixes the incorrect data type (from uint8_t to uint32_t) in
several private data area of the expressions.

It also cleans up this by translating several unsigned int to uint32_t.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: fix compilation due to missing NFPROTO_INET definition
Pablo Neira Ayuso [Thu, 9 Jan 2014 23:05:38 +0000 (00:05 +0100)] 
src: fix compilation due to missing NFPROTO_INET definition

This adds a copy of the include/linux/netfilter.h kernel header
that defines NFPROTO_INET, so libnftables compiles with relatively
old kernel headers in the system.

chain.c: In function 'nft_hooknum2str':
chain.c:53:7: error: 'NFPROTO_INET' undeclared (first use in this function)

This required to reorder and remove unneeded headers in src/expr/data_reg.c
to avoid a compilation warning due to redefinition of __visible.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: nft-parsing-test: use nft_ruleset_parse_file()
Arturo Borrero [Thu, 9 Jan 2014 11:19:17 +0000 (12:19 +0100)] 
tests: nft-parsing-test: use nft_ruleset_parse_file()

All testfiles are now enclosed in the corresponding top element, ie.

* XML: <nftables>...</nftables>
* JSON: {"nftables":[...]}

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: add interface to parse from file
Arturo Borrero [Thu, 9 Jan 2014 11:19:12 +0000 (12:19 +0100)] 
src: add interface to parse from file

This patch adds a new API to parse rule-set expressed in XML/JSON from
a file. A new enum nft_parse_input type is added for this purpose.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: rework and generalize the build/parse system
Arturo Borrero [Thu, 9 Jan 2014 11:19:06 +0000 (12:19 +0100)] 
src: rework and generalize the build/parse system

The intention behind this patch is to prepare the introduction of
the new API that will allow us to parse files that contain the rule-sets
expressed in XML/JSON format. This adds the NFT_PARSE_BUFFER that
indicates that the input is provided in a buffer, which is what we
currently support.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoMerge branch 'next-3.14' of git.netfilter.org:libnftables into inet
Patrick McHardy [Wed, 8 Jan 2014 18:01:04 +0000 (18:01 +0000)] 
Merge branch 'next-3.14' of git.netfilter.org:libnftables into inet

12 years agolibnftables: add support for inet family and mete nfproto/l4proto expressions
Patrick McHardy [Wed, 8 Jan 2014 18:00:19 +0000 (18:00 +0000)] 
libnftables: add support for inet family and mete nfproto/l4proto expressions

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoset_elem: add json parsing to API
Arturo Borrero [Tue, 7 Jan 2014 11:47:21 +0000 (12:47 +0100)] 
set_elem: add json parsing to API

Add missing support in the API function to parse a JSON set_elem.

I've renamed the main JSON parsing function to prevent clashing.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agomxml: add error reference of the top node
Arturo Borrero [Tue, 7 Jan 2014 11:47:16 +0000 (12:47 +0100)] 
mxml: add error reference of the top node

We know the top node we are building. Let the user also know it.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: new error reporting approach for XML/JSON parsers
Álvaro Neira Ayuso [Sun, 5 Jan 2014 23:51:14 +0000 (00:51 +0100)] 
src: new error reporting approach for XML/JSON parsers

I have added a new structure for reporting some errors in parser
that we can't cover with errno.

In this patch, we have three errors that we can't cover with errno:

NFT_PARSE_EBADINPUT : Bad XML/JSON format in the input
NFT_PARSE_EMISSINGNODE : Missing node in our input
NFT_PARSE_EBADTYPE : Wrong type value in a node

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: add nft-ruleset-get
Arturo Borrero [Mon, 23 Dec 2013 14:18:22 +0000 (15:18 +0100)] 
examples: add nft-ruleset-get

This example prints the ruleset, using the ruleset API of nftables.

The kernel patch c9c8e48 ("netfilter: nf_tables: dump sets in all existing
families") is required.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-set-get: retrieve all sets via unspec
Arturo Borrero [Wed, 9 Oct 2013 10:18:12 +0000 (12:18 +0200)] 
examples: nft-set-get: retrieve all sets via unspec

Other nftables objects are allowed to be dumped with NFPROTO_UNSPEC.
With sets is also possible since kernel patch c9c8e48 ("netfilter: nf_tables:
dump sets in all existing families").

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
12 years agotests: add table 'use' attr to testfiles
Arturo Borrero Gonzalez [Thu, 2 Jan 2014 10:49:06 +0000 (11:49 +0100)] 
tests: add table 'use' attr to testfiles

Parsing tests were failing because a missing 'use' attribute in tables.

validating xmlfiles/02-table.xml: FAILED
from file:     0</flags></table>
f
from snprintf: 0</flags><use>0</use
                         ^
[...]

validating jsonfiles/64-ruleset.json: FAILED
from file:     ,"flags":0}},{"chain
from snprintf: ,"flags":0,"use":0}}
                         ^

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: rename the parameter tag to node_name in jansson function
Álvaro Neira Ayuso [Tue, 31 Dec 2013 11:27:47 +0000 (12:27 +0100)] 
src: rename the parameter tag to node_name in jansson function

I have changed this parameter for having consistence with the
xml helper function. This patch is a cleanup.

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: update meta expr
Arturo Borrero [Thu, 26 Dec 2013 15:50:00 +0000 (16:50 +0100)] 
src: update meta expr

This patch adds userspace support for the meta expression in the set flavour.

This expression indicates that the packet has to be set with a property,
currently one of mark, priority or nftrace.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agobuild: properly handle --without-{xml,json}-parsing
Douglas Freed [Mon, 23 Dec 2013 09:14:57 +0000 (09:14 +0000)] 
build: properly handle --without-{xml,json}-parsing

This patch fixes how --without-{xml,json}-parsing (and subsequently
--with-{xml,json}-parsing=no) is handled.  Prior to this,
--without-{xml,json}-parsing actually resulted in libnftables being
built with that parsing enabled.

Signed-off-by: Douglas Freed <dwfreed@mtu.edu>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotable: Add support for NFTA_TABLE_USE attribute
Tomasz Bursztyka [Thu, 12 Dec 2013 13:12:59 +0000 (15:12 +0200)] 
table: Add support for NFTA_TABLE_USE attribute

This adds support for table's attribute "use" which let us know about
how many chains are in the table, if any.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoinclude: update netlink.h to 3.13
Tomasz Bursztyka [Thu, 12 Dec 2013 13:00:43 +0000 (15:00 +0200)] 
include: update netlink.h to 3.13

Use kernel header from 3.13-rc upstream kernel, this includes
documentation changes that were missing.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexamples: nft-rule-add: use existing batch infrastructure
Pablo Neira Ayuso [Tue, 10 Dec 2013 16:21:47 +0000 (17:21 +0100)] 
examples: nft-rule-add: use existing batch infrastructure

This patch reworks the existing example to add the rule:

  nft add rule ip filter input tcp dport 22 counter

It uses the existing nfnl batching approach using the generic mnl
netlink message batching infrastructure. It also removed the code
that uses xtables compat code.

Based on original patch by Arturo Borrero Gonzalez.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotest: add tests for expr queue
Eric Leblond [Sat, 30 Nov 2013 10:57:22 +0000 (11:57 +0100)] 
test: add tests for expr queue

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: add support for nfnetlink queue
Eric Leblond [Sat, 30 Nov 2013 10:57:21 +0000 (11:57 +0100)] 
expr: add support for nfnetlink queue

This patch adds a support of the queue target.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: expr-target: fix deprecation warning
Arturo Borrero [Thu, 28 Nov 2013 11:30:10 +0000 (12:30 +0100)] 
tests: expr-target: fix deprecation warning

This fixes the following warning:

In file included from nft-expr_target-test.c:19:0: /usr/include/linux/netfilter_ipv4/ipt_LOG.h:4:2: warning: #warning "Please update iptables, this file will be removed soon!" [-Wcpp]

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: extend test-script.sh to run XML and JSON tests
Arturo Borrero [Thu, 28 Nov 2013 11:30:16 +0000 (12:30 +0100)] 
tests: extend test-script.sh to run XML and JSON tests

Let's test the XML/JSON parsing with test-script.sh as well.

Singed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: consolidate netlink build header function
Pablo Neira Ayuso [Sun, 24 Nov 2013 20:01:49 +0000 (21:01 +0100)] 
src: consolidate netlink build header function

Add new function nft_nlmsg_build_hdr which consolidates all existing
functions to build headers per object. They basically look the same.
This patch still provides aliases for consistency in the naming
approach.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoinclude: fix possible clash in ifdef namespace
Pablo Neira Ayuso [Sun, 24 Nov 2013 19:43:49 +0000 (20:43 +0100)] 
include: fix possible clash in ifdef namespace

Use _LIBNFTABLES_ prefix to avoid possible clash with headers that
are defined in other libraries that may be used by third party
applications.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotests: add unit tests for libnftables
Ana Rey [Wed, 20 Nov 2013 11:23:12 +0000 (12:23 +0100)] 
tests: add unit tests for libnftables

These tests create an initial object 'a' whose attributes are
set to arbitrary values. Then, that object is converted to a
Netlink message which is parsed to obtain the object 'b'. If
things go well, the original object 'a' and the transformed
object 'b' should be equivalent. Thus, we make sure that object
transformations through the main library APIs are correct.

These tests have helped to catch the following bugs in this library:

(3cf788a72 expr: fix leak in target and match expressions)
(4182e574f expr: match: fix wrong flag setting in nft_rule_expr_match_parse)
(0bec6bc5e expr: log: release prefix)
(2b690deea expr: log: fix missing \0 when sending log prefix to kernel)
(e55c7afcf expr: target: fix wrong info length in nft_rule_expr_target_parse)
(8fc4d4bd2 expr: log: fix wrong attribute type in nft_rule_expr_log_parse)

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agotable/chain: add u8 setter and getter for family values
Ana Rey [Tue, 19 Nov 2013 12:01:56 +0000 (13:01 +0100)] 
table/chain: add u8 setter and getter for family values

These are needed to set the family value for chain and table.

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoexpr: log: fix wrong attribute type in nft_rule_expr_log_parse
Ana Rey [Tue, 19 Nov 2013 12:01:16 +0000 (13:01 +0100)] 
expr: log: fix wrong attribute type in nft_rule_expr_log_parse

I fixed it by using the correct value.

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

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

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

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

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

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

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

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

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

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

Expression flags were incorrectly set.

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

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

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

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

Release internal data area for match and target expressions.

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

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

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

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

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

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

Kill reference to undefined symbol.

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

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

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

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

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

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

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

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

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

Remove those EOPNOTSUPPs because they are unused.

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

Report error when building XML tree.

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

Ensure the tree is freed when done.

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

Before this patch, 0 was returned unconditionally.

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

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

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

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

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

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

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

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

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

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

Based on patch from Jan Engelhardt.

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

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

This closes netfilter bugzilla #868.

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

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

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

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

This patch adds support for the reject expression.

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

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

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

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

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

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

my fault, spotted by Phil Oester.

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

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

Based on patch from Florian Westphal, for nft.

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

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

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

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

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

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

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>