]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: parse/print in all basetypes subsequently
authorPatrick McHardy <kaber@trash.net>
Mon, 15 Apr 2013 14:18:17 +0000 (16:18 +0200)
committerPatrick McHardy <kaber@trash.net>
Thu, 18 Apr 2013 13:12:13 +0000 (15:12 +0200)
Go down the chain of basetypes until we find a ->parse()/->print() callback
or symbol table. Needed to invoke the generic link layer address parsing
function for the etheraddr_type.

Signed-off-by: Patrick McHardy <kaber@trash.net>
src/datatype.c

index f369d5f0e8f0ac68e280c0fa124ddd5d769b2985..c687edd478a72fe5b2116b4b83b3dd2a426d7182 100644 (file)
@@ -69,10 +69,13 @@ void datatype_print(const struct expr *expr)
 {
        const struct datatype *dtype = expr->dtype;
 
-       if (dtype->print != NULL)
-               return dtype->print(expr);
-       if (dtype->sym_tbl != NULL)
-               return symbolic_constant_print(dtype->sym_tbl, expr);
+       do {
+               if (dtype->print != NULL)
+                       return dtype->print(expr);
+               if (dtype->sym_tbl != NULL)
+                       return symbolic_constant_print(dtype->sym_tbl, expr);
+       } while ((dtype = dtype->basetype));
+
        BUG("datatype has no print method or symbol table\n");
 }
 
@@ -85,10 +88,13 @@ struct error_record *symbol_parse(const struct expr *sym,
 
        if (dtype == NULL)
                return error(&sym->location, "No symbol type information");
-       if (dtype->parse != NULL)
-               return dtype->parse(sym, res);
-       if (dtype->sym_tbl != NULL)
-               return symbolic_constant_parse(sym, dtype->sym_tbl, res);
+       do {
+               if (dtype->parse != NULL)
+                       return dtype->parse(sym, res);
+               if (dtype->sym_tbl != NULL)
+                       return symbolic_constant_parse(sym, dtype->sym_tbl,
+                                                      res);
+       } while ((dtype = dtype->basetype));
 
        return error(&sym->location,
                     "Can't parse symbolic %s expressions",
@@ -301,7 +307,7 @@ static struct error_record *lladdr_type_parse(const struct expr *sym,
                s = ++p;
        }
 
-       *res = constant_expr_alloc(&sym->location, &lladdr_type,
+       *res = constant_expr_alloc(&sym->location, sym->dtype,
                                   BYTEORDER_HOST_ENDIAN, len * BITS_PER_BYTE,
                                   buf);
        return NULL;