Skip to content

add typeof keyword

Florian Westphal netfilter-devel 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest10 patches 0 repliesNew
  2. v211 patches 0 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10parser: add a helper for concat expression handlingsrc/parser_bison.y+43 -560 replies
2/10src: store expr, not dtype to track data in setsinclude/datatype.h include/netlink.h include/rule.h +11 more+81 -630 replies
3/10proto: add proto_desc_id enumerationinclude/proto.h src/proto.c+73 -00 replies
4/10expr: add expr_ops_by_type()include/expression.h src/expression.c+13 -00 replies
5/10parser: add typeof keyword for declarationssrc/parser_bison.y src/scanner.l+45 -20 replies
6/10src: add "typeof" build/parse/print supportinclude/expression.h include/rule.h src/mnl.c +3 more+255 -200 replies
7/10mnl: round up the map data size toosrc/mnl.c+1 -10 replies
8/10evaluate: print a hint about 'typeof' syntax on 0 keylensrc/evaluate.c+18 -50 replies
9/10doc: mention 'typeof' as alternative to 'type' keyworddoc/nft.txt+9 -30 replies
10/10tests: add typeof test casestests/shell/testcases/maps/dumps/typeof_maps_0.nft tests/shell/testcases/maps/typeof_maps_0 tests/shell/testcases/sets/dumps/typeof_sets_0.nft +1 more+91 -00 replies

Reviews trailers per patch

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

Read the v3 thread

Cover letter [PATCH nft v3 00/10] add typeof keyword

This patch series adds the typeof keyword.

This depends on Pablos extensions to libnftnls udata parsing facilities.

named set can be configured as follows:

set os {
typeof osf name
elements = { "Linux", "Windows" }
}

The type is stored in the kernel via the udata infrastructure. On listing -- if a udata type is present -- nft will validate that this type matches the set key length and, if so, will print back the 'typeof' information.

Note that while 'typeof' can be used with concatenations, they only work as aliases for known types -- its currently not possible to use integer/string types via the 'typeof' keyword (its rejected at evaluation stage due to 0-length sub expression types).

Doing so requires a bit more work to dissect the correct key geometry on netlink dumps.

In case typeof udata is not there/invalid, the normal 'type' syntax is used.

This patch set isn't complete -- the test cases will not work yet because 'meta' and 'osf' lack the udata parse/buil callbacks.

This is caught at the parsing stage.

The following changes since commit ddbe652bf0f4ed300bae9497250130d68e4cbf5b:

py: load the SONAME-versioned shared object (2019-12-10 19:07:16 +0100)

are available in the Git repository at:

git://git.breakpoint.cc/fw/nftables.git typeof_rework_09

for you to fetch changes up to 02485d775dea55a067c6dbea0826ab3fc9ff7398:

tests: add typeof test cases (2019-12-17 12:19:51 +0100)

----------------------------------------------------------------
Florian Westphal (7):
parser: add a helper for concat expression handling
src: store expr, not dtype to track data in sets
src: add "typeof" build/parse/print support
mnl: round up the map data size too
evaluate: print a hint about 'typeof' syntax on 0 keylen
doc: mention 'typeof' as alternative to 'type' keyword
tests: add typeof test cases

Pablo Neira Ayuso (3):
proto: add proto_desc_id enumeration
expr: add expr_ops_by_type()
parser: add typeof keyword for declarations

 doc/nft.txt                                        |  12 +-
 include/datatype.h                                 |   1 -
 include/expression.h                               |   5 +
 include/netlink.h                                  |   1 -
 include/proto.h                                    |  27 ++++
 include/rule.h                                     |   7 +-
 src/datatype.c                                     |   5 -
 src/evaluate.c                                     |  81 +++++++----
 src/expression.c                                   |  14 +-
 src/json.c                                         |   4 +-
 src/mnl.c                                          |  30 ++++-
 src/monitor.c                                      |   2 +-
 src/netlink.c                                      | 149 +++++++++++++++++----
 src/parser_bison.y                                 | 148 +++++++++++---------
 src/parser_json.c                                  |   8 +-
 src/payload.c                                      |  75 +++++++++++
 src/proto.c                                        |  46 +++++++
 src/rule.c                                         |  48 +++++--
 src/scanner.l                                      |   1 +
 src/segtree.c                                      |   8 +-
 tests/shell/testcases/maps/dumps/typeof_maps_0.nft |  16 +++
 tests/shell/testcases/maps/typeof_maps_0           |  27 ++++
 tests/shell/testcases/sets/dumps/typeof_sets_0.nft |  19 +++
 tests/shell/testcases/sets/typeof_sets_0           |  29 ++++
 24 files changed, 621 insertions(+), 142 deletions(-)
 create mode 100644 tests/shell/testcases/maps/dumps/typeof_maps_0.nft
 create mode 100755 tests/shell/testcases/maps/typeof_maps_0
 create mode 100644 tests/shell/testcases/sets/dumps/typeof_sets_0.nft
 create mode 100755 tests/shell/testcases/sets/typeof_sets_0