Blame SOURCES/0025-json-Fix-for-recent-changes-to-context-structs.patch

34625f
From 5eff789ea5d32ad000805c727584ec0d4ee7a392 Mon Sep 17 00:00:00 2001
34625f
From: Phil Sutter <phil@nwl.cc>
34625f
Date: Wed, 24 Oct 2018 12:35:04 +0200
34625f
Subject: [PATCH] json: Fix for recent changes to context structs
34625f
34625f
Commits introducing nft_ctx pointer to netlink and eval contexts did not
34625f
update JSON code accordingly.
34625f
34625f
Fixes: 00f777bfc414a ("src: pass struct nft_ctx through struct eval_ctx")
34625f
Fixes: 2dc07bcd7eaa5 ("src: pass struct nft_ctx through struct netlink_ctx")
34625f
Signed-off-by: Phil Sutter <phil@nwl.cc>
34625f
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
34625f
(cherry picked from commit 841d5f5a3deacfe7b4245df0890849d8e4ad5817)
34625f
34625f
Conflicts:
34625f
-> Missing ct timeout support
34625f
34625f
Signed-off-by: Phil Sutter <psutter@redhat.com>
34625f
---
34625f
 src/json.c        | 69 ++++++++++++++++++++++++-----------------------
34625f
 src/parser_json.c |  5 +---
34625f
 2 files changed, 37 insertions(+), 37 deletions(-)
34625f
34625f
diff --git a/src/json.c b/src/json.c
34625f
index 66b02a934a24b..98581a3c2a3e4 100644
34625f
--- a/src/json.c
34625f
+++ b/src/json.c
34625f
@@ -211,8 +211,7 @@ static json_t *rule_print_json(struct output_ctx *octx,
34625f
 	return json_pack("{s:o}", "rule", root);
34625f
 }
34625f
 
34625f
-static json_t *chain_print_json(const struct output_ctx *octx,
34625f
-				const struct chain *chain)
34625f
+static json_t *chain_print_json(const struct chain *chain)
34625f
 {
34625f
 	json_t *root, *tmp;
34625f
 
34625f
@@ -247,7 +246,7 @@ static json_t *proto_name_json(uint8_t proto)
34625f
 	return json_integer(proto);
34625f
 }
34625f
 
34625f
-static json_t *obj_print_json(struct output_ctx *octx, const struct obj *obj)
34625f
+static json_t *obj_print_json(const struct obj *obj)
34625f
 {
34625f
 	const char *rate_unit = NULL, *burst_unit = NULL;
34625f
 	const char *type = obj_type_name(obj->type);
34625f
@@ -371,8 +370,7 @@ static json_t *table_flags_json(const struct table *table)
34625f
 	return root;
34625f
 }
34625f
 
