Skip to contentSkip to conversation

netlink: use set location for IO errors

PATCH New Patrick McHardy 1 participant 2 messages Mar 7, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 netlink: use set location for IO errors

We currently crash when reporting a permission denied error for set additions. This is due to using the wrong location, fix by passing in the set location.

---
 src/netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/netlink.c +1 -1
index b2bd3c5..daac64c 100644
@@ -777,7 +777,7 @@ int netlink_add_set(struct netlink_ctx *ctx, const struct handle *h,
 
 	err = mnl_nft_set_add(nf_sock, nls, NLM_F_EXCL | NLM_F_ECHO);
 	if (err < 0)
-		netlink_io_error(ctx, NULL, "Could not add set: %s",
+		netlink_io_error(ctx, &set->location, "Could not add set: %s",
 				 strerror(errno));
 
 	set->handle.set =
Signature · 1 line
1.8.5.3
#1 lore raw

PATCH 2/2 parser: add grammatical distinction for verdict maps

Currently the parser accepts verdicts in regular maps and non-verdicts in verdict maps and we have to check matching types during evaluation. Add grammar rules for verdict maps and seperate them from regular maps. This has a couple of advantages:

- We recognize verdict maps completely in the parser and any attempt to mix verdicts and other expressions will result in a syntax error. So far this hasn't actually been checked.

- Using verdicts in non-verdict mappings will also result in a syntax error instead of a datatype mismatch.

- There's a grammatical distinction between dictionaries and verdict maps, which are actually statements.

This is needed as preparation for a following patch to turn verdicts into pure statements, which in turn is needed to reinstate support for using the queue verdict in maps, which was broken by the introduction of the queue statement.

---
 src/parser.y | 52 +++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 13 deletions(-)
src/parser.y +39 -13
index dd09fb4..0d97ae9 100644
@@ -428,8 +428,11 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %type <expr>			map_expr
 %destructor { expr_free($$); }	map_expr
 
-%type <expr>			verdict_map_expr
-%destructor { expr_free($$); }	verdict_map_expr
+%type <expr>			verdict_map_stmt
+%destructor { expr_free($$); }	verdict_map_stmt
+
+%type <expr>			verdict_map_expr verdict_map_list_expr verdict_map_list_member_expr
+%destructor { expr_free($$); }	verdict_map_expr verdict_map_list_expr verdict_map_list_member_expr
 
 %type <expr>			set_expr set_list_expr set_list_member_expr
 %destructor { expr_free($$); }	set_expr set_list_expr set_list_member_expr
@@ -1072,12 +1075,45 @@ verdict_stmt		:	verdict_expr
 			{
 				$$ = verdict_stmt_alloc(&@$, $1);
 			}
-			|	verdict_map_expr
+			|	verdict_map_stmt
 			{
 				$$ = verdict_stmt_alloc(&@$, $1);
 			}
 			;
 
+verdict_map_stmt	:	concat_expr	VMAP	verdict_map_expr
+			{
+				$$ = map_expr_alloc(&@$, $1, $3);
+			}
+			;
+
+verdict_map_expr	:	'{'	verdict_map_list_expr	'}'
+			{
+				$2->location = @$;
+				$$ = $2;
+			}
+			;
+
+verdict_map_list_expr	:	verdict_map_list_member_expr
+			{
+				$$ = set_expr_alloc(&@$);
+				compound_expr_add($$, $1);
+			}
+			|	verdict_map_list_expr	COMMA	verdict_map_list_member_expr
+			{
+				compound_expr_add($1, $3);
+				$$ = $1;
+			}
+			|	verdict_map_list_expr	COMMA	opt_newline
+			;
+
+verdict_map_list_member_expr:	opt_newline	map_lhs_expr	COLON	verdict_expr	opt_newline
+			{
+				$$ = mapping_expr_alloc(&@$, $2, $4);
+			}
+			;
+
+
 counter_stmt		:	counter_stmt_alloc
 			|	counter_stmt_alloc	counter_args
 
@@ -1404,12 +1440,6 @@ map_expr		:	concat_expr	MAP	expr
 			}
 			;
 
-verdict_map_expr	:	concat_expr	VMAP	expr
-			{
-				$$ = map_expr_alloc(&@$, $1, $3);
-			}
-			;
-
 expr			:	concat_expr
 			|	set_expr
 			|       map_expr
@@ -1444,10 +1474,6 @@ set_list_member_expr	:	opt_newline	expr	opt_newline
 			{
 				$$ = mapping_expr_alloc(&@$, $2, $4);
 			}
-			|	opt_newline	map_lhs_expr	COLON	verdict_expr	opt_newline
-			{
-				$$ = mapping_expr_alloc(&@$, $2, $4);
-			}
 			;
 
 initializer_expr	:	expr
Signature · 1 line
1.8.5.3