From cb86c1691c6900881b43229c07779412ffc48154 Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Thu, 23 Jan 2014 17:42:34 +0000 Subject: ruleset: add XML/JSON export This patch adds the following operation: :~# nft export The XML/JSON output is provided raw by libnftnl, thus without format. In case of XML, you can give format with the `xmllint' tool from libxml2-tools: :~# nft list ruleset xml | xmllint --format - In case of JSON, you can use `json_pp' from perl standar package: :~# nft list ruleset json | json_pp A format field is added in struct cmd, and it will be reused in the import operation. Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Patrick McHardy --- src/rule.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/rule.c') diff --git a/src/rule.c b/src/rule.c index b43ce107..38cd63cf 100644 --- a/src/rule.c +++ b/src/rule.c @@ -18,7 +18,10 @@ #include #include #include +#include +#include +#include #include #include #include @@ -592,6 +595,21 @@ static int do_list_sets(struct netlink_ctx *ctx, const struct location *loc, return 0; } +static int do_command_export(struct netlink_ctx *ctx, struct cmd *cmd) +{ + struct nft_ruleset *rs = netlink_dump_ruleset(ctx, &cmd->handle, + &cmd->location); + + if (rs == NULL) + return -1; + + nft_ruleset_fprintf(stdout, rs, cmd->format, 0); + fprintf(stdout, "\n"); + + nft_ruleset_free(rs); + return 0; +} + static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd) { struct table *table = NULL; @@ -744,6 +762,8 @@ int do_command(struct netlink_ctx *ctx, struct cmd *cmd) return do_command_flush(ctx, cmd); case CMD_RENAME: return do_command_rename(ctx, cmd); + case CMD_EXPORT: + return do_command_export(ctx, cmd); default: BUG("invalid command object type %u\n", cmd->obj); } -- cgit v1.2.3