]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
7 years agonfnl_osf: display debugging information from --debug=mnl
Pablo Neira Ayuso [Fri, 31 Aug 2018 16:59:59 +0000 (18:59 +0200)] 
nfnl_osf: display debugging information from --debug=mnl

Otherwise this breaks tests/py/.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: missing dump for 0017ct_timeout_obj_0
Pablo Neira Ayuso [Fri, 31 Aug 2018 16:12:10 +0000 (18:12 +0200)] 
tests: shell: missing dump for 0017ct_timeout_obj_0

So we compare input and output are the same.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: osf: load pf.os from expr_evaluate_osf()
Fernando Fernandez Mancera [Thu, 30 Aug 2018 17:18:42 +0000 (19:18 +0200)] 
src: osf: load pf.os from expr_evaluate_osf()

Remove osf_init variable and call nfnl_osf_load_fingerprints() from
expr_evaluate_osf() instead of doing that from do_command_add() path.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: add tests for ct timeout objects
Harsha Sharma [Mon, 13 Aug 2018 19:39:28 +0000 (01:09 +0530)] 
tests: shell: add tests for ct timeout objects

Add tests for listing ct timeout objects and input from file.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: py: add ct timeout tests
Harsha Sharma [Mon, 13 Aug 2018 19:37:55 +0000 (01:07 +0530)] 
tests: py: add ct timeout tests

Add test for adding ct timeout objects and assigning it via rule.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add ct timeout support
Harsha Sharma [Mon, 13 Aug 2018 23:06:56 +0000 (01:06 +0200)] 
src: add ct timeout support

This patch adds support for adding, listing and deleting ct timeout
objects which can be assigned via rule to assign connection tracking
timeout policies via objref infrastructure.

 % nft add table filter
 % nft add chain filter output
 % nft add ct timeout filter test-tcp { protocol tcp \; policy = { established: 132, close: 13, close_wait: 17 } \; }
 % nft add rule filter output ct timeout set test-tcp
 % nft list ruleset

 table ip filter {
ct timeout test-tcp {
protocol tcp;
l3proto ip
policy = {established: 132, close_wait: 17, close: 13}
}

chain output {
ct timeout set "test-tcp"
}
 }

 % nft delete rule filter output handle <handle>
 % nft delete ct timeout filter test-tcp

Note: Original patch has been rework to use fixed size array for
timeouts and to validate timeout policy from the evaluation phase, once
we have access to the layer 4 protocol number. --pablo

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser_json: Fix crash in error reporting
Phil Sutter [Wed, 29 Aug 2018 14:25:09 +0000 (16:25 +0200)] 
parser_json: Fix crash in error reporting

When trying to add a chain to a non-existing table, error reporting
tries to dereference indesc pointer of the table's location. Hence make
sure the latter is initialized correctly.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agopy: trivial: Fix typo in comment string
Phil Sutter [Wed, 29 Aug 2018 14:24:52 +0000 (16:24 +0200)] 
py: trivial: Fix typo in comment string

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Add metainfo object to all output
Phil Sutter [Wed, 29 Aug 2018 14:23:28 +0000 (16:23 +0200)] 
JSON: Add metainfo object to all output

Right now this object merely contains the nftables version and release
name as well as a JSON schema version, but it could be extended
arbitrarily. In the future, this will also allow for non-compatible
schema changes should the need for this arise.

Adjust the parser to accept metainfo objects and make it verify
json_schema_version to be less than or equal to the one hard-coded in
the library.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Make match op mandatory, introduce 'in' operator
Phil Sutter [Wed, 29 Aug 2018 14:23:27 +0000 (16:23 +0200)] 
JSON: Make match op mandatory, introduce 'in' operator

This special operator is required for cases where missing operator does
not lead to same results as equal operator, i.e. with bitmasks on RHS.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Rename mangle statement properties
Phil Sutter [Wed, 29 Aug 2018 14:23:26 +0000 (16:23 +0200)] 
JSON: Rename mangle statement properties

Instead of the generic "left" and "right", use "key" and "value".

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Rename (v)map expression properties
Phil Sutter [Wed, 29 Aug 2018 14:23:25 +0000 (16:23 +0200)] 
JSON: Rename (v)map expression properties

Change the rather generic "left" and "right" into "key" and "data" as
suggested at NFWS.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Review payload expression
Phil Sutter [Wed, 29 Aug 2018 14:23:24 +0000 (16:23 +0200)] 
JSON: Review payload expression

For raw payloads, property "name" is not needed, it's clearly identified
by base/offset/len properties.

In non-raw payload expressions, rename property "name" to "protocol" as
suggested during NFWS.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Review verdict statement and expression
Phil Sutter [Wed, 29 Aug 2018 14:23:23 +0000 (16:23 +0200)] 
JSON: Review verdict statement and expression

Change jump and goto verdicts to become extensible by dedicating an
object for the target parameter.

While being at it, drop break and queue verdict expressions since they
don't seem to exist, no idea where I got those from in the first place.
For queue, there is a dedicated expression at least.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoJSON: Make meta statement/expression extensible
Phil Sutter [Wed, 29 Aug 2018 14:23:22 +0000 (16:23 +0200)] 
JSON: Make meta statement/expression extensible

Lessons learned from fwd statement: We must not assume a given
statement/expression may not receive further properties in the future.
Therefore make meta value an object with a property "key" instead of
just a string containing the key name.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Review libnftables-json.adoc
Phil Sutter [Wed, 29 Aug 2018 14:23:21 +0000 (16:23 +0200)] 
doc: Review libnftables-json.adoc

