]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_bison: compact and simplify list and reset syntax
authorFlorian Westphal <fw@strlen.de>
Thu, 16 Jan 2025 08:32:01 +0000 (09:32 +0100)
committerFlorian Westphal <fw@strlen.de>
Fri, 21 Feb 2025 21:54:10 +0000 (22:54 +0100)
Works:
list sets
list sets inet
list sets table inet foo

Doesn't work:
list sets inet foo

Same for "list counters", "list quotas", etc.

"reset" keyword however supports this:
reset counters inet foo

and aliased this to
reset counters table inet foo

This is inconsistent and not inuitive.

Moreover, unlike "list sets", "list maps" only supported "list maps" and
"list maps inet", without the ability to only list maps of a given table.

Compact this to unify the syntax so it becomes possible to omit the "table"
keyword for either reset or list mode.

flowtables, secmarks and synproxys keywords are updated too.  "flow table"
and "meters" are NOT changed since both of these are deprecated in favor
of standard nft sets.

Reported-by: Slavko <linux@slavino.sk>
Signed-off-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
doc/nft.txt
src/parser_bison.y

index 846ccfb28b92226e731eb81983f7b9553a2e95ad..c1bb49970a22302525d0cccacc5df7b9eee7b9cf 100644 (file)
@@ -587,7 +587,7 @@ section describes nft set syntax in more detail.
 [verse]
 *add set* ['family'] 'table' 'set' *{ type* 'type' | *typeof* 'expression' *;* [*flags* 'flags' *;*] [*timeout* 'timeout' *;*] [*gc-interval* 'gc-interval' *;*] [*elements = {* 'element'[*,* ...] *} ;*] [*size* 'size' *;*] [*comment* 'comment' *;*'] [*policy* 'policy' *;*] [*auto-merge ;*] *}*
 {*delete* | *destroy* | *list* | *flush* | *reset* } *set* ['family'] 'table' 'set'
-*list sets* ['family']
+*list sets* ['family'] ['table']
 *delete set* ['family'] 'table' *handle* 'handle'
 {*add* | *delete* | *destroy* } *element* ['family'] 'table' 'set' *{* 'element'[*,* ...] *}*
 
@@ -641,7 +641,7 @@ MAPS
 [verse]
 *add map* ['family'] 'table' 'map' *{ type* 'type' | *typeof* 'expression' [*flags* 'flags' *;*] [*elements = {* 'element'[*,* ...] *} ;*] [*size* 'size' *;*] [*comment* 'comment' *;*'] [*policy* 'policy' *;*] *}*
 {*delete* | *destroy* | *list* | *flush* | *reset* } *map* ['family'] 'table' 'map'
-*list maps* ['family']
+*list maps* ['family'] ['table']
 
 Maps store data based on some specific key used as input. They are uniquely identified by a user-defined name and attached to tables.
 
@@ -738,7 +738,7 @@ FLOWTABLES
 -----------
 [verse]
 {*add* | *create*} *flowtable* ['family'] 'table' 'flowtable' *{ hook* 'hook' *priority* 'priority' *; devices = {* 'device'[*,* ...] *} ; }*
-*list flowtables* ['family']
+*list flowtables* ['family'] ['table']
 {*delete* | *destroy* | *list*} *flowtable* ['family'] 'table' 'flowtable'
 *delete* *flowtable* ['family'] 'table' *handle* 'handle'
 
@@ -778,13 +778,8 @@ STATEFUL OBJECTS
 *destroy* 'counter' ['family'] 'table' *handle* 'handle'
 *destroy* 'quota' ['family'] 'table' *handle* 'handle'
 *destroy* 'limit' ['family'] 'table' *handle* 'handle'
-*list counters* ['family']
-*list quotas* ['family']
-*list limits* ['family']
-*reset counters* ['family']
-*reset quotas* ['family']
-*reset counters* ['family'] 'table'
-*reset quotas* ['family'] 'table'
+*list* { *counters* | *limits* | *quotas* } ['family'] ['table']
+*reset* { *counters* | *quotas* } ['family'] ['table']
 
 Stateful objects are attached to tables and are identified by a unique name.
 They group stateful information from rules, to reference them in rules the
index d15bf212489d53d62925b041d92589fc4f36dd0a..fa8dc83f7db8870dd74f432d093318b0043b0729 100644 (file)
@@ -723,6 +723,9 @@ int nft_lex(void *, void *, void *);
 %type <handle>                 basehook_spec
 %destructor { handle_free(&$$); } basehook_spec
 
+%type <handle>                 list_cmd_spec_any       list_cmd_spec_table
+%destructor { handle_free(&$$); } list_cmd_spec_any    list_cmd_spec_table
+
 %type <val>                    family_spec family_spec_explicit
 %type <val32>                  int_num chain_policy
 %type <prio_spec>              extended_prio_spec prio_spec
@@ -1570,6 +1573,13 @@ get_cmd                  :       ELEMENT         set_spec        set_block_expr
                        }
                        ;
 
+list_cmd_spec_table    :       TABLE   table_spec      { $$ = $2; }
+                       |       table_spec
+                       ;
+list_cmd_spec_any      :       list_cmd_spec_table
+                       |       ruleset_spec
+                       ;
+
 list_cmd               :       TABLE           table_spec
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_TABLE, &$2, &@$, NULL);
@@ -1586,74 +1596,50 @@ list_cmd                :       TABLE           table_spec
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_CHAINS, &$2, &@$, NULL);
                        }
-                       |       SETS            ruleset_spec
+                       |       SETS            list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
                        }
