From 343a51702656a6476e37cfb84609a82155c7fc5e Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Tue, 16 Jul 2019 19:03:55 +0200 Subject: src: store expr, not dtype to track data in sets This will be needed once we add support for the 'typeof' keyword to handle maps that could e.g. store 'ct helper' "type" values. Instead of: set foo { type ipv4_addr . mark; this would allow set foo { typeof(ip saddr) . typeof(ct mark); (exact syntax TBD). This would be needed to allow sets that store variable-sized data types (string, integer and the like) that can't be used at at the moment. Adding special data types for everything is problematic due to the large amount of different types needed. For anonymous sets, e.g. "string" can be used because the needed size can be inferred from the statement, e.g. 'osf name { "Windows", "Linux }', but in case of named sets that won't work because 'type string' lacks the context needed to derive the size information. With 'typeof(osf name)' the context is there, but at the moment it won't help because the expression is discarded instantly and only the data type is retained. Signed-off-by: Florian Westphal --- src/netlink.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src/netlink.c') diff --git a/src/netlink.c b/src/netlink.c index 9fc0b171..46897e43 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -534,7 +534,7 @@ enum nft_data_types dtype_map_to_kernel(const struct datatype *dtype) } } -const struct datatype *dtype_map_from_kernel(enum nft_data_types type) +static const struct datatype *dtype_map_from_kernel(enum nft_data_types type) { switch (type) { case NFT_DATA_VERDICT: @@ -581,10 +581,10 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx, const struct nftnl_set *nls) { const struct nftnl_udata *ud[NFTNL_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 struct datatype *keytype, *datatype = NULL; + uint32_t flags, key, objtype = 0; bool automerge = false; const char *udata; struct set *set; @@ -618,6 +618,8 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx, flags = nftnl_set_get_u32(nls, NFTNL_SET_FLAGS); if (set_is_datamap(flags)) { + uint32_t data; + data = nftnl_set_get_u32(nls, NFTNL_SET_DATA_TYPE); datatype = dtype_map_from_kernel(data); if (datatype == NULL) { @@ -626,8 +628,7 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx, data); return NULL; } - } else - datatype = NULL; + } if (set_is_objmap(flags)) { objtype = nftnl_set_get_u32(nls, NFTNL_SET_OBJ_TYPE); @@ -650,16 +651,13 @@ struct set *netlink_delinearize_set(struct netlink_ctx *ctx, set->objtype = objtype; + set->data = NULL; if (datatype) - set->datatype = datatype_get(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; - } + set->data = constant_expr_alloc(&netlink_location, + set_datatype_alloc(datatype, databyteorder), + databyteorder, + nftnl_set_get_u32(nls, NFTNL_SET_DATA_LEN) * BITS_PER_BYTE, + NULL); if (nftnl_set_is_set(nls, NFTNL_SET_TIMEOUT)) set->timeout = nftnl_set_get_u64(nls, NFTNL_SET_TIMEOUT); @@ -847,10 +845,10 @@ int netlink_delinearize_setelem(struct nftnl_set_elem *nlse, goto out; data = netlink_alloc_data(&netlink_location, &nld, - set->datatype->type == TYPE_VERDICT ? + set->data->dtype->type == TYPE_VERDICT ? NFT_REG_VERDICT : NFT_REG_1); - datatype_set(data, set->datatype); - data->byteorder = set->datatype->byteorder; + datatype_set(data, set->data->dtype); + data->byteorder = set->data->byteorder; if (data->byteorder == BYTEORDER_HOST_ENDIAN) mpz_switch_byteorder(data->value, data->len / BITS_PER_BYTE); -- cgit v1.2.3