summaryrefslogtreecommitdiffstats
path: root/src/json.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-10-11 17:49:00 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-10-15 13:37:51 +0200
commit9e88aae28e9f44d010f3ecf7577357f4c0e7d622 (patch)
treee76ae3b1c7719ca9d5525acb4903d4843a8c0088 /src/json.c
parent90ed4fb3855f0d9d881b812c75e338e5e93081ba (diff)
monitor: Use libnftables JSON output
This switches 'nft monitor' JSON output from using libnftnl's to libnftables' implementation. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c
index a0a2b9db..f5d97c62 100644
--- a/src/json.c
+++ b/src/json.c
@@ -148,6 +148,19 @@ static json_t *set_print_json(struct output_ctx *octx, const struct set *set)
return json_pack("{s:o}", type, root);
}
+/* XXX: Merge with set_print_json()? */
+static json_t *element_print_json(struct output_ctx *octx,
+ const struct set *set)
+{
+ json_t *root = expr_print_json(set->init, octx);
+
+ return json_pack("{s: {s:s, s:s, s:s, s:o}}", "element",
+ "family", family2str(set->handle.family),
+ "table", set->handle.table.name,
+ "name", set->handle.set.name,
+ "elem", root);
+}
+
static json_t *stmt_print_json(const struct stmt *stmt, struct output_ctx *octx)
{
char buf[1024];
@@ -1714,3 +1727,47 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
json_decref(root);
return 0;
}
+
+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_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));
+}
+
+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));
+}
+
+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));
+}
+
+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));
+}
+
+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));
+}
+
+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));
+}