]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
11 years agoparser: fix parsing of ethernet protocol types
Pablo Neira Ayuso [Wed, 15 Jan 2014 20:12:38 +0000 (21:12 +0100)] 
parser: fix parsing of ethernet protocol types

This allows us to use the protocol type keyword, eg.

nft add rule ip filter output meta protocol ip6 counter
                                            ^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpr: relational: don't surpress '==' for LHS binops in output
Patrick McHardy [Wed, 15 Jan 2014 15:39:10 +0000 (15:39 +0000)] 
expr: relational: don't surpress '==' for LHS binops in output

This patch changes the output of relational expressions to not surpress
the '==' when the LHS is a binop, f.i.

... meta mark & 0x00000003 0x00000001

becomes

... meta mark & 0x00000003 == 0x00000001

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink: use stdout for debugging
Pablo Neira Ayuso [Wed, 15 Jan 2014 14:56:57 +0000 (15:56 +0100)] 
netlink: use stdout for debugging

Suggested-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosegtree: add new segtree debugging option
Pablo Neira Ayuso [Wed, 15 Jan 2014 12:14:25 +0000 (13:14 +0100)] 
segtree: add new segtree debugging option

Currently, nft displays the debugging information if it's compiled with
--enable-debug (which seems a good idea) and when intervals are used
in maps. Add a new option to enable debugging to segtree, so we only
get this information when explicitly requested.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agopayload: fix name of eth_proto
Patrick McHardy [Wed, 15 Jan 2014 11:57:28 +0000 (11:57 +0000)] 
payload: fix name of eth_proto

It's "ether" now since we've changed the keyword.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agometa: fix mismerge
Patrick McHardy [Wed, 15 Jan 2014 11:53:23 +0000 (11:53 +0000)] 
meta: fix mismerge

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agometa: don't require "meta" keyword for a subset of meta expressions
Patrick McHardy [Wed, 15 Jan 2014 07:35:20 +0000 (07:35 +0000)] 
meta: don't require "meta" keyword for a subset of meta expressions

Don't require the meta keyword for mark, iif, oif, iifname, oifname,
skuid, skgid, nftrace, rtclassid and secmark.

The protocol and length types still need the meta keyword to avoid
grammar conflicts.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Conflicts:
src/parser.y

11 years agoexpr: remove secmark from ct and meta expression
Patrick McHardy [Wed, 15 Jan 2014 11:11:10 +0000 (11:11 +0000)] 
expr: remove secmark from ct and meta expression

The secctx should be used instead of the secmark. Remove for now.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoscanner: add aliases to symbols for easier interaction with most shells
Pablo Neira Ayuso [Tue, 14 Jan 2014 14:55:14 +0000 (15:55 +0100)] 
scanner: add aliases to symbols for easier interaction with most shells

These symbols need to be escaped in bash and if you use them without
escaping then, it can lead to confusion. This patch adds nominal
aliases, eg.

 nft add rule filter output meta mark and 0x3 eq 0x1

as an alternative to:

 nft add rule filter output meta mark \& 0x3 == 0x1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonft: scanner: fixed problem with ipv6 address
Ana Rey [Wed, 15 Jan 2014 07:42:28 +0000 (07:42 +0000)] 
nft: scanner: fixed problem with ipv6 address

There is a problem with the follow ipv6 address combination:

nft add rule ip6 t_ip61 filter-input ip6 saddr ::1234:1234:1234:1234:1234:1234:1234

1234::1234:1234:1234:1234:1234:1234
1234:1234::1234:1234:1234:1234:1234
1234:1234:1234::1234:1234:1234:1234
1234:1234:1234:1234::1234:1234:1234
1234:1234:1234:1234:1234::1234:1234
::1234:1234:1234:1234:1234:1234
1234::1234:1234:1234:1234:1234
1234:1234::1234:1234:1234:1234
1234:1234:1234::1234:1234:1234
1234:1234:1234:1234::1234:1234
::1234:1234:1234:1234:1234
1234::1234:1234:1234:1234
1234:1234::1234:1234:1234
1234:1234:1234::1234:1234
::1234:1234:1234:1234
1234::1234:1234:1234
1234:1234::1234:1234
::1234:1234:1234
1234::1234:1234

The problem was in the scanner (src/scanner.l). Several brackets were missed
and the result was an incorrect interpretation.

Fix it by adding some brackets in a regular expression in src/scanner.l

Signed-off-by: Ana Rey <anarey@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoscanner: rename address selector from 'eth' to 'ether'
Pablo Neira Ayuso [Tue, 14 Jan 2014 11:07:44 +0000 (12:07 +0100)] 
scanner: rename address selector from 'eth' to 'ether'

eth may easily occur when using ifname masks. This could be also
fixed by interpreting 'eth' as a simple string in the parser but
I think this selector also looks more similar to what we use in
tcpdump.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoRevert "parser: replace "vmap" keyword by "map""
Patrick McHardy [Tue, 14 Jan 2014 12:37:36 +0000 (12:37 +0000)] 
Revert "parser: replace "vmap" keyword by "map""

This reverts commit 5e8f8a1807917f92e568437598670b0026462c1c.

I missed that this introduces shift-reduce conflicts. Revert for now.

11 years agoparser: replace "vmap" keyword by "map"
Patrick McHardy [Tue, 14 Jan 2014 12:30:48 +0000 (12:30 +0000)] 
parser: replace "vmap" keyword by "map"

Consistently use "map" to express mappings.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agofiles: replace interpreter during installation
Arturo Borrero Gonzalez [Mon, 13 Jan 2014 09:37:45 +0000 (09:37 +0000)] 
files: replace interpreter during installation

