]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
5 years agomain: use one data-structure to initialize getopt_long(3) arguments and help.
Jeremy Sowden [Thu, 5 Mar 2020 14:48:05 +0000 (14:48 +0000)] 
main: use one data-structure to initialize getopt_long(3) arguments and help.

By generating the getopt_long(3) optstring and options, and the help
from one source, we reduce the chance that they may get out of sync.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomain: interpolate default include path into help format-string.
Jeremy Sowden [Thu, 5 Mar 2020 14:48:04 +0000 (14:48 +0000)] 
main: interpolate default include path into help format-string.

The default include path is a string literal defined as a preprocessor
macro by autoconf.  We can just interpolate it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomain: include '--reversedns' in help.
Jeremy Sowden [Thu, 5 Mar 2020 14:48:03 +0000 (14:48 +0000)] 
main: include '--reversedns' in help.

The long option for '-N' was omitted from the help.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomain: include '-d' in help.
Jeremy Sowden [Thu, 5 Mar 2020 14:48:02 +0000 (14:48 +0000)] 
main: include '-d' in help.

The short option for '--debug' was omitted from the help.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoparser_bison: fix rshift statement expression.
Jeremy Sowden [Mon, 9 Mar 2020 11:07:47 +0000 (11:07 +0000)] 
parser_bison: fix rshift statement expression.

The RHS of RSHIFT statement expressions should be primary_stmt_expr, not
primary_rhs_expr.

Fixes: dccab4f646b4 ("parser_bison: consolidate stmt_expr rule")
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomain: remove duplicates from option string.
Jeremy Sowden [Wed, 4 Mar 2020 08:57:35 +0000 (08:57 +0000)] 
main: remove duplicates from option string.

The string of options passed to getopt_long(3) contains duplicates.
Update it to match the opt_vals enum which immediately precedes it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomain: add more information to `nft -V`.
Jeremy Sowden [Tue, 3 Mar 2020 23:15:30 +0000 (00:15 +0100)] 
main: add more information to `nft -V`.

In addition to the package-version and release-name, output the CLI
implementation (if any) and whether mini-gmp was used, e.g.:

    $ ./src/nft -V
    nftables v0.9.3 (Topsy)
      cli:          linenoise
      json:         yes
      minigmp:      no
      libxtables:   yes

[pablo@netfilter.org: add json and libxtables, use -V ]

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: fix leaks.
Jeremy Sowden [Tue, 3 Mar 2020 09:48:33 +0000 (09:48 +0000)] 
src: fix leaks.

Some bitmask variables are not cleared.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agonetlink_delinearize: set shift RHS byte-order.
Jeremy Sowden [Tue, 3 Mar 2020 09:48:32 +0000 (09:48 +0000)] 
netlink_delinearize: set shift RHS byte-order.

The RHS operand for bitwise shift is in HBO.  Set this explicitly.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoevaluate: no need to swap byte-order for values of fewer than 16 bits.
Jeremy Sowden [Tue, 3 Mar 2020 09:48:31 +0000 (09:48 +0000)] 
evaluate: no need to swap byte-order for values of fewer than 16 bits.

Endianness is not meaningful for objects smaller than 2 bytes and the
byte-order conversions are no-ops in the kernel, so just update the
expression as if it were constant.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoevaluate: convert the byte-order of payload statement arguments.
Jeremy Sowden [Tue, 3 Mar 2020 09:48:30 +0000 (09:48 +0000)] 
evaluate: convert the byte-order of payload statement arguments.

Since shift operations require host byte-order, we need to be able to
convert the result of the shift back to network byte-order, in a rule
like:

  nft add rule ip t c tcp dport set tcp dport lshift 1

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoevaluate: don't evaluate payloads twice.
Jeremy Sowden [Tue, 3 Mar 2020 09:48:29 +0000 (09:48 +0000)] 
evaluate: don't evaluate payloads twice.

Payload munging means that evaluation of payload expressions may not be
idempotent.  Add a flag to prevent them from being evaluated more than
once.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoevaluate: simplify calculation of payload size.
Jeremy Sowden [Tue, 3 Mar 2020 09:48:28 +0000 (09:48 +0000)] 
evaluate: simplify calculation of payload size.

Use div_round_up and one statement.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoevaluate: add separate variables for lshift and xor binops.
Jeremy Sowden [Tue, 3 Mar 2020 09:48:27 +0000 (09:48 +0000)] 
evaluate: add separate variables for lshift and xor binops.

stmt_evaluate_payload has distinct variables for some, but not all, the
binop expressions it creates.  Add variables for the rest.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agosrc: support for offload chain flag
Pablo Neira Ayuso [Tue, 3 Mar 2020 12:14:59 +0000 (13:14 +0100)] 
src: support for offload chain flag

This patch extends the basechain definition to allow users to specify
the offload flag. This flag enables hardware offload if your drivers
supports it.

 # cat file.nft
 table netdev x {
    chain y {
       type filter hook ingress device eth0 priority 10; flags offload;
    }
 }
 # nft -f file.nft

Note: You have to enable offload via ethtool:

 # ethtool -K eth0 hw-tc-offload on

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: update nat_addr_port with typeof+concat maps
Florian Westphal [Wed, 26 Feb 2020 12:15:54 +0000 (13:15 +0100)] 
tests: update nat_addr_port with typeof+concat maps

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoexpressions: concat: add typeof support
Florian Westphal [Sat, 22 Feb 2020 21:02:49 +0000 (22:02 +0100)] 
expressions: concat: add typeof support

