path: root/include/json.h
diff options
authorJose M. Guisado Gomez <>2020-08-04 12:38:46 +0200
committerPablo Neira Ayuso <>2020-12-02 10:45:15 +0100
commitcb7e02f44d6a6fd1c6001e23cecb3d7534110617 (patch)
tree7c4f1876a86ca65bed87ecf3cbb826a46794bf00 /include/json.h
parent389a0e1edc89a4048a272e569d3349b1d43bc567 (diff)
src: enable json echo output when reading native syntax
This patch fixes a bug in which nft did not print any output when specifying --echo and --json and reading nft native syntax. This patch respects behavior when input is json, in which the output would be the identical input plus the handles. Adds a json_echo member inside struct nft_ctx to build and store the json object containing the json command objects, the object is built using a mock monitor to reuse monitor json code. This json object is only used when we are sure we have not read json from input. [ added json_alloc_echo() to compile without json support --pablo ] Fixes: Signed-off-by: Jose M. Guisado Gomez <> Tested-by: Eric Garver <> Signed-off-by: Pablo Neira Ayuso <>
Diffstat (limited to 'include/json.h')
1 files changed, 6 insertions, 0 deletions
diff --git a/include/json.h b/include/json.h
index 20d6c2a4..41142208 100644
--- a/include/json.h
+++ b/include/json.h
@@ -111,6 +111,7 @@ void monitor_print_rule_json(struct netlink_mon_handler *monh,
int json_events_cb(const struct nlmsghdr *nlh,
struct netlink_mon_handler *monh);
+void json_alloc_echo(struct nft_ctx *ctx);
void json_print_echo(struct nft_ctx *ctx);
#else /* ! HAVE_LIBJANSSON */
@@ -251,6 +252,11 @@ static inline int json_events_cb(const struct nlmsghdr *nlh,
return -1;
+static inline void json_alloc_echo(struct nft_ctx *ctx)
+ /* empty */
static inline void json_print_echo(struct nft_ctx *ctx)
/* empty */