Many systems (for example Debian) don't recognice `#!nft -f' as a
valid interpreter.

A short way to handle this is to provide the full path to the interpreter
in the shebang.
That is what this patch does: update the shebang's path during installation.

For example, if you are installing under /usr/local, the shebang becomes:
 #!/usr/local/sbin/nft -f

If using --prefix=/, then:
 #!/sbin/nft -f

NOTE: If the shebang in source files are changed in a future, this sed script
should be updated as well.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonftables: drop hard coded install using root user owner and group
Kevin Fenzi [Mon, 13 Jan 2014 06:36:45 +0000 (06:36 +0000)] 
nftables: drop hard coded install using root user owner and group

Packaging systems build as a non priv user, so can't install as root. Users
installing from source can 'sudo make install' or run 'make install' as root

Signed-off-by: Kevin Fenzi <kevin@scrye.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink: fix wrong type in attributes
Pablo Neira Ayuso [Fri, 10 Jan 2014 12:47:57 +0000 (13:47 +0100)] 
netlink: fix wrong type in attributes

Fix inconsistent attribute types in meta and cmp expressions, use
uint32_t. This problem was added when converting nft to use libmnl
and libnftables.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: fix crash when parsing unresolvable mark values
Patrick McHardy [Fri, 10 Jan 2014 09:28:37 +0000 (09:28 +0000)] 
meta: fix crash when parsing unresolvable mark values

*res has undefined contents, set to NULL before invoking the parse function
to make sure the test for != NULL doesn't falsely return true.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agodatatype: revert "fix crash if wrong integer type is passed"
Patrick McHardy [Fri, 10 Jan 2014 09:28:37 +0000 (09:28 +0000)] 
datatype: revert "fix crash if wrong integer type is passed"

Revert commit a320531e7:

We have generic type checks that handle this case just fine and indeed
the bugzilla entry mentioned in the reverted patch states:

BUG: invalid input descriptor type 538976288
nft: src/erec.c:100: erec_print: Assertion `0' failed.
Abandon

So the problem is not related to datatypes at all and generic type
checking works perfectly fine:

<cmdline>:1:52-57: Error: datatype mismatch, expected Ethernet protocol, expression has type Internet protocol
add rule ip6 filter input position 4 meta protocol icmpv6 accept
                                     ~~~~~~~~~~~~~ ^^^^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agoerec: fix error markup for errors starting at column 0
Patrick McHardy [Fri, 10 Jan 2014 09:28:37 +0000 (09:28 +0000)] 
erec: fix error markup for errors starting at column 0

For errors starting at column 0, we must not subtract 1 to avoid underflow.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonftables: shorten "could not process rule in batch" message
Patrick McHardy [Fri, 10 Jan 2014 09:28:37 +0000 (09:28 +0000)] 
nftables: shorten "could not process rule in batch" message

Remove the "in batch" part, it makes most messages exceed a single line, the
user doesn't care about this and we process even single rules in "batches".

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonftables: fix supression of "permission denied" errors
Patrick McHardy [Thu, 9 Jan 2014 18:54:02 +0000 (18:54 +0000)] 
nftables: fix supression of "permission denied" errors

Introduction of batch support broke displaying of EPERM since those are
generated by the kernel before batch processing starts and thus have the
sequence number of the NFNL_MSG_BATCH_BEGIN message instead of the
command messages. Also only a single error message is generated for the
entire batch.

This patch fixes this by noting the batch sequence number and displaying
the error for all commands since this is what would happen if the
permission check was inside batch processing as every other check.

Signed-off-by: Patrick McHardy <kaber@trash.net>
11 years agonetlink: fix dictionary feature with data mappings
Pablo Neira Ayuso [Fri, 27 Dec 2013 11:48:40 +0000 (12:48 +0100)] 
netlink: fix dictionary feature with data mappings

This patch fixes dictionary feature, that allows you to conditionally
set packet fields based on a given selector, eg.

 add rule ip filter input meta dnat set tcp dport map { 22 => 1.1.1.1, 23 => 2.2.2.2 }

This means that traffic flowing to tcp port 22 is dnatted to address
1.1.1.1 and tcp port 23 is dnatted to address 2.2.2.2.

This feature was partially broken by aae836a ("src: use libnftables")
although it also needs the kernel fix ("netfilter: nf_tables: fix wrong
datatype in nft_validate_data_load()").

This patch also fixes endianness issues when displaying the mark
via `list table' related to list_setelem_cb() since the byteorder
was left unset for the data part of a set element.

 meta mark set tcp dport map { telnet => 0x02000000, ssh => 0x01000000}
                                            ^                  ^
Note the wrong endianness in the example above.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: print netlink message if if --debug=netlink in mnl_talk()
Pablo Neira Ayuso [Fri, 27 Dec 2013 11:36:12 +0000 (12:36 +0100)] 
mnl: print netlink message if if --debug=netlink in mnl_talk()

Useful for debugging purposes.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: don't set NLM_F_ACK flag in mnl_nft_rule_batch_[add|del]
Pablo Neira Ayuso [Sat, 7 Dec 2013 19:06:30 +0000 (20:06 +0100)] 
mnl: don't set NLM_F_ACK flag in mnl_nft_rule_batch_[add|del]

If the NLM_F_ACK flag is unset, the kernel still explicitly reports
errors. Thus, we can save the handling of many explicit (useless) ack
messages that indicate success.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: fix rule flushing atomically
Pablo Neira Ayuso [Fri, 6 Dec 2013 09:24:20 +0000 (10:24 +0100)] 
src: fix rule flushing atomically

