]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
6 years agopy: Adjust Nftables class to output flags changes
Phil Sutter [Wed, 31 Oct 2018 12:53:16 +0000 (13:53 +0100)] 
py: Adjust Nftables class to output flags changes

Introduce setter/getter methods for each introduced output flag. Ignore
NFT_CTX_OUTPUT_NUMERIC_ALL for now since it's main purpose is for
internal use.

Adjust the script in tests/py accordingly: Due to the good defaults,
only numeric proto output has to be selected - this is not a must, but
allows for the test cases to remain unchanged.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: fix json_events_cb() declaration when libjansson is not present
Laura Garcia Liebana [Wed, 31 Oct 2018 11:54:18 +0000 (12:54 +0100)] 
json: fix json_events_cb() declaration when libjansson is not present

When nftables is configured without libjansson support, the following
compilation error is shown:

monitor.c: In function ‘netlink_echo_callback’:
monitor.c:910:10: error: too many arguments to function ‘json_events_cb’
   return json_events_cb(nlh, &echo_monh);
          ^~~~~~~~~~~~~~

This patch makes a declaration of the json_events_cb() function
consistent.

Fixes: bb32d8db9a12 ("JSON: Add support for echo option")
Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: remove unnecessary extra asterisk at the end of option line
Pablo Neira Ayuso [Mon, 29 Oct 2018 21:04:55 +0000 (22:04 +0100)] 
doc: remove unnecessary extra asterisk at the end of option line

For --guid, --numeric-protocol and --numeric-priority.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoexpression: always print range expression numerically
Pablo Neira Ayuso [Mon, 29 Oct 2018 20:50:49 +0000 (21:50 +0100)] 
expression: always print range expression numerically

Otherwise we end up displaying things that we cannot parse as input.
Moreover, in a range, it's relevant to the user the values that are
enclosed in the range, so let's print this numerically.

Fixes: baa4e0e3fa5f ("src: add NFT_CTX_OUTPUT_NUMERIC_PROTO")
Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add -p to print layer 4 protocol numerically
Pablo Neira Ayuso [Mon, 29 Oct 2018 20:43:25 +0000 (21:43 +0100)] 
src: add -p to print layer 4 protocol numerically

We keep printing layer 4 protocols as literals since we do not use
/etc/protocols. Add -p option to print layer 4 protocols numerically.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: get rid of nft_ctx_output_{get,set}_numeric()
Pablo Neira Ayuso [Mon, 29 Oct 2018 15:03:32 +0000 (16:03 +0100)] 
src: get rid of nft_ctx_output_{get,set}_numeric()

This patch adds NFT_CTX_OUTPUT_NUMERIC_SYMBOL, which replaces the last
client of the numeric level approach.

This patch updates `-n' option semantics to display all output
numerically.

Note that monitor code was still using the -n option to skip printing
the process name, this patch updates that path too to print it
inconditionally to simplify things.

Given the numeric levels have no more clients after this patch, remove
that code.

Update several tests/shell not to use -nn.

This patch adds NFT_CTX_OUTPUT_NUMERIC_ALL which enables all flags to
provide a fully numerical output.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add -y to priority base chain nummerically
Pablo Neira Ayuso [Mon, 29 Oct 2018 13:15:14 +0000 (14:15 +0100)] 
src: add -y to priority base chain nummerically

By default base chains are printed using default hook priority
definitions. Add -y option to print them as numbers.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add NFT_CTX_OUTPUT_NUMERIC_PROTO
Pablo Neira Ayuso [Mon, 29 Oct 2018 13:04:07 +0000 (14:04 +0100)] 
src: add NFT_CTX_OUTPUT_NUMERIC_PROTO

We keep printing layer 4 protocols as literals since we do not use
/etc/protocols. This new flag allows us to print it as a number.

libnftables internally uses this to print layer 4 protocol as numbers
when part of a range.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: default to numeric UID and GID listing
Pablo Neira Ayuso [Mon, 29 Oct 2018 11:49:00 +0000 (12:49 +0100)] 
src: default to numeric UID and GID listing

Like iptables-save, print UID and GID as numeric values by default.

Add a new option `-u' to print the UID and GID names as defined by
/etc/passwd and /etc/group.

Note that -n is ignored after this patch, since default are numeric
printing for UID and GID.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add nft_ctx_output_{get,set}_echo() to nft_ctx_output_{get,set}_flags
Pablo Neira Ayuso [Mon, 29 Oct 2018 11:11:09 +0000 (12:11 +0100)] 
src: add nft_ctx_output_{get,set}_echo() to nft_ctx_output_{get,set}_flags

Add NFT_CTX_OUTPUT_ECHO flag and echo the command that has been send to
the kernel.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add nft_ctx_output_{get,set}_json() to nft_ctx_output_{get,set}_flags
Pablo Neira Ayuso [Sat, 27 Oct 2018 10:02:02 +0000 (12:02 +0200)] 
src: add nft_ctx_output_{get,set}_json() to nft_ctx_output_{get,set}_flags

