fix map update with concatenation and timeouts
Florian Westphal
maintainercover fix map update with concatenation and timeouts
When "update" is used with a map, nft will ignore a given timeout. Futhermore, listing is broken, only the first data expression gets decoded:
in:
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr . ct original proto-dst timeout 90s }
out:
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr }
Missing timeout is input bug (never passed to kernel), mussing "proto-dst" is output bug.
Also add a test case.
Florian Westphal (3):
netlink_delinearize: fix decoding of concat data element
netlink_linearize: fix timeout with map updates
tests: add a test case for map update from packet path with concat
src/netlink_delinearize.c | 8 ++++++++ src/netlink_linearize.c | 7 +++++++ .../maps/dumps/typeof_maps_concat_update_0.nft | 12 ++++++++++++ .../testcases/maps/typeof_maps_concat_update_0 | 18 ++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 tests/shell/testcases/maps/dumps/typeof_maps_concat_update_0.nft create mode 100755 tests/shell/testcases/maps/typeof_maps_concat_update_0
Signature · 1 line
2.38.1
Florian Westphal
maintainerPATCH 1/3 netlink_delinearize: fix decoding of concat data element
Its possible to use update as follows:
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr . ct original proto-dst }
... but when listing, only the first element of the concatenation is shown.
Check if the element size is too small and parse subsequent registers as well.
--- src/netlink_delinearize.c | 8 ++++++++ 1 file changed, 8 insertions(+)
src/netlink_delinearize.c +8 -0
@@ -1660,6 +1660,14 @@ static void netlink_parse_dynset(struct netlink_parse_ctx *ctx,if (nftnl_expr_is_set (nle,NFTNL_EXPR_DYNSET_SREG_DATA )) { sreg_data =netlink_parse_register (nle,NFTNL_EXPR_DYNSET_SREG_DATA ); expr_data =netlink_get_register (ctx, loc, sreg_data); + +if (expr_data->len < set->data->len) { +expr_free (expr_data); + expr_data =netlink_parse_concat_expr (ctx, loc, sreg_data, set->data->len); +if (expr_data ==NULL ) +netlink_error (ctx, loc, +"Could not parse dynset map data expessions" ); + } }if (expr_data !=NULL ) {
Signature · 1 line
2.38.1
Florian Westphal
maintainerPATCH 2/3 netlink_linearize: fix timeout with map updates
In reply to Florian WestphalMap updates can use timeouts, just like with sets, but the linearization step did not pass this info to the kernel.
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr . ct original proto-dst timeout 90s
Listing this won't show the "timeout 90s" because kernel never saw it to begin with.
NB: The above line attaches the timeout to the data element, but there are no separate timeouts for the key and the value.
An alternative is to reject "key : value timeout X" from the parser or evaluation step.
--- src/netlink_linearize.c | 7 +++++++ 1 file changed, 7 insertions(+)
src/netlink_linearize.c +7 -0
@@ -1520,6 +1520,13 @@ static void netlink_gen_map_stmt(struct netlink_linearize_ctx *ctx,nftnl_expr_set_u32 (nle,NFTNL_EXPR_DYNSET_SET_ID , set->handle.set_id);nft_rule_add_expr (ctx, nle, &stmt->location); +if (stmt->map.key->timeout >0 ) +nftnl_expr_set_u64 (nle,NFTNL_EXPR_DYNSET_TIMEOUT , + stmt->map.key->timeout); +else if (stmt->map.data->timeout >0 ) +nftnl_expr_set_u64 (nle,NFTNL_EXPR_DYNSET_TIMEOUT , + stmt->map.data->timeout); +list_for_each_entry (this, &stmt->map.stmt_list, list) num_stmts++;
Signature · 1 line
2.38.1
Pablo Neira Ayuso
maintainerRe: [PATCH nft 2/3] netlink_linearize: fix timeout with map updates
Quoted 5 lines · Florian Westphal
Map updates can use timeouts, just like with sets, but the linearization step did not pass this info to the kernel.
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr . ct original proto-dst timeout 90s
Quoted 8 lines
Listing this won't show the "timeout 90s" because kernel never saw it to begin with.
NB: The above line attaches the timeout to the data element, but there are no separate timeouts for the key and the value.
An alternative is to reject "key : value timeout X" from the parser or evaluation step.
You mean, timeout is accepted both from key : value sides of the mapping, right?
It makes more sense to restrict it to the key side, that would require a follow up patch.
Thanks.
Florian Westphal
maintainerRe: [PATCH nft 2/3] netlink_linearize: fix timeout with map updates
Quoted 9 lines · Pablo Neira Ayuso
Quoted 8 lines · Florian Westphal
Map updates can use timeouts, just like with sets, but the linearization step did not pass this info to the kernel.
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr . ct original proto-dst timeout 90s
Listing this won't show the "timeout 90s" because kernel never saw it to begin with.
Quoted 8 lines
Quoted 5 lines
NB: The above line attaches the timeout to the data element, but there are no separate timeouts for the key and the value.
An alternative is to reject "key : value timeout X" from the parser or evaluation step.
You mean, timeout is accepted both from key : value sides of the mapping, right?
Yes, exactly, you can even to
ip saddr timeout 1m : 0x42 timeout 1s
Quoted 2 lines
It makes more sense to restrict it to the key side, that would require a follow up patch.
Ok, works for me, should be easy to do.
Florian Westphal
maintainerPATCH 3/3 tests: add a test case for map update from packet path with concat
In reply to Florian Westphaladd a second test case for map updates, this time with both a timeout and a data element that consists of a concatenation.
--- .../maps/dumps/typeof_maps_concat_update_0.nft | 12 ++++++++++++ .../testcases/maps/typeof_maps_concat_update_0 | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/shell/testcases/maps/dumps/typeof_maps_concat_update_0.nft create mode 100755 tests/shell/testcases/maps/typeof_maps_concat_update_0
tests/shell/testcases/maps/dumps/typeof_maps_concat_update_0.nft new file +12 -0
@@ -0,0 +1,12 @@ +table ip foo { + map pinned { + typeof ip daddr . tcp dport : ip daddr . tcp dport + size 65535 + flags dynamic,timeout + timeout 6m + } + + chain pr { + meta l4proto tcp update @pinned { ip saddr . ct original proto-dst timeout 1m30s : ct original ip daddr . ct reply proto-src } + } +}
tests/shell/testcases/maps/typeof_maps_concat_update_0 new file +18 -0
@@ -0,0 +1,18 @@ +#!/bin/bash + +# check update statement does print both concatentations (key and data). + +EXPECTED="table ip foo { + map pinned { + typeof ip daddr . tcp dport : ip daddr . tcp dport + size 65535 + flags dynamic,timeout + timeout 6m + } + chain pr { + meta l4proto tcp update @pinned { ip saddr . ct original proto-dst : ct original ip daddr . ct reply proto-src timeout 1m30s } + } +}" + +set -e +$NFT -f - <<< $EXPECTED
Signature · 1 line
2.38.1
Pablo Neira Ayuso
maintainerQuoted 9 lines · Florian Westphal
When "update" is used with a map, nft will ignore a given timeout. Futhermore, listing is broken, only the first data expression gets decoded:
in:
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr . ct original proto-dst timeout 90s }
out:
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr }
Quoted 4 lines
Missing timeout is input bug (never passed to kernel), mussing "proto-dst" is output bug.
Also add a test case.
Series LGTM, thanks.
I might follow up to restrict the timeout to the key side unless you would like to look into this.
Florian Westphal
maintainerQuoted 13 lines · Pablo Neira Ayuso
Quoted 12 lines · Florian Westphal
When "update" is used with a map, nft will ignore a given timeout. Futhermore, listing is broken, only the first data expression gets decoded:
in:
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr . ct original proto-dst timeout 90s }
out:
meta l4proto tcp update @pinned { ip saddr . ct original proto-src : ip daddr }Missing timeout is input bug (never passed to kernel), mussing "proto-dst" is output bug.
Quoted 6 lines
Quoted 1 line
Also add a test case.
Series LGTM, thanks.
I might follow up to restrict the timeout to the key side unless you would like to look into this.
I've pushed this series out; I fixed the typo in patch 1 and I mangled patch 2 to reject data-element timeouts from the eval phase.