]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: store byteorder for set data
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 27 Feb 2017 22:42:03 +0000 (23:42 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 27 Feb 2017 23:55:29 +0000 (00:55 +0100)
Add new UDATA_SET_DATABYTEORDER attribute for NFTA_SET_UDATA to store
the datatype byteorder. This is required if integer_type is used on the
rhs of the mapping given that this datatype comes with no specific
byteorder.

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

index f5160daf4d8efef1b6de58bdf4f48468c3d18e15..ed12774d0ba7cc4ec15c74d0424abfffe9540428 100644 (file)
@@ -479,6 +479,7 @@ enum udata_type {
 
 enum udata_set_type {
        UDATA_SET_KEYBYTEORDER,
+       UDATA_SET_DATABYTEORDER,
        __UDATA_SET_MAX,
 };
 #define UDATA_SET_MAX (__UDATA_SET_MAX - 1)
index 07a611804a9015a34bad8e6781195fc170551148..5498516686ad89b49f4472c6f3ccb46039ca18b5 100644 (file)
@@ -1174,7 +1174,9 @@ static int expr_evaluate_map(struct eval_ctx *ctx, struct expr **expr)
                                                    ctx->ectx.len,
                                                    ctx->ectx.byteorder,
                                                    mappings);
-               mappings->set->datatype = ectx.dtype;
+
+               mappings->set->datatype = set_datatype_alloc(ectx.dtype,
+                                                            ectx.byteorder);
                mappings->set->datalen  = ectx.len;
 
                map->mappings = mappings;
index d643034f77ca15723c5a55a957bccd9fa112ef15..8b0fc9403361934295f9d7d653aefdcda259c1ed 100644 (file)
@@ -1112,6 +1112,7 @@ static int set_parse_udata_cb(const struct nftnl_udata *attr, void *data)
 
        switch (type) {
        case UDATA_SET_KEYBYTEORDER:
+       case UDATA_SET_DATABYTEORDER:
                if (len != sizeof(uint32_t))
                        return -1;
                break;
@@ -1128,6 +1129,7 @@ static struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
        const struct nftnl_udata *ud[UDATA_SET_MAX + 1] = {};
        uint32_t flags, key, data, data_len, objtype = 0;
        enum byteorder keybyteorder = BYTEORDER_INVALID;
+       enum byteorder databyteorder = BYTEORDER_INVALID;
        const struct datatype *keytype, *datatype;
        const char *udata;
        struct set *set;
@@ -1142,6 +1144,8 @@ static struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
 
                if (ud[UDATA_SET_KEYBYTEORDER])
                        keybyteorder = *((uint32_t *)nftnl_udata_get(ud[UDATA_SET_KEYBYTEORDER]));
+               if (ud[UDATA_SET_DATABYTEORDER])
+                       databyteorder = *((uint32_t *)nftnl_udata_get(ud[UDATA_SET_DATABYTEORDER]));
        }
 
        key = nftnl_set_get_u32(nls, NFTNL_SET_KEY_TYPE);
@@ -1181,7 +1185,11 @@ static struct set *netlink_delinearize_set(struct netlink_ctx *ctx,
 
        set->objtype = objtype;
 
-       set->datatype = datatype;
+       if (datatype)
+               set->datatype = set_datatype_alloc(datatype, databyteorder);
+       else
+               set->datatype = NULL;
+
        if (nftnl_set_is_set(nls, NFTNL_SET_DATA_LEN)) {
                data_len = nftnl_set_get_u32(nls, NFTNL_SET_DATA_LEN);
                set->datalen = data_len * BITS_PER_BYTE;
@@ -1279,6 +1287,12 @@ static int netlink_add_set_batch(struct netlink_ctx *ctx,
        if (!nftnl_udata_put(udbuf, UDATA_SET_KEYBYTEORDER, sizeof(uint32_t),
                             &set->keytype->byteorder))
                memory_allocation_error();
+
+       if (set->flags & NFT_SET_MAP &&
+           !nftnl_udata_put(udbuf, UDATA_SET_DATABYTEORDER, sizeof(uint32_t),
+                            &set->datatype->byteorder))
+               memory_allocation_error();
+
        nftnl_set_set_data(nls, NFTNL_SET_USERDATA, nftnl_udata_buf_data(udbuf),
                           nftnl_udata_buf_len(udbuf));
        nftnl_udata_buf_free(udbuf);
index 6045747710db43c88bc985a352b569f30a7bc966..f5ff1103c9f1362fe08a1432d94d8896d8a8f04c 100644 (file)
@@ -211,6 +211,8 @@ void set_free(struct set *set)
                expr_free(set->init);
        handle_free(&set->handle);
        set_datatype_destroy(set->keytype);
+       if (set->datatype)
+               set_datatype_destroy(set->datatype);
        xfree(set);
 }