]> git.ipfire.org Git - thirdparty/nftables.git/log
thirdparty/nftables.git
2 years agobuild: Bump version to v0.9.9 v0.9.9
Pablo Neira Ayuso [Tue, 25 May 2021 16:35:56 +0000 (18:35 +0200)] 
build: Bump version to v0.9.9

Update release name based on the Fearless Fosdick series: Prudence Pimpleton.

Bump dependencies on libnftnl.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agodoc: tiny spelling fix in stateful object section s/an/a
Florian Westphal [Tue, 25 May 2021 15:12:20 +0000 (17:12 +0200)] 
doc: tiny spelling fix in stateful object section s/an/a

Quoting Duncan Roe:
  Tiny nit: suggest "by a unique" instead of "by an unique".
  "a" reads better to this native en-GB speaker at least.

Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agoinclude: missing sctp_chunk.h in Makefile.am
Pablo Neira Ayuso [Tue, 25 May 2021 12:04:36 +0000 (14:04 +0200)] 
include: missing sctp_chunk.h in Makefile.am

Fix make distcheck.

Fixes: 0e3871cfd9a1 ("exthdr: Implement SCTP Chunk matching")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agoexpression: display an error on unknown datatype
Pablo Neira Ayuso [Mon, 24 May 2021 20:05:02 +0000 (22:05 +0200)] 
expression: display an error on unknown datatype

 # nft describe foo
 datatype foo is invalid

Fixes: 21cbab5b6ffe ("expression: extend 'nft describe' to allow listing data types")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agoevaluate: allow == and != in the new shortcut syntax to match for flags
Pablo Neira Ayuso [Mon, 24 May 2021 19:54:36 +0000 (21:54 +0200)] 
evaluate: allow == and != in the new shortcut syntax to match for flags

The flags / mask syntax only allows for ==, !=  and the implicit
operation (which is == in this case).

 # nft add rule x y tcp flags ! syn / syn,ack
 Error: either == or != is allowed
 add rule x y tcp flags ! syn / syn,ack
              ^^^^^^^^^^^^^^^^^^^^^^^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agofiles: improve secmark.nft example
Dominick Grift [Mon, 24 May 2021 09:47:51 +0000 (11:47 +0200)] 
files: improve secmark.nft example

use proper priorities to ensure that ct works properly

Signed-off-by: Dominick Grift <dominick.grift@defensec.nl>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agoexpr_postprocess: Avoid an unintended fall through
Phil Sutter [Thu, 20 May 2021 13:11:37 +0000 (15:11 +0200)] 
expr_postprocess: Avoid an unintended fall through

Parsing a range expression, the switch case fell through to prefix
expression case, thereby recursing once more for expr->left. This seems
not to have caused harm, but is certainly not intended.

Fixes: ee4391d0ac1e7 ("nat: transform range to prefix expression when possible")
Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agorule: skip exact matches on fuzzy lookup
Pablo Neira Ayuso [Wed, 19 May 2021 20:57:13 +0000 (22:57 +0200)] 
rule: skip exact matches on fuzzy lookup

The fuzzy lookup is exercised from the error path, when no object is
found. Remove branch that checks for exact matching since that should
not ever happen.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agocmd: typo in chain fuzzy lookup
Pablo Neira Ayuso [Wed, 19 May 2021 20:27:42 +0000 (22:27 +0200)] 
cmd: typo in chain fuzzy lookup

Refer to chain, not table.

Error: No such file or directory; did you mean table ‘z’ in family ip?
add chain x y { type filter nat prerouting priority dstnat; }
            ^

It should say instead:

Error: No such file or directory; did you mean chain ‘z’ in table ip ‘x’?

[ Florian added args check for fmt to the netlink_io_error() prototype. ]

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agolibnftables: location-based error reporting for chain type
Pablo Neira Ayuso [Wed, 19 May 2021 19:57:41 +0000 (21:57 +0200)] 
libnftables: location-based error reporting for chain type

Store the location of the chain type for better error reporting.

Several users that compile custom kernels reported that error
reporting is misleading when accidentally selecting
CONFIG_NFT_NAT=n.

After this patch, a better hint is provided:

 # nft 'add chain x y { type nat hook prerouting priority dstnat; }'
 Error: Could not process rule: No such file or directory
 add chain x y { type nat hook prerouting priority dstnat; }
                      ^^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agodoc: nft.8: Extend monitor description by trace
Phil Sutter [Wed, 19 May 2021 11:12:48 +0000 (13:12 +0200)] 
doc: nft.8: Extend monitor description by trace

Briefly describe 'nft monitor trace' command functionality.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agodoc: document cgroupv2
Pablo Neira Ayuso [Wed, 19 May 2021 09:18:28 +0000 (11:18 +0200)] 
doc: document cgroupv2

This patch adds documentation for cgroupsv2 support.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agoexthdr: Implement SCTP Chunk matching
Phil Sutter [Tue, 4 May 2021 11:41:38 +0000 (13:41 +0200)] 
exthdr: Implement SCTP Chunk matching

Extend exthdr expression to support scanning through SCTP packet chunks
and matching on fixed fields' values.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Florian Westphal <fw@strlen.de>
2 years agojson: Simplify non-tcpopt exthdr printing a bit
Phil Sutter [Tue, 4 May 2021 11:18:11 +0000 (13:18 +0200)] 
json: Simplify non-tcpopt exthdr printing a bit

