parser_bison: Accept arbitrary user-defined names by quoting
Phil Sutter
reviewerPATCH v2 1/1 parser_bison: Accept arbitrary user-defined names by quoting
Parser already allows to quote user-defined strings in some places to avoid clashing with defined keywords, but not everywhere. Extend this support further and add a test case for it.
---
Changes since v1:
- Fix testcase, I forgot to commit adjustments done to it.
Note: This is a reduced variant of "src: Quote user-defined names" sent
back in January. Discussion was not conclusive regarding whether to quote these names on output or not, but I assume allowing for users to specify them by adding quotes is a step forward without drawbacks.
--- src/parser_bison.y | 3 ++- .../shell/testcases/nft-f/0018quoted-names_0 | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 tests/shell/testcases/nft-f/0018quoted-names_0
src/parser_bison.y +2 -1
@@ -1761,7 +1761,7 @@ flowtable_list_expr : flowtable_expr_member | flowtable_list_expr COMMA opt_newline ; -flowtable_expr_member : STRING +flowtable_expr_member : string { $$ = symbol_expr_alloc(&@$, SYMBOL_VALUE, current_scope(state),
@@ -1968,6 +1968,7 @@ chain_policy : ACCEPT { $$ = NF_ACCEPT; } ; identifier : STRING + | QUOTED_STRING ; string : STRING
tests/shell/testcases/nft-f/0018quoted-names_0 new file +20 -0
@@ -0,0 +1,20 @@ +#!/bin/bash + +# Test if keywords are allowed as names if quoted + +set -e + +RULESET=' +table inet "day" { + chain "minute" {} + set "hour" { type inet_service; } + flowtable "second" { hook ingress priority 0; devices = { "lo" }; } + counter "table" { packets 0 bytes 0 } + quota "chain" { 10 bytes } +}' + +$NFT -f - <<< "$RULESET" + +# XXX: not possible (yet) +#OUTPUT=$($NFT list ruleset) +#$NFT -f - <<< "$OUTPUT"
Signature · 1 line
2.21.0
Pablo Neira Ayuso
maintainerQuoted 9 lines · Phil Sutter
Parser already allows to quote user-defined strings in some places to avoid clashing with defined keywords, but not everywhere. Extend this support further and add a test case for it.
Signed-off-by Phil Sutter <[email protected]>---
Changes since v1:
- Fix testcase, I forgot to commit adjustments done to it.
Quoted 5 lines
Note: This is a reduced variant of "src: Quote user-defined names" sent
back in January. Discussion was not conclusive regarding whether to quote these names on output or not, but I assume allowing for users to specify them by adding quotes is a step forward without drawbacks.
So this will fail later on, right?
nft list ruleset > file.nft
nft -f file.nft
Quoted 56 lines
--- src/parser_bison.y | 3 ++- .../shell/testcases/nft-f/0018quoted-names_0 | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 tests/shell/testcases/nft-f/0018quoted-names_0src/parser_bison.y +2
-1@@ -1761,7 +1761,7 @@ flowtable_list_expr : flowtable_expr_member | flowtable_list_expr COMMA opt_newline ; -flowtable_expr_member : STRING +flowtable_expr_member : string { $$ = symbol_expr_alloc(&@$, SYMBOL_VALUE, current_scope(state),@@ -1968,6 +1968,7 @@ chain_policy : ACCEPT { $$ = NF_ACCEPT; } ; identifier : STRING + | QUOTED_STRING ; string : STRINGtests/shell/testcases/nft-f/0018quoted-names_0 new file +20
-0@@ -0,0 +1,20 @@ +#!/bin/bash + +# Test if keywords are allowed as names if quoted + +set -e + +RULESET=' +table inet "day" { + chain "minute" {} + set "hour" { type inet_service; } + flowtable "second" { hook ingress priority 0; devices = { "lo" }; } + counter "table" { packets 0 bytes 0 } + quota "chain" { 10 bytes } +}' + +$NFT -f - <<< "$RULESET" + +# XXX: not possible (yet) +#OUTPUT=$($NFT list ruleset) +#$NFT -f - <<< "$OUTPUT"Signature · 1 line
2.21.0
Phil Sutter
reviewerHi Pablo,
Quoted 16 lines · Pablo Neira Ayuso
Quoted 9 lines · Phil Sutter
Parser already allows to quote user-defined strings in some places to avoid clashing with defined keywords, but not everywhere. Extend this support further and add a test case for it.
Signed-off-by Phil Sutter <[email protected]>---
Changes since v1:
- Fix testcase, I forgot to commit adjustments done to it.Quoted 5 lines
Note: This is a reduced variant of "src: Quote user-defined names" sent
back in January. Discussion was not conclusive regarding whether to quote these names on output or not, but I assume allowing for users to specify them by adding quotes is a step forward without drawbacks.
Quoted 4 lines
So this will fail later on, right?
nft list ruleset > file.nft
nft -f file.nft
Yes, that's right. I sent a complete version which does the necessary quoting on output in January[1], but discussion wasn't conclusive. You had a different approach which accepts the quotes as part of the name but you weren't happy with it, either. I *think* you wanted to search for ways to solve this from within bison but we never got back to it anymore.
This simplified patch is merely trying to make things consistent regarding user-defined names. IIRC, I can already have an interface named "month", use that in a netdev family chain declaration (quoted) and 'nft list ruleset' will print it unquoted, so it can't be applied anymore. Without my patch, it is simply impossible to use certain recognized keywords as names for tables, chains, etc., even if one accepted the implications it has.
Cheers, Phil
[1] Message-Id: <[email protected]>
Pablo Neira Ayuso
maintainerQuoted 31 lines · Phil Sutter
Hi Pablo,
Quoted 16 lines · Pablo Neira Ayuso
Quoted 9 lines · Phil Sutter
Parser already allows to quote user-defined strings in some places to avoid clashing with defined keywords, but not everywhere. Extend this support further and add a test case for it.
Signed-off-by Phil Sutter <[email protected]>---
Changes since v1:
- Fix testcase, I forgot to commit adjustments done to it.Quoted 5 lines
Note: This is a reduced variant of "src: Quote user-defined names" sent
back in January. Discussion was not conclusive regarding whether to quote these names on output or not, but I assume allowing for users to specify them by adding quotes is a step forward without drawbacks.Quoted 4 lines
So this will fail later on, right?
nft list ruleset > file.nft
nft -f file.nftYes, that's right. I sent a complete version which does the necessary quoting on output in January[1], but discussion wasn't conclusive. You had a different approach which accepts the quotes as part of the name but you weren't happy with it, either. I *think* you wanted to search for ways to solve this from within bison but we never got back to it anymore.
Quoted 7 lines
This simplified patch is merely trying to make things consistent regarding user-defined names. IIRC, I can already have an interface named "month", use that in a netdev family chain declaration (quoted) and 'nft list ruleset' will print it unquoted, so it can't be applied anymore. Without my patch, it is simply impossible to use certain recognized keywords as names for tables, chains, etc., even if one accepted the implications it has.
I'm not arguing there's something to fix.
I'm telling this is still incomplete.
Would you allocate a bit of time to discuss this during the NFWS?
Pablo Neira Ayuso
maintainerQuoted 40 lines · Pablo Neira Ayuso
Quoted 31 lines · Phil Sutter
Hi Pablo,
Quoted 16 lines · Pablo Neira Ayuso
Quoted 9 lines · Phil Sutter
Parser already allows to quote user-defined strings in some places to avoid clashing with defined keywords, but not everywhere. Extend this support further and add a test case for it.
Signed-off-by Phil Sutter <[email protected]>---
Changes since v1:
- Fix testcase, I forgot to commit adjustments done to it.Quoted 5 lines
Note: This is a reduced variant of "src: Quote user-defined names" sent
back in January. Discussion was not conclusive regarding whether to quote these names on output or not, but I assume allowing for users to specify them by adding quotes is a step forward without drawbacks.Quoted 4 lines
So this will fail later on, right?
nft list ruleset > file.nft
nft -f file.nftYes, that's right. I sent a complete version which does the necessary quoting on output in January[1], but discussion wasn't conclusive. You had a different approach which accepts the quotes as part of the name but you weren't happy with it, either. I *think* you wanted to search for ways to solve this from within bison but we never got back to it anymore.
Quoted 7 lines
This simplified patch is merely trying to make things consistent regarding user-defined names. IIRC, I can already have an interface named "month", use that in a netdev family chain declaration (quoted) and 'nft list ruleset' will print it unquoted, so it can't be applied anymore. Without my patch, it is simply impossible to use certain recognized keywords as names for tables, chains, etc., even if one accepted the implications it has.
Quoted 5 lines
I'm not arguing there's something to fix.
I'm telling this is still incomplete.
Would you allocate a bit of time to discuss this during the NFWS?
I mean, a quick summary of the different options for a complete solution for this, and we decide there.
Unless you tell me this is very urgent :-)
Phil Sutter
reviewerHi Pablo,
Quoted 43 lines · Pablo Neira Ayuso
Quoted 42 lines · Pablo Neira Ayuso
Quoted 31 lines · Phil Sutter
Hi Pablo,
Quoted 16 lines · Pablo Neira Ayuso
Quoted 9 lines · Phil Sutter
Parser already allows to quote user-defined strings in some places to avoid clashing with defined keywords, but not everywhere. Extend this support further and add a test case for it.
Signed-off-by Phil Sutter <[email protected]>---
Changes since v1:
- Fix testcase, I forgot to commit adjustments done to it.Quoted 5 lines
Note: This is a reduced variant of "src: Quote user-defined names" sent
back in January. Discussion was not conclusive regarding whether to quote these names on output or not, but I assume allowing for users to specify them by adding quotes is a step forward without drawbacks.Quoted 4 lines
So this will fail later on, right?
nft list ruleset > file.nft
nft -f file.nftYes, that's right. I sent a complete version which does the necessary quoting on output in January[1], but discussion wasn't conclusive. You had a different approach which accepts the quotes as part of the name but you weren't happy with it, either. I *think* you wanted to search for ways to solve this from within bison but we never got back to it anymore.
Quoted 7 lines
This simplified patch is merely trying to make things consistent regarding user-defined names. IIRC, I can already have an interface named "month", use that in a netdev family chain declaration (quoted) and 'nft list ruleset' will print it unquoted, so it can't be applied anymore. Without my patch, it is simply impossible to use certain recognized keywords as names for tables, chains, etc., even if one accepted the implications it has.
I'm not arguing there's something to fix.
Quoted 8 lines
Quoted 3 lines
I'm telling this is still incomplete.
Would you allocate a bit of time to discuss this during the NFWS?
I mean, a quick summary of the different options for a complete solution for this, and we decide there.
Unless you tell me this is very urgent :-)
That's a great idea! I'll check my inbox for more of those unfinished topics. :)
Thanks, Phil