diff options
author | Phil Sutter <phil@nwl.cc> | 2024-03-09 00:27:38 +0100 |
---|---|---|
committer | Phil Sutter <phil@nwl.cc> | 2024-03-19 18:24:47 +0100 |
commit | c56d77cc82988391ab8f2514214c0088cbc7d89e (patch) | |
tree | ed1aba19a49f251911eae6e954e847d5c9dda0c2 /src/parser_json.c | |
parent | 2a0fe52eca32acc8927c97e164b5e79337073ceb (diff) |
json: Support maps with concatenated data
Dump such maps with an array of types in "map" property, make the parser
aware of this.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src/parser_json.c')
-rw-r--r-- | src/parser_json.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/parser_json.c b/src/parser_json.c index ff52423a..bb027448 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -3255,7 +3255,7 @@ static struct cmd *json_parse_cmd_add_set(struct json_ctx *ctx, json_t *root, enum cmd_ops op, enum cmd_obj obj) { struct handle h = { 0 }; - const char *family = "", *policy, *dtype_ext = NULL; + const char *family = "", *policy; json_t *tmp, *stmt_json; struct set *set; @@ -3308,19 +3308,19 @@ static struct cmd *json_parse_cmd_add_set(struct json_ctx *ctx, json_t *root, return NULL; } - if (!json_unpack(root, "{s:s}", "map", &dtype_ext)) { - const struct datatype *dtype; + if (!json_unpack(root, "{s:o}", "map", &tmp)) { + if (json_is_string(tmp)) { + const char *s = json_string_value(tmp); - set->objtype = string_to_nft_object(dtype_ext); + set->objtype = string_to_nft_object(s); + } if (set->objtype) { set->flags |= NFT_SET_OBJECT; - } else if ((dtype = datatype_lookup_byname(dtype_ext))) { - set->data = constant_expr_alloc(&netlink_location, - dtype, dtype->byteorder, - dtype->size, NULL); + } else if ((set->data = json_parse_dtype_expr(ctx, tmp))) { set->flags |= NFT_SET_MAP; } else { - json_error(ctx, "Invalid map type '%s'.", dtype_ext); + json_error(ctx, "Invalid map type '%s'.", + json_dumps(tmp, 0)); set_free(set); handle_free(&h); return NULL; |