This was just duplicate code apart from the object's name.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agoscanner: sctp: Move to own scope
Phil Sutter [Tue, 4 May 2021 11:06:32 +0000 (13:06 +0200)] 
scanner: sctp: Move to own scope

This isolates only "vtag" token for now.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Florian Westphal <fw@strlen.de>
2 years agodatatype: skip cgroupv2 rootfs in listing
Pablo Neira Ayuso [Tue, 18 May 2021 12:31:58 +0000 (14:31 +0200)] 
datatype: skip cgroupv2 rootfs in listing

cgroupv2 path is expressed from the /sys/fs/cgroup folder, update
listing to skip it.

 # nft add rule x y socket cgroupv2 level 1 "user.slice" counter
 # nft list ruleset
 table ip x {
        chain y {
                type filter hook input priority filter; policy accept;
                socket cgroupv2 level 1 "user.slice" counter
        }
 }

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agosrc: use PRIu64 format
Pablo Neira Ayuso [Tue, 18 May 2021 11:45:05 +0000 (13:45 +0200)] 
src: use PRIu64 format

Fix the following compilation warnings on x86_32.

datatype.c: In function ‘cgroupv2_type_print’:
datatype.c:1387:22: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=]
   nft_print(octx, "%lu", id);
                    ~~^   ~~
                    %llu

meta.c: In function ‘date_type_print’:
meta.c:411:21: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Wformat=]
  nft_print(octx, "%lu", tstamp);
                   ~~^   ~~~~~~
                   %llu

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agoparser_bison: add shortcut syntax for matching flags without binary operations
Pablo Neira Ayuso [Wed, 12 May 2021 23:34:01 +0000 (01:34 +0200)] 
parser_bison: add shortcut syntax for matching flags without binary operations

This patch adds the following shortcut syntax:

expression flags / flags

instead of:

expression and flags == flags

For example:

tcp flags syn,ack / syn,ack,fin,rst
                  ^^^^^^^   ^^^^^^^^^^^^^^^
                   value         mask

instead of:

tcp flags and (syn|ack|fin|rst) == syn|ack

The second list of comma-separated flags represents the mask which are
examined and the first list of comma-separated flags must be set.

You can also use the != operator with this syntax:

tcp flags != fin,rst / syn,ack,fin,rst

This shortcut is based on the prefix notation, but it is also similar to
the iptables tcp matching syntax.

This patch introduces the flagcmp expression to print the tcp flags in
this new notation. The delinearize path transforms the binary expression
to this new flagcmp expression whenever possible.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agocache: check errno before invoking cache_release()
Marco Oliverio [Thu, 13 May 2021 14:10:32 +0000 (16:10 +0200)] 
cache: check errno before invoking cache_release()

if genid changes during cache_init(), check_genid() sets errno to EINTR to force
a re-init of the cache.

cache_release() may inadvertly change errno by calling free().  Indeed free()
may invoke madvise() that changes errno to ENOSYS on system where kernel is
configured without support for this syscall.

Signed-off-by: Marco Oliverio <marco.oliverio@tanaza.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agonetlink_delinearize: fix binary operation postprocessing with sets
Pablo Neira Ayuso [Wed, 12 May 2021 23:42:13 +0000 (01:42 +0200)] 
netlink_delinearize: fix binary operation postprocessing with sets

If the right-hand side expression of the binary expression is a set,
then, skip the postprocessing step otherwise the tests/py report the
following warning:

 # ./nft-test.py inet/tcp.t
 inet/tcp.t: WARNING: line 80: 'add rule ip test-ip4 input tcp flags & (syn|fin) == (syn|fin)': 'tcp flags & (fin | syn) == fin | syn' mismatches 'tcp flags ! fin,syn'
 inet/tcp.t: WARNING: line 83: 'add rule ip test-ip4 input tcp flags & (fin | syn | rst | psh | ack | urg) == { fin, ack, psh | ack, fin | psh | ack }': 'tcp flags & (fin | syn | rst | psh | ack | urg) == { fin, ack, psh | ack, fin | psh | ack }' mismatches 'tcp flags ! fin,syn,rst,psh,ack,urg'

This listing is not correct.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agotests: shell: don't assume fixed handle value in cache/0008_delete_by_handle_0
Pablo Neira Ayuso [Wed, 12 May 2021 14:19:56 +0000 (16:19 +0200)] 
tests: shell: don't assume fixed handle value in cache/0008_delete_by_handle_0

This test is occasionally reporting warning in one of my test boxes.
Update this test to extract the handle from ruleset listing, use
rudimentary invocation of the cut command to work around this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agoevaluate: don't crash on set definition with incorrect datatype
Pablo Neira Ayuso [Mon, 10 May 2021 16:52:47 +0000 (18:52 +0200)] 
evaluate: don't crash on set definition with incorrect datatype

Cache updates have resurrected the bug described in 5afa5a164ff1
("evaluate: check for NULL datatype in rhs in lookup expr").

This is triggered by testcases/cache/0008_delete_by_handle_0.

Fixes: df48e56e987f ("cache: add hashtable cache for sets")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agosrc: add set element catch-all support
Pablo Neira Ayuso [Mon, 10 May 2021 16:52:45 +0000 (18:52 +0200)] 
src: add set element catch-all support