Drop the bits for TABLE from synopsis section - adding the remaining
objects there as well is tedious and tends to become unreadable. Instead
assume that readers will find the objects' descriptions in their
sections.

Also fix JSON syntax in many objects: The properties are enclosed in an
object, of course.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Improve example in libnftables-json(5)
Phil Sutter [Wed, 29 Aug 2018 14:23:20 +0000 (16:23 +0200)] 
doc: Improve example in libnftables-json(5)

The introductory example was a bit flawed in that the third command
('list ruleset') wouldn't yield expected results due to all three
commands ending in a single transaction and therefore the changes of the
first two commands were not committed yet at the time ruleset was
listed.

Instead demonstrate adding a chain and a rule to the new table.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotest: shell: Test cases for standard prios for flowtables
Máté Eckl [Fri, 24 Aug 2018 15:47:17 +0000 (17:47 +0200)] 
test: shell: Test cases for standard prios for flowtables

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotest: shell: Test cases for standard chain prios
Máté Eckl [Fri, 24 Aug 2018 15:47:15 +0000 (17:47 +0200)] 
test: shell: Test cases for standard chain prios

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Document implicit dependency creation for icmp/icmpv6
Phil Sutter [Fri, 24 Aug 2018 11:35:37 +0000 (13:35 +0200)] 
doc: Document implicit dependency creation for icmp/icmpv6

As suggested at NFWS, the implicit nfproto dependencies generated by
icmp/icmpv6 header field matches should be documented along with how to
achieve matching on unusual packets.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: py: Fix coloring of differences
Phil Sutter [Fri, 24 Aug 2018 11:27:25 +0000 (13:27 +0200)] 
tests: py: Fix coloring of differences

This was surprisingly hard to get right, but this should do the trick.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: build: run make on each ./configure option
Pablo Neira Ayuso [Wed, 29 Aug 2018 16:21:16 +0000 (18:21 +0200)] 
tests: build: run make on each ./configure option

Not only ./configure, but make sure compilation does not break for each
option.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: build: run make distcheck from fresh clone
Pablo Neira Ayuso [Wed, 29 Aug 2018 16:17:52 +0000 (18:17 +0200)] 
tests: build: run make distcheck from fresh clone

Just for sanity reasons.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: tproxy: add json support
Florian Westphal [Wed, 29 Aug 2018 09:37:41 +0000 (11:37 +0200)] 
src: tproxy: add json support

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: tproxy: relax family restrictions
Florian Westphal [Wed, 29 Aug 2018 09:37:40 +0000 (11:37 +0200)] 
src: tproxy: relax family restrictions

evaluation step currently prohibits

tproxy ip to 1.2.3.4 in ip family, and
tproxy ip6 to dead::1 in ip6.

This seems an arbitrary limitation, just accept this.
The current restriction would make json output support harder than needed,
as the tproxy expression generated from json path would have to
special-case the table its currently in, rather than just using the
family attribute in the json output.

