summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-05-08 13:08:37 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-05-11 12:16:59 +0200
commite70354f53e9f6be4a4be31dbc46c5e23291d3587 (patch)
tree8d0bb763d9e80c5eb33e899666552e2bd414053b /src/main.c
parente77b31f53a61a8995cd6baf91a6e557260f401bd (diff)
libnftables: Implement JSON output support
Although technically there already is support for JSON output via 'nft export json' command, it is hardly useable since it exports all the gory details of nftables VM. Also, libnftables has no control over what is exported since the content comes directly from libnftnl. Instead, implement JSON format support for regular 'nft list' commands. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/main.c b/src/main.c
index d26ea018..f3615974 100644
--- a/src/main.c
+++ b/src/main.c
@@ -31,6 +31,7 @@ enum opt_vals {
OPT_FILE = 'f',
OPT_INTERACTIVE = 'i',
OPT_INCLUDEPATH = 'I',
+ OPT_JSON = 'j',
OPT_NUMERIC = 'n',
OPT_STATELESS = 's',
OPT_IP2NAME = 'N',
@@ -40,7 +41,7 @@ enum opt_vals {
OPT_INVALID = '?',
};
-#define OPTSTRING "hvcf:iI:vnsNae"
+#define OPTSTRING "hvcf:iI:jvnsNae"
static const struct option options[] = {
{
@@ -95,6 +96,10 @@ static const struct option options[] = {
.val = OPT_ECHO,
},
{
+ .name = "json",
+ .val = OPT_JSON,
+ },
+ {
.name = NULL
}
};
@@ -112,6 +117,7 @@ static void show_help(const char *name)
" -f, --file <filename> Read input from <filename>\n"
" -i, --interactive Read input from interactive CLI\n"
"\n"
+" -j, --json Format output in JSON\n"
" -n, --numeric When specified once, show network addresses numerically (default behaviour).\n"
" Specify twice to also show Internet services (port numbers) numerically.\n"
" Specify three times to also show protocols, user IDs, and group IDs numerically.\n"
@@ -255,6 +261,9 @@ int main(int argc, char * const *argv)
case OPT_ECHO:
nft_ctx_output_set_echo(nft, true);
break;
+ case OPT_JSON:
+ nft_ctx_output_set_json(nft, true);
+ break;
case OPT_INVALID:
exit(EXIT_FAILURE);
}