]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
monitor: add assignment check for json_echo
authorJose M. Guisado Gomez <guigom@riseup.net>
Sun, 6 Dec 2020 10:12:33 +0000 (11:12 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 8 Dec 2020 11:47:04 +0000 (12:47 +0100)
When --echo and --json is specified and native syntax is read, only the
last instruction is printed. This happens because the reference to the
json_echo is reassigned each time netlink_echo_callback is executed for
an instruction to be echoed.

Add an assignment check for json_echo to avoid reassigning it.

Fixes: cb7e02f44d6a (src: enable json echo output when reading native syntax)
Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/monitor.c

index a733a9f0a3ad82b8fd2bb85a8236b7385a1ac5ad..2b5325ea34c372e0f962595b2ea73acc0837685f 100644 (file)
@@ -939,8 +939,8 @@ int netlink_echo_callback(const struct nlmsghdr *nlh, void *data)
        if (nft_output_json(&nft->output)) {
                if (nft->json_root)
                        return json_events_cb(nlh, &echo_monh);
-
-               json_alloc_echo(nft);
+               if (!nft->json_echo)
+                       json_alloc_echo(nft);
                echo_monh.format = NFTNL_OUTPUT_JSON;
        }