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