diff options
author | Florian Westphal <fw@strlen.de> | 2017-09-14 22:59:13 +0200 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2017-09-27 15:18:14 +0200 |
commit | da06a74244cbe4b02431ea2c34b8299f3562c9ff (patch) | |
tree | 5f060ff612d59e67d15b3ac796c9af85d6dd9d14 /src/parser_bison.y | |
parent | 027734420b213560ab7e261d6b4b969e16e97343 (diff) |
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 <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/parser_bison.y')
-rw-r--r-- | src/parser_bison.y | 65 |
1 files changed, 33 insertions, 32 deletions
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 <val> time_spec quota_used -%type <val> type_identifier_list -%type <datatype> data_type +%type <expr> data_type_expr data_type_atom_expr +%destructor { expr_free($$); } data_type_expr data_type_atom_expr %type <cmd> line %destructor { cmd_free($$); } line @@ -1405,9 +1405,9 @@ set_block_alloc : /* empty */ set_block : /* empty */ { $$ = $<set>-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 */ { $$ = $<set>-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); } ; |