summaryrefslogtreecommitdiffstats
path: root/src/chain.c
diff options
context:
space:
mode:
authorArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>2013-02-08 17:51:56 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2013-02-08 19:12:55 +0100
commit26e06d838d6471f5233c1da3fee012bf113564a5 (patch)
tree0482737475d6dd151cd74a4e94bd82cff9278232 /src/chain.c
parent1cef3296c64244736a000ab0d146d05ca1ac4b8b (diff)
src: add XML output support
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/chain.c')
-rw-r--r--src/chain.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/chain.c b/src/chain.c
index e12f82b..3c83e6d 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -437,8 +437,28 @@ int nft_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_chain *c)
}
EXPORT_SYMBOL(nft_chain_nlmsg_parse);
-int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *c,
- uint32_t type, uint32_t flags)
+static int nft_chain_snprintf_xml(char *buf, size_t size, struct nft_chain *c)
+{
+ return snprintf(buf, size,
+ "<chain name=\"%s\" handle=\"%lu\""
+ " bytes=\"%lu\" packets=\"%lu\" >\n"
+ "\t<properties>\n"
+ "\t\t<flags value=\"%d\" />\n"
+ "\t\t<type value=\"%s\" />\n"
+ "\t\t<table value=\"%s\" />\n"
+ "\t\t<prio value=\"%d\" />\n"
+ "\t\t<use value=\"%d\" />\n"
+ "\t\t<hooknum value=\"%d\" />\n"
+ "\t\t<policy value=\"%d\" />\n"
+ "\t\t<family value=\"%d\" />\n"
+ "\t</properties>\n"
+ "</chain>\n",
+ c->name, c->handle, c->bytes, c->packets,
+ c->flags, c->type, c->table, c->prio,
+ c->use, c->hooknum, c->policy, c->family);
+}
+
+static int nft_chain_snprintf_default(char *buf, size_t size, struct nft_chain *c)
{
return snprintf(buf, size, "family=%u table=%s chain=%s type=%s "
"hook=%u prio=%d policy=%d use=%d "
@@ -446,6 +466,20 @@ int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *c,
c->family, c->table, c->name, c->type, c->hooknum,
c->prio, c->policy, c->use, c->packets, c->bytes);
}
+
+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_XML:
+ return nft_chain_snprintf_xml(buf, size, c);
+ case NFT_CHAIN_O_DEFAULT:
+ return nft_chain_snprintf_default(buf, size, c);
+ default:
+ break;
+ }
+ return -1;
+}
EXPORT_SYMBOL(nft_chain_snprintf);
struct nft_chain_list {