nft is currently retrieving the list of rule from the kernel, then
deleting each rule one by one. This is slow and not safe. Fix it
by sending a deletion command in a batch without specifying the
chain.

This change requires the kernel fix entitled:
netfilter: nf_tables: fix missing rules flushing per table

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: fix inconsistent name usage in nft_*_nlmsg_build_hdr calls
Arturo Borrero [Mon, 2 Dec 2013 16:07:18 +0000 (17:07 +0100)] 
mnl: fix inconsistent name usage in nft_*_nlmsg_build_hdr calls

Minor fix, given that all those functions are aliases.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoparser: add 'delete map' syntax
Phil Oester [Sat, 30 Nov 2013 20:41:21 +0000 (12:41 -0800)] 
parser: add 'delete map' syntax

Creating a map is done via "add map".  However, to delete a map requires using
"delete set", which is confusing.  Add the appropriate synonym to parser.
The downside to this is that one can now delete a set with "delete map", but
this seems a minor issue.  It could of course be fixed by adding a new
CMD_OBJ_MAP.

This closes netfilter bugzilla #879.

Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agorule: missing set cleanup in do_command_list
Phil Oester [Sat, 30 Nov 2013 20:15:52 +0000 (12:15 -0800)] 
rule: missing set cleanup in do_command_list

When listing a table in interactive mode, the set list is not cleaned up.  Thus
the number of displayed sets grows with each successive listing.  Attached
patch adds the necessary list cleanup to do_command_list.

Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexamples: adjust new chain type syntax in sets_and_maps file
Phil Oester [Fri, 29 Nov 2013 20:32:29 +0000 (12:32 -0800)] 
examples: adjust new chain type syntax in sets_and_maps file

This example file has not been updated with new syntax.

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoparser: segfault in top scope define
Phil Oester [Fri, 29 Nov 2013 20:30:04 +0000 (12:30 -0800)] 
parser: segfault in top scope define

nft segfaults if a symbol is added in top_scope, because of a missing
init_list_head.  Trivial example:

    define ip_set = {192.168.1.2, 192.168.2.3}
    add rule filter output ip daddr $ip_set counter

This closes netfilter bugzilla #877.

Reported-by: Anand Raj Manickam <anandrm@gmail.com>
Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: relax restriction on UID/GID parsing
Pablo Neira Ayuso [Fri, 29 Nov 2013 10:23:09 +0000 (11:23 +0100)] 
meta: relax restriction on UID/GID parsing

nft is currently rejecting unknown UID/GID if they don't exist in the
system, relax this as Bjørnar Ness considers this is a valid scenario.
Now this only reports an error if you pass an unknown user (expressed as
string or if the UID/GID goes above 32 bits).

Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: fix endianness in UID/GID
Pablo Neira Ayuso [Fri, 29 Nov 2013 10:28:07 +0000 (11:28 +0100)] 
meta: fix endianness in UID/GID

 add rule filter output meta skuid vmap { 1000 => accept }
 list table filter
 meta skuid map { 3892510720 => accept}
                  ^--------^
        this is 1000 in network byte order

Reported-by: Bjørnar Ness <bjornar.ness@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: improve rule deletion per chain
Pablo Neira Ayuso [Sun, 24 Nov 2013 19:06:51 +0000 (20:06 +0100)] 
netlink: improve rule deletion per chain

With this patch, nft asks the kernel for deleting all rules in a chain.
This replaces the current behaviour that requires to dump all the rules,
then iterate over that list to delete one by one, which is prone to races
and slowier.

After this patch, the following two commands are equivalent:

 nft flush chain filter input
 nft delete rule filter input

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agodatatype: fix missing nul-terminated string in string_type_print
Pablo Neira Ayuso [Sun, 24 Nov 2013 18:49:15 +0000 (19:49 +0100)] 
datatype: fix missing nul-terminated string in string_type_print

Thomas Berger reported that he is seeing garbage after valid string
values, eg.

