On Tue, Jul 30, 2019 at 04:37:31PM +0200, Florian Westphal wrote:
[...]
> diff --git a/include/rule.h b/include/rule.h
> index ee881b9ccd17..dfb6b5482a1c 100644
> --- a/include/rule.h
> +++ b/include/rule.h
> @@ -277,8 +277,7 @@ extern struct rule *rule_lookup_by_index(const struct
> chain *chain,
> * @gc_int: garbage collection interval
> * @timeout: default timeout value
> * @key: key expression (data type, length))
> - * @datatype: mapping data type
> - * @datalen: mapping data len
> + * @data: mapping data expression
> * @objtype: mapping object type
> * @init: initializer
> * @rg_cache: cached range element (left)
> @@ -295,8 +294,7 @@ struct set {
> uint32_t gc_int;
> uint64_t timeout;
> struct expr *key;
> - const struct datatype *datatype;
> - unsigned int datalen;
> + struct expr *data;
> uint32_t objtype;
> struct expr *init;
> struct expr *rg_cache;
[...]
> diff --git a/src/evaluate.c b/src/evaluate.c
> index 48c65cd2f35a..6277f6545c1b 100644
> --- a/src/evaluate.c
> +++ b/src/evaluate.c
> @@ -1332,6 +1332,63 @@ static int expr_evaluate_set(struct eval_ctx *ctx,
> struct expr **expr)
> return 0;
> }
>
> +static struct expr *concat_expr_alloc_by_type_FIXME(uint32_t type)
> +{
> + struct expr *concat_expr = concat_expr_alloc(&netlink_location);
> + unsigned int n;
> + int size = 0;
> +
> + n = div_round_up(fls(type), TYPE_BITS);
> + while (n > 0 && concat_subtype_id(type, --n)) {
> + const struct datatype *i;
> + struct expr *expr;
> +
> + i = concat_subtype_lookup(type, n);
> + if (i == NULL)
> + return NULL;
> +
> + if (i->size == 0)
> + size = -1;
> + else if (size >= 0)
> + size += i->size;
> +
> + expr = constant_expr_alloc(&netlink_location, i, i->byteorder,
> + i->size, NULL);
> +
> + compound_expr_add(concat_expr, expr);
> + }
> +
> + /* can be incorrect in case of i->size being 0 (variable length). */
> + concat_expr->len = size > 0 ? size : 0;
> +
> + return concat_expr;
> +}
> +
> +static struct expr *
> +data_expr_alloc_by_type_FIXME(enum nft_data_types type, enum byteorder
> keybyteorder)
There is no support for concatenations from the right hand side of the
mapping, so I would just calloc a constant expression itself. Hence,
you wont' need concat_expr_alloc_by_type_FIXME() and this function
will be more simple. Same comment applies to dtype_map_from_kernel().
In general, I agree in the direction where this is going, that is,
turn the datatype field in the set object into an expression.
Thanks.