summaryrefslogtreecommitdiffstats
path: root/src/chain.c
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/chain.c
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/chain.c')
-rw-r--r--src/chain.c27
1 files changed, 27 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: