]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: replace DTYPE_F_ALLOC by bitfield
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 19 Aug 2024 19:09:04 +0000 (21:09 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 21 Aug 2024 21:22:47 +0000 (23:22 +0200)
Only user of the datatype flags field is DTYPE_F_ALLOC, replace it by
bitfield, squash byteorder to 8 bits which is sufficient.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/datatype.h
src/datatype.c

index 09b84eca27a72bd6e68abd4ff2be1b19bd980a82..df3bc3850b51da9d56562e918c134971c5dd7e22 100644 (file)
@@ -120,15 +120,6 @@ enum byteorder {
 
 struct expr;
 
-/**
- * enum datatype_flags
- *
- * @DTYPE_F_ALLOC:             datatype is dynamically allocated
- */
-enum datatype_flags {
-       DTYPE_F_ALLOC           = (1 << 0),
-};
-
 struct parse_ctx;
 /**
  * struct datatype
@@ -145,11 +136,12 @@ struct parse_ctx;
  * @print:     function to print a constant of this type
  * @parse:     function to parse a symbol and return an expression
  * @sym_tbl:   symbol table for this type
- * @refcnt:    reference counter (only for DTYPE_F_ALLOC)
+ * @refcnt:    reference counter (only for dynamically allocated, see .alloc)
  */
 struct datatype {
        uint32_t                        type;
-       enum byteorder                  byteorder;
+       enum byteorder                  byteorder:8;
+       uint32_t                        alloc:1;
        unsigned int                    flags;
        unsigned int                    size;
        unsigned int                    subtypes;
index 9293f38ed71390180750f1aa85c7b41d24b5a7a3..ea73eaf9a691d6e305f558bc82b8643d3490f28d 100644 (file)
@@ -1347,7 +1347,7 @@ static struct datatype *datatype_alloc(void)
        struct datatype *dtype;
 
        dtype = xzalloc(sizeof(*dtype));
-       dtype->flags = DTYPE_F_ALLOC;
+       dtype->alloc = 1;
        dtype->refcnt = 1;
 
        return dtype;
@@ -1359,7 +1359,7 @@ const struct datatype *datatype_get(const struct datatype *ptr)
 
        if (!dtype)
                return NULL;
-       if (!(dtype->flags & DTYPE_F_ALLOC))
+       if (!dtype->alloc)
                return dtype;
 
        dtype->refcnt++;
@@ -1389,7 +1389,7 @@ struct datatype *datatype_clone(const struct datatype *orig_dtype)
        *dtype = *orig_dtype;
        dtype->name = xstrdup(orig_dtype->name);
        dtype->desc = xstrdup(orig_dtype->desc);
-       dtype->flags = DTYPE_F_ALLOC | orig_dtype->flags;
+       dtype->alloc = 1;
        dtype->refcnt = 1;
 
        return dtype;
@@ -1401,7 +1401,7 @@ void datatype_free(const struct datatype *ptr)
 
        if (!dtype)
                return;
-       if (!(dtype->flags & DTYPE_F_ALLOC))
+       if (!dtype->alloc)
                return;
 
        assert(dtype->refcnt != 0);