Add a catchall expression (EXPR_SET_ELEM_CATCHALL).

Use the asterisk (*) to represent the catch-all set element, e.g.

 table x {
     set y {
type ipv4_addr
counter
elements = { 1.2.3.4 counter packets 0 bytes 0, * counter packets 0 bytes 0 }
     }
 }

Special handling for segtree: zap the catch-all element from the set
element list and re-add it after processing.

Remove wildcard_expr deadcode in src/parser_bison.y

This patch also adds several tests for the tests/py and tests/shell
infrastructures.

Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agoparser_bison: add set_elem_key_expr rule
Pablo Neira Ayuso [Mon, 10 May 2021 16:52:40 +0000 (18:52 +0200)] 
parser_bison: add set_elem_key_expr rule

Add a rule to specify the set key expression in preparation for the
catch-all element support.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
2 years agodoc: Reduce size of NAT statement synopsis
Phil Sutter [Thu, 6 May 2021 08:12:45 +0000 (10:12 +0200)] 
doc: Reduce size of NAT statement synopsis

Introduce non-terminals representing address and port which may
represent ranges as well. Combined with dropping the distinction between
PR_FLAGS and PRF_FLAGS, all the lines for each nat statement type can be
combined.

Signed-off-by: Phil Sutter <phil@nwl.cc>
2 years agotests: Introduce 0043_concatenated_ranges_1 for subnets of different sizes
Stefano Brivio [Wed, 5 May 2021 22:23:14 +0000 (00:23 +0200)] 
tests: Introduce 0043_concatenated_ranges_1 for subnets of different sizes

The report from https://bugzilla.netfilter.org/show_bug.cgi?id=1520
showed a display issue with particular IPv6 mask lengths in elements
of sets with concatenations. Make sure we cover insertion and listing
of different mask lengths in concatenated set elements for IPv4 and
IPv6.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
2 years agosegtree: Fix range_mask_len() for subnet ranges exceeding unsigned int
Stefano Brivio [Wed, 5 May 2021 22:23:13 +0000 (00:23 +0200)] 
segtree: Fix range_mask_len() for subnet ranges exceeding unsigned int

As concatenated ranges are fetched from kernel sets and displayed to
the user, range_mask_len() evaluates whether the range is suitable for
display as netmask, and in that case it calculates the mask length by
right-shifting the endpoints until no set bits are left, but in the
existing version the temporary copies of the endpoints are derived by
copying their unsigned int representation, which doesn't suffice for
IPv6 netmask lengths, in general.

PetrB reports that, after inserting a /56 subnet in a concatenated set
element, it's listed as a /64 range. In fact, this happens for any
IPv6 mask shorter than 64 bits.

Fix this issue by simply sourcing the range endpoints provided by the
caller and setting the temporary copies with mpz_init_set(), instead
of fetching the unsigned int representation. The issue only affects
displaying of the masks, setting elements already works as expected.

Reported-by: PetrB <petr.boltik@gmail.com>
Bugzilla: https://bugzilla.netfilter.org/show_bug.cgi?id=1520
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agosrc: add cgroupsv2 support
Pablo Neira Ayuso [Tue, 20 Apr 2021 23:26:46 +0000 (01:26 +0200)] 
src: add cgroupsv2 support

Add support for matching on the cgroups version 2.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoevaluate: remove object from cache on delete object command
Pablo Neira Ayuso [Thu, 29 Apr 2021 16:15:08 +0000 (18:15 +0200)] 
evaluate: remove object from cache on delete object command

Update the cache to remove this object from the evaluation phase.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoevaluate: remove flowtable from cache on delete flowtable command
Pablo Neira Ayuso [Thu, 29 Apr 2021 16:07:34 +0000 (18:07 +0200)] 
evaluate: remove flowtable from cache on delete flowtable command

Update the cache to remove this flowtable from the evaluation phase.
Add flowtable_cache_del() function for this purpose.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoevaluate: remove set from cache on delete set command
Pablo Neira Ayuso [Thu, 29 Apr 2021 15:49:25 +0000 (17:49 +0200)] 
evaluate: remove set from cache on delete set command

Update the cache to remove this set from the evaluation phase.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoevaluate: remove chain from cache on delete chain command
Pablo Neira Ayuso [Thu, 29 Apr 2021 15:41:25 +0000 (17:41 +0200)] 
evaluate: remove chain from cache on delete chain command

Update the cache to remove this chain from the evaluation phase. Add
chain_cache_del() function for this purpose.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: add hashtable cache for table
Pablo Neira Ayuso [Thu, 29 Apr 2021 20:23:05 +0000 (22:23 +0200)] 
cache: add hashtable cache for table

Add a hashtable for fast table lookups.

Tables that reside in the cache use the table->cache_hlist and
table->cache_list heads.

Table that are created from command line / ruleset are also added
to the cache.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoevaluate: add object to the cache
Pablo Neira Ayuso [Thu, 15 Apr 2021 12:00:26 +0000 (14:00 +0200)] 
evaluate: add object to the cache

If the cache does not contain this object that is defined in this batch,
add it to the cache. This allows for references to this new object in
the same batch.

This patch also adds missing handle_merge() to set the object name,
otherwise object name is NULL and obj_cache_find() crashes.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: missing table cache for several policy objects
Pablo Neira Ayuso [Thu, 15 Apr 2021 12:00:22 +0000 (14:00 +0200)] 
cache: missing table cache for several policy objects