We obviously still reject the family in case it mismatches
the table family (e.g., can't use ip address in ip6 table).

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: osf: add json support
Florian Westphal [Wed, 29 Aug 2018 09:37:39 +0000 (11:37 +0200)] 
src: osf: add json support

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoparser: avoid nf_key_proto redefinitions
Florian Westphal [Wed, 29 Aug 2018 09:37:38 +0000 (11:37 +0200)] 
parser: avoid nf_key_proto redefinitions

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: build: no need for root to run build tests
Pablo Neira Ayuso [Wed, 29 Aug 2018 11:08:32 +0000 (13:08 +0200)] 
tests: build: no need for root to run build tests

Plain user is just fine.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agojson: Fix compile error
Phil Sutter [Tue, 28 Aug 2018 20:26:56 +0000 (22:26 +0200)] 
json: Fix compile error

Commit 9e45a28ca467f ("src: honor /etc/services") broke compiling with
JSON support enabled: inet_service_type_print() is not suited for
converting inet_service datatype into JSON at all.

In order to avoid having to replicate the port value resolving into
human-readable name in inet_service_type_json(), just return a numeric
value. At least for JSON output, this probably makes most sense either
way since the output is expected to be parsed by scripts which have an
easier time with numers than names anyway.

Fixes: 9e45a28ca467f ("src: honor /etc/services")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: honor /etc/services
Pablo Neira Ayuso [Fri, 24 Aug 2018 09:04:30 +0000 (11:04 +0200)] 
src: honor /etc/services

This partial patch reverts:

ccc5da470e76 ("datatype: Replace getnameinfo() by internal lookup table")
f0f99006d34b ("datatype: Replace getaddrinfo() by internal lookup table")

so /etc/services is used to interpret service names, eg.

# nft add rule x y tcp dport \"ssh\"

Then, listing looks like:

# nft list ruleset -l
table x {
chain y {
...
tcp dport "ssh"
}
}

Major changes with regards to the original approach are:

1) Services are displayed in text via `-l' option.
2) Services are user-defined, just like mappings in /etc/iproute2/*
   files and connlabel.conf, so they are displayed enclosed in quotes.

Note that original service name code was broken since it parses both udp
and tcp service names but it only displays tcp services names as
literal. This is because NI_DGRAM is missing. This patch makes nft falls
back on udp services if no literal was found in the initial tcp service
name query. Proper way to handle would be to add infrastructure to store
protocol context information in struct output_ctx.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Make invalid chain priority error more specific
Máté Eckl [Thu, 23 Aug 2018 10:51:07 +0000 (12:51 +0200)] 
src: Make invalid chain priority error more specific

So far if invalid priority name was specified the error message referred
to the whole chain/flowtable specification:

nft> add chain ip x h { type filter hook prerouting priority first; }
Error: 'first' is invalid priority in this context.
add chain ip x h { type filter hook prerouting priority first; }
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

With this patch this reference is made specific to the priority
specification:

nft> add chain ip x h { type filter hook prerouting priority first; }
Error: 'first' is invalid priority in this context.
add chain ip x h { type filter hook prerouting priority first; }
                                               ^^^^^^^^^^^^^^

`prio_spec` is also reused to keep naming intuitive. The parser section
formerly named `prio_spec` is renamed to `int_num` as it basically
provides the mathematical set of integer numbers.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: integrate stateful expressions into sets and maps
Pablo Neira Ayuso [Fri, 24 Aug 2018 07:52:22 +0000 (09:52 +0200)] 
src: integrate stateful expressions into sets and maps

The following example shows how to populate a set from the packet path
using the destination IP address, for each entry there is a counter. The
entry expires after the 1 hour timeout if no packets matching this entry
are seen.

 table ip x {
        set xyz {
                type ipv4_addr
                size 65535
                flags dynamic,timeout
                timeout 1h
        }

        chain y {
                type filter hook output priority filter; policy accept;
                update @xyz { ip daddr counter } counter
        }
 }

Similar example, that creates a mapping better IP address and mark,
where the mark is assigned using an incremental sequence generator from
0 to 1 inclusive.

 table ip x {
        map xyz {
                type ipv4_addr : mark
                size 65535
                flags dynamic,timeout
                timeout 1h
        }

        chain y {
                type filter hook input priority filter; policy accept;
                update @xyz { ip saddr counter : numgen inc mod 2 }
        }
 }

Supported stateful statements are: limit, quota, counter and connlimit.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: simplify map statement
Pablo Neira Ayuso [Fri, 24 Aug 2018 07:52:17 +0000 (09:52 +0200)] 
src: simplify map statement

Instead of using the map expression, store dynamic key and data
separately since they need special handling than constant maps.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: do not print elements in dynamically populated sets with `-s'
Pablo Neira Ayuso [Fri, 24 Aug 2018 07:52:14 +0000 (09:52 +0200)] 
rule: do not print elements in dynamically populated sets with `-s'

Ruleset listing with --stateless should not display the content of
sets that are dynamically populated from the packet path.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agostatement: incorrect spacing in set reference
Pablo Neira Ayuso [Fri, 24 Aug 2018 07:52:11 +0000 (09:52 +0200)] 
statement: incorrect spacing in set reference

        chain y {
                type filter hook output priority filter; policy accept;
                update @xyz{ ip daddr }
                          ^^

Missing space between set reference and the element statement. This does
not break restoring the ruleset but it is inconsistent to the viewer.

There is also an extra space after the element statement that is
enclosed in brackets.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: osf: import nfnl_osf.c to load osf fingerprints
Fernando Fernandez Mancera [Wed, 22 Aug 2018 15:03:46 +0000 (17:03 +0200)] 
src: osf: import nfnl_osf.c to load osf fingerprints

Import iptables/utils/nfnl_osf.c into nftables tree with some changes in order
to load OS fingerprints automatically from pf.os file.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: mnl: make nft_mnl_talk() public
Fernando Fernandez Mancera [Wed, 22 Aug 2018 15:03:45 +0000 (17:03 +0200)] 
src: mnl: make nft_mnl_talk() public

As we are going to use the function nft_mnl_talk() from the incoming
nftnl_osf.c, we make it public.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agofiles: osf: copy iptables/utils/pf.os into nftables tree
Fernando Fernandez Mancera [Wed, 22 Aug 2018 15:03:44 +0000 (17:03 +0200)] 
files: osf: copy iptables/utils/pf.os into nftables tree

As we are going to need pf.os file to load OS fingerprints from the incoming
nfnl_osf.c, we copy it into the nftables tree directory "files/osf/".

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: Fix build failure in rule.c
Duncan Roe [Sat, 18 Aug 2018 02:00:59 +0000 (12:00 +1000)] 
rule: Fix build failure in rule.c

Commit c8a0e8c90 added #include <linux/netfilter_bridge.h> but that header needs
the definition of IFNAMSIZ from <net/if.h>
Sample build failure:

  CC       evaluate.lo
In file included from ../include/linux/netfilter_bridge.h:10:0,
                 from rule.c:32:
/usr/include/linux/if_pppox.h:42:20: error: 'IFNAMSIZ' undeclared here (not in a function)
  char          dev[IFNAMSIZ];          /* Local device to use */
                    ^
Makefile:687: recipe for target 'rule.lo' failed

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Add script to build PDF files
Duncan Roe [Fri, 17 Aug 2018 04:01:17 +0000 (14:01 +1000)] 
doc: Add script to build PDF files

See comments at end of doc/build_pdfs.sh

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agobuild: remove PDF documentation generation
Pablo Neira Ayuso [Tue, 14 Aug 2018 12:51:45 +0000 (14:51 +0200)] 
build: remove PDF documentation generation

This adds unnecessary complexity to our build infrastructure. People can
just manually generate them in PDF in case they need too. So let's keep
it simple and remove this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: missing modules in cleanup path
Pablo Neira Ayuso [Thu, 16 Aug 2018 18:37:42 +0000 (20:37 +0200)] 
tests: shell: missing modules in cleanup path

Update script with missing new kernel modules.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Remove double-spacing in text
Duncan Roe [Tue, 14 Aug 2018 04:31:51 +0000 (14:31 +1000)] 
doc: Remove double-spacing in text

Double-spacing in .txt files has no effect on PDF or man page output and
can make it hard to locate phrases when editing, so remove them.

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: fix 0012different_defines_0 with meta mark
Pablo Neira Ayuso [Tue, 14 Aug 2018 13:32:06 +0000 (15:32 +0200)] 
tests: shell: fix 0012different_defines_0 with meta mark

Since 6dd848339444 ("src: meta: always prefix 'meta' for almost all
tokens"), the unqualified meta are discouraged. Adjust test not to fail.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoevaluate: reject: Allow icmpx in inet/bridge families
Phil Sutter [Mon, 13 Aug 2018 16:58:57 +0000 (18:58 +0200)] 
evaluate: reject: Allow icmpx in inet/bridge families

Commit 3e6ab2b335142 added restraints on reject types for bridge and
inet families but aparently those were too strict: If a rule in e.g.
inet family contained a match which introduced a protocol dependency,
icmpx type rejects were disallowed for no obvious reason.

Allow icmpx type rejects in inet family regardless of protocol
dependency since we either have IPv4 or IPv6 traffic in there and for
both icmpx is fine.

Merge restraints in bridge family with those for TCP reset since it
already does what is needed, namely checking that ether proto is either
IPv4 or IPv6.

Fixes: 3e6ab2b335142 ("evaluate: reject: check in bridge and inet the network context in reject")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Set/print standard chain prios with textual names
Máté Eckl [Fri, 3 Aug 2018 08:55:33 +0000 (10:55 +0200)] 
src: Set/print standard chain prios with textual names

This patch adds the possibility to use textual names to set the chain priority
to standard values so that numeric values do not need to be learnt any more for
basic usage.

Basic arithmetic can also be done with them to ease the addition of
relatively higher/lower priority chains.
Addition and substraction is possible.

Values are also printed with their friendly name within the range of
<basicprio> +- 10.

Also numeric printing is supported in case of -nnn option
(numeric == NFT_NUMERIC_ALL)

The supported name-value pairs and where they are valid is based on how
x_tables use these values when registering their base chains. (See
iptables/nft.c in the iptables repository).

Also see the compatibility matrices extracted from the man page:

       Standard priority names, family and hook compatibility matrix
       ┌─────────┬───────┬────────────────┬─────────────┐
       │Name     │ Value │ Families       │ Hooks       │
       ├─────────┼───────┼────────────────┼─────────────┤
       │         │       │                │             │
       │raw      │ -300  │ ip, ip6, inet  │ all         │
       ├─────────┼───────┼────────────────┼─────────────┤
       │         │       │                │             │
       │mangle   │ -150  │ ip, ip6, inet  │ all         │
       ├─────────┼───────┼────────────────┼─────────────┤
       │         │       │                │             │
       │dstnat   │ -100  │ ip, ip6, inet  │ prerouting  │
       ├─────────┼───────┼────────────────┼─────────────┤
       │         │       │                │             │
       │filter   │ 0     │ ip, ip6, inet, │ all         │
       │         │       │ arp, netdev    │             │
       ├─────────┼───────┼────────────────┼─────────────┤
       │         │       │                │             │
       │security │ 50    │ ip, ip6, inet  │ all         │
       ├─────────┼───────┼────────────────┼─────────────┤
       │         │       │                │             │
       │srcnat   │ 100   │ ip, ip6, inet  │ postrouting │
       └─────────┴───────┴────────────────┴─────────────┘

       Standard priority names and hook compatibility for the bridge family
       ┌───────┬───────┬─────────────┐
       │       │       │             │
       │Name   │ Value │ Hooks       │
       ├───────┼───────┼─────────────┤
       │       │       │             │
       │dstnat │ -300  │ prerouting  │
       ├───────┼───────┼─────────────┤
       │       │       │             │
       │filter │ -200  │ all         │
       ├───────┼───────┼─────────────┤
       │       │       │             │
       │out    │ 100   │ output      │
       ├───────┼───────┼─────────────┤
       │       │       │             │
       │srcnat │ 300   │ postrouting │
       └───────┴───────┴─────────────┘

This can be also applied for flowtables wher it works as a netdev family
chain.

Example:
nft> add table ip x
nft> add chain ip x y { type filter hook prerouting priority raw; }
nft> add chain ip x z { type filter hook prerouting priority mangle + 1; }
nft> add chain ip x w { type filter hook prerouting priority dstnat - 5; }
nft> add chain ip x r { type filter hook prerouting priority filter + 10; }
nft> add chain ip x t { type filter hook prerouting priority security; }
nft> add chain ip x q { type filter hook postrouting priority srcnat + 11; }
nft> add chain ip x h { type filter hook prerouting priority 15; }
nft>
nft> add flowtable ip x y { hook ingress priority filter + 5 ; devices = {enp0s31f6}; }
nft>
nft> add table arp x
nft> add chain arp x y { type filter hook input priority filter + 5; }
nft>
nft> add table bridge x
nft> add chain bridge x y { type filter hook input priority filter + 9; }
nft> add chain bridge x z { type filter hook prerouting priority dstnat; }
nft> add chain bridge x q { type filter hook postrouting priority srcnat; }
nft> add chain bridge x k { type filter hook output priority out; }
nft>
nft> list ruleset
table ip x {
flowtable y {
hook ingress priority filter + 5
devices = { enp0s31f6 }
}

chain y {
type filter hook prerouting priority raw; policy accept;
}

chain z {
type filter hook prerouting priority mangle + 1; policy accept;
}

chain w {
type filter hook prerouting priority dstnat - 5; policy accept;
}

chain r {
type filter hook prerouting priority filter + 10; policy accept;
}

chain t {
type filter hook prerouting priority security; policy accept;
}

chain q {
type filter hook postrouting priority 111; policy accept;
}

chain h {
type filter hook prerouting priority 15; policy accept;
}
}
table arp x {
chain y {
type filter hook input priority filter + 5; policy accept;
}
}
table bridge x {
chain y {
type filter hook input priority filter + 9; policy accept;
}

chain z {
type filter hook prerouting priority dstnat; policy accept;
}

chain q {
type filter hook postrouting priority srcnat; policy accept;
}

chain k {
type filter hook output priority out; policy accept;
}
}
nft> # Everything should fail after this
nft> add chain ip x h { type filter hook prerouting priority first; }
Error: 'first' is invalid priority in this context.
add chain ip x h { type filter hook prerouting priority first; }
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
nft> add chain ip x q { type filter hook prerouting priority srcnat + 11; }
Error: 'srcnat' is invalid priority in this context.
add chain ip x q { type filter hook prerouting priority srcnat + 11; }
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
nft> add chain arp x y { type filter hook input priority raw; }
Error: 'raw' is invalid priority in this context.
add chain arp x y { type filter hook input priority raw; }
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
nft> add flowtable ip x y { hook ingress priority magle; devices = {enp0s31f6}; }
Error: 'magle' is invalid priority.
add flowtable ip x y { hook ingress priority magle; devices = {enp0s31f6}; }
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
nft> add chain bridge x r { type filter hook postrouting priority dstnat; }
Error: 'dstnat' is invalid priority in this context.
add chain bridge x r { type filter hook postrouting priority dstnat; }
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
nft> add chain bridge x t { type filter hook prerouting priority srcnat; }
Error: 'srcnat' is invalid priority in this context.
add chain bridge x t { type filter hook prerouting priority srcnat; }
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agonft: doc: fix make distcheck
Arushi Singhal [Wed, 8 Aug 2018 05:19:26 +0000 (10:49 +0530)] 
nft: doc: fix make distcheck

fix make distcheck for conversion to asciidoc.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft: doc: fix typos in asciidoc
Arushi Singhal [Sat, 11 Aug 2018 10:56:46 +0000 (16:26 +0530)] 
nft: doc: fix typos in asciidoc

Correct all the typos done while converting man page source to asciidoc.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: shell: validate too deep jumpstack from basechain
Pablo Neira Ayuso [Wed, 8 Aug 2018 19:52:50 +0000 (21:52 +0200)] 
tests: shell: validate too deep jumpstack from basechain

If there is no basechain, the validation is never exercised.

Too deep nested chains are fine as long as they are not connected to a
basechain.

Update test to add a basechain so we exercise validation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: user niggles
Duncan Roe [Tue, 7 Aug 2018 03:54:01 +0000 (13:54 +1000)] 
doc: user niggles

 - data-types.txt: "user space" -> userspace to match usage in statements.txt &
   data-types.txt
 - nft.txt: "an user-defined" sounds odd to a native English speaker (trust me)
   so change to "a user-defined"

These patches are applied on top of Máté's previous 2, but apply fine
without them (2 occurrences of "offset -5 lines").

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Add comment possibility to man page
Máté Eckl [Mon, 6 Aug 2018 18:58:21 +0000 (20:58 +0200)] 
doc: Add comment possibility to man page

Commenting is really useful in complex rulesets, however it is not
documented that they can be added to any rule.

This patch adds commenting possibility to the man page.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Acked-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: fix syntax for RULES
Máté Eckl [Mon, 6 Aug 2018 18:58:19 +0000 (20:58 +0200)] 
doc: fix syntax for RULES

[] means optional but 'add' or 'insert' is not optional one of them is required
which is usually signed with {} braces.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Acked-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: py: test osf with sets
Pablo Neira Ayuso [Tue, 7 Aug 2018 15:58:21 +0000 (17:58 +0200)] 
tests: py: test osf with sets

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoparser_bison: allow to use new osf expression from assignment statement
Pablo Neira Ayuso [Tue, 7 Aug 2018 15:45:15 +0000 (17:45 +0200)] 
parser_bison: allow to use new osf expression from assignment statement

So the following rule to set the conntrack mark based on the OS passive
recognition works:

 # nft add rule x y ct mark set osf name map { "Windows" : 1, "MacOs" : 2 }

Fixes: 9f28b685b473 ("src: introduce passive OS fingerprint matching")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: improve test cases for osf
Fernando Fernandez Mancera [Tue, 7 Aug 2018 09:44:07 +0000 (11:44 +0200)] 
tests: improve test cases for osf

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: use NFT_OSF_MAXGENRELEN instead of IFNAMSIZ in osf.c
Fernando Fernandez Mancera [Tue, 7 Aug 2018 09:44:06 +0000 (11:44 +0200)] 
src: use NFT_OSF_MAXGENRELEN instead of IFNAMSIZ in osf.c

As no "genre" in pf.os exceed 16 bytes of length, we reduce
NFT_OSF_MAXGENRELEN parameter to 16 bytes and use it instead of IFNAMSIZ.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Changes following detailed comparison with last XML version
Duncan Roe [Mon, 6 Aug 2018 01:14:48 +0000 (11:14 +1000)] 
doc: Changes following detailed comparison with last XML version

These were found by a combination of tkdiff and side-by-side man pages

Most changes preserve or (occasionally) fix highlighting, casing or plurality.
No major omissions were found.

 - data-types.txt: (Nothing special)
 - nft.txt:
   -- changed "`nft' stands for Netfilter" back to "`nf' stands for Netfilter"
   -- removed mysterious plus sign
 - payload-expression.txt:
   -- XML had MTU as 16-bit so changed back from 32. Is that correct?
 - primary-expression.txt: (Nothing special)
 - statements.txt: (Nothing special)