fwtest01 ~ # nft -i
nft> table filter
nft> add chain filter input
nft> add rule filter input meta iifname "lo" accept
nft> list table filter
table ip filter {
        chain input {
                 meta iifname "lo�.�" accept
        }
...

The buffer that is allocated in the stack does not include room to
nul-terminate the string accordingly. This patch fixes bugzilla
report #872:

https://bugzilla.netfilter.org/show_bug.cgi?id=872

Reported-by: Thomas Berger <loki@lokis-chaos.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: only display wanted chain in listing
Eric Leblond [Mon, 18 Nov 2013 07:40:21 +0000 (08:40 +0100)] 
netlink: only display wanted chain in listing

When specifying a chain to list, all created chains were displayed
with a void content:

 # nft list chain filter
 table ip filter {
   chain input {
   }

   chain new {
    counter packets 17971 bytes 2380637 accept
    counter packets 0 bytes 0 accept
   }
  }

With the attached patch, only the asked chain is displayed:

  # nft list chain filter
  table ip filter {
   chain new {
    counter packets 17971 bytes 2380637 accept # handle 36
    counter packets 0 bytes 0 accept # handle 40
   }
  }

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoverdict: fix delinearize in case of jump
Eric Leblond [Sun, 17 Nov 2013 23:54:45 +0000 (00:54 +0100)] 
verdict: fix delinearize in case of jump

The name of the chain was not handled in case of a jump or a goto.
This patch adds parsing of the chain.

Reported-by: Alex Chapman <ajchapman88@hotmail.co.uk>
Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agojump: fix logic in netlink linearize
Eric Leblond [Sun, 17 Nov 2013 23:54:44 +0000 (00:54 +0100)] 
jump: fix logic in netlink linearize

Logic in the test was inverted. The result was the jump string
not to be set.

Reported-by: Alex Chapman <ajchapman88@hotmail.co.uk>
Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoexpression: fix indent
Eric Leblond [Sun, 17 Nov 2013 23:54:43 +0000 (00:54 +0100)] 
expression: fix indent

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonftables: delete debian/ directory
Arturo Borrero [Thu, 14 Nov 2013 15:44:38 +0000 (16:44 +0100)] 
nftables: delete debian/ directory

The debian/ dir does not belong here, we already discussed this
with Debian maintainers many times before.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agobuild: relax compilation not to break on warning
Pablo Neira Ayuso [Mon, 4 Nov 2013 11:34:39 +0000 (12:34 +0100)] 
build: relax compilation not to break on warning

Remove -Werror, as bison and flex generate unclean code that may
break compilation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoparser: fix warning on deprecated directive in bison
Pablo Neira Ayuso [Mon, 4 Nov 2013 10:30:41 +0000 (11:30 +0100)] 
parser: fix warning on deprecated directive in bison

src/parser.y:93.1-13: warning: deprecated directive, use ‘%name-prefix’ [-Wdeprecated]
 %name-prefix="nft_"
 ^^^^^^^^^^^^^
Reported-by: Anatol Pomozov <anatol.pomozov@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agopayload: fix ethernet type protocol matching
Pablo Neira Ayuso [Wed, 30 Oct 2013 12:33:50 +0000 (13:33 +0100)] 
payload: fix ethernet type protocol matching

This fixes ethernet type protocol matching, which is needed
to match network layer information, eg.

 nft add rule bridge filter input ip protocol icmp counter

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink_linearize: finish reject support
Pablo Neira Ayuso [Fri, 25 Oct 2013 15:01:58 +0000 (17:01 +0200)] 
netlink_linearize: finish reject support

This patch finishes the reject support.

Reported-by: Jiri Benc <jbenc@redhat.com>
Tested-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agostatement: avoid huge rodata array
Florian Westphal [Tue, 22 Oct 2013 12:35:02 +0000 (14:35 +0200)] 
statement: avoid huge rodata array

commit b259d1a ('src: operational limit match') creates huge
array, increasing nft binary size from ~240k to ~5m on x86_64.

Use switch statement instead.

Signed-off-by: Florian Westphal <fw@strlen.de>
11 years agosrc: operational limit match
Phil Oester [Sat, 5 Oct 2013 16:44:56 +0000 (09:44 -0700)] 
src: 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>
11 years agosrc: fix return code
Arturo Borrero Gonzalez [Fri, 11 Oct 2013 11:03:08 +0000 (13:03 +0200)] 
src: fix return code

Exit with NFT_EXIT_FAILURE if something went wrong in the netlink code.

Before this patch:

internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]

0

After this patch:

internal:0:0-0: Error: Could not find chain `asd' in table `filter': [...]

1

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: fix nft flush operation
Eric Leblond [Wed, 2 Oct 2013 23:08:08 +0000 (01:08 +0200)] 
netlink: fix nft flush operation

nft_netlink function is already calling mnl_batch_end and
mnl_batch_begin so it is not necessary to do it in the
netlink_flush_rules function. Doing this result in a invalid
netlink message which is discarded by the kernel.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: only flush asked table/chain
Eric Leblond [Wed, 2 Oct 2013 23:08:07 +0000 (01:08 +0200)] 
netlink: only flush asked table/chain

The flush operation was not limiting the flush to the table or
chain specified on command line. The result was that all the rules
for a given family are flush independantly of the flush command.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: suppress useless variable
Eric Leblond [Wed, 2 Oct 2013 23:08:06 +0000 (01:08 +0200)] 
netlink: suppress useless variable

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agomnl: fix typo in comment
Eric Leblond [Wed, 2 Oct 2013 23:08:05 +0000 (01:08 +0200)] 
mnl: fix typo in comment

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: Add support for IPv6 NAT
Eric Leblond [Sun, 29 Sep 2013 09:53:29 +0000 (11:53 +0200)] 
src: Add support for IPv6 NAT

This patch adds support for IPv6 NAT. It adds IPv6 support in
evaluation and in delinearization which were the only missing parts.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: fix IPv6 prefix computation
Eric Leblond [Sun, 29 Sep 2013 09:53:28 +0000 (11:53 +0200)] 
netlink: fix IPv6 prefix computation

The prefix building algorithm in netlink phase was incorrect in
IPv6.

For example, when adding the following rule
 nft add rule ip6 nat postrouting ip6 saddr 2::/64 --debug=all

we had:

 ip6 nat postrouting 0 0
  [ payload load 16b @ network header + 8 => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0x00000000 0x99361540 0x00007f8d 0x2e33a1eb ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ]
  [ cmp eq reg 1 0x00000200 0x00000000 0x00000000 0x00000000 ]

With the patch the result is as expected:

 ip6 nat postrouting 0 0
  [ payload load 16b @ network header + 8 => reg 1 ]
  [ bitwise reg 1 = (reg=1 & 0xffffffff 0xffffffff 0x00000000 0x00000000 ) ^ 0x00000000 0x00000000 0x00000000 0x00000000 ]
  [ cmp eq reg 1 0x00000200 0x00000000 0x00000000 0x00000000 ]

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoinclude: cache a copy of nfnetlink.h
Tomasz Bursztyka [Mon, 30 Sep 2013 09:22:42 +0000 (12:22 +0300)] 
include: cache a copy of nfnetlink.h

