Skip to contentSkip to conversation

parser_bison: Accept arbitrary user-defined names by quoting

PATCH Superseded Phil Sutter 1 participant 1 message Jun 24, 2019 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 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.

---
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  | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100755 tests/shell/testcases/nft-f/0018quoted-names_0
src/parser_bison.y +2 -1
index 670e91f544c75..de8b097a4c222 100644
@@ -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 +19 -0
new file mode 100755
index 0000000000000..9655a48d492c0
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# Test if keywords are allowed as names if quoted
+
+set -e
+
+# XXX: interface names are arbitrary, too (flowtable, chain)
+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"
+OUTPUT=$($NFT list ruleset)
+$NFT -f - <<< "$OUTPUT"
Signature · 1 line
2.21.0