Populate the cache with tables for several policy objects types.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoevaluate: add flowtable to the cache
Pablo Neira Ayuso [Thu, 15 Apr 2021 12:00:20 +0000 (14:00 +0200)] 
evaluate: add flowtable to the cache

If the cache does not contain this flowtable that is defined in this
batch, then add it to the cache. This allows for references to this new
flowtable in the same batch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoevaluate: add set to the cache
Pablo Neira Ayuso [Thu, 15 Apr 2021 12:00:16 +0000 (14:00 +0200)] 
evaluate: add set to the cache

If the cache does not contain the set that is defined in this batch, add
it to the cache. This allows for references to this new set in the same
batch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: add set_cache_del() and use it
Pablo Neira Ayuso [Thu, 15 Apr 2021 13:06:07 +0000 (15:06 +0200)] 
cache: add set_cache_del() and use it

Update set_cache_del() from the monitor path to remove sets
in the cache.

Fixes: df48e56e987f ("cache: add hashtable cache for sets")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: add hashtable cache for flowtable
Pablo Neira Ayuso [Thu, 29 Apr 2021 20:19:07 +0000 (22:19 +0200)] 
cache: add hashtable cache for flowtable

Add flowtable hashtable cache.

Actually I am not expecting that many flowtables to benefit from the
hashtable to be created by streamline this code with tables, chains,
sets and policy objects.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: add hashtable cache for object
Pablo Neira Ayuso [Thu, 29 Apr 2021 20:09:15 +0000 (22:09 +0200)] 
cache: add hashtable cache for object

This patch adds a hashtable for object lookups.

This patch also splits table->objs in two:

- Sets that reside in the cache are stored in the new
  tables->cache_obj and tables->cache_obj_ht.

- Set that defined via command line / ruleset file reside in
  tables->obj.

Sets in the cache (already in the kernel) are not placed in the
table->objs list.

By keeping separated lists, objs defined via command line / ruleset file
can be added to cache.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agosrc: consolidate object cache infrastructure
Pablo Neira Ayuso [Thu, 29 Apr 2021 19:55:34 +0000 (21:55 +0200)] 
src: consolidate object cache infrastructure

This patch consolidates the object cache infrastructure. Update set and
chains to use it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agosrc: consolidate nft_cache infrastructure
Pablo Neira Ayuso [Thu, 29 Apr 2021 18:29:09 +0000 (20:29 +0200)] 
src: consolidate nft_cache infrastructure

- prepend nft_ prefix to nft_cache API and internal functions
- move declarations to cache.h (and remove redundant declarations)
- move struct nft_cache definition to cache.h

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agosrc: pass chain name to chain_cache_find()
Pablo Neira Ayuso [Thu, 29 Apr 2021 18:04:55 +0000 (20:04 +0200)] 
src: pass chain name to chain_cache_find()

You can identify chains through the unique handle in deletions, update
this interface to take a string instead of the handle to prepare for
the introduction of 64-bit handle chain lookups.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agorule: skip fuzzy lookup for unexisting 64-bit handle
Pablo Neira Ayuso [Thu, 29 Apr 2021 23:01:17 +0000 (01:01 +0200)] 
rule: skip fuzzy lookup for unexisting 64-bit handle

Deletion by handle, if incorrect, should not exercise the misspell
lookup functions.

Fixes: 3a0e07106f66 ("src: combine extended netlink error reporting with mispelling support")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agosrc: unbreak deletion by table handle
Pablo Neira Ayuso [Thu, 29 Apr 2021 22:30:05 +0000 (00:30 +0200)] 
src: unbreak deletion by table handle

Use NFTA_TABLE_HANDLE instead of NFTA_TABLE_NAME to refer to the
table 64-bit unique handle.

Fixes: 7840b9224d5b ("evaluate: remove table from cache on delete table")
Fixes: f8aec603aa7e ("src: initial extended netlink error reporting")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agotests: shell: remove missing modules
Pablo Neira Ayuso [Thu, 29 Apr 2021 16:20:53 +0000 (18:20 +0200)] 
tests: shell: remove missing modules

Update run-tests.sh to remove the following modules:

- nft_reject_netdev
- nft_xfrm
- nft_synproxy

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoparser_bison: missing relational operation on flag list
Pablo Neira Ayuso [Mon, 19 Apr 2021 09:56:15 +0000 (11:56 +0200)] 
parser_bison: missing relational operation on flag list