If nft is compiled without nftables Linux kernel headers installed, we
hit a compilation error:

src/mnl.c: In function ‘mnl_batch_put’:
src/mnl.c:117:16: error: ‘NFNL_SUBSYS_NFTABLES’ undeclared (first use in
this function)
src/mnl.c:117:16: note: each undeclared identifier is reported only once
for each function it appears in
src/mnl.c: In function ‘mnl_batch_begin’:
src/mnl.c:125:16: error: ‘NFNL_MSG_BATCH_BEGIN’ undeclared (first use in
this function)
src/mnl.c: In function ‘mnl_batch_end’:
src/mnl.c:130:16: error: ‘NFNL_MSG_BATCH_END’ undeclared (first use in
this function)

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: add rule batching support
Pablo Neira Ayuso [Sun, 22 Sep 2013 18:41:03 +0000 (20:41 +0200)] 
src: add rule batching support

This patch allows nft to put all rule update messages into one
single batch that is sent to the kernel if `-f' option is used.
In order to provide fine grain error reporting, I decided to
to correlate the netlink message sequence number with the
correspoding command sequence number, which is the same. Thus,
nft can identify what rules trigger problems inside a batch
and report them accordingly.

Moreover, to avoid playing buffer size games at batch building
stage, ie. guess what is the final size of the batch for this
ruleset update will be, this patch collects batch pages that
are converted to iovec to ensure linearization when the batch
is sent to the kernel. This reduces the amount of unnecessary
memory usage that is allocated for the batch.

This patch uses the libmnl nlmsg batching infrastructure and it
requires the kernel patch entitled (netfilter: nfnetlink: add batch
support and use it from nf_tables).

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: iif/oifname should be host byte order
Florian Westphal [Fri, 20 Sep 2013 14:01:33 +0000 (16:01 +0200)] 
meta: iif/oifname should be host byte order

src/nft add rule filter output meta oifname eth0

doesn't work on x86.  Problem is that nft declares these as
BYTEORDER_INVALID, but when converting the string mpz_import_data
treats INVALID like BIG_ENDIAN.

[ cmp eq reg 1 0x00000000 0x00000000 0x65000000 0x00306874 ]

as kernel nft_cmp_eval basically boils down to

memcmp(reg, skb->dev->name, sizeof(reg) comparision fails.

with patch:
[ cmp eq reg 1 0x30687465 0x00000000 0x00000000 0x00000000 ]

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonetlink: use uint32_t instead of size_t for attribute length
Pablo Neira Ayuso [Thu, 19 Sep 2013 20:57:47 +0000 (22:57 +0200)] 
netlink: use uint32_t instead of size_t for attribute length

According to libnftables change 437d610, now the length obtained
via getter function is uint32_t, not size_t anymore.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agodisplay family in table listing
Eric Leblond [Mon, 16 Sep 2013 16:27:38 +0000 (18:27 +0200)] 
display family in table listing

As family was not displayed in table listing, it was not possible
to restore an ipv6 table saved via 'nft list table ip6 TABLE'.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoUpdate chain creation format.
Eric Leblond [Mon, 16 Sep 2013 16:27:37 +0000 (18:27 +0200)] 
Update chain creation format.

type keyword is now mandatory when creating a new chain. This
patc halso implement the change required following the usage of human
notation in hook.

It also suppressed non currently supported mangle chains.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoSuppress non working examples.
Eric Leblond [Mon, 16 Sep 2013 16:27:36 +0000 (18:27 +0200)] 
Suppress non working examples.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonat: add mandatory family attribute
Eric Leblond [Mon, 16 Sep 2013 16:27:35 +0000 (18:27 +0200)] 
nat: add mandatory family attribute

NFT_EXPR_NAT_FAMILY is a mandatory attribute for NAT rules and
it was not set by nftables.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agolog: s/threshold/queue-threshold/
Florian Westphal [Fri, 13 Sep 2013 14:44:48 +0000 (16:44 +0200)] 
log: s/threshold/queue-threshold/

on input we expect "queue-threshold" token, so use the same
name when printing the output.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agopayload: fix endianess of ARP operation code
Pablo Neira Ayuso [Sat, 14 Sep 2013 18:37:26 +0000 (20:37 +0200)] 
payload: fix endianess of ARP operation code

So it display compatibility command:

xtables-arp -A INPUT --opcode Reply -j DROP

accordinly:

arp plen 4 arp operation reply counter packets 0 bytes 0 drop

11 years agosrc: Better error reporting if chain type is invalid
Tomasz Bursztyka [Wed, 4 Sep 2013 09:50:20 +0000 (12:50 +0300)] 
src: Better error reporting if chain type is invalid

This patch verifies at command line parsing that given chain type
is valid. Possibilities are: filter, nat, and route.

nft add chain test test { type cheese hook input priority 0 };
<cmdline>:1:28-33: Error: unknown chain type cheese
add chain test test { type cheese hook input priority 0 };
                           ^^^^^^

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agodatatype: fix mark parsing if string is used
Pablo Neira Ayuso [Wed, 4 Sep 2013 11:13:35 +0000 (13:13 +0200)] 
datatype: fix mark parsing if string is used

This fixes string mark parsing. Note that /etc/iproute2/rt_marks may
contain mapping between string and mark values.

This fixes here:

add rule filter output meta mark 0 counter

Assumming that:

cat /etc/iproute2/rt_marks

says:

0 test

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agometa: fix output display of meta length
Pablo Neira Ayuso [Wed, 4 Sep 2013 10:51:13 +0000 (12:51 +0200)] 
meta: fix output display of meta length

nft list table filter

Before:
meta len 1000 counter packets 0 bytes 0
After:
meta length 1000 counter packets 0 bytes 0

Now it doesn't break with nft -f.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agotests: Update bate chain creation according to latest syntax changes
Tomasz Bursztyka [Wed, 4 Sep 2013 09:50:22 +0000 (12:50 +0300)] 
tests: Update bate chain creation according to latest syntax changes

Adding type, plain hook's name and priority keyword.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: Add priority keyword on base chain description
Tomasz Bursztyka [Wed, 4 Sep 2013 09:50:21 +0000 (12:50 +0300)] 
src: Add priority keyword on base chain description

Instead of:
add chain foo bar { type route hook input 0; }

it should be now:
add chain foo bar { type route hook input priority 0; }

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
11 years agosrc: Wrap netfilter hooks around human readable strings
Tomasz Bursztyka [Wed, 4 Sep 2013 09:50:19 +0000 (12:50 +0300)] 
src: Wrap netfilter hooks around human readable strings

This allows to use unique, human readable, hook names for the command
line and let the user being unaware of the complex netfilter's hook
names and there difference depending on the netfilter family.

So:
add chain foo bar { type route hook NF_INET_LOCAL_IN 0; }

becomes:
add chain foo bar { type route hook input 0; }

It also fixes then the difference in hook values between families.
I.e. ARP family has different values for input, forward and output
compared to IPv4, IPv6 or bridge.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agoINSTALL: Update dependency list and repository URLs
Tomasz Bursztyka [Thu, 29 Aug 2013 06:18:39 +0000 (09:18 +0300)] 
INSTALL: Update dependency list and repository URLs

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: Fix base chain printing
Tomasz Bursztyka [Wed, 28 Aug 2013 08:33:07 +0000 (11:33 +0300)] 
src: Fix base chain printing

Relying on chain's hooknum to know whether the chain is a base one or
not is bogus: having 0 as hooknum is a valid number. Thus setting the
right flag and handling it is the way to go, as parser does already.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: allow to specify the base chain type
Pablo Neira Ayuso [Thu, 22 Aug 2013 15:26:31 +0000 (17:26 +0200)] 
src: allow to specify the base chain type

This patch allows you to specify the type of the base chain, eg.

add table mangle
add chain mangle OUTPUT { type route hook NF_INET_LOCAL_OUT 0; }

The chain type determines the semantics of the chain, we currently
have three types:

* filter, used for plain packet filtering.
* nat, it only sees the first packet of the flow.
* route, which is the equivalent of the iptables mangle table, that
  triggers a re-route if there is any change in some of the packet header
  fields, eg. IP TOS/DSCP, or the packet metainformation, eg. mark.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agodatatype: fix wrong endianess in numeric ports
Pablo Neira Ayuso [Sat, 24 Aug 2013 10:27:57 +0000 (12:27 +0200)] 
datatype: fix wrong endianess in numeric ports

In (5075879 datatype: validate port number in inet_service_type_parse),
conversion to network byte order was missing.

Reported-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agonftables: add additional --numeric level
Phil Oester [Thu, 15 Aug 2013 23:24:11 +0000 (16:24 -0700)] 
nftables: add additional --numeric level

Personally, I like seeing ports and IPs numerically, but prefer protocols
to be shown by name.  As such, add a third --numeric level which will
show protocols by number, splitting them out from ports.

  -n/--numeric                  When specified once, show network addresses numerically.
                                When specified twice, also show Internet services,
                                user IDs and group IDs numerically.
                                When specified thrice, also show protocols numerically.

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agolog: convert group and qthreshold to use u16
Pablo Neira Ayuso [Sat, 17 Aug 2013 10:41:49 +0000 (12:41 +0200)] 
log: convert group and qthreshold to use u16

Required since (netfilter: nft_log: group and qthreshold are 2^16)
kernel change.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agodatatype: allow protocols by number in inet_protocol_type_parse
Phil Oester [Thu, 15 Aug 2013 23:09:07 +0000 (16:09 -0700)] 
datatype: allow protocols by number in inet_protocol_type_parse

nftables does not currently allow specifying protocols by number.  Below
patch adds this capability.

Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agodatatype: validate port number in inet_service_type_parse
Phil Oester [Thu, 15 Aug 2013 17:19:11 +0000 (10:19 -0700)] 
datatype: validate port number in inet_service_type_parse

At present, nft accepts out of range port values such as in this example:

    nft add rule ip filter input tcp dport 123456 accept

Attached patch adds checks for both integer overflow and 16 bit overflow,
and avoids getaddrinfo call in the (common) case of digit input. Example
above now produces this output:

    <cmdline>:1:36-41: Error: Service out of range
    add rule ip filter input tcp dport 123456 accept
                                       ^^^^^^
Signed-off-by: Phil Oester <kernel@linuxace.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
11 years agosrc: Add icmpv6 support
Eric Leblond [Sun, 28 Jul 2013 22:30:56 +0000 (00:30 +0200)] 
src: Add icmpv6 support

This patch adds ICMPv6 support to nftables. It is now possible to
write rules such as:

  nft add rule ip6 filter input icmpv6 type nd-router-advert accept

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodatatype: fix crash if wrong integer type is passed
Pablo Neira Ayuso [Wed, 24 Jul 2013 13:14:22 +0000 (15:14 +0200)] 
datatype: fix crash if wrong integer type is passed

Eric Leblond reported that this command:

nft add rule ip6 filter input position 4 meta protocol icmpv6 accept

crashes nft. The problem is that 'icmpv6' is wrong there, as
meta protocol is expecting an ethernet protocol, that can be
expressed as an hexadecimal.

Now this command displays the following error:

<cmdline>:1:52-57: Error: This is not a valid Ethernet protocol
add rule ip6 filter input position 4 meta protocol icmpv6 accept
                                                   ^^^^^^

This closes bugzilla #834:
https://bugzilla.netfilter.org/show_bug.cgi?id=834

Reported-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: Add support for insertion inside rule list
Eric Leblond [Sat, 6 Jul 2013 15:33:57 +0000 (17:33 +0200)] 
src: Add support for insertion inside rule list

This patch adds support to insert and to add rule using a rule
handle as reference. The rule handle syntax has an new optional
position field which take a handle as argument.

Two examples:

  nft add rule filter output position 5 ip daddr 1.2.3.1 drop
  nft insert rule filter output position 5 ip daddr 1.2.3.1 drop

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agomnl: use nft_*_list_add_tail
Pablo Neira Ayuso [Tue, 16 Jul 2013 20:35:07 +0000 (22:35 +0200)] 
mnl: use nft_*_list_add_tail

Adapt it to the semantic fix that has been applied to libnftables,
nft_*_list_add now inserts nodes, instead of appending them.

Signed-off-by: Pablo Neira Ayuso <pablo@soleta.eu>
12 years agodatatype: fix table listing if name resolution is not available
Pablo Neira Ayuso [Sat, 6 Jul 2013 14:38:18 +0000 (16:38 +0200)] 
datatype: fix table listing if name resolution is not available

nft list table filter returns garbage here for IP and IPv6 addresses if
no name resolution is available. The output looks good if `-n' is used
in that case.

