Skip to content

Enableruntime queue selection via jhash, numgen and map statement

Florian Westphal netfilter-devel 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest8 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8evaluate: fix hash expression maxvalsrc/evaluate.c+6 -20 replies
2/8parser: restrict queue num expressivenesssrc/parser_bison.y+7 -10 replies
3/8src: add queue expr and flags to queue_stmt_allocinclude/statement.h src/netlink_delinearize.c src/parser_bison.y +2 more+25 -220 replies
4/8parser: add queue_stmt_compatsrc/parser_bison.y+11 -80 replies
5/8parser: new queue flag input formatdoc/statements.txt src/parser_bison.y src/statement.c +1 more+19 -110 replies
6/8src: queue: allow use of arbitrary queue expressionsdoc/statements.txt src/evaluate.c src/netlink_delinearize.c +3 more+93 -250 replies
7/8tests: extend queue testcases for new sreg supporttests/py/any/queue.t tests/py/any/queue.t.json tests/py/any/queue.t.payload+82 -00 replies
8/8src: queue: allow use of MAP statement for queue number retrievaldoc/statements.txt src/parser_bison.y tests/py/any/queue.t +2 more+49 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH nft 0/8] Enableruntime queue selection via jhash, numgen and map statement

Back in 2016 Liping Zhang added support to kernel and libnftnl to specify a source register containing the queue number to use.

This was never added to nft itself, so allow this.

On linearization side, check if attached expression is a range. If its not, allocate a new register and set NFTNL_EXPR_QUEUE_SREG_QNUM attribute after generating the lowlevel expressions for the kernel.

On delinarization we need to check for presence of NFTNL_EXPR_QUEUE_SREG_QNUM and decode the expression(s) when present.

Also need to do postprocessing for STMT_QUEUE so that the protocol context is set correctly, without this only raw payload expressions will be shown (@nh,32,...) instead of 'ip ...'.

Unfortunately, it turned out that just removing the eval checks to allow arbitrary statements as 'num' argument results in parser problems.

One example is this:
queue num jhash ip saddr mod 4 bypass

This fails because scanner is still in 'ip' state, not 'queue', when "bypass" is read, so this will not be recognized as belonging to the queue statement.

This series solves this in the following way:
1. On output, nft will now always prepend the flags, i.e. queue flags bypass num 42

2. On input, 'queue num' is restricted to numbers and ranges. This is backwards compatible because range and value were the only permitted inputs (eval step rejects non-constant expressions).

3. To use numgen or jhash, new grammar is added:
queue flags bypass to jhash ip saddr mod 4

I've restricted the 'to' expressions to numgen, (sym)hash and map for now.

This can be relaxed later on if other usecases become available.

Florian Westphal (8):
evaluate: fix hash expression maxval
parser: restrict queue num expressiveness
src: add queue expr and flags to queue_stmt_alloc
parser: add queue_stmt_compat
parser: new queue flag input format
src: queue: allow use of arbitrary queue expressions
tests: extend queue testcases for new sreg support
src: queue: allow use of MAP statement for queue number retrieval

 doc/statements.txt           | 10 +++-
 include/statement.h          |  3 +-
 src/evaluate.c               | 21 +++++----
 src/netlink_delinearize.c    | 56 +++++++++++++++-------
 src/netlink_linearize.c      | 28 +++++++++--
 src/parser_bison.y           | 38 ++++++++++++---
 src/parser_json.c            | 22 ++++-----
 src/statement.c              | 30 +++++++++---
 tests/py/any/queue.t         | 18 ++++++--
 tests/py/any/queue.t.json    | 90 ++++++++++++++++++++++++++++++++++++
 tests/py/any/queue.t.payload | 25 ++++++++++
 11 files changed, 281 insertions(+), 60 deletions(-)
Signature · 1 line
2.31.1