This patch does not address any of the following observations:

1. Title has changed from nft to NFT

2. There is no attempt at justification.

3. There is no attempt at hyphenation.

4. Long lines of code now wrap instead of indenting nicely.
   See e.g. "tcp option" line under EXTENSION HEADER EXPRESSIONS

5. Tables have a lot of empty lines in them.

6. Occasionally there is severe wrapping,
   e.g. under CHAINS see add/create/delete/&c. which wrap at about cc40.

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Miscellaneous spelling fixes
Duncan Roe [Sat, 4 Aug 2018 08:54:04 +0000 (18:54 +1000)] 
doc: Miscellaneous spelling fixes

These were found by ispell -p ./ispell_nft *.txt in nftables/doc.

 - ispell.nft: Added some new words
 - nft.txt: (nothing special)
 - payload-expression.txt: lengthbits and offsetbits were run together
   before the conversion to .txt, but the conversion lost the underlining
 - primary-expression.txt: ispell suggested rtclassid instead of rtlclassid,
   which agres with previous usage
 - stateful-objects.txt: (nothing special)
 - statements.txt: nonbase chains changed back to non-base chains as it used to
   be

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: resolve run-together IPv6 address specification headers
Duncan Roe [Sat, 4 Aug 2018 07:26:51 +0000 (17:26 +1000)] 
doc: resolve run-together IPv6 address specification headers

