* [PATCH nft] parser_bison: simplify syntax to list all sets in table
@ 2025-01-11 14:37 Pablo Neira Ayuso
2025-01-11 16:24 ` Florian Westphal
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2025-01-11 14:37 UTC (permalink / raw)
To: netfilter-devel; +Cc: fw, linux
Revisit f99ccda252fa ("parser: allow listing sets in one table") to add
an alias to list all sets in a given table, eg.
# nft list sets ip x
table ip x {
set s1 {
type ipv4_addr
}
set s2 {
type ipv4_addr
}
}
This is similar to 275989737ec4 ("parser_bison: simplify reset syntax").
Update nft(8) manpage too.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
doc/nft.txt | 2 ++
src/parser_bison.y | 5 +++++
2 files changed, 7 insertions(+)
diff --git a/doc/nft.txt b/doc/nft.txt
index 846ccfb28b92..12de0181ab91 100644
--- a/doc/nft.txt
+++ b/doc/nft.txt
@@ -588,6 +588,8 @@ section describes nft set syntax in more detail.
*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'
+*list set* ['family'] 'table' 'set'
*delete set* ['family'] 'table' *handle* 'handle'
{*add* | *delete* | *destroy* } *element* ['family'] 'table' 'set' *{* 'element'[*,* ...] *}*
diff --git a/src/parser_bison.y b/src/parser_bison.y
index c8714812532d..ac8de398f8a7 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -1590,8 +1590,13 @@ list_cmd : TABLE table_spec
{
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
}
+ | SETS table_spec
+ {
+ $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
+ }
| SETS TABLE table_spec
{
+ /* alias of previous rule. */
$$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$3, &@$, NULL);
}
| SET set_spec
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH nft] parser_bison: simplify syntax to list all sets in table
2025-01-11 14:37 [PATCH nft] parser_bison: simplify syntax to list all sets in table Pablo Neira Ayuso
@ 2025-01-11 16:24 ` Florian Westphal
2025-01-11 22:45 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Florian Westphal @ 2025-01-11 16:24 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: netfilter-devel, fw, linux
Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> Revisit f99ccda252fa ("parser: allow listing sets in one table") to add
> an alias to list all sets in a given table, eg.
[..]
> diff --git a/src/parser_bison.y b/src/parser_bison.y
> index c8714812532d..ac8de398f8a7 100644
> --- a/src/parser_bison.y
> +++ b/src/parser_bison.y
> @@ -1590,8 +1590,13 @@ list_cmd : TABLE table_spec
> {
> $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
> }
> + | SETS table_spec
> + {
> + $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
> + }
> | SETS TABLE table_spec
> {
> + /* alias of previous rule. */
> $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$3, &@$, NULL);
> }
I have concerns wrt. to ever expanding list of aliases, it causes divergence as
to what is allowed:
<keyword>
<keyword> inet
<keyword> inet foo
<keyword> table inet foo
In some cases, all of these work (4 being aliased to 3).
In others, e.g. "counters" or "quotas" "inet foo" won't work.
It would be good to at least be consistent. What about this?
It would be good to compact it further, this is all because of
copypastry +slow divergence on later addendums to command subsets.
src/parser_bison.y | 63 +++++++++++++---------------------------------
1 file changed, 17 insertions(+), 46 deletions(-)
diff --git a/src/parser_bison.y b/src/parser_bison.y
index c8714812532d..1f4e78b1b692 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -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,50 +1596,34 @@ 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);
@@ -1728,36 +1722,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 +1742,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);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH nft] parser_bison: simplify syntax to list all sets in table
2025-01-11 16:24 ` Florian Westphal
@ 2025-01-11 22:45 ` Pablo Neira Ayuso
0 siblings, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2025-01-11 22:45 UTC (permalink / raw)
To: Florian Westphal; +Cc: netfilter-devel, linux
On Sat, Jan 11, 2025 at 05:24:45PM +0100, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > Revisit f99ccda252fa ("parser: allow listing sets in one table") to add
> > an alias to list all sets in a given table, eg.
>
> [..]
>
> > diff --git a/src/parser_bison.y b/src/parser_bison.y
> > index c8714812532d..ac8de398f8a7 100644
> > --- a/src/parser_bison.y
> > +++ b/src/parser_bison.y
> > @@ -1590,8 +1590,13 @@ list_cmd : TABLE table_spec
> > {
> > $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
> > }
> > + | SETS table_spec
> > + {
> > + $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$2, &@$, NULL);
> > + }
> > | SETS TABLE table_spec
> > {
> > + /* alias of previous rule. */
> > $$ = cmd_alloc(CMD_LIST, CMD_OBJ_SETS, &$3, &@$, NULL);
> > }
>
> I have concerns wrt. to ever expanding list of aliases, it causes divergence as
> to what is allowed:
>
> <keyword>
> <keyword> inet
> <keyword> inet foo
> <keyword> table inet foo
>
> In some cases, all of these work (4 being aliased to 3).
> In others, e.g. "counters" or "quotas" "inet foo" won't work.
>
> It would be good to at least be consistent. What about this?
>
> It would be good to compact it further, this is all because of
> copypastry +slow divergence on later addendums to command subsets.
Consolidating aliases is indeed better approach, please go ahead
submit this patch.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-11 22:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-11 14:37 [PATCH nft] parser_bison: simplify syntax to list all sets in table Pablo Neira Ayuso
2025-01-11 16:24 ` Florian Westphal
2025-01-11 22:45 ` Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.