summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/json.c19
-rw-r--r--src/parser_json.c27
2 files changed, 43 insertions, 3 deletions
diff --git a/src/json.c b/src/json.c
index 2a13dfe7..84bdaa39 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1530,6 +1530,14 @@ static json_t *do_list_flowtables_json(struct netlink_ctx *ctx, struct cmd *cmd)
return root;
}
+static json_t *generate_json_metainfo(void)
+{
+ return json_pack("{s: {s:s, s:s, s:i}}", "metainfo",
+ "version", PACKAGE_VERSION,
+ "release_name", RELEASE_NAME,
+ "json_schema_version", JSON_SCHEMA_VERSION);
+}
+
int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
{
struct table *table = NULL;
@@ -1596,10 +1604,15 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
BUG("invalid command object type %u\n", cmd->obj);
}
- if (json_is_array(root) && !json_array_size(root)) {
- json_decref(root);
- root = json_null();
+ if (!json_is_array(root)) {
+ json_t *tmp = json_array();
+
+ json_array_append_new(tmp, root);
+ root = tmp;
}
+
+ json_array_insert_new(root, 0, generate_json_metainfo());
+
root = json_pack("{s:o}", "nftables", root);
json_dumpf(root, ctx->octx->output_fp, 0);
json_decref(root);
diff --git a/src/parser_json.c b/src/parser_json.c
index 6870434e..6af9d075 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -3118,6 +3118,22 @@ static struct cmd *json_parse_cmd(struct json_ctx *ctx, json_t *root)
return NULL;
}
+static int json_verify_metainfo(struct json_ctx *ctx, json_t *root)
+{
+ int schema_version;
+
+ if (!json_unpack(root, "{s:i}", "json_schema_version", &schema_version))
+ return 0;
+
+ if (schema_version > JSON_SCHEMA_VERSION) {
+ json_error(ctx, "Schema version %d not supported, maximum supported version is %d\n",
+ schema_version, JSON_SCHEMA_VERSION);
+ return 1;
+ }
+
+ return 0;
+}
+
static int __json_parse(struct json_ctx *ctx, json_t *root)
{
struct eval_ctx ectx = {
@@ -3142,11 +3158,22 @@ static int __json_parse(struct json_ctx *ctx, json_t *root)
/* this is more or less from parser_bison.y:716 */
LIST_HEAD(list);
struct cmd *cmd;
+ json_t *tmp2;
if (!json_is_object(value)) {
json_error(ctx, "Unexpected command array element of type %s, expected object.", json_typename(value));
return -1;
}
+
+ tmp2 = json_object_get(value, "metainfo");
+ if (tmp2) {
+ if (json_verify_metainfo(ctx, tmp2)) {
+ json_error(ctx, "Metainfo verification failed.");
+ return -1;
+ }
+ continue;
+ }
+
cmd = json_parse_cmd(ctx, value);
if (!cmd) {