This run-together header has been there since before the conversion to .txt.

Also the comment starting "without []" wrapped around in an 80cc xterm,
so split into 2 comment lines and fixed grammar (extrs "the").

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Remove UTF8(?) sequences
Duncan Roe [Sat, 4 Aug 2018 01:16:07 +0000 (11:16 +1000)] 
doc: Remove UTF8(?) sequences

There were some forced hyphenations which only ever looked right in an
80-column terminal and now don't all look right even there e.g.

searched for included files. This op- tion may be specified

Also the URL on the last line

a"http://creativecommons.org/licenses/by-sa/4.0/a(C)

Tested using man in the C locale

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotest: py: fix osf testcases warning
Fernando Fernandez Mancera [Fri, 3 Aug 2018 23:31:49 +0000 (01:31 +0200)] 
test: py: fix osf testcases warning

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agoinclude: add missing osf.h
Pablo Neira Ayuso [Fri, 3 Aug 2018 23:37:43 +0000 (01:37 +0200)] 
include: add missing osf.h

And update Makefile.am accordingly.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: add osf expression to man page
Fernando Fernandez Mancera [Fri, 3 Aug 2018 22:17:50 +0000 (00:17 +0200)] 
doc: add osf expression to man page

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: py: add test cases for "osf" matching
Fernando Fernandez Mancera [Fri, 3 Aug 2018 21:47:12 +0000 (23:47 +0200)] 
tests: py: add test cases for "osf" matching

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: introduce passive OS fingerprint matching
Fernando Fernandez Mancera [Fri, 3 Aug 2018 21:47:11 +0000 (23:47 +0200)] 
src: introduce passive OS fingerprint matching