34625f
-static json_t *table_print_json(const struct output_ctx *octx,
34625f
-				const struct table *table)
34625f
+static json_t *table_print_json(const struct table *table)
34625f
 {
34625f
 	json_t *root, *tmp;
34625f
 
34625f
@@ -1295,17 +1293,17 @@ static json_t *table_print_json_full(struct netlink_ctx *ctx,
34625f
 	struct obj *obj;
34625f
 	struct set *set;
34625f
 
34625f
-	tmp = table_print_json(ctx->octx, table);
34625f
+	tmp = table_print_json(table);
34625f
 	json_array_append_new(root, tmp);
34625f
 
34625f
 	list_for_each_entry(obj, &table->objs, list) {
34625f
-		tmp = obj_print_json(ctx->octx, obj);
34625f
+		tmp = obj_print_json(obj);
34625f
 		json_array_append_new(root, tmp);
34625f
 	}
34625f
 	list_for_each_entry(set, &table->sets, list) {
34625f
 		if (set->flags & NFT_SET_ANONYMOUS)
34625f
 			continue;
34625f
-		tmp = set_print_json(ctx->octx, set);
34625f
+		tmp = set_print_json(&ctx->nft->output, set);
34625f
 		json_array_append_new(root, tmp);
34625f
 	}
34625f
 	list_for_each_entry(flowtable, &table->flowtables, list) {
34625f
@@ -1313,11 +1311,11 @@ static json_t *table_print_json_full(struct netlink_ctx *ctx,
34625f
 		json_array_append_new(root, tmp);
34625f
 	}
34625f
 	list_for_each_entry(chain, &table->chains, list) {
34625f
-		tmp = chain_print_json(ctx->octx, chain);
34625f
+		tmp = chain_print_json(chain);
34625f
 		json_array_append_new(root, tmp);
34625f
 
34625f
 		list_for_each_entry(rule, &chain->rules, list) {
34625f
-			tmp = rule_print_json(ctx->octx, rule);
34625f
+			tmp = rule_print_json(&ctx->nft->output, rule);
34625f
 			json_array_append_new(root, tmp);
34625f
 		}
34625f
 	}
34625f
@@ -1331,7 +1329,7 @@ static json_t *do_list_ruleset_json(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	json_t *root = json_array();
34625f
 	struct table *table;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (family != NFPROTO_UNSPEC &&
34625f
 		    table->handle.family != family)
34625f
 			continue;
34625f
@@ -1348,12 +1346,12 @@ static json_t *do_list_tables_json(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	json_t *root = json_array();
34625f
 	struct table *table;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (family != NFPROTO_UNSPEC &&
34625f
 		    table->handle.family != family)
34625f
 			continue;
34625f
 
34625f
-		json_array_append_new(root, table_print_json(ctx->octx, table));
34625f
+		json_array_append_new(root, table_print_json(table));
34625f
 	}
34625f
 
34625f
 	return root;
34625f
@@ -1377,10 +1375,10 @@ static json_t *do_list_chain_json(struct netlink_ctx *ctx,
34625f
 		    strcmp(cmd->handle.chain.name, chain->handle.chain.name))
34625f
 			continue;
34625f
 
34625f
-		json_array_append_new(root, chain_print_json(ctx->octx, chain));
34625f
+		json_array_append_new(root, chain_print_json(chain));
34625f
 
34625f
 		list_for_each_entry(rule, &chain->rules, list) {
34625f
-			json_t *tmp = rule_print_json(ctx->octx, rule);
34625f
+			json_t *tmp = rule_print_json(&ctx->nft->output, rule);
34625f
 
34625f
 			json_array_append_new(root, tmp);
34625f
 		}
34625f
@@ -1395,13 +1393,13 @@ static json_t *do_list_chains_json(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	struct table *table;
34625f
 	struct chain *chain;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (cmd->handle.family != NFPROTO_UNSPEC &&
34625f
 		    cmd->handle.family != table->handle.family)
34625f
 			continue;
34625f
 
34625f
 		list_for_each_entry(chain, &table->chains, list) {
34625f
-			json_t *tmp = chain_print_json(ctx->octx, chain);
34625f
+			json_t *tmp = chain_print_json(chain);
34625f
 
34625f
 			json_array_append_new(root, tmp);
34625f
 		}
34625f
@@ -1418,17 +1416,17 @@ static json_t *do_list_set_json(struct netlink_ctx *ctx,
34625f
 	if (set == NULL)
34625f
 		return json_null();
34625f
 
34625f
-	return json_pack("[o]", set_print_json(ctx->octx, set));
34625f
+	return json_pack("[o]", set_print_json(&ctx->nft->output, set));
34625f
 }
34625f
 
34625f
 static json_t *do_list_sets_json(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 {
34625f
-	struct output_ctx *octx = ctx->octx;
34625f
+	struct output_ctx *octx = &ctx->nft->output;
34625f
 	json_t *root = json_array();
34625f
 	struct table *table;
34625f
 	struct set *set;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (cmd->handle.family != NFPROTO_UNSPEC &&
34625f
 		    cmd->handle.family != table->handle.family)
34625f
 			continue;
34625f
@@ -1458,7 +1456,7 @@ static json_t *do_list_obj_json(struct netlink_ctx *ctx,
34625f
 	struct table *table;
34625f
 	struct obj *obj;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (cmd->handle.family != NFPROTO_UNSPEC &&
34625f
 		    cmd->handle.family != table->handle.family)
34625f
 			continue;
34625f
@@ -1473,8 +1471,7 @@ static json_t *do_list_obj_json(struct netlink_ctx *ctx,
34625f
 			     strcmp(cmd->handle.obj.name, obj->handle.obj.name)))
34625f
 				continue;
34625f
 
34625f
-			json_array_append_new(root,
34625f
-					      obj_print_json(ctx->octx, obj));
34625f
+			json_array_append_new(root, obj_print_json(obj));
34625f
 		}
34625f
 	}
34625f
 
34625f
@@ -1487,7 +1484,7 @@ static json_t *do_list_flowtables_json(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	struct flowtable *flowtable;
34625f
 	struct table *table;
34625f
 
34625f
-	list_for_each_entry(table, &ctx->cache->list, list) {
34625f
+	list_for_each_entry(table, &ctx->nft->cache.list, list) {
34625f
 		if (cmd->handle.family != NFPROTO_UNSPEC &&
34625f
 		    cmd->handle.family != table->handle.family)
34625f
 			continue;
34625f
@@ -1507,7 +1504,7 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 	json_t *root;
34625f
 
34625f
 	if (cmd->handle.table.name)
34625f
-		table = table_lookup(&cmd->handle, ctx->cache);
34625f
+		table = table_lookup(&cmd->handle, &ctx->nft->cache);
34625f
 
34625f
 	switch (cmd->obj) {
34625f
 	case CMD_OBJ_TABLE:
34625f
@@ -1572,7 +1569,7 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
34625f
 		root = json_null();
34625f
 	}
34625f
 	root = json_pack("{s:o}", "nftables", root);
34625f
-	json_dumpf(root, ctx->octx->output_fp, 0);
34625f
+	json_dumpf(root, ctx->nft->output.output_fp, 0);
34625f
 	json_decref(root);
34625f
 	return 0;
34625f
 }
34625f
@@ -1581,42 +1578,48 @@ static void monitor_print_json(struct netlink_mon_handler *monh,
34625f
 			       const char *cmd, json_t *obj)
34625f
 {
34625f
 	obj = json_pack("{s:o}", cmd, obj);
34625f
-	json_dumpf(obj, monh->ctx->octx->output_fp, 0);
34625f
+	json_dumpf(obj, monh->ctx->nft->output.output_fp, 0);
34625f
 	json_decref(obj);
34625f
 }
34625f
 
34625f
 void monitor_print_table_json(struct netlink_mon_handler *monh,
34625f
 			      const char *cmd, struct table *t)
34625f
 {
34625f
-	monitor_print_json(monh, cmd, table_print_json(monh->ctx->octx, t));
34625f
+	monitor_print_json(monh, cmd, table_print_json(t));
34625f
 }
34625f
 
34625f
 void monitor_print_chain_json(struct netlink_mon_handler *monh,
34625f
 			      const char *cmd, struct chain *c)
34625f
 {
34625f
-	monitor_print_json(monh, cmd, chain_print_json(monh->ctx->octx, c));
34625f
+	monitor_print_json(monh, cmd, chain_print_json(c));
34625f
 }
34625f
 
34625f
 void monitor_print_set_json(struct netlink_mon_handler *monh,
34625f
 			    const char *cmd, struct set *s)
34625f
 {
34625f
-	monitor_print_json(monh, cmd, set_print_json(monh->ctx->octx, s));
34625f
+	struct output_ctx *octx = &monh->ctx->nft->output;
34625f
+
34625f
+	monitor_print_json(monh, cmd, set_print_json(octx, s));
34625f
 }
34625f
 
34625f
 void monitor_print_element_json(struct netlink_mon_handler *monh,
34625f
 				const char *cmd, struct set *s)
34625f
 {
34625f
-	monitor_print_json(monh, cmd, element_print_json(monh->ctx->octx, s));
34625f
+	struct output_ctx *octx = &monh->ctx->nft->output;
34625f
+
34625f
+	monitor_print_json(monh, cmd, element_print_json(octx, s));
34625f
 }
34625f
 
34625f
 void monitor_print_obj_json(struct netlink_mon_handler *monh,
34625f
 			    const char *cmd, struct obj *o)
34625f
 {
34625f
-	monitor_print_json(monh, cmd, obj_print_json(monh->ctx->octx, o));
34625f
+	monitor_print_json(monh, cmd, obj_print_json(o));
34625f
 }
34625f
 
34625f
 void monitor_print_rule_json(struct netlink_mon_handler *monh,
34625f
 			     const char *cmd, struct rule *r)
34625f
 {
34625f
-	monitor_print_json(monh, cmd, rule_print_json(monh->ctx->octx, r));
34625f
+	struct output_ctx *octx = &monh->ctx->nft->output;
34625f
+
34625f
+	monitor_print_json(monh, cmd, rule_print_json(octx, r));
34625f
 }
34625f
diff --git a/src/parser_json.c b/src/parser_json.c
34625f
index 30de17f8a1e26..817415c15fb89 100644
34625f
--- a/src/parser_json.c
34625f
+++ b/src/parser_json.c
34625f
@@ -3025,11 +3025,8 @@ static struct cmd *json_parse_cmd(struct json_ctx *ctx, json_t *root)
34625f
 static int __json_parse(struct json_ctx *ctx, json_t *root)
34625f
 {
34625f
 	struct eval_ctx ectx = {
34625f
-		.nf_sock = ctx->nft->nf_sock,
34625f
+		.nft = ctx->nft,
34625f
 		.msgs = ctx->msgs,
34625f
-		.cache = &ctx->nft->cache,
34625f
-		.octx = &ctx->nft->output,
34625f
-		.debug_mask = ctx->nft->debug_mask,
34625f
 	};
34625f
 	json_t *tmp, *value;
34625f
 	size_t index;
34625f
-- 
34625f
2.19.0
34625f