Add NFT_CTX_OUTPUT_JSON flag and display output in json format.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add nft_ctx_output_{get,set}_handle() to nft_ctx_output_{get,set}_flags
Pablo Neira Ayuso [Sat, 27 Oct 2018 09:55:00 +0000 (11:55 +0200)] 
src: add nft_ctx_output_{get,set}_handle() to nft_ctx_output_{get,set}_flags

Add NFT_CTX_OUTPUT_HANDLE flag and print handle that uniquely identify
objects from new output flags interface.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: add nft_ctx_output_{get,set}_stateless() to nft_ctx_output_{get,flags}_flags
Pablo Neira Ayuso [Sat, 27 Oct 2018 09:44:09 +0000 (11:44 +0200)] 
src: add nft_ctx_output_{get,set}_stateless() to nft_ctx_output_{get,flags}_flags

Add NFT_CTX_OUTPUT_STATELESS flag and enable stateless printing from new
output flags interface.

This patch adds nft_output_save_flags() and nft_output_restore_flags()
to temporarily disable stateful printing

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: Revert --literal, add -S/--service
Pablo Neira Ayuso [Wed, 24 Oct 2018 15:37:47 +0000 (17:37 +0200)] 
src: Revert --literal, add -S/--service

This is a partial revert of b0f6a45b25dd1 ("src: add --literal option")
which was added during the development cycle before 0.9.1 is released.

After looking at patch: https://patchwork.ozlabs.org/patch/969864/ that
allows to print priority, uid, gid and protocols as numerics, I decided
to revisit this to provide individual options to turn on literal
printing.

What I'm proposing is to provide a good default for everyone, and
provide options to turn on literal/numeric printing.

This patch adds nft_ctx_output_{set,get}_flags() and define two flags to
enable reverse DNS lookups and to print ports as service names.

This patch introduces -S/--services, to print service names as per
/etc/services.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft.8: Document log level audit
Phil Sutter [Sat, 27 Oct 2018 10:15:50 +0000 (12:15 +0200)] 
nft.8: Document log level audit

Since this pseudo log level fundamentally changes behaviour of log
statement, dedicate this mode a separate paragraph.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoJSON: Add support for echo option
Phil Sutter [Fri, 26 Oct 2018 13:01:38 +0000 (15:01 +0200)] 
JSON: Add support for echo option

The basic principle is to not return a JSON object freshly created from
netlink responses, but just update the existing user-provided one to
make sure callers get back exactly what they expect.

To achieve that, keep the parsed JSON object around in a global variable
('cur_root') and provide a custom callback to insert handles into it
from received netlink messages. The tricky bit here is updating rules
since unique identification is problematic. Therefore drop possibly
present handles from input and later assume updates are received in
order so the first rule not having a handle set is the right one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests/shell: Add testcase for cache update problems
Phil Sutter [Fri, 26 Oct 2018 09:42:05 +0000 (11:42 +0200)] 
tests/shell: Add testcase for cache update problems

The first test in there shows how the current cache update strategy
causes trouble. The second test shows that proposed "locking" of cache
when local entries are added is flawed, too.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoevaluate: stmt_evaluate_map() needs right hand side evaluation too
Pablo Neira Ayuso [Thu, 25 Oct 2018 17:35:10 +0000 (19:35 +0200)] 
evaluate: stmt_evaluate_map() needs right hand side evaluation too

The data side of the mapping that is dynamically generated needs to be
evaluated as well.

Fixes: 0e90798e9812 ("src: simplify map statement")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoevaluate: do not pass EXPR_SET_ELEM to stmt_evaluate_arg() for set/map evaluation
Pablo Neira Ayuso [Thu, 25 Oct 2018 17:18:28 +0000 (19:18 +0200)] 
evaluate: do not pass EXPR_SET_ELEM to stmt_evaluate_arg() for set/map evaluation

Otherwise, we cannot validate mismatching length size when combining raw
expressions with sets and maps, eg.

 # cat /tmp/test
 table ip nftlb {
       map persistency {
               type ipv4_addr : mark
               size 65535
               timeout 1h
       }

       chain pre {
               type filter hook prerouting priority filter; policy accept;
               ip protocol { tcp, udp } update @persistency { @th,0,16 : numgen inc mod 2 offset 100 }
       }
 }

 # nft -f /tmp/test
 /tmp/test:10:68-75: Error: datatype mismatch: expected IPv4 address, expression has type integer with length 16
                    ip protocol { tcp, udp } update @persistency { @th,0,16 : numgen inc mod 2 offset 100 }
                                             ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Pass inner expression instead, instead of the wrapping set element
expression.