Add support for "osf" expression. Example:

table ip foo {
chain bar {
type filter hook input priority 0; policy accept;
osf name "Linux" counter packets 3 bytes 132
}
}

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: correct some typos in asciidoc
Arushi Singhal [Tue, 31 Jul 2018 13:34:33 +0000 (19:04 +0530)] 
doc: correct some typos in asciidoc

Correct some typo mistakes done while converting man page source to
asciidoc.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Expose socket mark via socket expression
Máté Eckl [Wed, 1 Aug 2018 18:09:22 +0000 (20:09 +0200)] 
src: Expose socket mark via socket expression

This can be used like ct mark or meta mark except it cannot be set. doc
and tests are included.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Add tproxy statement to man page
Máté Eckl [Wed, 1 Aug 2018 18:01:47 +0000 (20:01 +0200)] 
doc: Add tproxy statement to man page

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
7 years agotests: py: Add test cases for tproxy support
Máté Eckl [Fri, 20 Jul 2018 07:46:44 +0000 (09:46 +0200)] 
tests: py: Add test cases for tproxy support

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: Add tproxy support
Máté Eckl [Fri, 20 Jul 2018 07:40:09 +0000 (09:40 +0200)] 
src: Add tproxy support

This patch adds support for transparent proxy functionality which is
supported in ip, ip6 and inet tables.

The syntax is the following:
tproxy [{|ip|ip6}] to {<ip address>|:<port>|<ip address>:<port>}

It looks for a socket listening on the specified address or port and
assigns it to the matching packet.

In an inet table, a packet matches for both families until address is
specified.
Network protocol family has to be specified **only** in inet tables if
address is specified.

As transparent proxy support is implemented for sockets with layer 4
information, a transport protocol header criterion has to be set in the
same rule. eg. 'meta l4proto tcp' or 'udp dport 4444'