The problem is that getnameinfo() returns:

EAI_AGAIN   -3    /* Temporary failure in name resolution.  */

Without working name resolution. To fix this, force a fall back to
numeric resolution in that case.

While at it, fix also possible resolution of services in case of
that /etc/services is missing in the system.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agonetlink: fix network address prefix
Pablo Neira Ayuso [Sat, 22 Jun 2013 17:12:24 +0000 (19:12 +0200)] 
netlink: fix network address prefix

eg. nft add rule filter output ip daddr 192.168.1.0/24 counter

so far, this operation was only possible using sets.

nft add rule filter output ip daddr \{ 192.168.1.0/24 \} counter

While at it, move all binop postprocess code to a new function that
contains this transformation and the existing bitmask to constant
(as used by eg. ct state new,established).

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: use libnftables
Pablo Neira Ayuso [Thu, 13 Jun 2013 14:38:33 +0000 (16:38 +0200)] 
src: use libnftables

This patch migrates nft to use the libnftables library, that is used
by the iptables over nftables compat utility as well. Most of the
conversion was pretty straight forward. Some small significant changes
happened in the handling of set element and immediate data abstraction
that libnl provides. libnftables is a bit more granular since it splits
the struct nfnl_nft_data into three attributes: verdict, chain and plain
data (used in maps).

