evaluate: restore interval + concatenation in anonymous set
Pablo Neira Ayuso
maintainerPATCH 2/2 evaluate: restore interval + concatenation in anonymous set
Perform the table and set lookup only for non-anonymous sets, where the incremental cache update is required.
The problem fixed by 7aa08d45031e ("evaluate: Perform set evaluation on implicitly declared (anonymous) sets") resurrected after the cache rework.
# nft add rule x y tcp sport . tcp dport vmap { ssh . 0-65535 : accept, 0-65535 . ssh : accept }
BUG: invalid range expression type concat
nft: expression.c:1422: range_expr_value_low: Assertion `0' failed.
AbortAdd a test case to make sure this does not happen again.
--- src/evaluate.c | 17 +++++++++-------- tests/py/ip/ip.t | 2 ++ tests/py/ip/ip.t.payload | 9 +++++++++ tests/py/ip/ip.t.payload.bridge | 11 +++++++++++ tests/py/ip/ip.t.payload.inet | 11 +++++++++++ tests/py/ip/ip.t.payload.netdev | 11 +++++++++++ 6 files changed, 53 insertions(+), 8 deletions(-)
src/evaluate.c +9 -8
@@ -3781,15 +3781,16 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)struct stmt *stmt;const char *type; - table =table_cache_find (&ctx->nft->cache.table_cache, - ctx->cmd->handle.table.name, - ctx->cmd->handle.family); -if (table ==NULL ) -return table_not_found (ctx); +if (!(set->flags &NFT_SET_ANONYMOUS )) { + table =table_cache_find (&ctx->nft->cache.table_cache, + set->handle.table.name, + set->handle.family); +if (table ==NULL ) +return table_not_found (ctx); -if (!(set->flags &NFT_SET_ANONYMOUS ) && - !set_cache_find (table, set->handle.set.name)) -set_cache_add (set_get (set), table); +if (!set_cache_find (table, set->handle.set.name)) +set_cache_add (set_get (set), table); + }if (!(set->flags &NFT_SET_INTERVAL ) && set->automerge)return set_error (ctx, set,"auto-merge only works with interval sets" );
tests/py/ip/ip.t +2 -0
@@ -123,3 +123,5 @@ iif "lo" ip protocol set 1;ok iif "lo" ip dscp set af23;ok iif "lo" ip dscp set cs0;ok + +ip saddr . ip daddr { 192.0.2.1 . 10.0.0.1-10.0.0.2 };ok
tests/py/ip/ip.t.payload +9 -0
@@ -506,3 +506,12 @@ ip test-ip4 input [ bitwise reg 1 = ( reg 1 & 0x000000ff ) ^ 0x00000100 ] [ payload write reg 1 => 2b @ network header + 8 csum_type 1 csum_off 10 csum_flags 0x1 ] +# ip saddr . ip daddr { 192.0.2.1 . 10.0.0.1-10.0.0.2 } +__set%d test-ip4 87 size 1 +__set%d test-ip4 0 + element 010200c0 0100000a - 010200c0 0200000a : 0 [end] +ip + [ payload load 4b @ network header + 12 => reg 1 ] + [ payload load 4b @ network header + 16 => reg 9 ] + [ lookup reg 1 set __set%d ] +
tests/py/ip/ip.t.payload.bridge +11 -0
@@ -662,3 +662,14 @@ bridge test-bridge input [ bitwise reg 1 = ( reg 1 & 0x000003ff ) ^ 0x00000000 ] [ payload write reg 1 => 2b @ network header + 0 csum_type 1 csum_off 10 csum_flags 0x0 ] +# ip saddr . ip daddr { 192.0.2.1 . 10.0.0.1-10.0.0.2 } +__set%d test-bridge 87 size 1 +__set%d test-bridge 0 + element 010200c0 0100000a - 010200c0 0200000a : 0 [end] +bridge + [ meta load protocol => reg 1 ] + [ cmp eq reg 1 0x00000008 ] + [ payload load 4b @ network header + 12 => reg 1 ] + [ payload load 4b @ network header + 16 => reg 9 ] + [ lookup reg 1 set __set%d ] +
tests/py/ip/ip.t.payload.inet +11 -0
@@ -662,3 +662,14 @@ inet test-inet input [ bitwise reg 1 = ( reg 1 & 0x000000ff ) ^ 0x00000100 ] [ payload write reg 1 => 2b @ network header + 8 csum_type 1 csum_off 10 csum_flags 0x1 ] +# ip saddr . ip daddr { 192.0.2.1 . 10.0.0.1-10.0.0.2 } +__set%d test-inet 87 size 1 +__set%d test-inet 0 + element 010200c0 0100000a - 010200c0 0200000a : 0 [end] +inet + [ meta load nfproto => reg 1 ] + [ cmp eq reg 1 0x00000002 ] + [ payload load 4b @ network header + 12 => reg 1 ] + [ payload load 4b @ network header + 16 => reg 9 ] + [ lookup reg 1 set __set%d ] +
tests/py/ip/ip.t.payload.netdev +11 -0
@@ -662,3 +662,14 @@ netdev test-netdev ingress [ bitwise reg 1 = ( reg 1 & 0x000000ff ) ^ 0x00000100 ] [ payload write reg 1 => 2b @ network header + 8 csum_type 1 csum_off 10 csum_flags 0x1 ] +# ip saddr . ip daddr { 192.0.2.1 . 10.0.0.1-10.0.0.2 } +__set%d test-netdev 87 size 1 +__set%d test-netdev 0 + element 010200c0 0100000a - 010200c0 0200000a : 0 [end] +netdev + [ meta load protocol => reg 1 ] + [ cmp eq reg 1 0x00000008 ] + [ payload load 4b @ network header + 12 => reg 1 ] + [ payload load 4b @ network header + 16 => reg 9 ] + [ lookup reg 1 set __set%d ] +
Signature · 1 line
2.20.1
Phil Sutter
reviewerHi Pablo,
Quoted 12 lines · Pablo Neira Ayuso
Perform the table and set lookup only for non-anonymous sets, where the incremental cache update is required.
The problem fixed by
7aa08d45031e("evaluate: Perform set evaluation on implicitly declared (anonymous) sets") resurrected after the cache rework.# nft add rule x y tcp sport . tcp dport vmap { ssh . 0-65535 : accept, 0-65535 . ssh : accept } BUG: invalid range expression type concat nft: expression.c:1422: range_expr_value_low: Assertion `0' failed. Abort
Quoted 4 lines
Add a test case to make sure this does not happen again.
Fixes 5ec5c706d993 ("cache: add hashtable cache for table")Signed-off-by Pablo Neira Ayuso <[email protected]>
This triggers a warning:
evaluate.c: In function 'set_evaluate':
evaluate.c:3870:13: warning: 'table' may be used uninitialized in this function [-Wmaybe-uninitialized]
3870 | if (set_cache_find(table, set->handle.set.name) == NULL)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cheers, Phil
Pablo Neira Ayuso
maintainerQuoted 20 lines · Phil Sutter
Hi Pablo,
Quoted 12 lines · Pablo Neira Ayuso
Perform the table and set lookup only for non-anonymous sets, where the incremental cache update is required.
The problem fixed by
7aa08d45031e("evaluate: Perform set evaluation on implicitly declared (anonymous) sets") resurrected after the cache rework.# nft add rule x y tcp sport . tcp dport vmap { ssh . 0-65535 : accept, 0-65535 . ssh : accept } BUG: invalid range expression type concat nft: expression.c:1422: range_expr_value_low: Assertion `0' failed. AbortQuoted 4 lines
Add a test case to make sure this does not happen again.
Fixes 5ec5c706d993 ("cache: add hashtable cache for table")Signed-off-by Pablo Neira Ayuso <[email protected]>
Quoted 6 lines
This triggers a warning:
evaluate.c: In function 'set_evaluate':
evaluate.c:3870:13: warning: 'table' may be used uninitialized in this function [-Wmaybe-uninitialized]
3870 | if (set_cache_find(table, set->handle.set.name)== NULL)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hm, this needs to be restricted to anonymous sets, attaching patch.
src/evaluate.c +2 -1
@@ -3867,7 +3867,8 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set) } ctx->set =NULL ; -if (set_cache_find (table, set->handle.set.name) ==NULL ) +if (!(set->flags &NFT_SET_ANONYMOUS ) && + !set_cache_find (table, set->handle.set.name))set_cache_add (set_get (set), table);return 0 ;
Pablo Neira Ayuso
maintainerQuoted 21 lines · Pablo Neira Ayuso
Quoted 20 lines · Phil Sutter
Hi Pablo,
Quoted 16 lines · Pablo Neira Ayuso
Perform the table and set lookup only for non-anonymous sets, where the incremental cache update is required.
The problem fixed by
7aa08d45031e("evaluate: Perform set evaluation on implicitly declared (anonymous) sets") resurrected after the cache rework.# nft add rule x y tcp sport . tcp dport vmap { ssh . 0-65535 : accept, 0-65535 . ssh : accept } BUG: invalid range expression type concat nft: expression.c:1422: range_expr_value_low: Assertion `0' failed. AbortAdd a test case to make sure this does not happen again.
Fixes 5ec5c706d993 ("cache: add hashtable cache for table")Signed-off-by Pablo Neira Ayuso <[email protected]>
Quoted 8 lines
Quoted 6 lines
This triggers a warning:
evaluate.c: In function 'set_evaluate':
evaluate.c:3870:13: warning: 'table' may be used uninitialized in this function [-Wmaybe-uninitialized]
3870 | if (set_cache_find(table, set->handle.set.name)== NULL)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Hm, this needs to be restricted to anonymous sets, attaching patch.
It's a false positive though, there is a check for anonymous set a few lines before. I'll apply this patch if this makes gcc happy on your side.
Quoted 14 lines
src/evaluate.c +2
-1@@ -3867,7 +3867,8 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set) } ctx->set =NULL ; -if (set_cache_find (table, set->handle.set.name) ==NULL ) +if (!(set->flags &NFT_SET_ANONYMOUS ) && + !set_cache_find (table, set->handle.set.name))set_cache_add (set_get (set), table);return 0 ;
Pablo Neira Ayuso
maintainerQuoted 29 lines · Pablo Neira Ayuso
Quoted 28 lines · Pablo Neira Ayuso
Quoted 26 lines · Phil Sutter
Hi Pablo,
Quoted 12 lines · Pablo Neira Ayuso
Perform the table and set lookup only for non-anonymous sets, where the incremental cache update is required.
The problem fixed by
7aa08d45031e("evaluate: Perform set evaluation on implicitly declared (anonymous) sets") resurrected after the cache rework.# nft add rule x y tcp sport . tcp dport vmap { ssh . 0-65535 : accept, 0-65535 . ssh : accept } BUG: invalid range expression type concat nft: expression.c:1422: range_expr_value_low: Assertion `0' failed. AbortQuoted 4 lines
Add a test case to make sure this does not happen again.
Fixes 5ec5c706d993 ("cache: add hashtable cache for table")Signed-off-by Pablo Neira Ayuso <[email protected]>This triggers a warning:
evaluate.c: In function 'set_evaluate':
evaluate.c:3870:13: warning: 'table' may be used uninitialized in this function [-Wmaybe-uninitialized]
3870 | if (set_cache_find(table, set->handle.set.name)== NULL)| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 4 lines
Quoted 1 line
Hm, this needs to be restricted to anonymous sets, attaching patch.
It's a false positive though, there is a check for anonymous set a few lines before. I'll apply this patch if this makes gcc happy on your side.
Actually, this code should not be there. The set is already in the cache.
src/evaluate.c +0 -3
@@ -3867,9 +3867,6 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set) } ctx->set =NULL ; -if (set_cache_find (table, set->handle.set.name) ==NULL ) -set_cache_add (set_get (set), table); -return 0 ; }