summaryrefslogtreecommitdiffstats
path: root/src/rule.c
diff options
context:
space:
mode:
authorArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>2014-01-23 17:42:34 +0000
committerPatrick McHardy <kaber@trash.net>2014-01-23 17:42:34 +0000
commitcb86c1691c6900881b43229c07779412ffc48154 (patch)
tree4017d9fa5d34d883f2c432d84e91ce86df53c879 /src/rule.c
parent2f61f093c3149465f2a68764b25c817adbe87fcd (diff)
ruleset: add XML/JSON export
This patch adds the following operation: :~# nft export <xml|json> 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 <arturo.borrero.glez@gmail.com> Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src/rule.c')
-rw-r--r--src/rule.c20
1 files changed, 20 insertions, 0 deletions
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 <statement.h>
#include <rule.h>
#include <utils.h>
+#include <netlink.h>
+#include <libnftnl/common.h>
+#include <libnftnl/ruleset.h>
#include <netinet/ip.h>
#include <linux/netfilter.h>
#include <linux/netfilter_arp.h>
@@ -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);
}