summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlvaro Neira Ayuso <alvaroneay@gmail.com>2013-06-08 03:36:04 +0000
committerPablo Neira Ayuso <pablo@netfilter.org>2013-06-08 19:28:56 +0200
commit28aece8907a66af30e3b88882c371f9fa3358371 (patch)
tree4eda5eff230fd0b634ea6a8b42b7e2bbe6f9a5a0 /src
parentff48b0628e95d458bd38e1a95aeed116bcabb133 (diff)
chain: add function to export tables in JSON format
Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/chain.c27
-rw-r--r--src/internal.h1
2 files changed, 28 insertions, 0 deletions
diff --git a/src/chain.c b/src/chain.c
index 7775dfc..1c53daa 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -688,6 +688,31 @@ int nft_chain_parse(struct nft_chain *c, enum nft_chain_parse_type type,
}
EXPORT_SYMBOL(nft_chain_parse);
+static int nft_chain_snprintf_json(char *buf, size_t size, struct nft_chain *c)
+{
+ return snprintf(buf, size,
+ "{ \"chain\": {"
+ "\"name\": \"%s\","
+ "\"handle\": %lu,"
+ "\"bytes\": %lu,"
+ "\"packets\": %lu,"
+ "\"version\": %d,"
+ "\"properties\": {"
+ "\"type\" : \"%s\","
+ "\"table\" : \"%s\","
+ "\"prio\" : %d,"
+ "\"use\" : %d,"
+ "\"hooknum\" : %d,"
+ "\"policy\" : %d,"
+ "\"family\" : %d"
+ "}"
+ "}"
+ "}",
+ c->name, c->handle, c->bytes, c->packets,
+ NFT_CHAIN_JSON_VERSION, c->type, c->table,
+ c->prio, c->use, c->hooknum, c->policy, c->family);
+}
+
static int nft_chain_snprintf_xml(char *buf, size_t size, struct nft_chain *c)
{
return snprintf(buf, size,
@@ -721,6 +746,8 @@ int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *c,
uint32_t type, uint32_t flags)
{
switch(type) {
+ case NFT_CHAIN_O_JSON:
+ return nft_chain_snprintf_json(buf, size, c);
case NFT_CHAIN_O_XML:
return nft_chain_snprintf_xml(buf, size, c);
case NFT_CHAIN_O_DEFAULT:
diff --git a/src/internal.h b/src/internal.h
index 0c5de21..769926b 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -21,6 +21,7 @@
#define NFT_CHAIN_XML_VERSION 0
#define NFT_RULE_XML_VERSION 0
#define NFT_TABLE_JSON_VERSION 0
+#define NFT_CHAIN_JSON_VERSION 0
struct expr_ops;