assorted updates and fixes
Pablo Neira Ayuso
maintainercover assorted updates and fixes
Hi,
This batch contains several assorted updates and fixes:
1) Skip lookup for mistyped names if handle is used.
2) Assert of non-nul name when {table,chain,obj,flowtable}_cache_find() is used to catch for bugs when handle is used.
3) Consolidate repetitive cache name hash.
4) Restrict reset command to use name only because NFT_MSG_GETSET and NFT_MSG_GETSETELEM is missing lookup by handle in the kernel.
5) Allow to delete a map with handle, for consistency with the existing command to delete a set.
Pablo Neira Ayuso (5):
rule: skip fuzzy lookup if object name is not available
cache: assert name is non-nul when looking up
cache: pass name to cache_add()
parser_bison: only reset by name is supported by now
parser_bison: allow delete command with map via handle
include/cache.h | 2 +- src/cache.c | 60 ++++++++----------- src/parser_bison.y | 6 +- src/rule.c | 12 ++++ .../bogons/nft-f/null_set_name_crash | 2 + .../testcases/cache/0008_delete_by_handle_0 | 4 ++ .../cache/0009_delete_by_handle_incorrect_0 | 1 + 7 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 tests/shell/testcases/bogons/nft-f/null_set_name_crash
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 1/5 rule: skip fuzzy lookup if object name is not available
Skip fuzzy lookup for suggestions when handles are used.
Note that 4cf97abfee61 ("rule: Avoid segfault with anonymous chains") already skips it for chain.
--- src/rule.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
src/rule.c +12 -0
@@ -211,6 +211,9 @@ struct set *set_lookup_fuzzy(const char *set_name,struct table *table;struct set *set; +if (!set_name) +return NULL ; +string_misspell_init (&st);list_for_each_entry (table, &cache->table_cache.list, cache.list) {
@@ -1214,6 +1217,9 @@ struct table *table_lookup_fuzzy(const struct handle *h,struct string_misspell_state st;struct table *table; +if (!h->table.name) +return NULL ; +string_misspell_init (&st);list_for_each_entry (table, &cache->table_cache.list, cache.list) {
@@ -1696,6 +1702,9 @@ struct obj *obj_lookup_fuzzy(const char *obj_name,struct table *table;struct obj *obj; +if (!obj_name) +return NULL ; +string_misspell_init (&st);list_for_each_entry (table, &cache->table_cache.list, cache.list) {
@@ -2191,6 +2200,9 @@ struct flowtable *flowtable_lookup_fuzzy(const char *ft_name,struct table *table;struct flowtable *ft; +if (!ft_name) +return NULL ; +string_misspell_init (&st);list_for_each_entry (table, &cache->table_cache.list, cache.list) {
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/5 cache: assert name is non-nul when looking up
In reply to Pablo Neira Ayuso{table,chain,set,obj,flowtable}_cache_find() should not be called when handles are used
--- src/cache.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
src/cache.c +9 -2
@@ -551,8 +551,7 @@ struct table *table_cache_find(const struct cache *cache,struct table *table;uint32_t hash; -if (!name) -return NULL ; +assert (name); hash =djb_hash (name) %NFT_CACHE_HSIZE ;list_for_each_entry (table, &cache->ht[hash], cache.hlist) {
@@ -672,6 +671,8 @@ struct chain *chain_cache_find(const struct table *table, const char *name)struct chain *chain;uint32_t hash; +assert (name); + hash =djb_hash (name) %NFT_CACHE_HSIZE ;list_for_each_entry (chain, &table->chain_cache.ht[hash], cache.hlist) {if (!strcmp (chain->handle.chain.name, name))
@@ -840,6 +841,8 @@ struct set *set_cache_find(const struct table *table, const char *name)struct set *set;uint32_t hash; +assert (name); + hash =djb_hash (name) %NFT_CACHE_HSIZE ;list_for_each_entry (set, &table->set_cache.ht[hash], cache.hlist) {if (!strcmp (set->handle.set.name, name))
@@ -954,6 +957,8 @@ struct obj *obj_cache_find(const struct table *table, const char *name,struct obj *obj;uint32_t hash; +assert (name); + hash =djb_hash (name) %NFT_CACHE_HSIZE ;list_for_each_entry (obj, &table->obj_cache.ht[hash], cache.hlist) { if (!strcmp(obj->handle.obj.name, name) &&
@@ -1058,6 +1063,8 @@ struct flowtable *ft_cache_find(const struct table *table, const char *name)struct flowtable *ft;uint32_t hash; +assert (name); + hash =djb_hash (name) %NFT_CACHE_HSIZE ;list_for_each_entry (ft, &table->ft_cache.ht[hash], cache.hlist) {if (!strcmp (ft->handle.flowtable.name, name))
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/5 cache: pass name to cache_add()
In reply to Pablo Neira AyusoConsolidate the name hash in the cache_add() function.
No functional changes are intended.
--- include/cache.h | 2 +- src/cache.c | 49 +++++++++++++++---------------------------------- 2 files changed, 16 insertions(+), 35 deletions(-)
include/cache.h +1 -1
@@ -123,7 +123,7 @@ struct cache_item {void cache_init (struct cache *cache);void cache_free (struct cache *cache); -void cache_add (struct cache_item *item,struct cache *cache,uint32_t hash); +void cache_add (struct cache_item *item,struct cache *cache,const char *name);void cache_del (struct cache_item *item);void table_cache_add (struct table *table,struct nft_cache *cache);
src/cache.c +15 -34
139 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 4/5 parser_bison: only reset by name is supported by now
In reply to Pablo Neira AyusoNFT_MSG_GETSET does not support for handle lookup yet, restrict this to reset by name by now.
Add a bogon test reported by Florian Westphal.
--- src/parser_bison.y | 4 ++-- tests/shell/testcases/bogons/nft-f/null_set_name_crash | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 tests/shell/testcases/bogons/nft-f/null_set_name_crash
src/parser_bison.y +2 -2
@@ -1757,11 +1757,11 @@ reset_cmd : COUNTERS list_cmd_spec_any { $$ = cmd_alloc(CMD_RESET, CMD_OBJ_ELEMENTS, &$2, &@$, $3); } - | SET set_or_id_spec + | SET set_spec { $$ = cmd_alloc(CMD_RESET, CMD_OBJ_SET, &$2, &@$, NULL); } - | MAP set_or_id_spec + | MAP set_spec { $$ = cmd_alloc(CMD_RESET, CMD_OBJ_MAP, &$2, &@$, NULL); }
tests/shell/testcases/bogons/nft-f/null_set_name_crash new file +2 -0
@@ -0,0 +1,2 @@ +table y { } +reset set y handle 6
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 5/5 parser_bison: allow delete command with map via handle
In reply to Pablo Neira AyusoFor consistency with sets, allow delete via handle for maps too.
This fix requires the handle hashtable lookup infrastructure.
--- src/parser_bison.y | 2 +- tests/shell/testcases/cache/0008_delete_by_handle_0 | 4 ++++ tests/shell/testcases/cache/0009_delete_by_handle_incorrect_0 | 1 + 3 files changed, 6 insertions(+), 1 deletion(-)
src/parser_bison.y +1 -1
@@ -1450,7 +1450,7 @@ delete_cmd : TABLE table_or_id_spec { $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SET, &$2, &@$, NULL); } - | MAP set_spec + | MAP set_or_id_spec { $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SET, &$2, &@$, NULL); }
tests/shell/testcases/cache/0008_delete_by_handle_0 +4 -0
@@ -16,6 +16,10 @@ $NFT add set t s { type ipv4_addr\; } HANDLE=`$NFT -a list ruleset | grep "set.*handle" | cut -d' ' -f6` $NFT delete set t handle $HANDLE +$NFT add map t m { type ipv4_addr : ipv4_addr\; } +HANDLE=`$NFT -a list ruleset | grep "map.*handle" | cut -d' ' -f6` +$NFT delete map t handle $HANDLE + $NFT add flowtable t f { hook ingress priority 0\; devices = { lo } \; } HANDLE=`$NFT -a list ruleset | grep "flowtable.*handle" | cut -d' ' -f6` $NFT delete flowtable t handle $HANDLE
tests/shell/testcases/cache/0009_delete_by_handle_incorrect_0 +1 -0
@@ -3,6 +3,7 @@ $NFT delete table handle 4000 && exit 1 $NFT delete chain t handle 4000 && exit 1 $NFT delete set t handle 4000 && exit 1 +$NFT delete map t handle 4000 && exit 1 $NFT delete flowtable t handle 4000 && exit 1 $NFT delete counter t handle 4000 && exit 1 exit 0
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerQuoted 4 lines · Pablo Neira Ayuso
Hi,
This batch contains several assorted updates and fixes:
Quoted 8 lines
1) Skip lookup for mistyped names if handle is used.
2) Assert of non-nul name when {table,chain,obj,flowtable}_cache_find() is used to catch for bugs when handle is used.
3) Consolidate repetitive cache name hash.
4) Restrict reset command to use name only becauseNFT_MSG_GETSETandNFT_MSG_GETSETELEMis missing lookup by handle in the kernel.
5) Allow to delete a map with handle, for consistency with the existing command to delete a set.
Pushed out.