Fixes: 0e90798e9812 ("src: simplify map statement")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Work around segfault when encountering xt stmt
Phil Sutter [Wed, 24 Oct 2018 19:14:37 +0000 (21:14 +0200)] 
json: Work around segfault when encountering xt stmt

When trying to convert an xt stmt into JSON, print() callback was
called. Though the code in src/xt.c does not respect output_fp,
therefore buffer wasn't filled as expected making libjansson to puke:

| # nft -j list ruleset
| warning: stmt ops xt have no json callback
| nft: json.c:169: stmt_print_json: Assertion `__out' failed.
| Aborted (core dumped)

Avoid this by detecting xt stmt ops and returning a stub.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonetlink: remove netlink_batch_send()
Pablo Neira Ayuso [Wed, 24 Oct 2018 16:47:15 +0000 (18:47 +0200)] 
netlink: remove netlink_batch_send()

Replace it by direct call to mnl_batch_talk().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: remove alloc_nftnl_flowtable()
Pablo Neira Ayuso [Wed, 24 Oct 2018 16:37:48 +0000 (18:37 +0200)] 
mnl: remove alloc_nftnl_flowtable()

We can remove alloc_nftnl_flowtable() and consolidate infrastructure in
the src/mnl.c file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: Improve error checking in mnl_nft_event_listener()
Phil Sutter [Wed, 24 Oct 2018 16:05:55 +0000 (18:05 +0200)] 
mnl: Improve error checking in mnl_nft_event_listener()

When trying to adjust receive buffer size, the second call to
setsockopt() was not error-checked.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Fix for recent changes to context structs
Phil Sutter [Wed, 24 Oct 2018 10:35:04 +0000 (12:35 +0200)] 
json: Fix for recent changes to context structs

Commits introducing nft_ctx pointer to netlink and eval contexts did not
update JSON code accordingly.

Fixes: 00f777bfc414a ("src: pass struct nft_ctx through struct eval_ctx")
Fixes: 2dc07bcd7eaa5 ("src: pass struct nft_ctx through struct netlink_ctx")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Fix osf ttl support
Phil Sutter [Wed, 24 Oct 2018 10:35:03 +0000 (12:35 +0200)] 
json: Fix osf ttl support

Having to use numerical values for ttl property in JSON is not
practical as these values are arbitrary and meaningful only in
netfilter. Instead align JSON output/input with standard API, accepting
names for TTL matching strategy.

Also add missing documentation in libnftables-json man page and fix JSON
equivalent in tests/py.

Fixes: 03eafe098d5ee ("osf: add ttl option support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoinclude: Fix comment for struct eval_ctx
Phil Sutter [Wed, 24 Oct 2018 10:35:02 +0000 (12:35 +0200)] 
include: Fix comment for struct eval_ctx

Previous change to that struct missed to update the comment.

Fixes: 00f777bfc414a ("src: pass struct nft_ctx through struct eval_ctx")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: use either name or handle to refer to objects
Pablo Neira Ayuso [Tue, 23 Oct 2018 17:07:23 +0000 (19:07 +0200)] 
mnl: use either name or handle to refer to objects

We can only specify either name or handle to refer to objects.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: remove alloc_nftnl_obj()
Pablo Neira Ayuso [Tue, 23 Oct 2018 16:59:07 +0000 (18:59 +0200)] 
mnl: remove alloc_nftnl_obj()

We can remove alloc_nftnl_obj() and consolidate infrastructure in the
src/mnl.c file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: move socket open and reopen to mnl.c
Pablo Neira Ayuso [Tue, 23 Oct 2018 16:24:31 +0000 (18:24 +0200)] 
src: move socket open and reopen to mnl.c

These functions are part of the mnl backend, move them there. Remove
netlink_close_sock(), use direct call to mnl_socket_close().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: osf: add ttl option to man page
Fernando Fernandez Mancera [Mon, 22 Oct 2018 20:46:19 +0000 (22:46 +0200)] 
doc: osf: add ttl option to man page

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoosf: add ttl option support
Fernando Fernandez Mancera [Tue, 23 Oct 2018 15:06:22 +0000 (17:06 +0200)] 
osf: add ttl option support

Add support for ttl option in "osf" expression. Example:

table ip foo {
chain bar {
type filter hook input priority filter; policy accept;
osf ttl skip name "Linux"
}
}

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonetlink: reset mnl_socket field in struct nft_ctx on EINTR
Pablo Neira Ayuso [Mon, 22 Oct 2018 19:20:44 +0000 (21:20 +0200)] 
netlink: reset mnl_socket field in struct nft_ctx on EINTR

Otherwise we keep using the old netlink socket if we hit EINTR.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: pass struct nft_ctx through struct netlink_ctx
Pablo Neira Ayuso [Mon, 22 Oct 2018 19:18:19 +0000 (21:18 +0200)] 
src: pass struct nft_ctx through struct netlink_ctx

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: pass struct nft_ctx through struct eval_ctx
Pablo Neira Ayuso [Mon, 22 Oct 2018 10:38:35 +0000 (12:38 +0200)] 
src: pass struct nft_ctx through struct eval_ctx

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: shell: Extend get element test
Phil Sutter [Mon, 22 Oct 2018 13:45:09 +0000 (15:45 +0200)] 
tests: shell: Extend get element test

Despite the recent fixes, the test still fails. While trying to address
the remaining issues, I found more potentially problematic inputs so
extend the test by those.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: Document ct timeout support
Harsha Sharma [Thu, 18 Oct 2018 18:12:20 +0000 (23:42 +0530)] 
doc: Document ct timeout support

Add documentation for creating ct timeout objects and assigning timeout
policies via rules.

Signed-off-by: Harsha Sharma <harshasharmaiitr@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoevaluate: bogus bail out with raw expression from dynamic sets
Pablo Neira Ayuso [Wed, 17 Oct 2018 10:31:22 +0000 (12:31 +0200)] 
evaluate: bogus bail out with raw expression from dynamic sets

The following ruleset that uses raw expressions:

 table ip nftlb {
        map persistency {
                type inet_service : mark
                size 65535
                timeout 1h
                elements = { 53 expires 59m55s864ms : 0x00000064, 80 expires 59m58s924ms : 0x00000065, 443 expires 59m56s220ms : 0x00000064 }
        }

        chain pre {
                type filter hook prerouting priority filter; policy accept;
                ip protocol { tcp, udp } update @persistencia { @th,0,16 : numgen inc mod 2 offset 100 }
        }
 }

bogusly bails out with:

 /tmp/test:9:57-64: Error: datatype mismatch: expected internet network service, expression has type integer
         ip protocol { tcp, udp } update @persistencia { @th,0,16 : numgen inc mod 2 offset 100 }
                                  ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix the problem by evaluating expression basetype and length in this case.

Reported-by: Laura Garcia <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: remove opts field from struct xt_stmt
Pablo Neira Ayuso [Tue, 16 Oct 2018 18:56:57 +0000 (20:56 +0200)] 
src: remove opts field from struct xt_stmt

This is never used, ie. always NULL.

Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Acked-by: Phil Sutter <phil@nwl.cc>
6 years agosrc: add support for setting secmark
Christian Göttsche [Mon, 15 Oct 2018 12:18:36 +0000 (14:18 +0200)] 
src: add support for setting secmark

Add support for new nft object secmark holding security context strings.

The following should demonstrate its usage (based on SELinux context):

    # define a tag containing a context string
    nft add secmark inet filter sshtag \"system_u:object_r:ssh_server_packet_t:s0\"
    nft list secmarks

    # set the secmark
    nft add rule inet filter input tcp dport 22 meta secmark set sshtag

    # map usage
    nft add map inet filter secmapping { type inet_service : secmark \; }
    nft add element inet filter secmapping { 22 : sshtag }
    nft list maps
    nft list map inet filter secmapping
    nft add rule inet filter input meta secmark set tcp dport map @secmapping

[ Original patch based on v0.9.0. Rebase on top on git HEAD. --pablo ]

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Fix memleak in dup_stmt_json()
Phil Sutter [Fri, 12 Oct 2018 15:50:15 +0000 (17:50 +0200)] 
json: Fix memleak in dup_stmt_json()

The variable 'root' is always assigned to after initialization, so there
is no point in initializing it upon declaration.

Fixes: e70354f53e9f6 ("libnftables: Implement JSON output support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoparser_json: Fix for ineffective family value checks
Phil Sutter [Fri, 12 Oct 2018 15:23:24 +0000 (17:23 +0200)] 
parser_json: Fix for ineffective family value checks

Since handle->family is unsigned, checking for value < 0 never yields
true. Overcome this by changing parse_family() to return an error code
and write the parsed family value into a pointer passed as parameter.

The above change required a bit more cleanup to avoid passing pointers
to signed variables to the function. Also leverage json_parse_family() a
bit more to reduce code side.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agolibnftables: Fix memleak in nft_parse_bison_filename()
Phil Sutter [Fri, 12 Oct 2018 11:22:55 +0000 (13:22 +0200)] 
libnftables: Fix memleak in nft_parse_bison_filename()

Allocated scanner object leaks when returning to caller. For some odd
reason, this was missed by the commit referenced below.

Fixes: bd82e03e15df8 ("libnftables: Move scanner object into struct nft_ctx")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoFix memleak in netlink_parse_fwd() error path
Phil Sutter [Fri, 12 Oct 2018 10:54:09 +0000 (12:54 +0200)] 
Fix memleak in netlink_parse_fwd() error path

Make sure allocated 'stmt' is freed before returning to caller.

Fixes: 30d45266bf38b ("expr: extend fwd statement to support address and family")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: monitor: Test JSON output as well
Phil Sutter [Thu, 11 Oct 2018 15:49:01 +0000 (17:49 +0200)] 
tests: monitor: Test JSON output as well

Enhance monitor test suite to test check JSON output as well. Note that
for now there is no support for --echo output testing with JSON.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomonitor: Use libnftables JSON output
Phil Sutter [Thu, 11 Oct 2018 15:49:00 +0000 (17:49 +0200)] 
monitor: Use libnftables JSON output

This switches 'nft monitor' JSON output from using libnftnl's to
libnftables' implementation.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomonitor: Fix printing of ct objects
Phil Sutter [Thu, 11 Oct 2018 15:48:59 +0000 (17:48 +0200)] 
monitor: Fix printing of ct objects

Monitor output is supposed to be single lined without tabs, but ct
object were printed with newlines and tabs hard-coded. Fixing this
wasn't too hard given that there is 'stmt_separator' to also include
semi-colons where required if newline was removed.

A more obvious mistake was position of object type in monitor output:
Like with other object types, it has to occur between command and table
spec. As a positive side-effect, this aligns ct objects better with
others (see obj_type_name_array for instance).

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomonitor: Drop 'update table' and 'update chain' cases
Phil Sutter [Thu, 11 Oct 2018 15:48:58 +0000 (17:48 +0200)] 
monitor: Drop 'update table' and 'update chain' cases

There seems to be no situation where this comes to play. Also, since
there is no 'nft update table/chain' command, this is inconsistent with
input.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomonitor: Drop fake XML support
Phil Sutter [Thu, 11 Oct 2018 15:48:57 +0000 (17:48 +0200)] 
monitor: Drop fake XML support

Since libnftnl doesn't support XML formatting, pretending to do so in
nft monitor is pointless.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Add ct timeout support
Phil Sutter [Thu, 11 Oct 2018 15:48:56 +0000 (17:48 +0200)] 
json: Add ct timeout support

Add support for printing and parsing ct timeout objects to JSON API.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agojson: Drop unused symbolic_constant_json() stub
Phil Sutter [Thu, 11 Oct 2018 15:48:55 +0000 (17:48 +0200)] 
json: Drop unused symbolic_constant_json() stub

This seems like a left-over from day 1: Said function is static in
json.c, so there is no point in providing a stub when compiling with
JSON disabled.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests/py: Add missing JSON bits for inet/meta.t
Phil Sutter [Thu, 11 Oct 2018 15:48:54 +0000 (17:48 +0200)] 
tests/py: Add missing JSON bits for inet/meta.t

Those were forgotten when renaming meta secpath to meta ipsec.

Fixes: 8f55ed41d0070 ("src: rename meta secpath to meta ipsec")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosegtree: set proper error cause on existing elements
Pablo Neira Ayuso [Wed, 10 Oct 2018 17:19:18 +0000 (19:19 +0200)] 
segtree: set proper error cause on existing elements

Adding new elements result in a confusing "Success" error message.

 # nft add element x y { 0-3 }
 [...]
 Error: Could not process rule: Success
 add element x y { 0-3 }
 ^^^^^^^^^^^^^^^^^^^^^^^^

after this patch, this reports:

 Error: Could not process rule: File exists
 add element x y { 0-3 }
 ^^^^^^^^^^^^^^^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosegtree: incorrect handling of last element in get_set_decompose()
Pablo Neira Ayuso [Wed, 10 Oct 2018 13:41:04 +0000 (15:41 +0200)] 
segtree: incorrect handling of last element in get_set_decompose()

Add range to the list of matching elements.

Fixes: 95629758a5ec ("segtree: bogus range via get set element on existing elements")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: remove netlink_flush_chain()
Pablo Neira Ayuso [Wed, 10 Oct 2018 13:10:16 +0000 (15:10 +0200)] 
src: remove netlink_flush_chain()

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: remove netlink_flush_table()
Pablo Neira Ayuso [Wed, 10 Oct 2018 13:08:25 +0000 (15:08 +0200)] 
src: remove netlink_flush_table()

Just a simple wrapper function, replace it by direct call to
mnl_nft_rule_del().

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: remove alloc_nftnl_set()
Pablo Neira Ayuso [Wed, 10 Oct 2018 12:17:44 +0000 (14:17 +0200)] 
mnl: remove alloc_nftnl_set()

We can remove alloc_nftnl_set() and consolidate infrastructure in the
src/mnl.c file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: remove alloc_nftnl_rule()
Pablo Neira Ayuso [Wed, 10 Oct 2018 11:30:12 +0000 (13:30 +0200)] 
mnl: remove alloc_nftnl_rule()

We can remove alloc_nftnl_rule() and consolidate infrastructure in the
src/mnl.c file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: remove alloc_nftnl_chain()
Pablo Neira Ayuso [Wed, 26 Sep 2018 15:57:01 +0000 (17:57 +0200)] 
mnl: remove alloc_nftnl_chain()

The netlink layer sits in between the mnl and the rule layers, remove
it. We can remove alloc_nftnl_chain() and consolidate infrastructure in
the src/mnl.c file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agomnl: remove alloc_nftnl_table()
Pablo Neira Ayuso [Wed, 26 Sep 2018 14:20:08 +0000 (16:20 +0200)] 
mnl: remove alloc_nftnl_table()

The netlink layer sits in between the mnl and the rule layers, remove
it. We can remove alloc_nftnl_table() and consolidate infrastructure in
the src/mnl.c file.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: get rid of netlink_genid_get()
Pablo Neira Ayuso [Fri, 28 Sep 2018 12:55:56 +0000 (14:55 +0200)] 
src: get rid of netlink_genid_get()

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonetlink: remove markup json parsing code
Pablo Neira Ayuso [Wed, 26 Sep 2018 14:23:19 +0000 (16:23 +0200)] 
netlink: remove markup json parsing code

We have better json support these days, remove libnftnl json support.

While at it, remove test file for this too.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoparser_bison: Fix for ECN keyword in LHS of relational
Phil Sutter [Fri, 24 Aug 2018 11:26:57 +0000 (13:26 +0200)] 
parser_bison: Fix for ECN keyword in LHS of relational

Of all possible TCP flags, 'ecn' is special since it is recognized by
lex as a keyword (there is a a field in IPv4 and IPv6 headers with the
same name). Therefore it is listed in keyword_expr, but that was
sufficient for RHS only. The following statement reproduces the issue:

| tcp flags & (syn | ecn) == (syn | ecn)

The solution is to limit binop expressions to accept an RHS expression
on RHS ("real" LHS expressions don't make much sense there anyway),
which then allows keyword_expr to occur there. In order to maintain the
recursive behaviour if braces are present, allow primary_rhs_expr to
consist of a basic_rhs_expr enclosed in braces. This in turn requires
for braced RHS part in relational_expr to be dropped, otherwise bison
complains about shift/reduce conflict.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosegtree: stop iteration on existing elements in case range is found
Pablo Neira Ayuso [Wed, 3 Oct 2018 14:19:47 +0000 (16:19 +0200)] 
segtree: stop iteration on existing elements in case range is found

No need to keep iterating once the range object has been allocated.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agorule: fix memleak in do_get_setelems()
Pablo Neira Ayuso [Wed, 3 Oct 2018 14:05:32 +0000 (16:05 +0200)] 
rule: fix memleak in do_get_setelems()

Release set and elements in case of error.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosegtree: memleak in get_set_decompose()
Pablo Neira Ayuso [Wed, 3 Oct 2018 10:16:40 +0000 (12:16 +0200)] 
segtree: memleak in get_set_decompose()

Release set content on error. Moreover, release input set content in
case we finally manage to decompose it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosegtree: disantangle get_set_interval_end()
Pablo Neira Ayuso [Wed, 3 Oct 2018 10:09:09 +0000 (12:09 +0200)] 
segtree: disantangle get_set_interval_end()

This function overrides the left pointer. Instead update this function
to return the range that we found to enclose the left element. Note that
we may not find a closing right element - therefore, it is a standalone
element - in that case this function returns NULL.

Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosegtree: bogus range via get set element on existing elements
Pablo Neira Ayuso [Mon, 1 Oct 2018 12:51:24 +0000 (14:51 +0200)] 
segtree: bogus range via get set element on existing elements

 table ip x {
        set y {
                type inet_service
                flags interval
                elements = { 10, 20-30, 40, 50-60 }
        }
 }

 # nft get element x y { 20-40 }
 table ip x {
        set y {
                type inet_service
                flags interval
                elements = { 20-40 }
        }
 }

20 and 40 exist in the tree, but they are part of different ranges.
This patch adds a new get_set_decompose() function to validate that the
left and the right side of the range.

Reported-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests: shell: Test 'get element' command
Phil Sutter [Fri, 28 Sep 2018 16:17:31 +0000 (18:17 +0200)] 
tests: shell: Test 'get element' command

This command is currently broken when used in sets with ranges. Test
various variants against known data and check if output is as expected.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoinclude: add missing xfrm.h to Makefile.am
Fernando Fernandez Mancera [Sun, 30 Sep 2018 09:09:30 +0000 (11:09 +0200)] 
include: add missing xfrm.h to Makefile.am

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: shell: Improve performance of 0021prio_0
Phil Sutter [Tue, 25 Sep 2018 12:24:16 +0000 (14:24 +0200)] 
tests: shell: Improve performance of 0021prio_0

This test called nft binary 391 times and took about 38s to complete on
my testing VM. Improve this by writing all commands into a temporary
file for processing in a single nft call. Reduces run-time to about 4s.

Interestingly, piping the sub-process's output directly into 'nft -f -'
leads to spurious errors (parser complaining about perfectly fine
syntax). It seems like handling large input this way is not possible.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: shell: Improve gen_chains() in 0021prio_0
Phil Sutter [Tue, 25 Sep 2018 12:24:15 +0000 (14:24 +0200)] 
tests: shell: Improve gen_chains() in 0021prio_0

Enhance the function to accept an optional fourth parameter specifying
the device name, then use it for netdev family. Also remove dubled empty
lines and instead put together what belongs together.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: shell: Drop one-time use variables in 0021prio_0
Phil Sutter [Tue, 25 Sep 2018 12:24:14 +0000 (14:24 +0200)] 
tests: shell: Drop one-time use variables in 0021prio_0

There is really no point in declaring a variable which is used just
once. Also mark function local variables as such to make sure they don't
overwrite global ones.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: shell: Fix indenting in 0021prio_0
Phil Sutter [Tue, 25 Sep 2018 12:24:13 +0000 (14:24 +0200)] 
tests: shell: Fix indenting in 0021prio_0

Pointless indenting doesn't increase readability, merely makes the
script seem more complicated than it actually is.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agoparser_bison: Fix for chain prio name 'out'
Phil Sutter [Tue, 25 Sep 2018 12:24:12 +0000 (14:24 +0200)] 
parser_bison: Fix for chain prio name 'out'

Since 'out' is defined as a keyword in scanner.l, using it as a chain
priority name without quotes is not possible. Fix this by introducing
'extended_prio_name' in bison which may be either a string (as before)
or OUT, which is then converted into a string.

Fixes: c8a0e8c90e2d1 ("src: Set/print standard chain prios with textual names")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agosrc: add ipsec (xfrm) expression
Máté Eckl [Wed, 5 Sep 2018 09:16:44 +0000 (11:16 +0200)] 
src: add ipsec (xfrm) expression

This allows matching on ipsec tunnel/beet addresses in xfrm state
associated with a packet, ipsec request id and the SPI.

Examples:

 ipsec in ip saddr 192.168.1.0/24
 ipsec out ip6 daddr @endpoints
 ipsec in spi 1-65536

Joint work with Florian Westphal.

Cc: Máté Eckl <ecklm94@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agosrc: rename meta secpath to meta ipsec
Florian Westphal [Wed, 5 Sep 2018 09:16:43 +0000 (11:16 +0200)] 
src: rename meta secpath to meta ipsec

for symmetry with 'rt ipsec'.  "meta secpath" still works.

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: rt: add support to check if route will perform ipsec transformation
Florian Westphal [Wed, 5 Sep 2018 09:16:42 +0000 (11:16 +0200)] 
src: rt: add support to check if route will perform ipsec transformation

Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agodoc: Re-work RULES:add/insert/replace to read better.
Duncan Roe [Fri, 21 Sep 2018 01:54:27 +0000 (11:54 +1000)] 
doc: Re-work RULES:add/insert/replace to read better.

It was tempting to remove "position" from the synopsis,
but have left that for another patch.

Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoevaluate: throw distinct error if map exists but contains no objects
Florian Westphal [Thu, 20 Sep 2018 15:21:45 +0000 (17:21 +0200)] 
evaluate: throw distinct error if map exists but contains no objects

nft would throw misleading error in case map exists but doesn't contain
expected objects.

nft add rule filter in ct helper set tcp dport map @foo
Error: Expression is not a map
add rule filter in ct helper set tcp dport map @foo
                                               ^^^^
nft list table filter
table ip filter {
        map foo {
                type inet_service : ifname
        }
...

clarify this.

Reported-by: Christian Göttsche <cgzones@googlemail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agodoc: Review man page building in Makefile.am
Phil Sutter [Fri, 14 Sep 2018 09:00:23 +0000 (11:00 +0200)] 
doc: Review man page building in Makefile.am

Previously, changes to any of the included adoc snippets in nft.txt were
not detected and hence the man page not updated (unless 'make clean' was
called). It seems like the '.txt.8' target only considers foo.txt when
trying to generate foo.8, so get rid of that and introduce a dedicated
target for nft.8.

While doing so, apply a few other minor changes:

* Although nft.8 target has to list all included adoc snippets as a
  dependency, it is sufficient to call a2x with the main one (i.e.,
  nft.txt) only.

* Keep common a2x parameters in a variable.

* Use ${A2X} everywhere and hide all calls behind ${AM_V_GEN}, not just
  the one for nft.8.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agonft.8: Update meta pkt_type value description
Phil Sutter [Fri, 14 Sep 2018 09:00:14 +0000 (11:00 +0200)] 
nft.8: Update meta pkt_type value description

Commit 8a7f6de536408 ("meta: fix pkttype name and add 'other' symbol")
deprecated pkt_type value 'unicast' (for it being misleading) and
introduced 'host' and 'other' but it did not update documentation
accordingly. Fix this by replacing 'unicast' with 'host' in
documentation and adding 'other'.

While being at it, make sure these literal values are recognized as
such: Put them in all lower-case (as required by the parser) and in bold
font (to stand out a bit more).

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agotests/py: Fix JSON for icmp*.t
Phil Sutter [Tue, 11 Sep 2018 20:14:27 +0000 (22:14 +0200)] 
tests/py: Fix JSON for icmp*.t

A recent change to ip/icmp.t and ip6/icmpv6.t did not update JSON
equivalents accordingly, fix this.

Fixes: 0f44d4f627535 ("proto: fix icmp/icmpv6 code datatype")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agojson: Print range expressions numerically
Phil Sutter [Tue, 11 Sep 2018 20:14:26 +0000 (22:14 +0200)] 
json: Print range expressions numerically

This applies the same change as in commit 85b1e3c0052ef ("src: Always
print range expressions numerically") to JSON output for consistency.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agojson: Make inet_service_type_json() respect literal level
Phil Sutter [Tue, 11 Sep 2018 20:14:25 +0000 (22:14 +0200)] 
json: Make inet_service_type_json() respect literal level

This brings inet_service_type_json() on par with
inet_service_type_print(). Despite datatype_print()'s ability to use the
'print' callback, a dedicated 'json' callback is required to make port
numbers appear as numbers in JSON output instead of strings. Therefore
go with a bit of code duplication here.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agojson: Fix datatype_json() for literal level
Phil Sutter [Tue, 11 Sep 2018 20:14:24 +0000 (22:14 +0200)] 
json: Fix datatype_json() for literal level

If a datatype doesn't provide a 'json' callback, datatype_json() uses
fmemopen() to grab the output from 'print' callback. When doing so,
reuse the existing output context instead of creating a dedicated one to
make sure all output-related settings are exactly as expected.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests/py: Check differing rule output for sanity
Phil Sutter [Wed, 29 Aug 2018 14:33:38 +0000 (16:33 +0200)] 
tests/py: Check differing rule output for sanity

If an added rule's listing differs from the input (either expected or
not), reinsert that output and check payload again to make sure the
asymmetry doesn't lead to (internal) changes in ruleset.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agosrc: Fix literal check for inet_service type
Phil Sutter [Mon, 10 Sep 2018 14:18:10 +0000 (16:18 +0200)] 
src: Fix literal check for inet_service type

Since literal option is supposed to be a level, matching for equality is
not correct here since the level may be higher than NFT_LITERAL_PORT.

This fixes for ports being printed numerically if '-l' option was given
twice.

Fixes: b0f6a45b25dd1 ("src: add --literal option")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 years agoproto: fix icmp/icmpv6 code datatype
Florian Westphal [Tue, 4 Sep 2018 11:53:59 +0000 (13:53 +0200)] 
proto: fix icmp/icmpv6 code datatype

Andrew A. Sabitov says:
  I'd like to use a set (concatenation) of icmpv6 type and icmpv6 code
  and check incoming icmpv6 traffic against it:

  add set inet fw in_icmpv6_types { type icmpv6_type . icmpv6_code; }
  add element inet fw in_icmpv6_types { 1 . 0 } # no route to destination
  add element inet fw in_icmpv6_types { 1 . 1 } # communication with destination administratively prohibited
  # ...

 add rule inet fw in_icmpv6 icmpv6 type . icmpv6 code @in_icmpv6_types \
   limit rate 15/minute accept

yields:
Error: can not use variable sized data types (integer) in concat expressions
        icmpv6 type . icmpv6 code @in_icmpv6_types
         ~~~~~~~~~~~~~~^^^^^^^^^^^

Change 'code' type to the icmp/icmpv6 code type.
Needs minor change to test suite as nft will now display
human-readable names instead of numeric codes.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1276
Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests: fix json output for osf, socket and tproxy expressions
Florian Westphal [Mon, 3 Sep 2018 14:15:22 +0000 (16:15 +0200)] 
tests: fix json output for osf, socket and tproxy expressions

Signed-off-by: Florian Westphal <fw@strlen.de>
6 years agotests/py: Make nft-test.py a little more robust
Phil Sutter [Wed, 29 Aug 2018 14:33:39 +0000 (16:33 +0200)] 
tests/py: Make nft-test.py a little more robust

When adding a new test, missing payload file causes nft-test.py to choke
due to accessing undeclared variables. Fix this by making sure relevant
variables are declared outside of try-catch blocks.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>
6 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>