I have added a new file src/mnl.c that contains the low level netlink
communication that now resides in nftables source tree instead of
the library. This should help to implement the batching support using
libmnl in follow up patches.

I also spent some significant amount of time running my tests to make
sure that we don't increase the number of bugs that we already have
(I plan to provide a list of those that I have detected and diagnosed,
so anyone else can help us to fix them).

As a side effect, this change should also prepare the ground for
JSON and XML support anytime soon.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agometa: replace rtnl_tc_handle2str and rtnl_tc_str2handle
Pablo Neira Ayuso [Fri, 21 Jun 2013 13:27:11 +0000 (15:27 +0200)] 
meta: replace rtnl_tc_handle2str and rtnl_tc_str2handle

Provide replacements for rtnl_tc_handle2str and rtnl_tc_str2handle,
it removes the dependency with libnl-route.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agometa: use if_nametoindex and if_indextoname
Pablo Neira Ayuso [Sun, 16 Jun 2013 22:43:43 +0000 (00:43 +0200)] 
meta: use if_nametoindex and if_indextoname

Instead of having a cache of ifindex based on libnl. Those functions
basically use rtnetlink as well to perform the translation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: family field in struct handle is unsigned
Pablo Neira Ayuso [Mon, 17 Jun 2013 15:54:56 +0000 (17:54 +0200)] 
rule: family field in struct handle is unsigned

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: get it sync with current include/linux/netfilter/nf_tables.h
Pablo Neira Ayuso [Thu, 13 Jun 2013 15:25:57 +0000 (17:25 +0200)] 
src: get it sync with current include/linux/netfilter/nf_tables.h

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoevaluate: fix range and comparison evaluation
Pablo Neira Ayuso [Wed, 12 Jun 2013 17:36:52 +0000 (19:36 +0200)] 
evaluate: fix range and comparison evaluation

This patch fixes these two commands:

nft add rule ip test test ip saddr 1.1.1.1-2.2.2.2
nft add rule ip test test ip saddr < 1.1.1.1

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agosrc: fix counter restoration
Eric Leblond [Sat, 8 Jun 2013 23:08:47 +0000 (01:08 +0200)] 
src: fix counter restoration

It was not possible to restore a ruleset countaining counter. The
packets and bytes fields were not known from the parser but they
were in the output of the list command.

