diff options
author | Patrick McHardy <kaber@trash.net> | 2014-12-13 07:50:36 +0000 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2014-12-16 18:20:54 +0100 |
commit | 551d2a09ab93dfbc402b4a5789e6d865a168fb45 (patch) | |
tree | 0c0f88a8bfced5b215cc987ea5f797a1ea6c2489 /src | |
parent | 25b19818c46d6fea81f3b951223f4ec7fa86ed55 (diff) |
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 <kaber@trash.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/netlink.c | 2 | ||||
-rw-r--r-- | src/parser_bison.y | 63 |
2 files changed, 43 insertions, 22 deletions
diff --git a/src/netlink.c b/src/netlink.c index e59e2977..feaea19a 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -986,6 +986,8 @@ static const struct datatype *dtype_map_from_kernel(enum nft_data_types type) case NFT_DATA_VERDICT: return &verdict_type; default: + if (type & ~TYPE_MASK) + return concat_type_alloc(type); return datatype_lookup(type); } } 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 <string> identifier string comment_spec %destructor { xfree($$); } identifier string comment_spec +%type <val> type_identifier +%type <datatype> data_type + %type <cmd> line %destructor { cmd_free($$); } line @@ -915,14 +919,9 @@ set_block_alloc : /* empty */ set_block : /* empty */ { $$ = $<set>-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 */ { $$ = $<set>-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 { $<chain>0->type = chain_type_name_lookup($2); |