]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: add new subtypes field to account number of concat data types
authorPatrick McHardy <kaber@trash.net>
Sat, 13 Dec 2014 07:50:34 +0000 (07:50 +0000)
committerPatrick McHardy <kaber@trash.net>
Tue, 16 Dec 2014 17:20:54 +0000 (18:20 +0100)
Using the size is confusing since it usually holds the size of
the data. Add a new "subtypes" member, which holds the number
of datatypes the concat type is made of.

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

index 3f13dcde47cc07117fdf7d7908cfd06667c0d2fd..50b85c31d8b0da017b1609ac0d51885f8669dd67 100644 (file)
@@ -115,6 +115,7 @@ enum datatype_flags {
  * @byteorder: byteorder of type (non-basetypes only)
  * @flags:     flags
  * @size:      type size (fixed sized non-basetypes only)
+ * @subtypes:  number of subtypes (concat type)
  * @name:      type name
  * @desc:      type description
  * @basetype:  basetype for subtypes, determines type compatibilty
@@ -128,6 +129,7 @@ struct datatype {
        enum byteorder                  byteorder;
        unsigned int                    flags;
        unsigned int                    size;
+       unsigned int                    subtypes;
        const char                      *name;
        const char                      *desc;
        const struct datatype           *basetype;
index 807b0f1811d88d3ff333dffe640bb7ba023b192c..8583531fcb728ab7860171e8e317bc92da548e2d 100644 (file)
@@ -929,10 +929,10 @@ const struct datatype *concat_type_alloc(const struct expr *expr)
        struct expr *i;
        char desc[256] = "concatenation of (";
        char name[256] = "";
-       unsigned int type = 0, size = 0;
+       unsigned int type = 0, size = 0, subtypes = 0;
 
        list_for_each_entry(i, &expr->expressions, list) {
-               if (size != 0) {
+               if (subtypes != 0) {
                        strncat(desc, ", ", sizeof(desc) - strlen(desc) - 1);
                        strncat(name, " . ", sizeof(name) - strlen(name) - 1);
                }
@@ -941,13 +941,15 @@ const struct datatype *concat_type_alloc(const struct expr *expr)
 
                type <<= 8;
                type  |= i->dtype->type;
-               size++;
+               size  += i->dtype->size;
+               subtypes++;
        }
        strncat(desc, ")", sizeof(desc) - strlen(desc) - 1);
 
        dtype           = dtype_alloc();
        dtype->type     = type;
        dtype->size     = size;
+       dtype->subtypes = subtypes;
        dtype->name     = xstrdup(name);
        dtype->desc     = xstrdup(desc);
        dtype->parse    = concat_type_parse;
index 07326607cd7b6dc894b297600d217752469c225c..79edf02166203b5fb5cd536b137ee9ca15a65409 100644 (file)
@@ -605,10 +605,10 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr)
 {
        const struct datatype *dtype = ctx->ectx.dtype, *tmp;
        unsigned int type = dtype ? dtype->type : 0;
-       int off = dtype ? dtype->size: 0;
+       int off = dtype ? dtype->subtypes : 0;
        unsigned int flags = EXPR_F_CONSTANT | EXPR_F_SINGLETON;
        struct expr *i, *next;
-       unsigned int n;
+       unsigned int n, len = 0;
 
        n = 1;
        list_for_each_entry_safe(i, next, &(*expr)->expressions, list) {
@@ -624,11 +624,13 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr)
                        return -1;
                flags &= i->flags;
 
+               len += i->len;
                n++;
        }
 
        (*expr)->flags |= flags;
        (*expr)->dtype = concat_type_alloc(*expr);
+       (*expr)->len   = len;
 
        if (off > 0)
                return expr_error(ctx->msgs, *expr,