]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
concat: add concat subtype lookup/id helpers
authorPatrick McHardy <kaber@trash.net>
Mon, 22 Dec 2014 16:45:48 +0000 (17:45 +0100)
committerPatrick McHardy <kaber@trash.net>
Sun, 11 Jan 2015 08:14:08 +0000 (08:14 +0000)
Signed-off-by: Patrick McHardy <kaber@trash.net>
include/datatype.h
src/datatype.c
src/evaluate.c
src/parser_bison.y

index f05f9877c772fe3c7b104f2160b9517b6a4793e1..3c3f42f372db3a76bb1f241bd019056dc1dc151f 100644 (file)
@@ -215,4 +215,20 @@ extern const struct datatype time_type;
 extern const struct datatype *concat_type_alloc(uint32_t type);
 extern void concat_type_destroy(const struct datatype *dtype);
 
+static inline uint32_t concat_subtype_add(uint32_t type, uint32_t subtype)
+{
+       return type << TYPE_BITS | subtype;
+}
+
+static inline uint32_t concat_subtype_id(uint32_t type, unsigned int n)
+{
+       return (type >> TYPE_BITS * n) & TYPE_MASK;
+}
+
+static inline const struct datatype *
+concat_subtype_lookup(uint32_t type, unsigned int n)
+{
+       return datatype_lookup(concat_subtype_id(type, n));
+}
+
 #endif /* NFTABLES_DATATYPE_H */
index 76f2af13820682e286814bd189a4f1a82fe17b6b..c93f76a3857a6fa5e3fefe5b5cd6efaf27b59b52 100644 (file)
@@ -931,8 +931,8 @@ const struct datatype *concat_type_alloc(uint32_t type)
        unsigned int size = 0, subtypes = 0, n;
 
        n = div_round_up(fls(type), TYPE_BITS);
-       while ((type >> TYPE_BITS * --n) & TYPE_MASK) {
-               i = datatype_lookup((type >> TYPE_BITS * n) & TYPE_MASK);
+       while (concat_subtype_id(type, --n)) {
+               i = concat_subtype_lookup(type, n);
                if (i == NULL)
                        return NULL;
 
index 00c6d9189919365a69a5e41d8721beaaa84dce82..53f3cf0a4ada16cfd9fc0594209e1b170e8c8553 100644 (file)
@@ -612,25 +612,22 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr)
        int off = dtype ? dtype->subtypes : 0;
        unsigned int flags = EXPR_F_CONSTANT | EXPR_F_SINGLETON;
        struct expr *i, *next;
-       unsigned int n;
 
-       n = 1;
        list_for_each_entry_safe(i, next, &(*expr)->expressions, list) {
                if (dtype && off == 0)
                        return expr_binary_error(ctx->msgs, i, *expr,
                                                 "unexpected concat component, "
                                                 "expecting %s",
                                                 dtype->desc);
-               tmp = datatype_lookup((type >> TYPE_BITS * --off) & TYPE_MASK);
+
+               tmp = concat_subtype_lookup(type, --off);
                expr_set_context(&ctx->ectx, tmp, tmp->size);
 
                if (list_member_evaluate(ctx, &i) < 0)
                        return -1;
                flags &= i->flags;
 
-               ntype <<= TYPE_BITS;
-               ntype  |= i->dtype->type;
-               n++;
+               ntype = concat_subtype_add(ntype, i->dtype->type);
        }
 
        (*expr)->flags |= flags;
index b20f4debdbbf2dda6642bdc45c70605828712bdf..6c46d09819f257163b1531454bca104eb6261e6f 100644 (file)
@@ -1020,8 +1020,7 @@ type_identifier           :       identifier
                                                   state->msgs);
                                        YYERROR;
                                }
-                               $$ <<= TYPE_BITS;
-                               $$ |= dtype->type;
+                               $$ = concat_subtype_add($$, dtype->type);
                        }
                        ;