]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser: alloc specifying concat types in set declarations
authorPatrick McHardy <kaber@trash.net>
Sat, 13 Dec 2014 07:50:36 +0000 (07:50 +0000)
committerPatrick McHardy <kaber@trash.net>
Tue, 16 Dec 2014 17:20:54 +0000 (18:20 +0100)
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>
src/netlink.c
src/parser_bison.y

index e59e297748134b925b152df1976c099c2004d71e..feaea19af0d09f95c8ae316725a1ce1993008a5b 100644 (file)
@@ -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);
        }
 }
index 99dbd088b0ef389c5bb116fa645d1dc248056a79..3059d59add848cea2a625a02111588c3e8ac0106 100644 (file)
@@ -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);