From: Alvaro Neira <alvaroneay@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: [libnftables PATCH 1/2] Add function for exporting chain to JSON Format
Date: Sat, 08 Jun 2013 15:36:04 +0200 [thread overview]
Message-ID: <20130608133604.10197.76262.stgit@Ph0enix> (raw)
In-Reply-To: <20130608133222.10197.21456.stgit@Ph0enix>
From: Alvaro Neira Ayuso <alvaroneay@gmail.com>
---
include/libnftables/chain.h | 1 +
src/chain.c | 27 +++++++++++++++++++++++++++
src/internal.h | 1 +
3 files changed, 29 insertions(+)
diff --git a/include/libnftables/chain.h b/include/libnftables/chain.h
index f06f743..3645eaa 100644
--- a/include/libnftables/chain.h
+++ b/include/libnftables/chain.h
@@ -44,6 +44,7 @@ void nft_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_chain
enum {
NFT_CHAIN_O_DEFAULT = 0,
NFT_CHAIN_O_XML,
+ NFT_CHAIN_O_JSON,
};
enum nft_chain_parse_type {
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;
next prev parent reply other threads:[~2013-06-08 13:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-08 13:35 [libnftables PATCH 0/2] Series short description Alvaro Neira
2013-06-08 13:36 ` Alvaro Neira [this message]
2013-06-08 17:31 ` [libnftables PATCH 1/2] Add function for exporting chain to JSON Format Pablo Neira Ayuso
2013-06-08 13:36 ` [libnftables PATCH 2/2] Implementation for to test the function for exporting chains to JSON format Alvaro Neira
2013-06-08 17:32 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130608133604.10197.76262.stgit@Ph0enix \
--to=alvaroneay@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).