From 551d2a09ab93dfbc402b4a5789e6d865a168fb45 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Sat, 13 Dec 2014 07:50:36 +0000 Subject: parser: alloc specifying concat types in set declarations Support specification of concat types in set declarations: add set filter test { type ipv4_addr . inet_service } Netlink delinearization is changed to reconstruct the type from the id. Signed-off-by: Patrick McHardy --- src/parser_bison.y | 63 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 22 deletions(-) (limited to 'src/parser_bison.y') diff --git a/src/parser_bison.y b/src/parser_bison.y index 99dbd088..3059d59a 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -132,6 +132,7 @@ static void location_update(struct location *loc, struct location *rhs, int n) struct stmt *stmt; struct expr *expr; struct set *set; + const struct datatype *datatype; } %token TOKEN_EOF 0 "end of file" @@ -396,6 +397,9 @@ static void location_update(struct location *loc, struct location *rhs, int n) %type identifier string comment_spec %destructor { xfree($$); } identifier string comment_spec +%type type_identifier +%type data_type + %type line %destructor { cmd_free($$); } line @@ -915,14 +919,9 @@ set_block_alloc : /* empty */ set_block : /* empty */ { $$ = $-1; } | set_block common_block | set_block stmt_seperator - | set_block TYPE identifier stmt_seperator + | set_block TYPE data_type stmt_seperator { - $1->keytype = datatype_lookup_byname($3); - if ($1->keytype == NULL) { - erec_queue(error(&@3, "unknown datatype %s", $3), - state->msgs); - YYERROR; - } + $1->keytype = $3; $$ = $1; } | set_block FLAGS set_flag_list stmt_seperator @@ -960,23 +959,11 @@ map_block : /* empty */ { $$ = $-1; } | map_block common_block | map_block stmt_seperator | map_block TYPE - identifier COLON identifier + data_type COLON data_type stmt_seperator { - $1->keytype = datatype_lookup_byname($3); - if ($1->keytype == NULL) { - erec_queue(error(&@3, "unknown datatype %s", $3), - state->msgs); - YYERROR; - } - - $1->datatype = datatype_lookup_byname($5); - if ($1->datatype == NULL) { - erec_queue(error(&@5, "unknown datatype %s", $5), - state->msgs); - YYERROR; - } - + $1->keytype = $3; + $1->datatype = $5; $$ = $1; } | map_block FLAGS set_flag_list stmt_seperator @@ -1006,6 +993,38 @@ set_policy_spec : PERFORMANCE { $$ = NFT_SET_POL_PERFORMANCE; } | MEMORY { $$ = NFT_SET_POL_MEMORY; } ; +data_type : type_identifier + { + if ($1 & ~TYPE_MASK) + $$ = concat_type_alloc($1); + else + $$ = datatype_lookup($1); + } + ; + +type_identifier : identifier + { + const struct datatype *dtype = datatype_lookup_byname($1); + if (dtype == NULL) { + erec_queue(error(&@1, "unknown datatype %s", $1), + state->msgs); + YYERROR; + } + $$ = dtype->type; + } + | type_identifier DOT identifier + { + const struct datatype *dtype = datatype_lookup_byname($3); + if (dtype == NULL) { + erec_queue(error(&@3, "unknown datatype %s", $3), + state->msgs); + YYERROR; + } + $$ <<= TYPE_BITS; + $$ |= dtype->type; + } + ; + hook_spec : TYPE STRING HOOK STRING PRIORITY NUM { $0->type = chain_type_name_lookup($2); -- cgit v1.2.3