If user says 'type integer; ...' in a set definition, don't just throw an error -- provide a hint that a width can be provided via ', bitsize'. Signed-off-by: Florian Westphal <fw@xxxxxxxxx> --- src/evaluate.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/evaluate.c b/src/evaluate.c index 91d6b254c659..2e93100349d7 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -3307,6 +3307,32 @@ static int setelem_evaluate(struct eval_ctx *ctx, struct expr **expr) return 0; } +static int set_key_error(struct eval_ctx *ctx, const struct set *set, + const char *type) +{ + if (set->key->dtype == &integer_type || + set->key->dtype == &string_type) + return set_error(ctx, set, "unqualified key type " + "specified in %s definition. Did you mean \"type %s,%d\"?", + type, set->key->dtype->name, 128); + + return set_error(ctx, set, "unqualified key type %s " + "specified in %s definition", + set->key->dtype->name, type); +} + +static int set_datamap_error(struct eval_ctx *ctx, const struct set *set) +{ + if (set->data->dtype == &integer_type || + set->data->dtype == &string_type) + return set_error(ctx, set, "unqualified mapping data type " + "specified in map definition. Did you mean \"type %s,%d\"?", + set->data->dtype->name, 128); + + return set_error(ctx, set, "unqualified mapping data " + "type specified in map definition"); +} + static int set_evaluate(struct eval_ctx *ctx, struct set *set) { struct table *table; @@ -3331,9 +3357,7 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set) return -1; if (set->key->len == 0) - return set_error(ctx, set, "unqualified key type %s " - "specified in %s definition", - set->key->dtype->name, type); + return set_key_error(ctx, set, type); } if (set->flags & NFT_SET_INTERVAL && set->key->etype == EXPR_CONCAT) @@ -3345,8 +3369,7 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set) "specify mapping data type"); if (set->data->len == 0 && set->data->dtype->type != TYPE_VERDICT) - return set_error(ctx, set, "unqualified mapping data " - "type specified in map definition"); + return set_datamap_error(ctx, set); } else if (set_is_objmap(set->flags)) { if (set->data) { assert(set->data->etype == EXPR_VALUE); -- 2.23.0