-                       |       SETS            TABLE   table_spec
-                       {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$3, &@$, NULL);
-                       }
                        |       SET             set_spec
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SET, &$2, &@$, NULL);
                        }
-                       |       COUNTERS        ruleset_spec
+                       |       COUNTERS        list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_COUNTERS, &$2, &@$, NULL);
                        }
-                       |       COUNTERS        TABLE   table_spec
-                       {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_COUNTERS, &$3, &@$, NULL);
-                       }
                        |       COUNTER         obj_spec        close_scope_counter
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_COUNTER, &$2, &@$, NULL);
                        }
-                       |       QUOTAS          ruleset_spec
+                       |       QUOTAS          list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_QUOTAS, &$2, &@$, NULL);
                        }
-                       |       QUOTAS          TABLE   table_spec
-                       {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_QUOTAS, &$3, &@$, NULL);
-                       }
                        |       QUOTA           obj_spec        close_scope_quota
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_QUOTA, &$2, &@$, NULL);
                        }
-                       |       LIMITS          ruleset_spec
+                       |       LIMITS          list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_LIMITS, &$2, &@$, NULL);
                        }
-                       |       LIMITS          TABLE   table_spec
-                       {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_LIMITS, &$3, &@$, NULL);
-                       }
                        |       LIMIT           obj_spec        close_scope_limit
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_LIMIT, &$2, &@$, NULL);
                        }
-                       |       SECMARKS        ruleset_spec
+                       |       SECMARKS        list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SECMARKS, &$2, &@$, NULL);
                        }
-                       |       SECMARKS        TABLE   table_spec
-                       {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SECMARKS, &$3, &@$, NULL);
-                       }
                        |       SECMARK         obj_spec        close_scope_secmark
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SECMARK, &$2, &@$, NULL);
                        }
-                       |       SYNPROXYS       ruleset_spec
+                       |       SYNPROXYS       list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SYNPROXYS, &$2, &@$, NULL);
                        }
-                       |       SYNPROXYS       TABLE   table_spec
-                       {
-                               $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SYNPROXYS, &$3, &@$, NULL);
-                       }
                        |       SYNPROXY        obj_spec        close_scope_synproxy
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SYNPROXY, &$2, &@$, NULL);
@@ -1678,7 +1664,7 @@ list_cmd          :       TABLE           table_spec
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_METER, &$2, &@$, NULL);
                        }
-                       |       FLOWTABLES      ruleset_spec
+                       |       FLOWTABLES      list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_FLOWTABLES, &$2, &@$, NULL);
                        }
@@ -1686,7 +1672,7 @@ list_cmd          :       TABLE           table_spec
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_FLOWTABLE, &$2, &@$, NULL);
                        }
-                       |       MAPS            ruleset_spec
+                       |       MAPS            list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_LIST, CMD_OBJ_MAPS, &$2, &@$, NULL);
                        }
@@ -1728,36 +1714,18 @@ basehook_spec           :       ruleset_spec
                        }
                        ;
 
-reset_cmd              :       COUNTERS        ruleset_spec
+reset_cmd              :       COUNTERS        list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_RESET, CMD_OBJ_COUNTERS, &$2, &@$, NULL);
                        }
-                       |       COUNTERS        table_spec
-                       {
-                               $$ = cmd_alloc(CMD_RESET, CMD_OBJ_COUNTERS, &$2, &@$, NULL);
-                       }
-                       |       COUNTERS        TABLE   table_spec
-                       {
-                               /* alias of previous rule. */
-                               $$ = cmd_alloc(CMD_RESET, CMD_OBJ_COUNTERS, &$3, &@$, NULL);
-                       }
                        |       COUNTER         obj_spec        close_scope_counter
                        {
                                $$ = cmd_alloc(CMD_RESET, CMD_OBJ_COUNTER, &$2,&@$, NULL);
                        }
-                       |       QUOTAS          ruleset_spec
+                       |       QUOTAS          list_cmd_spec_any
                        {
                                $$ = cmd_alloc(CMD_RESET, CMD_OBJ_QUOTAS, &$2, &@$, NULL);
                        }
-                       |       QUOTAS          TABLE   table_spec
-                       {
-                               $$ = cmd_alloc(CMD_RESET, CMD_OBJ_QUOTAS, &$3, &@$, NULL);
-                       }
-                       |       QUOTAS          table_spec
-                       {
-                               /* alias of previous rule. */
-                               $$ = cmd_alloc(CMD_RESET, CMD_OBJ_QUOTAS, &$2, &@$, NULL);
-                       }
                        |       QUOTA           obj_spec        close_scope_quota
                        {
                                $$ = cmd_alloc(CMD_RESET, CMD_OBJ_QUOTA, &$2, &@$, NULL);
@@ -1766,15 +1734,10 @@ reset_cmd               :       COUNTERS        ruleset_spec
                        {
                                $$ = cmd_alloc(CMD_RESET, CMD_OBJ_RULES, &$2, &@$, NULL);
                        }
-                       |       RULES           table_spec
+                       |       RULES           list_cmd_spec_table
                        {
                                $$ = cmd_alloc(CMD_RESET, CMD_OBJ_TABLE, &$2, &@$, NULL);
                        }
-                       |       RULES           TABLE   table_spec
-                       {
-                               /* alias of previous rule. */
-                               $$ = cmd_alloc(CMD_RESET, CMD_OBJ_TABLE, &$3, &@$, NULL);
-                       }
                        |       RULES           chain_spec
                        {
                                $$ = cmd_alloc(CMD_RESET, CMD_OBJ_CHAIN, &$2, &@$, NULL);