This patch fixes the issue by restoring correctly the counters if
they are present in the command.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agorule: display hook info
Eric Leblond [Sat, 8 Jun 2013 23:08:46 +0000 (01:08 +0200)] 
rule: display hook info

It was not possible to restore a ruleset because of missing
hook information. This patch adds hooknum output to list
operation.

[ Mangled this patch to use a string array mapping hook numbers
  and name --pablo ]

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agodatatype: concat expression only releases dynamically allocated datatype
Pablo Neira Ayuso [Thu, 6 Jun 2013 11:25:39 +0000 (13:25 +0200)] 
datatype: concat expression only releases dynamically allocated datatype

Eric Leblond reports a crash with the following invalid command:

 nft add rule global filter ip daddr . tcp dport { 192.168.0.1 . 22\; 192.168.0.3 . 89 } drop

Note that the semicolon is incorrect in that concatenation,
it should be a comma.

The backtrace shows:
(gdb) bt
 #0  0x00007ffff6f39295 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
 #1  0x00007ffff6f3c438 in __GI_abort () at abort.c:90
 #2  0x00007ffff6f7486b in __libc_message (do_abort=do_abort@entry=2, fmt=fmt@entry=0x7ffff7070d28 "*** Error in `%s': %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:199
 #3  0x00007ffff6f7eac6 in malloc_printerr (action=3, str=0x7ffff706ccca "free(): invalid pointer", ptr=<optimized out>) at malloc.c:4902
 #4  0x00007ffff6f7f843 in _int_free (av=<optimized out>, p=0x428530, have_lock=0) at malloc.c:3758
 #5  0x000000000041aae8 in xfree (ptr=0x428540 <invalid_type>) at src/utils.c:29
 #6  0x000000000040bc43 in concat_type_destroy (dtype=0x428540 <invalid_type>) at src/datatype.c:690
 #7  0x000000000040cebf in concat_expr_destroy (expr=0x643b90) at src/expression.c:571
[...]

It's trying to release 'invalid_type', which was not dynamically
allocated. Note that before the evaluation step, the invalid type
is attached to the expressions.

Since nftables allocates a dynamic datatype for concatenations in
case that needs to be released in the exit path. All datatypes
except this, are allocated in the BSS. Since we have no way to
differenciate between these two, add a flag so we can recognize
dynamically allocated datatypes.

While at it, rename dtype->type from enum to explicit uint32_t, as
it is used to store the concatenation type mask as well.

Reported-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agocli: reset terminal when CTRL+d is pressed
Eric Leblond [Sun, 2 Jun 2013 10:18:03 +0000 (12:18 +0200)] 
cli: reset terminal when CTRL+d is pressed

The terminal was not correctly resetted when CTRL+d was pressed.
The result was that reset has to be called from shell after exit.

12 years agocli: add quit command
Eric Leblond [Sun, 2 Jun 2013 10:03:13 +0000 (12:03 +0200)] 
cli: add quit command

12 years agorule: list elements in set in any case
Eric Leblond [Fri, 31 May 2013 08:50:32 +0000 (10:50 +0200)] 
rule: list elements in set in any case

"nft list table" command was not displaying the elements of named
set. This was thus not possible to restore a ruleset by using the
listing output. This patch modifies the code to display the elements
of set in all cases.

12 years agodoc: fix inversion of operator and object.
Eric Leblond [Thu, 30 May 2013 13:33:16 +0000 (15:33 +0200)] 
doc: fix inversion of operator and object.

12 years agorule: add flag to display rule handle as comment
Eric Leblond [Thu, 30 May 2013 04:22:46 +0000 (04:22 +0000)] 
rule: add flag to display rule handle as comment

Knowing the rule handle is necessary to be able to delete a single
rule. It was not displayed till now in the output and it was thus
impossible to remove a single rule.
This patch modify the listing output to add a comment containing
the handle when the -a/--handle flag is provided.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agocli: complete basic functionality of the interactive mode
Pablo Neira Ayuso [Tue, 14 May 2013 17:49:13 +0000 (19:49 +0200)] 
cli: complete basic functionality of the interactive mode

This patch adds missing code to get basic interactive mode
operative via `nft -i', including parsing, evaluation,
command execution via netlink and error reporting.

Autocomplete is not yet implemented.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
12 years agoparser: fix size of internet protocol expressions matching keywords
Patrick McHardy [Mon, 22 Apr 2013 23:08:26 +0000 (01:08 +0200)] 
parser: fix size of internet protocol expressions matching keywords

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoparser: include leading '.' in concat subexpression location
Patrick McHardy [Mon, 22 Apr 2013 17:58:54 +0000 (19:58 +0200)] 
parser: include leading '.' in concat subexpression location

Make error messages point to the entire subexpression.

Before:

filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh}
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^

After:

filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh}
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>
12 years agoexpr: catch missing and excess elements in concatenations
Patrick McHardy [Mon, 22 Apr 2013 16:50:44 +0000 (18:50 +0200)] 
expr: catch missing and excess elements in concatenations

# nft -nn filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh }
<cmdline>:1:50-66: Error: datatype mismatch, expected concatenation of (IPv4 address, internet network service, internet network service), expression has type concatenation of (IPv4 address, internet network service)
filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh }
                                                 ^^^^^^^^^^^^^^^^^

# nft -nn filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh}
<cmdline>:1:76-78: Error: unexpected concat component, expecting concatenation of (IPv4 address, internet network service, internet network service)
filter output ip daddr . tcp dport . tcp dport { 192.168.0.1 . ssh . ssh . ssh}
                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^

Signed-off-by: Patrick McHardy <kaber@trash.net>