Example ruleset:
table ip x {
chain y {
type filter hook prerouting priority -150; policy accept;
tcp dport ntp tproxy to 1.1.1.1
udp dport ssh tproxy to :2222
}
}
table ip6 x {
chain y {
type filter hook prerouting priority -150; policy accept;
tcp dport ntp tproxy to [dead::beef]
udp dport ssh tproxy to :2222
}
}
table inet x {
chain y {
type filter hook prerouting priority -150; policy accept;
tcp dport 321 tproxy to :ssh
tcp dport 99 tproxy ip to 1.1.1.1:999
udp dport 155 tproxy ip6 to [dead::beef]:smux
}
}

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: statements.txt: Wrap extra long lines to 80 chars
Máté Eckl [Wed, 1 Aug 2018 17:28:52 +0000 (19:28 +0200)] 
doc: statements.txt: Wrap extra long lines to 80 chars

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: stateful-objects.txt: Wrap extra long lines to 80 chars
Máté Eckl [Wed, 1 Aug 2018 17:28:51 +0000 (19:28 +0200)] 
doc: stateful-objects.txt: Wrap extra long lines to 80 chars

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: primary-expression.txt: Wrap extra long lines to 80 chars
Máté Eckl [Wed, 1 Aug 2018 17:28:50 +0000 (19:28 +0200)] 
doc: primary-expression.txt: Wrap extra long lines to 80 chars

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: payload-expression.txt: Wrap extra long lines to 80 chars
Máté Eckl [Wed, 1 Aug 2018 17:28:49 +0000 (19:28 +0200)] 
doc: payload-expression.txt: Wrap extra long lines to 80 chars

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: data-types.txt: Wrap extra long lines to 80 chars
Máté Eckl [Wed, 1 Aug 2018 17:28:48 +0000 (19:28 +0200)] 
doc: data-types.txt: Wrap extra long lines to 80 chars

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: nft.txt: Wrap extra long lines to 80 chars
Máté Eckl [Wed, 1 Aug 2018 13:53:16 +0000 (15:53 +0200)] 
doc: nft.txt: Wrap extra long lines to 80 chars

When I tried to send a patch that included man page update I got the
following error from git send-email:
fatal: patch.patch:287: patch contains a line longer than 998 characters
Line 287 was a non-modified line so it was there before my patch.

Even this patch can only be sent with mutt but not with git send-email.

This patch tries to fix this issue by wrapping extra long lines to 80
characters wide.

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: remove nft.xml from CLEANFILES
Florian Westphal [Thu, 26 Jul 2018 15:10:15 +0000 (17:10 +0200)] 
doc: remove nft.xml from CLEANFILES

This file doesn't exist.

Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft: doc: Convert man page source to asciidoc
Arushi Singhal [Wed, 25 Jul 2018 11:26:43 +0000 (16:56 +0530)] 
nft: doc: Convert man page source to asciidoc

This patch converts nft.xml into asciidoc markup.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: fix a typo in socket.h
Fernando Fernandez Mancera [Sat, 21 Jul 2018 19:39:09 +0000 (21:39 +0200)] 
src: fix a typo in socket.h

Fix a typo in socket_template struct description.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: meta: always prefix 'meta' for almost all tokens
Florian Westphal [Tue, 3 Jul 2018 14:16:51 +0000 (16:16 +0200)] 
src: meta: always prefix 'meta' for almost all tokens

got following bug report:

nft add ... ct mark set mark and 0x10

... always sets 0.
What reporter meant to write instead was 'ct mark', not 'mark'.

We can't just remove support for 'mark' and force
'meta mark', but we can start to discourage it by printing meta prefix too.

Later on, we could start to print deprecation warning if needed.
Followup patch can also change
"iifname" etc. to "meta iifname".

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: add test case for rename-to-same-name
Florian Westphal [Tue, 17 Jul 2018 05:11:12 +0000 (07:11 +0200)] 
tests: add test case for rename-to-same-name

kernel currently permits chains with same name when a transaction renames
2 chains to the same new name.  Add a test case for this.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests: shell: validate maximum chain depth
Pablo Neira Ayuso [Wed, 11 Jul 2018 22:21:49 +0000 (00:21 +0200)] 
tests: shell: validate maximum chain depth

Original script from Taehee Yoo.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: shell: add tests for listing objects
Harsha Sharma [Tue, 10 Jul 2018 20:00:21 +0000 (22:00 +0200)] 
tests: shell: add tests for listing objects

Add tests for listing specific object for a given table name and all
objects of a table.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: list only the table containing object
Harsha Sharma [Sun, 8 Jul 2018 10:41:03 +0000 (12:41 +0200)] 
rule: list only the table containing object

For e.g.

 % nft list ct helper ip raw cthelp1
 table ip filter {
 }
 table ip raw {
ct helper cthelp1 {
type "ftp" protocol tcp
l3proto ip
}
 }

With this patch, print only table raw.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests: check ifname use in concatenated sets
Florian Westphal [Thu, 28 Jun 2018 00:16:38 +0000 (02:16 +0200)] 
tests: check ifname use in concatenated sets

error was:
 nft create set inet filter keepalived_ranges4 { type inet_service . ifname \; }
 Error: Empty string is not allowed

This was fixed in
6b00b9537e181 ("evaluate: skip evaluation of datatype concatenations").

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonft: set: print dynamic flag when set
Florian Westphal [Fri, 6 Jul 2018 19:08:26 +0000 (21:08 +0200)] 
nft: set: print dynamic flag when set

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agodoc: describe dynamic flag and caveats for packet-path updates
Florian Westphal [Fri, 6 Jul 2018 18:54:20 +0000 (20:54 +0200)] 
doc: describe dynamic flag and caveats for packet-path updates

This fails:

nft add table ip filter
nft add chain ip filter input '{' type filter hook input priority 0 ';' '}'
nft add set ip filter protocols '{' type inet_proto ';' '}'
nft add rule ip filter input iifname lo set add ip protocol @protocols
                                                  ^^^^^^^^^^^^^^^^^^^