Complete e6c32b2fa0b8 ("src: add negation match on singleton bitmask
value") which was missing comma-separated list of flags.

This patch provides a shortcut for:

    tcp flags and fin,rst == 0

which allows to check for the packet whose fin and rst bits are unset:

    # nft add rule x y tcp flags not fin,rst counter

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoparser: allow to load stateful ct connlimit elements in sets
Laura Garcia Liebana [Tue, 13 Apr 2021 09:03:41 +0000 (11:03 +0200)] 
parser: allow to load stateful ct connlimit elements in sets

This patch fixes a syntax error after loading a nft
dump with a set including stateful ct connlimit elements.

Having a nft dump as per below:

table ip nftlb {
set connlimit-set {
type ipv4_addr
size 65535
flags dynamic
elements = { 84.245.120.167 ct count over 20 , 86.111.207.45 ct count over 20 ,
             173.212.220.26 ct count over 20 , 200.153.13.235 ct count over 20  }
}
}

The syntax error is shown when loading the ruleset.

root# nft -f connlimit.nft
connlimit.nft:15997:31-32: Error: syntax error, unexpected ct, expecting comma or '}'
elements = { 84.245.120.167 ct count over 20 , 86.111.207.45 ct count over 20 ,
                            ^^
connlimit.nft:16000:9-22: Error: syntax error, unexpected string
     173.212.220.26 ct count over 20 , 200.153.13.235 ct count over 20  }
     ^^^^^^^^^^^^^^

After applying this patch a kernel panic is raised running
nft_rhash_gc() although no packet reaches the set.

The following patch [0] should be used as well:

4d8f9065830e5 ("netfilter: nftables: clone set element expression template")

Note that the kernel patch will produce the emptying of the
connection tracking, so the restore of the conntrack states
should be considered.

[0]: https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git/commit/?id=4d8f9065830e526c83199186c5f56a6514f457d2

Signed-off-by: Laura Garcia Liebana <nevola@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoevaluate: check if nat statement map specifies a transport header expr
Florian Westphal [Tue, 6 Apr 2021 16:34:19 +0000 (18:34 +0200)] 
evaluate: check if nat statement map specifies a transport header expr

Importing the systemd nat table fails:

table ip io.systemd.nat {
 map map_port_ipport {
   type inet_proto . inet_service : ipv4_addr . inet_service
   elements = { tcp . 8088 : 192.168.162.117 . 80 }
 }
 chain prerouting {
   type nat hook prerouting priority dstnat + 1; policy accept;
    fib daddr type local dnat ip addr . port to meta l4proto . th dport map @map_port_ipport
 }
}
ruleset:9:48-59: Error: transport protocol mapping is only valid after transport protocol match

To resolve this (no transport header base specified), check if the
map itself contains a network base protocol expression.

This allows nft to import the ruleset.
Import still fails with same error if 'inet_service' is removed
from the map, as it should.

Reported-by: Henning Reich <henning.reich@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agomnl: Increase BATCH_PAGE_SIZE to support huge rulesets
Phil Sutter [Wed, 14 Apr 2021 11:47:47 +0000 (13:47 +0200)] 
mnl: Increase BATCH_PAGE_SIZE to support huge rulesets

Apply the same change from iptables-nft to nftables to keep them in
sync with regards to max supported transaction sizes.

Signed-off-by: Phil Sutter <phil@nwl.cc>
3 years agoMakefile: missing owner.h file
Pablo Neira Ayuso [Sat, 3 Apr 2021 18:24:45 +0000 (20:24 +0200)] 
Makefile: missing owner.h file

Add it to include/Makefile.am, this fixes `make distcheck'.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agofiles: move example files away from /etc
Jan Engelhardt [Tue, 30 Mar 2021 14:46:53 +0000 (16:46 +0200)] 
files: move example files away from /etc

As per file-hierarchy(5), /etc is for "system-specific configuration", not
"vendor-supplied default configuration files".

Moreover, the comments in all-in-one.nft say it is an example, and so,
not a vendor config either.

Move it out of /etc.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: bail out if chain list cannot be fetched from kernel
Pablo Neira Ayuso [Fri, 2 Apr 2021 18:48:00 +0000 (20:48 +0200)] 
cache: bail out if chain list cannot be fetched from kernel

Do not report success if chain cache list cannot be built.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: add hashtable cache for sets
Pablo Neira Ayuso [Fri, 2 Apr 2021 18:26:15 +0000 (20:26 +0200)] 
cache: add hashtable cache for sets

This patch adds a hashtable for set lookups.

This patch also splits table->sets in two:

- Sets that reside in the cache are stored in the new
  tables->cache_set and tables->cache_set_ht.

- Set that defined via command line / ruleset file reside in
  tables->set.

Sets in the cache (already in the kernel) are not placed in the
table->sets list.

By keeping separated lists, sets defined via command line / ruleset file
can be added to cache.

Adding 10000 sets, before:

 # time nft -f x
 real    0m6,415s
 user    0m3,126s
 sys     0m3,284s

After:

 # time nft -f x
 real    0m3,949s
 user    0m0,743s
 sys     0m3,205s

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: check for NULL chain in cache_init()
Pablo Neira Ayuso [Thu, 1 Apr 2021 21:15:02 +0000 (23:15 +0200)] 
cache: check for NULL chain in cache_init()

Another process might race to add chains after chain_cache_init().
The generation check does not help since it comes after cache_init().
NLM_F_DUMP_INTR only guarantees consistency within one single netlink
dump operation, so it does not help either (cache population requires
several netlink dump commands).

Let's be safe and do not assume the chain exists in the cache when
populating the rule cache.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: statify chain_cache_dump()
Pablo Neira Ayuso [Thu, 1 Apr 2021 20:25:28 +0000 (22:25 +0200)] 
cache: statify chain_cache_dump()

Only used internally in cache.c

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoevaluate: use chain hashtable for lookups
Pablo Neira Ayuso [Thu, 1 Apr 2021 20:25:24 +0000 (22:25 +0200)] 
evaluate: use chain hashtable for lookups

Instead of the linear list lookup.

Before this patch:

real    0m21,735s
user    0m20,329s
sys     0m1,384s

After:

real    0m10,910s
user    0m9,448s
sys     0m1,434s

chain_lookup() is removed since linear list lookups are only used by the
fuzzy chain name matching for error reporting.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agosrc: split chain list in table
Pablo Neira Ayuso [Thu, 1 Apr 2021 20:19:30 +0000 (22:19 +0200)] 
src: split chain list in table

This patch splits table->lists in two:

- Chains that reside in the cache are stored in the new
  tables->cache_chain and tables->cache_chain_ht. The hashtable chain
  cache allows for fast chain lookups.

- Chains that defined via command line / ruleset file reside in
  tables->chains.

Note that chains in the cache (already in the kernel) are not placed in
the table->chains.

By keeping separated lists, chains defined via command line / ruleset
file can be added to cache.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agocache: rename chain_htable to cache_chain_ht
Pablo Neira Ayuso [Thu, 1 Apr 2021 20:18:29 +0000 (22:18 +0200)] 
cache: rename chain_htable to cache_chain_ht

Rename the hashtable chain that is used for fast cache lookups.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoproto: replace vlan ether type with 8021q
Florian Westphal [Fri, 2 Apr 2021 10:54:53 +0000 (12:54 +0200)] 
proto: replace vlan ether type with 8021q

Previous patches added "8021ad" mnemonic for IEEE 802.1AD frame type.
This adds the 8021q shorthand for the existing 'vlan' frame type.

nft will continue to recognize 'ether type vlan', but listing
will now print 8021q.

Adjust all test cases accordingly.

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agotests: add 8021.AD vlan test cases
Florian Westphal [Thu, 1 Apr 2021 14:08:46 +0000 (16:08 +0200)] 
tests: add 8021.AD vlan test cases

Check nft doesn't remove the explicit '8021ad' type check and that
the expected dependency chains are generated.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agopayload: be careful on vlan dependency removal
Florian Westphal [Thu, 1 Apr 2021 14:08:45 +0000 (16:08 +0200)] 
payload: be careful on vlan dependency removal

'vlan ...' implies 8021Q frame.  In case the expression tests something else
(802.1AD for example) its not an implictly added one, so keep it.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoproto: add 8021ad as mnemonic for IEEE 802.1AD (0x88a8) ether type
Florian Westphal [Thu, 1 Apr 2021 14:08:44 +0000 (16:08 +0200)] 
proto: add 8021ad as mnemonic for IEEE 802.1AD (0x88a8) ether type

Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agosrc: vlan: allow matching vlan id insider 802.1ad frame
Florian Westphal [Thu, 1 Apr 2021 14:08:43 +0000 (16:08 +0200)] 
src: vlan: allow matching vlan id insider 802.1ad frame

This makes "ether type 0x88a8 vlan id 342" work.

Before this change, nft would still insert a dependency on 802.1q so the
rule would never match.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agonetlink: don't crash when set elements are not evaluated as expected
Florian Westphal [Tue, 30 Mar 2021 23:26:19 +0000 (01:26 +0200)] 
netlink: don't crash when set elements are not evaluated as expected

define foo = 2001:db8:123::/48

table inet filter {
set foo {
typeof ip6 saddr
elements = $foo
}
}

gives crash.  This now exits with:

stdin:1:14-30: Error: Unexpected initial set type prefix
define foo = 2001:db8:123::/48
             ^^^^^^^^^^^^^^^^^

For literals, bison parser protects us, as it enforces
'elements = { 2001:... '.

For 'elements = $foo' we can't detect it at parsing stage as the '$foo'
symbol might as well evaluate to "{ 2001, ...}" (i.e. we can't do a
set element allocation).

So at least detect this from set instantiaton.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoparser_bison: simplify flowtable offload flag parser
Pablo Neira Ayuso [Wed, 31 Mar 2021 14:14:03 +0000 (16:14 +0200)] 
parser_bison: simplify flowtable offload flag parser

Remove ft_flags_spec rule.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agomnl: do not set flowtable flags twice
Pablo Neira Ayuso [Wed, 31 Mar 2021 14:07:13 +0000 (16:07 +0200)] 
mnl: do not set flowtable flags twice

Flags are already set on from mnl_nft_flowtable_add(), remove duplicated
code.

Fixes: e6cc9f37385 ("nftables: add flags offload to flowtable")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agorule: remove semicolon in flowtable offload
Pablo Neira Ayuso [Thu, 25 Mar 2021 12:06:02 +0000 (13:06 +0100)] 
rule: remove semicolon in flowtable offload

opts->stmt_separator already prints the semicolon when needed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoparser: fix scope closure of COUNTER token
Florian Westphal [Thu, 25 Mar 2021 09:34:40 +0000 (10:34 +0100)] 
parser: fix scope closure of COUNTER token

It is closed after allocation, which is too early: this
stopped 'packets' and 'bytes' from getting parsed correctly.

Also add a test case for this.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agosrc: add datatype->describe()
Pablo Neira Ayuso [Wed, 24 Mar 2021 16:19:32 +0000 (17:19 +0100)] 
src: add datatype->describe()

As an alternative to print the datatype values when no symbol table is
available. Use it to print protocols available via getprotobynumber()
which actually refers to /etc/protocols.

Not very efficient, getprotobynumber() causes a series of open()/close()
calls on /etc/protocols, but this is called from a non-critical path.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1503
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agonftables: add flags offload to flowtable
Frank Wunderlich [Sun, 21 Mar 2021 16:49:16 +0000 (17:49 +0100)] 
nftables: add flags offload to flowtable

allow flags (currently only offload) in flowtables like it is stated
here: https://lwn.net/Articles/804384/

tested on mt7622/Bananapi-R64

table ip filter {
flowtable f {
hook ingress priority filter + 1
devices = { lan3, lan0, wan }
flags offload;
}

chain forward {
type filter hook forward priority filter; policy accept;
ip protocol { tcp, udp } flow add @f
}
}

table ip nat {
chain post {
type nat hook postrouting priority filter; policy accept;
oifname "wan" masquerade
}
}

Signed-off-by: Frank Wunderlich <frank-w@public-files.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agodoc: no need to define a set in ct state
Pablo Neira Ayuso [Wed, 24 Mar 2021 16:54:33 +0000 (17:54 +0100)] 
doc: no need to define a set in ct state

ct state are flags, no need to define a set for this.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agodoc: use symbolic names for chain priorities
Simon Ruderich [Tue, 9 Mar 2021 10:53:30 +0000 (11:53 +0100)] 
doc: use symbolic names for chain priorities

This replaces the numbers with the matching symbolic names with one
exception: The NAT example used "priority 0" for the prerouting
priority. This is replaced by "dstnat" which has priority -100 which is
the new recommended priority.

Also use spaces instead of tabs for consistency in lines which require
updates.

Signed-off-by: Simon Ruderich <simon@ruderich.org>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agotests: shell: fix 0025empty_dynset_0
Pablo Neira Ayuso [Wed, 24 Mar 2021 12:36:14 +0000 (13:36 +0100)] 
tests: shell: fix 0025empty_dynset_0

Use bash, otherwise it reports here:

testcases/nft-f/0025empty_dynset_0: 22: Syntax error: redirection unexpected

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agotests: shell: flowtable add after delete in batch
Pablo Neira Ayuso [Wed, 17 Mar 2021 19:50:12 +0000 (20:50 +0100)] 
tests: shell: flowtable add after delete in batch

Check for bogus EEXIST and EBUSY errors.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agosegtree: release single element already contained in an interval
Pablo Neira Ayuso [Tue, 16 Mar 2021 23:44:09 +0000 (00:44 +0100)] 
segtree: release single element already contained in an interval

Before this patch:

 table ip x {
        chain y {
                ip saddr { 1.1.1.1-1.1.1.2, 1.1.1.1 }
        }
 }

results in:

 table ip x {
        chain y {
                ip saddr { 1.1.1.1 }
        }
 }

due to incorrect interval merge logic.

If the element 1.1.1.1 is already contained in an existing interval
1.1.1.1-1.1.1.2, release it.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1512
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoparser: add missing scope_close annotation for RT keyword
Florian Westphal [Wed, 24 Mar 2021 11:07:05 +0000 (12:07 +0100)] 
parser: add missing scope_close annotation for RT keyword

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: log: move to own scope
Florian Westphal [Tue, 16 Mar 2021 23:40:36 +0000 (00:40 +0100)] 
scanner: log: move to own scope

GROUP and PREFIX are used by igmp and nat, so they can't be moved out of
INITIAL scope yet.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: counter: move to own scope
Florian Westphal [Tue, 16 Mar 2021 23:40:35 +0000 (00:40 +0100)] 
scanner: counter: move to own scope

move bytes/packets away from initial state.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: add support for scope nesting
Florian Westphal [Tue, 16 Mar 2021 23:40:34 +0000 (00:40 +0100)] 
scanner: add support for scope nesting

Adding a COUNTER scope introduces parsing errors.  Example:

add rule  ... counter ip saddr 1.2.3.4

This is supposed to be

    COUNTER IP SADDR SYMBOL

but it will be parsed as

    COUNTER IP STRING SYMBOL

... and rule fails with unknown saddr.
This is because IP state change gets popped right after it was pushed.

bison parser invokes scanner_pop_start_cond() helper via
'close_scope_counter' rule after it has processed the entire 'counter' rule.
But that happens *after* flex has executed the 'IP' rule.

IOW, the sequence of events is not the exepcted
"COUNTER close_scope_counter IP SADDR SYMBOL close_scope_ip", it is
"COUNTER IP close_scope_counter".

close_scope_counter pops the just-pushed SCANSTATE_IP and returns the
scanner to SCANSTATE_COUNTER, so next input token (saddr) gets parsed
as a string, which gets then rejected from bison.

To resolve this, defer the pop operation until the current state is done.
scanner_pop_start_cond() already gets the scope that it has been
completed as an argument, so we can compare it to the active state.

If those are not the same, just defer the pop operation until the
bison reports its done with the active flex scope.

This leads to following sequence of events:
  1. flex switches to SCANSTATE_COUNTER
  2. flex switches to SCANSTATE_IP
  3. bison calls scanner_pop_start_cond(SCANSTATE_COUNTER)
  4. flex remains in SCANSTATE_IP, bison continues
  5. bison calls scanner_pop_start_cond(SCANSTATE_IP) once the entire
     ip rule has completed: this pops both IP and COUNTER.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: avoid -fasan heap overflow warnings
Florian Westphal [Thu, 18 Mar 2021 16:31:30 +0000 (17:31 +0100)] 
scanner: avoid -fasan heap overflow warnings

Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: secmark: move to own scope
Florian Westphal [Thu, 11 Mar 2021 13:23:13 +0000 (14:23 +0100)] 
scanner: secmark: move to own scope

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: move until,over,used keywords away from init state
Florian Westphal [Thu, 11 Mar 2021 13:23:12 +0000 (14:23 +0100)] 
scanner: move until,over,used keywords away from init state

Only applicable for limit and quota. "ct count" also needs 'over'.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: quota: move to own scope
Florian Westphal [Thu, 11 Mar 2021 13:23:11 +0000 (14:23 +0100)] 
scanner: quota: move to own scope

... and move "used" keyword to it.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: limit: move to own scope
Florian Westphal [Thu, 11 Mar 2021 13:23:10 +0000 (14:23 +0100)] 
scanner: limit: move to own scope

Moves rate and burst out of INITIAL.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: vlan: move to own scope
Florian Westphal [Thu, 11 Mar 2021 13:23:09 +0000 (14:23 +0100)] 
scanner: vlan: move to own scope

ID needs to remain exposed as its used by ct, icmp, icmp6 and so on.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: remove saddr/daddr from initial state
Florian Westphal [Thu, 11 Mar 2021 13:23:08 +0000 (14:23 +0100)] 
scanner: remove saddr/daddr from initial state

This can now be reduced to expressions that can expect saddr/daddr tokens.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: arp: move to own scope
Florian Westphal [Thu, 11 Mar 2021 13:23:07 +0000 (14:23 +0100)] 
scanner: arp: move to own scope

allows to move the arp specific tokens out of the INITIAL scope.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: add ether scope
Florian Westphal [Thu, 11 Mar 2021 13:23:06 +0000 (14:23 +0100)] 
scanner: add ether scope

just like previous change: useless as-is, but prepares
for removal of saddr/daddr from INITIAL scope.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: add fib scope
Florian Westphal [Thu, 11 Mar 2021 13:23:05 +0000 (14:23 +0100)] 
scanner: add fib scope

makes no sense as-is because all keywords need to stay
in the INITIAL scope.

This can be changed after all saddr/daddr users have been scoped.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: ip6: move to own scope
Florian Westphal [Thu, 11 Mar 2021 13:23:04 +0000 (14:23 +0100)] 
scanner: ip6: move to own scope

move flowlabel and hoplimit.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: ip: move to own scope
Florian Westphal [Thu, 11 Mar 2021 13:23:03 +0000 (14:23 +0100)] 
scanner: ip: move to own scope

Move the ip option names (rr, lsrr, ...) out of INITIAL scope.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: ct: move to own scope
Florian Westphal [Thu, 11 Mar 2021 13:23:02 +0000 (14:23 +0100)] 
scanner: ct: move to own scope

This allows moving multiple ct specific keywords out of INITIAL scope.
Next few patches follow same pattern:
 1. add a scope_close_XXX rule
 2. add a SCANSTATE_XXX & make flex switch to it when
    encountering XXX keyword
 3. make bison leave SCANSTATE_XXXX when it has seen the complete
    expression.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agosrc: move remaining cache functions in rule.c to cache.c
Pablo Neira Ayuso [Thu, 11 Mar 2021 12:34:10 +0000 (13:34 +0100)] 
src: move remaining cache functions in rule.c to cache.c

Move all the cache logic to src/cache.c

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
3 years agoscanner: socket: move to own scope
Florian Westphal [Mon, 8 Mar 2021 17:18:37 +0000 (18:18 +0100)] 
scanner: socket: move to own scope

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: rt: move to own scope
Florian Westphal [Mon, 8 Mar 2021 17:18:36 +0000 (18:18 +0100)] 
scanner: rt: move to own scope

classid and nexthop can be moved out of INIT scope.
Rest are still needed because tehy are used by other expressions as
well.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: ipsec: move to own scope
Florian Westphal [Mon, 8 Mar 2021 17:18:35 +0000 (18:18 +0100)] 
scanner: ipsec: move to own scope

... and hide the ipsec specific tokens from the INITITAL scope.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: queue: move to own scope
Florian Westphal [Mon, 8 Mar 2021 17:18:34 +0000 (18:18 +0100)] 
scanner: queue: move to own scope

allows to remove 3 queue specific keywords from INITIAL scope.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: introduce start condition stack
Florian Westphal [Mon, 8 Mar 2021 17:18:33 +0000 (18:18 +0100)] 
scanner: introduce start condition stack

Add a small initial chunk of flex start conditionals.

This starts with two low-hanging fruits, numgen and j/symhash.

NUMGEN and HASH start conditions are entered from flex when
the corresponding expression token is encountered.

Flex returns to the INIT condition when the bison parser
has seen a complete numgen/hash statement.

This intentionally uses a stack rather than BEGIN()
to eventually support nested states.

The scanner_pop_start_cond() function argument is not used yet, but
will need to be used later to deal with nesting.

Signed-off-by: Florian Westphal <fw@strlen.de>
3 years agoscanner: remove unused tokens
Florian Westphal [Mon, 8 Mar 2021 17:18:32 +0000 (18:18 +0100)] 
scanner: remove unused tokens

Signed-off-by: Florian Westphal <fw@strlen.de>