From da06a74244cbe4b02431ea2c34b8299f3562c9ff Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Thu, 14 Sep 2017 22:59:13 +0200 Subject: src: store expression as set key instead of data type Doing so retains legth information in case of unqualified data types, e.g. we now have 'meta iifname' expression instead of an (unqualified) string type. This allows to eventually use iifnames as set keys without adding yet another special data type for them. Signed-off-by: Florian Westphal Acked-by: Pablo Neira Ayuso --- src/parser_bison.y | 65 +++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'src/parser_bison.y') diff --git a/src/parser_bison.y b/src/parser_bison.y index 970d773e..c7ba1495 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -478,8 +478,8 @@ static void location_update(struct location *loc, struct location *rhs, int n) %type time_spec quota_used -%type type_identifier_list -%type data_type +%type data_type_expr data_type_atom_expr +%destructor { expr_free($$); } data_type_expr data_type_atom_expr %type line %destructor { cmd_free($$); } line @@ -1405,9 +1405,9 @@ set_block_alloc : /* empty */ set_block : /* empty */ { $$ = $-1; } | set_block common_block | set_block stmt_separator - | set_block TYPE data_type stmt_separator + | set_block TYPE data_type_expr stmt_separator { - $1->keytype = $3; + $1->key = $3; $$ = $1; } | set_block FLAGS set_flag_list stmt_separator @@ -1459,28 +1459,30 @@ map_block : /* empty */ { $$ = $-1; } | map_block common_block | map_block stmt_separator | map_block TYPE - data_type COLON data_type + data_type_expr COLON data_type_expr stmt_separator { - $1->keytype = $3; - $1->datatype = $5; + $1->key = $3; + $1->datatype = $5->dtype; + + expr_free($5); $1->flags |= NFT_SET_MAP; $$ = $1; } | map_block TYPE - data_type COLON COUNTER + data_type_expr COLON COUNTER stmt_separator { - $1->keytype = $3; + $1->key = $3; $1->objtype = NFT_OBJECT_COUNTER; $1->flags |= NFT_SET_OBJECT; $$ = $1; } | map_block TYPE - data_type COLON QUOTA + data_type_expr COLON QUOTA stmt_separator { - $1->keytype = $3; + $1->key = $3; $1->objtype = NFT_OBJECT_QUOTA; $1->flags |= NFT_SET_OBJECT; $$ = $1; @@ -1512,16 +1514,7 @@ set_policy_spec : PERFORMANCE { $$ = NFT_SET_POL_PERFORMANCE; } | MEMORY { $$ = NFT_SET_POL_MEMORY; } ; -data_type : type_identifier_list - { - if ($1 & ~TYPE_MASK) - $$ = concat_type_alloc($1); - else - $$ = datatype_lookup($1); - } - ; - -type_identifier_list : type_identifier +data_type_atom_expr : type_identifier { const struct datatype *dtype = datatype_lookup_byname($1); if (dtype == NULL) { @@ -1530,20 +1523,28 @@ type_identifier_list : type_identifier xfree($1); YYERROR; } - xfree($1); - $$ = dtype->type; + $$ = constant_expr_alloc(&@1, dtype, dtype->byteorder, + dtype->size, NULL); } - | type_identifier_list DOT type_identifier + ; + +data_type_expr : data_type_atom_expr + | data_type_expr DOT data_type_atom_expr { - const struct datatype *dtype = datatype_lookup_byname($3); - if (dtype == NULL) { - erec_queue(error(&@3, "unknown datatype %s", $3), - state->msgs); - xfree($3); - YYERROR; + if ($1->ops->type != EXPR_CONCAT) { + $$ = concat_expr_alloc(&@$); + compound_expr_add($$, $1); + } else { + struct location rhs[] = { + [1] = @2, + [2] = @3, + }; + location_update(&$3->location, rhs, 2); + + $$ = $1; + $$->location = @$; } - xfree($3); - $$ = concat_subtype_add($$, dtype->type); + compound_expr_add($$, $3); } ; -- cgit v1.2.3