...as wrong set type gets chosen.
Describe dynamic flag and that sets should have both timeout and
max size set.

Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agoevaluate: skip evaluation of datatype concatenations
Pablo Neira Ayuso [Fri, 6 Jul 2018 18:07:54 +0000 (20:07 +0200)] 
evaluate: skip evaluation of datatype concatenations

These are not really expressions, so there is not value in place. The
expr_evaluate_concat() is called from set_evaluate() to calculate the
total length of the tuple.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1265
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: update manpage to document --literal option
Pablo Neira Ayuso [Tue, 3 Jul 2018 15:37:03 +0000 (17:37 +0200)] 
doc: update manpage to document --literal option

This patch describe the new --literal option.

Remove documentation on -N to prepare it for deprecation.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agosrc: add --literal option
Pablo Neira Ayuso [Tue, 3 Jul 2018 15:24:05 +0000 (17:24 +0200)] 
src: add --literal option

Default not to print the service name as we discussed during the NFWS.

 # nft list ruleset
 table ip x {
        chain y {
                tcp dport 22
                ip saddr 1.1.1.1
        }
 }

 # nft -l list ruleset
 table ip x {
        chain y {
                tcp dport ssh
                ip saddr 1.1.1.1
        }
 }

 # nft -ll list ruleset
 table ip x {
        chain y {
                tcp dport 22
                ip saddr 1dot1dot1dot1.cloudflare-dns.com
        }
 }

Then, -ll displays FQDN. just like the (now deprecated) --ip2name (-N)
option.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agorule: limit: don't print default burst value
Florian Westphal [Wed, 4 Jul 2018 13:10:12 +0000 (15:10 +0200)] 
rule: limit: don't print default burst value

limit http-traffic { rate 1/second } gets printed as
limit http-traffic { rate 1/second burst 5 packets }

caused tests/shell/run-tests.sh tests/shell/testcases/sets/0026named_limit_0

to return 'DUMP FAIL'.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: Add socket expression to man page
Máté Eckl [Tue, 3 Jul 2018 14:20:10 +0000 (16:20 +0200)] 
doc: Add socket expression to man page

Signed-off-by: Máté Eckl <ecklm94@gmail.com>
7 years agonftables: tests: shell: Replace "%" with "#" or "$"
Arushi Singhal [Sun, 1 Jul 2018 06:06:09 +0000 (11:36 +0530)] 
nftables: tests: shell: Replace "%" with "#" or "$"

Shell prompt ends with:
"%", indicates a C shell.
"$", indicates shell that's compatible with the Bash.
"#", indicates shell is running as the system's root.
So, "%" is replaced with "$" or "#".

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agonetlink_delinearize: Refactor meta_may_dependency_kill()
Phil Sutter [Thu, 21 Jun 2018 12:01:13 +0000 (14:01 +0200)] 
netlink_delinearize: Refactor meta_may_dependency_kill()

The original intent was to fix a bug: The following rule in inet table:

| meta nfproto ipv4 icmpv6 type echo-reply

Was added correctly but when printing the meta match was falsely
removed. The fix is to deny dependency killing if RHS family of nfproto
match doesn't match RHS family of l4proto match. Adding this to the
already large conditional led to even more unreadable code, therefore
this patch tries to clean that up (and also removes the partial code
duplication.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agosrc: trace: fix policy printing
Florian Westphal [Wed, 20 Jun 2018 21:06:04 +0000 (23:06 +0200)] 
src: trace: fix policy printing

policy type is erronously handled via verdict, this is wrong.
It is a different event type and needs to be handled as such.

before:
trace id 42b54e71 inet filter input packet: iif "lo" ip saddr 127.0.0.1 ..
trace id 42b54e71 inet filter input rule ip protocol icmp nftrace set 1 (verdict continue)
trace id 42b54e71 inet filter input verdict continue
trace id 42b54e71 inet filter input

after:
trace id 9f40c5c7 inet filter input packet: iif "lo" ip saddr 127.0.0.1 ..
trace id 9f40c5c7 inet filter input rule ip protocol icmp nftrace set 1 (verdict continue)
trace id 9f40c5c7 inet filter input verdict continue
trace id 9f40c5c7 inet filter input policy drop

Reported-by: vtol@gmx.net
Signed-off-by: Florian Westphal <fw@strlen.de>
7 years agotests/py: fix import when run from other directory
Eric Leblond [Thu, 21 Jun 2018 14:47:47 +0000 (16:47 +0200)] 
tests/py: fix import when run from other directory

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agotests/py: minor cleaning
Eric Leblond [Tue, 19 Jun 2018 21:46:56 +0000 (23:46 +0200)] 
tests/py: minor cleaning

Move import and use explicit parameter in object creation.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agodoc: fix make distcheck
Eric Leblond [Tue, 19 Jun 2018 21:46:55 +0000 (23:46 +0200)] 
doc: fix make distcheck

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agopython: set license and author in nftables.py
Eric Leblond [Tue, 19 Jun 2018 21:46:54 +0000 (23:46 +0200)] 
python: set license and author in nftables.py

It will be distributed separately so this worth setting things
correctly.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
7 years agopython: installation of binding via make install
Eric Leblond [Tue, 19 Jun 2018 21:46:53 +0000 (23:46 +0200)] 
python: installation of binding via make install

setup.py is used to build and install the python binding. Call
to setup.py are done in Makefile to proceed to build and
installation.

Signed-off-by: Eric Leblond <eric@regit.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>