From bb32d8db9a125d9676f87866e48ffbf0221ec16a Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 26 Oct 2018 15:01:38 +0200 Subject: JSON: Add support for echo option The basic principle is to not return a JSON object freshly created from netlink responses, but just update the existing user-provided one to make sure callers get back exactly what they expect. To achieve that, keep the parsed JSON object around in a global variable ('cur_root') and provide a custom callback to insert handles into it from received netlink messages. The tricky bit here is updating rules since unique identification is problematic. Therefore drop possibly present handles from input and later assume updates are received in order so the first rule not having a handle set is the right one. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/libnftables.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/libnftables.c') diff --git a/src/libnftables.c b/src/libnftables.c index e892083f..2f67bb34 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -467,6 +467,8 @@ err: } free(nlbuf); + if (!rc && nft->output.json && nft->output.echo) + json_print_echo(nft); return rc; } @@ -506,6 +508,8 @@ err: nft->scanner = NULL; } + if (!rc && nft->output.json && nft->output.echo) + json_print_echo(nft); return rc; } -- cgit v1.2.3