Previous patches allow to pass concatenations as the mapped-to
data type.

This doesn't work with typeof() because the concat expression has
no support to store the typeof data in the kernel, leading to:

map t2 {
    typeof numgen inc mod 2 : ip daddr . tcp dport

being shown as
     type 0 : ipv4_addr . inet_service

... which can't be parsed back by nft.

This allows the concat expression to store the sub-expressions
in set of nested attributes.

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoevaluate: stmt_evaluate_nat_map() only if stmt->nat.ipportmap == true
Pablo Neira Ayuso [Tue, 25 Feb 2020 09:28:13 +0000 (10:28 +0100)] 
evaluate: stmt_evaluate_nat_map() only if stmt->nat.ipportmap == true

stmt_evaluate_nat_map() is only called when the parser sets on
stmt->nat.ipportmap.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: shell: adjust tests to new nat concatenation syntax
Pablo Neira Ayuso [Mon, 24 Feb 2020 12:52:50 +0000 (13:52 +0100)] 
tests: shell: adjust tests to new nat concatenation syntax

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: nat concatenation support with anonymous maps
Pablo Neira Ayuso [Mon, 24 Feb 2020 12:28:34 +0000 (13:28 +0100)] 
src: nat concatenation support with anonymous maps

This patch extends the parser to define the mapping datatypes, eg.

  ... dnat ip addr . port to ip saddr map { 1.1.1.1 : 2.2.2.2 . 30 }
  ... dnat ip addr . port to ip saddr map @y

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: nat: add and use maps with both address and service
Florian Westphal [Mon, 24 Feb 2020 00:03:24 +0000 (01:03 +0100)] 
tests: nat: add and use maps with both address and service

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: allow nat maps containing both ip(6) address and port
Florian Westphal [Mon, 24 Feb 2020 00:03:23 +0000 (01:03 +0100)] 
src: allow nat maps containing both ip(6) address and port

nft will now be able to handle
map destinations {
type ipv4_addr . inet_service : ipv4_addr . inet_service
}

chain f {
dnat to ip daddr . tcp dport map @destinations
}

Something like this won't work though:
 meta l4proto tcp dnat ip6 to numgen inc mod 4 map { 0 : dead::f001 . 8080, ..

as we lack the type info to properly dissect "dead::f001" as an ipv6
address.

For the named map case, this info is available in the map
definition, but for the anon case we'd need to resort to guesswork.

Support is added by peeking into the map definition when evaluating
a nat statement with a map.
Right now, when a map is provided as address, we will only check that
the mapped-to data type matches the expected size (of an ipv4 or ipv6
address).

After this patch, if the mapped-to type is a concatenation, it will
take a peek at the individual concat expressions.  If its a combination
of address and service, nft will translate this so that the kernel nat
expression looks at the returned register that would store the
inet_service part of the octet soup returned from the lookup expression.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoevaluate: add two new helpers
Florian Westphal [Mon, 24 Feb 2020 00:03:22 +0000 (01:03 +0100)] 
evaluate: add two new helpers

In order to support 'dnat to ip saddr map @foo', where @foo returns
both an address and a inet_service, we will need to peek into the map
and process the concatenations sub-expressions.

Add two helpers for this, will be used in followup patches.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agonetlink: handle concatenations on set elements mappings
Florian Westphal [Mon, 24 Feb 2020 00:03:21 +0000 (01:03 +0100)] 
netlink: handle concatenations on set elements mappings

We can already handle concatenated keys, this extends concat
coverage to the data type as well, i.e. this can be dissected:

type ipv4_addr : ipv4_addr . inet_service

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoevaluate: process concat expressions when used as mapped-to expr
Florian Westphal [Mon, 24 Feb 2020 00:03:20 +0000 (01:03 +0100)] 
evaluate: process concat expressions when used as mapped-to expr

Needed to avoid triggering the 'dtype->size == 0' tests.
Evaluation will build a new concatenated type that holds the
size of the aggregate.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: add initial nat map test
Florian Westphal [Mon, 24 Feb 2020 00:03:19 +0000 (01:03 +0100)] 
tests: add initial nat map test

Will be extended to cover upcoming
'dnat to ip saddr . tcp dport map { \
  1.2.3.4 . 80 : 5.6.7.8 : 8080,
  2.2.3.4 . 80 : 7.6.7.8 : 1234,
   ...

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoexpression: use common code for expr_ops/expr_ops_by_type
Florian Westphal [Sat, 22 Feb 2020 21:12:02 +0000 (22:12 +0100)] 
expression: use common code for expr_ops/expr_ops_by_type

Useless duplication.  Also, this avoids bloating expr_ops_by_type()
when it needs to cope with more expressions.

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agotests: shell: avoid spurious failure when running in host namespace
Florian Westphal [Sat, 22 Feb 2020 08:46:40 +0000 (09:46 +0100)] 
tests: shell: avoid spurious failure when running in host namespace

Dump validation may fail:
- tcp dport { 22, 23 } counter packets 0 bytes 0
+ tcp dport { 22, 23 } counter packets 9 bytes 3400

... which is normal on host namespace.

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agotests: 0034get_element_0: do not discard stderr
Florian Westphal [Fri, 21 Feb 2020 23:02:25 +0000 (00:02 +0100)] 
tests: 0034get_element_0: do not discard stderr

run_tests.sh alreadty discards stderr by default, but will show it in
case the test script is run directly (passed as argument).

Discarding stderr also in the script prevents one from seeing
BUG() assertions and the like.

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoevaluate: print correct statement name on family mismatch
Florian Westphal [Thu, 20 Feb 2020 11:58:40 +0000 (12:58 +0100)] 
evaluate: print correct statement name on family mismatch

nft add rule inet filter c ip daddr 1.2.3.4 dnat ip6 to f00::1
Error: conflicting protocols specified: ip vs. unknown. You must specify ip or ip6 family in tproxy statement

Should be: ... "in nat statement".

Fixes: fbe27464dee4588d90 ("src: add nat support for the inet family")
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agomnl: do not use expr->identifier to fetch device name
Pablo Neira Ayuso [Wed, 19 Feb 2020 20:05:26 +0000 (21:05 +0100)] 
mnl: do not use expr->identifier to fetch device name

This string might not be nul-terminated, resulting in spurious errors
when adding netdev chains.

Fixes: 3fdc7541fba0 ("src: add multidevice support for netdev chain")
Fixes: 92911b362e90 ("src: add support to add flowtables")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoparser_bison: memleak in device parser
Pablo Neira Ayuso [Wed, 19 Feb 2020 19:56:42 +0000 (20:56 +0100)] 
parser_bison: memleak in device parser

==1135425== 9 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1135425==    at 0x483577F: malloc (vg_replace_malloc.c:309)
==1135425==    by 0x4BE846A: strdup (strdup.c:42)
==1135425==    by 0x48A5EDD: xstrdup (utils.c:75)
==1135425==    by 0x48C9A20: nft_lex (scanner.l:640)
==1135425==    by 0x48BC1A4: nft_parse (parser_bison.c:5682)
==1135425==    by 0x48AC336: nft_parse_bison_buffer (libnftables.c:375)
==1135425==    by 0x48AC336: nft_run_cmd_from_buffer (libnftables.c:443)
==1135425==    by 0x10A707: main (main.c:384)

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: Introduce test for set with concatenated ranges
Stefano Brivio [Fri, 14 Feb 2020 15:27:25 +0000 (16:27 +0100)] 
tests: Introduce test for set with concatenated ranges

This test checks that set elements can be added, deleted, that
addition and deletion are refused when appropriate, that entries
time out properly, and that they can be fetched by matching values
in the given ranges.

v5:
 - speed this up by performing the timeout test for one single
   permutation (Phil Sutter), by decreasing the number of
   permutations from 96 to 12 if this is invoked by run-tests.sh
   (Pablo Neira Ayuso) and by combining some commands into single
   nft calls where possible: with dash 0.5.8 on AMD Epyc 7351 the
   test now takes 1.8s instead of 82.5s
 - renumber test to 0043, 0042 was added meanwhile
v4: No changes
v3:
 - renumber test to 0042, 0041 was added meanwhile
v2:
 - actually check an IPv6 prefix, instead of specifying everything
   as explicit ranges in ELEMS_ipv6_addr
 - renumber test to 0041, 0038 already exists

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: improve error reporting when remove rules
Pablo Neira Ayuso [Wed, 19 Feb 2020 14:35:10 +0000 (15:35 +0100)] 
src: improve error reporting when remove rules

 # nft delete rule ip y z handle 7
 Error: Could not process rule: No such file or directory
 delete rule ip y z handle 7
                ^

 # nft delete rule ip x z handle 7
 Error: Could not process rule: No such file or directory
 delete rule ip x z handle 7
                  ^

 # nft delete rule ip x x handle 7
 Error: Could not process rule: No such file or directory
 delete rule ip x x handle 7
                           ^

 # nft replace rule x y handle 10 ip saddr 1.1.1.2 counter
 Error: Could not process rule: No such file or directory
 replace rule x y handle 10 ip saddr 1.1.1.2 counter
                         ^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: improve error reporting when setting policy on non-base chain
Pablo Neira Ayuso [Wed, 19 Feb 2020 13:57:26 +0000 (14:57 +0100)] 
src: improve error reporting when setting policy on non-base chain

When trying to set a policy to non-base chain:

 # nft add chain x y { policy accept\; }
 Error: Could not process rule: Operation not supported
 add chain x y { policy accept; }
                 ^^^^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomnl: extended error support for create command
Pablo Neira Ayuso [Wed, 19 Feb 2020 13:35:21 +0000 (14:35 +0100)] 
mnl: extended error support for create command

 # nft create table x
 Error: Could not process rule: File exists
 create table x
              ^

 # nft create chain x y
 Error: Could not process rule: File exists
 create chain x y
                ^

 # nft create set x y { typeof ip saddr\; }
 Error: Could not process rule: File exists
 create set x y { typeof ip saddr; }
              ^

 # nft create counter x y
 Error: Could not process rule: File exists
 create counter x y
                  ^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: combine extended netlink error reporting with mispelling support
Pablo Neira Ayuso [Tue, 18 Feb 2020 11:59:24 +0000 (12:59 +0100)] 
src: combine extended netlink error reporting with mispelling support

Preliminary support: only for the deletion command, e.g.

 # nft delete table twst
 Error: No such file or directory; did you mean table â€˜test’ in family ip?
 delete table twst
              ^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: initial extended netlink error reporting
Pablo Neira Ayuso [Mon, 17 Feb 2020 21:38:13 +0000 (22:38 +0100)] 
src: initial extended netlink error reporting

This patch correlates the in-kernel extended netlink error offset and
the location information.

Assuming 'foo' table does not exist, then error reporting shows:

 # nft delete table foo
 Error: Could not process rule: No such file or directory
 delete table foo
              ^^^

Similarly, if table uniquely identified by handle '1234' does not exist,
then error reporting shows:

 # nft delete table handle 1234
 Error: Could not process rule: No such file or directory
 delete table handle 1234
                     ^^^^

 Assuming 'bar' chain does not exists in the kernel, while 'foo' does:

 # nft delete chain foo bar
 Error: Could not process rule: No such file or directory
 delete chain foo bar
                  ^^^

 This also gives us a hint when adding rules:

 # nft add rule ip foo bar counter
 Error: Could not process rule: No such file or directory
 add rule ip foo bar counter
             ^^^

This is based on ("src: basic support for extended netlink errors") from
Florian Westphal, posted in 2018, with no netlink offset correlation
support.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoparser: incorrect handle location
Pablo Neira Ayuso [Mon, 17 Feb 2020 21:37:29 +0000 (22:37 +0100)] 
parser: incorrect handle location

Handle location is not correct, this leads to misleading error
reporting.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoscanner: use list_is_first() from scanner_pop_indesc()
Pablo Neira Ayuso [Thu, 13 Feb 2020 12:27:18 +0000 (13:27 +0100)] 
scanner: use list_is_first() from scanner_pop_indesc()

!list_empty() always stands true since the list is never empty
when calling scanner_pop_indesc().

Check for list_is_first() which actually tells us this is the
initial input file, hence, state->indesc is set to NULL.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: maps: update data expression dtype based on set
Florian Westphal [Thu, 13 Feb 2020 11:45:55 +0000 (12:45 +0100)] 
src: maps: update data expression dtype based on set

What we want:
-               update @sticky-set-svc-M53CN2XYVUHRQ7UB { ip saddr : 0x00000002 }
what we got:
+               update @sticky-set-svc-M53CN2XYVUHRQ7UB { ip saddr : 0x2000000 [invalid type] }

Reported-by: Serguei Bezverkhi <sbezverk@gmail.com>
Close: https://bugzilla.netfilter.org/show_bug.cgi?id=1405
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agotests: shell: validate error reporting with include and glob
Pablo Neira Ayuso [Thu, 13 Feb 2020 11:13:11 +0000 (12:13 +0100)] 
tests: shell: validate error reporting with include and glob

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: shell: add test for glob includes
Laurent Fasnacht [Mon, 10 Feb 2020 10:17:20 +0000 (10:17 +0000)] 
tests: shell: add test for glob includes

Including more than MAX_INCLUDE_DEPTH file in one statement should succeed.

This reproduces bug #1243.

Signed-off-by: Laurent Fasnacht <fasnacht@protonmail.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoscanner: remove parser_state->indesc_idx
Laurent Fasnacht [Mon, 10 Feb 2020 10:17:28 +0000 (10:17 +0000)] 
scanner: remove parser_state->indesc_idx

Now that we have a proper stack implementation, we don't need an
additional counter for the number of buffer state pushed.

Signed-off-by: Laurent Fasnacht <fasnacht@protonmail.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoscanner: fix indesc_list stack to be in the correct order
Laurent Fasnacht [Mon, 10 Feb 2020 10:17:27 +0000 (10:17 +0000)] 
scanner: fix indesc_list stack to be in the correct order

This fixes the location displayed in error messages.

Signed-off-by: Laurent Fasnacht <fasnacht@protonmail.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoInclusion depth was computed incorrectly for glob includes.
Laurent Fasnacht [Mon, 10 Feb 2020 10:17:35 +0000 (05:17 -0500)] 
Inclusion depth was computed incorrectly for glob includes.

Signed-off-by: Laurent Fasnacht <fasnacht@protonmail.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoscanner: remove parser_state->indescs static array
Laurent Fasnacht [Mon, 10 Feb 2020 10:17:24 +0000 (10:17 +0000)] 
scanner: remove parser_state->indescs static array

This static array is redundant with the indesc_list structure, but
is less flexible.

Signed-off-by: Laurent Fasnacht <fasnacht@protonmail.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoscanner: move indesc list append in scanner_push_indesc
Laurent Fasnacht [Mon, 10 Feb 2020 10:17:22 +0000 (10:17 +0000)] 
scanner: move indesc list append in scanner_push_indesc

Having a single point makes refactoring easier.

Signed-off-by: Laurent Fasnacht <fasnacht@protonmail.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoscanner: move the file descriptor to be in the input_descriptor structure
Laurent Fasnacht [Mon, 10 Feb 2020 10:17:21 +0000 (10:17 +0000)] 
scanner: move the file descriptor to be in the input_descriptor structure

This prevents a static allocation of file descriptors array, thus allows
more flexibility.

Signed-off-by: Laurent Fasnacht <fasnacht@protonmail.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoscanner: Extend asteriskstring definition
Phil Sutter [Thu, 6 Feb 2020 11:31:56 +0000 (12:31 +0100)] 
scanner: Extend asteriskstring definition

Accept escaped asterisks also mid-string and as only character.
Especially the latter will help when translating from iptables where
asterisk has no special meaning.

Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agodoc: nft.8: Mention wildcard interface matching
Phil Sutter [Thu, 6 Feb 2020 11:24:51 +0000 (12:24 +0100)] 
doc: nft.8: Mention wildcard interface matching

Special meaning of asterisk in interface names wasn't described
anywhere.

Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agodoc: nft.8: Describe element commands in their own section
Phil Sutter [Thu, 6 Feb 2020 16:01:23 +0000 (17:01 +0100)] 
doc: nft.8: Describe element commands in their own section

This unifies the redundant information in sets and maps sections and
also covers 'get' command.

Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agosrc: compute mnemonic port name much easier
Jan Engelhardt [Fri, 7 Feb 2020 11:43:21 +0000 (12:43 +0100)] 
src: compute mnemonic port name much easier

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: py: add bit-shift tests.
Jeremy Sowden [Mon, 3 Feb 2020 11:20:23 +0000 (11:20 +0000)] 
tests: py: add bit-shift tests.

Add a couple of Python test-cases for setting the CT mark to a bitwise
expression derived from the packet mark and vice versa.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: py: add missing JSON output.
Jeremy Sowden [Mon, 3 Feb 2020 11:20:22 +0000 (11:20 +0000)] 
tests: py: add missing JSON output.

The JSON output was missing for some existing tests.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: shell: add bit-shift tests.
Jeremy Sowden [Mon, 3 Feb 2020 11:20:21 +0000 (11:20 +0000)] 
tests: shell: add bit-shift tests.

Add a couple of shell test-cases for setting the CT mark to a bitwise
expression derived from the packet mark and vice versa.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoevaluate: change shift byte-order to host-endian.
Jeremy Sowden [Mon, 3 Feb 2020 11:20:20 +0000 (11:20 +0000)] 
evaluate: change shift byte-order to host-endian.

The byte-order of the righthand operands of the right-shifts generated
for payload and exthdr expressions is big-endian.  However, all right
operands should be host-endian.  Since evaluation of the shift binop
will insert a byte-order conversion to enforce this, change the
endianness in order to avoid the extra operation.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoevaluate: correct variable name.
Jeremy Sowden [Mon, 3 Feb 2020 11:20:19 +0000 (11:20 +0000)] 
evaluate: correct variable name.

Rename the `lshift` variable used to store an right-shift expression to
`rshift`.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoparser: add parenthesized statement expressions.
Jeremy Sowden [Mon, 3 Feb 2020 11:20:18 +0000 (11:20 +0000)] 
parser: add parenthesized statement expressions.

Primary and primary RHS expressions support parenthesized basic and
basic RHS expressions.  However, primary statement expressions do not
support parenthesized basic statement expressions.  Add them.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: Add support for concatenated set ranges
Stefano Brivio [Thu, 30 Jan 2020 00:16:57 +0000 (01:16 +0100)] 
src: Add support for concatenated set ranges

After exporting field lengths via NFTNL_SET_DESC_CONCAT attributes,
we now need to adjust parsing of user input and generation of
netlink key data to complete support for concatenation of set
ranges.

Instead of using separate elements for start and end of a range,
denoting the end element by the NFT_SET_ELEM_INTERVAL_END flag,
as it's currently done for ranges without concatenation, we'll use
the new attribute NFTNL_SET_ELEM_KEY_END as suggested by Pablo. It
behaves in the same way as NFTNL_SET_ELEM_KEY, but it indicates
that the included key represents the upper bound of a range.

For example, "packets with an IPv4 address between 192.0.2.0 and
192.0.2.42, with destination port between 22 and 25", needs to be
expressed as a single element with two keys:

  NFTA_SET_ELEM_KEY: 192.0.2.0 . 22
  NFTA_SET_ELEM_KEY_END: 192.0.2.42 . 25

To achieve this, we need to:

- adjust the lexer rules to allow multiton expressions as elements
  of a concatenation. As wildcards are not allowed (semantics would
  be ambiguous), exclude wildcards expressions from the set of
  possible multiton expressions, and allow them directly where
  needed. Concatenations now admit prefixes and ranges

- generate, for each element in a range concatenation, a second key
  attribute, that includes the upper bound for the range

- also expand prefixes and non-ranged values in the concatenation
  to ranges: given a set with interval and concatenation support,
  the kernel has no way to tell which elements are ranged, so they
  all need to be. For example, 192.0.2.0 . 192.0.2.9 : 1024 is
  sent as:

  NFTA_SET_ELEM_KEY: 192.0.2.0 . 1024
  NFTA_SET_ELEM_KEY_END: 192.0.2.9 . 1024

- aggregate ranges when elements received by the kernel represent
  concatenated ranges, see concat_range_aggregate()

- perform a few minor adjustments where interval expressions
  are already handled: we have intervals in these sets, but
  the set specification isn't just an interval, so we can't
  just aggregate and deaggregate interval ranges linearly

v4: No changes
v3:
 - rework to use a separate key for closing element of range instead of
   a separate element with EXPR_F_INTERVAL_END set (Pablo Neira Ayuso)
v2:
 - reworked netlink_gen_concat_data(), moved loop body to a new function,
   netlink_gen_concat_data_expr() (Phil Sutter)
 - dropped repeated pattern in bison file, replaced by a new helper,
   compound_expr_alloc_or_add() (Phil Sutter)
 - added set_is_nonconcat_range() helper (Phil Sutter)
 - in expr_evaluate_set(), we need to set NFT_SET_SUBKEY also on empty
   sets where the set in the context already has the flag
 - dropped additional 'end' parameter from netlink_gen_data(),
   temporarily set EXPR_F_INTERVAL_END on expressions and use that from
   netlink_gen_concat_data() to figure out we need to add the 'end'
   element (Phil Sutter)
 - replace range_mask_len() by a simplified version, as we don't need
   to actually store the composing masks of a range (Phil Sutter)

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: Add support for NFTNL_SET_DESC_CONCAT
Stefano Brivio [Thu, 30 Jan 2020 00:16:56 +0000 (01:16 +0100)] 
src: Add support for NFTNL_SET_DESC_CONCAT

To support arbitrary range concatenations, the kernel needs to know
how long each field in the concatenation is. The new libnftnl
NFTNL_SET_DESC_CONCAT set attribute describes this as an array of
lengths, in bytes, of concatenated fields.

While evaluating concatenated expressions, export the datatype size
into the new field_len array, and hand the data over via libnftnl.

Similarly, when data is passed back from libnftnl, parse it into
the set description.

When set data is cloned, we now need to copy the additional fields
in set_clone(), too.

This change depends on the libnftnl patch with title:
  set: Add support for NFTA_SET_DESC_CONCAT attributes

v4: No changes
v3: Rework to use set description data instead of a stand-alone
    attribute
v2: No changes

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoinclude: resync nf_tables.h cache copy
Stefano Brivio [Thu, 30 Jan 2020 00:16:55 +0000 (01:16 +0100)] 
include: resync nf_tables.h cache copy

Get this header in sync with nf-next as of merge commit
b3a608222336 (5.6-rc1-ish).

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: py: Support testing host binaries
Phil Sutter [Thu, 6 Feb 2020 00:36:01 +0000 (01:36 +0100)] 
tests: py: Support testing host binaries

Support -H/--host option to use host's libnftables.so.1. Alternatively
users may specify a custom library path via -l/--library option.

Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agotests: monitor: Support testing host's nft binary
Phil Sutter [Wed, 5 Feb 2020 18:48:53 +0000 (19:48 +0100)] 
tests: monitor: Support testing host's nft binary

Add support for -H/--host flag to use 'nft' tool from $PATH instead of
the local one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agotests: json_echo: Support testing host binaries
Phil Sutter [Fri, 10 Jan 2020 10:19:42 +0000 (11:19 +0100)] 
tests: json_echo: Support testing host binaries

Support -H/--host option to use host's libnftables.so.1. Alternatively
users may specify a custom library path via -l/--library option.

Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agotests: json_echo: Fix for Python3
Phil Sutter [Thu, 6 Feb 2020 00:21:30 +0000 (01:21 +0100)] 
tests: json_echo: Fix for Python3

The keys() method returns an object which does not support indexing, so
convert it to a list prior to doing so.

Fixes: a35e3a0cdc63a ("tests: json_echo: convert to py3")
Signed-off-by: Phil Sutter <phil@nwl.cc>
5 years agonetlink: add support for handling shift expressions.
Jeremy Sowden [Sun, 19 Jan 2020 22:57:09 +0000 (22:57 +0000)] 
netlink: add support for handling shift expressions.

The kernel supports bitwise shift operations, so add support to the
netlink linearization and delinearization code.  The number of bits (the
righthand operand) is expected to be a 32-bit value in host endianness.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoinclude: update nf_tables.h.
Jeremy Sowden [Sun, 19 Jan 2020 22:57:08 +0000 (22:57 +0000)] 
include: update nf_tables.h.

The kernel UAPI header includes a couple of new bitwise netlink
attributes and an enum.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agonetlink_delinearize: remove commented out pr_debug statement.
Jeremy Sowden [Sun, 19 Jan 2020 22:57:05 +0000 (22:57 +0000)] 
netlink_delinearize: remove commented out pr_debug statement.

The statement doesn't compile, so remove it.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agonetlink_delinearize: fix typo.
Jeremy Sowden [Sun, 19 Jan 2020 22:57:04 +0000 (22:57 +0000)] 
netlink_delinearize: fix typo.

s/Of/If/ in comment describing function.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agosrc: white-space fixes.
Jeremy Sowden [Sun, 19 Jan 2020 22:57:03 +0000 (22:57 +0000)] 
src: white-space fixes.

Remove some trailing white-space and fix some indentation.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoUpdate gitignore.
Jeremy Sowden [Sun, 19 Jan 2020 22:57:02 +0000 (22:57 +0000)] 
Update gitignore.

Add ctags and etags tag files, and Emacs back-up files.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoinclude: nf_tables: correct bitwise header comment.
Jeremy Sowden [Sun, 19 Jan 2020 10:58:01 +0000 (10:58 +0000)] 
include: nf_tables: correct bitwise header comment.

The comment documenting how bitwise expressions work includes a table
which summarizes the mask and xor arguments combined to express the
supported boolean operations.  However, the row for OR:

 mask    xor
 0       x

is incorrect.

  dreg = (sreg & 0) ^ x

is not equivalent to:

  dreg = sreg | x

What the code actually does is:

  dreg = (sreg & ~x) ^ x

Update the documentation to match.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: shell: update list of rmmod modules
Pablo Neira Ayuso [Wed, 22 Jan 2020 21:44:32 +0000 (22:44 +0100)] 
tests: shell: update list of rmmod modules

* Missing nft_fib_inet.
* nft_chain_nat_ipv4 and nft_chain_nat_ipv6 became nft_chain_nat.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: shell: set lookup and set update
Pablo Neira Ayuso [Wed, 22 Jan 2020 21:38:56 +0000 (22:38 +0100)] 
tests: shell: set lookup and set update

A simple test to cover set lookup and update in one rule.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agonetlink: Avoid potential NULL-pointer deref in netlink_gen_payload_stmt()
Phil Sutter [Mon, 20 Jan 2020 15:32:40 +0000 (16:32 +0100)] 
netlink: Avoid potential NULL-pointer deref in netlink_gen_payload_stmt()

With payload_needs_l4csum_update_pseudohdr() unconditionally
dereferencing passed 'desc' parameter and a previous check for it to be
non-NULL, make sure to call the function only if input is sane.

Fixes: 68de70f2b3fc6 ("netlink_linearize: fix IPv6 layer 4 checksum mangling")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agonetlink: Fix leaks in netlink_parse_cmp()
Phil Sutter [Mon, 20 Jan 2020 13:48:26 +0000 (14:48 +0100)] 
netlink: Fix leaks in netlink_parse_cmp()

This fixes several problems at once:

* Err path would leak expr 'right' in two places and 'left' in one.
* Concat case would leak 'right' by overwriting the pointer. Introduce a
  temporary variable to hold the new pointer.

Fixes: 6377380bc265f ("netlink_delinearize: handle relational and lookup concat expressions")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agonetlink: Fix leak in unterminated string deserializer
Phil Sutter [Mon, 20 Jan 2020 12:52:10 +0000 (13:52 +0100)] 
netlink: Fix leak in unterminated string deserializer

Allocated 'mask' expression is not freed before returning to caller,
although it is used temporarily only.

Fixes: b851ba4731d9f ("src: add interface wildcard matching")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoevaluate: better error notice when interval flag is not set on
Pablo Neira Ayuso [Fri, 10 Jan 2020 10:53:22 +0000 (11:53 +0100)] 
evaluate: better error notice when interval flag is not set on

Users get confused with the existing error notice, let's try a different one:

 # nft add element x y { 1.1.1.0/24 }
 Error: You must add 'flags interval' to your set declaration if you want to add prefix elements
 add element x y { 1.1.1.0/24 }
                   ^^^^^^^^^^

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1380
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Phil Sutter <phil@nwl.cc>
5 years agocache: Fix for doubled output after reset command
Phil Sutter [Tue, 14 Jan 2020 16:25:35 +0000 (17:25 +0100)] 
cache: Fix for doubled output after reset command

Reset command causes a dump of the objects to reset and adds those to
cache. Yet it ignored if the object in question was already there and up
to now CMD_RESET was flagged as NFT_CACHE_FULL.

Tackle this from two angles: First, reduce cache requirements of reset
command to the necessary bits which is table cache. This alone would
suffice if there wasn't interactive mode (and other libnftables users):
A cache containing the objects to reset might be in place already, so
add dumped objects to cache only if they don't exist already.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: shell: Search diff tool once and for all
Phil Sutter [Tue, 14 Jan 2020 15:50:35 +0000 (16:50 +0100)] 
tests: shell: Search diff tool once and for all

Instead of calling 'which diff' over and over again, just detect the
tool's presence in run-tests.sh and pass $DIFF to each testcase just
like with nft binary.

Fall back to using 'true' command to avoid the need for any conditional
calling in test cases.

While being at it, unify potential diff calls so that a string
comparison in shell happens irrespective of diff presence.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoxfrm: spi is big-endian
Florian Westphal [Tue, 14 Jan 2020 12:37:28 +0000 (13:37 +0100)] 
xfrm: spi is big-endian

the kernel stores spi in a __be32, so fix up the byteorder annotation.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomonitor: Fix output for ranges in anonymous sets
Phil Sutter [Mon, 13 Jan 2020 13:53:24 +0000 (14:53 +0100)] 
monitor: Fix output for ranges in anonymous sets

Previous fix for named interval sets was simply wrong: Instead of
limiting decomposing to anonymous interval sets, it effectively disabled
it entirely.

Since code needs to check for both interval and anonymous bits
separately, introduce set_is_interval() helper to keep the code
readable.

Also extend test case to assert ranges in anonymous sets are correctly
printed by echo or monitor modes. Without this fix, range boundaries are
printed as individual set elements.

Fixes: 5d57fa3e99bb9 ("monitor: Do not decompose non-anonymous sets")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: monitor: Support running individual test cases
Phil Sutter [Fri, 10 Jan 2020 10:15:45 +0000 (11:15 +0100)] 
tests: monitor: Support running individual test cases

Recognize testcase paths on command line and limit testing on those
only.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomonitor: Fix for use after free when printing map elements
Phil Sutter [Thu, 9 Jan 2020 16:43:11 +0000 (17:43 +0100)] 
monitor: Fix for use after free when printing map elements

When populating the dummy set, 'data' field must be cloned just like
'key' field.

Fixes: 343a51702656a ("src: store expr, not dtype to track data in sets")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomonitor: Do not decompose non-anonymous sets
Phil Sutter [Thu, 9 Jan 2020 12:34:20 +0000 (13:34 +0100)] 
monitor: Do not decompose non-anonymous sets

They have been decomposed already, trying to do that again causes a
segfault. This is a similar fix as in commit 8ecb885589591 ("src:
restore --echo with anonymous sets").

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomain: restore --debug
Pablo Neira Ayuso [Thu, 9 Jan 2020 17:16:18 +0000 (18:16 +0100)] 
main: restore --debug

Broken since options are mandatory before commands.

Fixes: fb9cea50e8b3 ("main: enforce options before commands")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoevaluate: fix expr_set_context call for shift binops.
Jeremy Sowden [Mon, 6 Jan 2020 22:35:10 +0000 (22:35 +0000)] 
evaluate: fix expr_set_context call for shift binops.

expr_evaluate_binop calls expr_set_context for shift expressions to set
the context data-type to `integer`.  This clobbers the byte-order of the
context, resulting in unexpected conversions to NBO.  For example:

  $ sudo nft flush ruleset
  $ sudo nft add table t
  $ sudo nft add chain t c '{ type filter hook output priority mangle; }'
  $ sudo nft add rule t c oif lo tcp dport ssh ct mark set '0x10 | 0xe'
  $ sudo nft add rule t c oif lo tcp dport ssh ct mark set '0xf << 1'
  $ sudo nft list table t
  table ip t {
          chain c {
                  type filter hook output priority mangle; policy accept;
                  oif "lo" tcp dport 22 ct mark set 0x0000001e
                  oif "lo" tcp dport 22 ct mark set 0x1e000000
          }
  }

Replace it with a call to __expr_set_context and set the byteorder to
that of the left operand since this is the value being shifted.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agotests: shell: delete flowtable after flushing chain
Pablo Neira Ayuso [Fri, 3 Jan 2020 16:46:24 +0000 (17:46 +0100)] 
tests: shell: delete flowtable after flushing chain

This patch adds a test to cover delete flowtable after chain flush
including two rule references to the flowtable.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agoscanner: incorrect error reporting after file inclusion
Pablo Neira Ayuso [Thu, 2 Jan 2020 15:37:31 +0000 (16:37 +0100)] 
scanner: incorrect error reporting after file inclusion

scanner_pop_buffer() incorrectly sets the current input descriptor. The
state->indesc_idx field actually stores the number of input descriptors
in the stack, decrement it and then update the current input descriptor
accordingly.

Fixes: 60e917fa7cb5 ("src: dynamic input_descriptor allocation")
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1383
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agometa: add slave device matching
Florian Westphal [Wed, 18 Dec 2019 11:10:41 +0000 (12:10 +0100)] 
meta: add slave device matching

Adds "meta sdif" and "meta sdifname".
Both only work in input/forward hook of ipv4/ipv6/inet family.

Cc: Martin Willi <martin@strongswan.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agodoc: Fix typo in IGMP section
Benjamin Poirier [Thu, 26 Dec 2019 00:08:37 +0000 (09:08 +0900)] 
doc: Fix typo in IGMP section

Signed-off-by: Benjamin Poirier <benjamin.poirier@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agomain: enforce options before commands
Pablo Neira Ayuso [Fri, 13 Dec 2019 10:32:46 +0000 (11:32 +0100)] 
main: enforce options before commands

This patch turns on POSIXLY_CORRECT on the getopt parser to enforce
options before commands. Users get a hint in such a case:

 # nft list ruleset -a
 Error: syntax error, options must be specified before commands
 nft list ruleset -a
    ^             ~~

This patch recovers 9fc71bc6b602 ("main: Fix for misleading error with
negative chain priority").

Tests have been updated.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
5 years agodoc: mention 'typeof' as alternative to 'type' keyword
Florian Westphal [Tue, 10 Dec 2019 14:42:48 +0000 (15:42 +0100)] 
doc: mention 'typeof' as alternative to 'type' keyword

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoevaluate: print a hint about 'typeof' syntax on 0 keylen
Florian Westphal [Tue, 10 Dec 2019 14:23:35 +0000 (15:23 +0100)] 
evaluate: print a hint about 'typeof' syntax on 0 keylen

If user says

'type integer; ...' in a set definition, don't just throw an error --
provide a hint that the typeof keyword can be used to provide
the needed size information.

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agotests: add typeof test cases
Florian Westphal [Fri, 16 Aug 2019 12:22:01 +0000 (14:22 +0200)] 
tests: add typeof test cases

Add sets using unspecific string/integer types, one with
osf name, other with vlan id.  Neither type can be used directly,
as they lack the type size information.

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agomnl: round up the map data size too
Florian Westphal [Tue, 10 Dec 2019 21:08:44 +0000 (22:08 +0100)] 
mnl: round up the map data size too

Same as key: if the size isn't divisible by BITS_PER_BYTE, we need to
round up, not down.

Without this, you can't store vlan ids in a map, as they are truncated
to 8 bit.

Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agoxfrm: add parse and build userdata interface
Pablo Neira Ayuso [Tue, 17 Dec 2019 17:17:02 +0000 (18:17 +0100)] 
xfrm: add parse and build userdata interface

Add support for meta userdata area.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agofib: add parse and build userdata interface
Pablo Neira Ayuso [Tue, 17 Dec 2019 17:17:01 +0000 (18:17 +0100)] 
fib: add parse and build userdata interface

Add support for meta userdata area.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
5 years agort: add parse and build userdata interface
Pablo Neira Ayuso [Tue, 17 Dec 2019 17:17:00 +0000 (18:17 +0100)] 
rt: add parse and build userdata interface

Add support for meta userdata area.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>