netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alvaro Neira <alvaroneay@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: [libnftables PATCH 1/2] Add functions for exporting tables to JSON format
Date: Fri, 07 Jun 2013 11:14:16 +0200	[thread overview]
Message-ID: <20130607091415.13002.47323.stgit@Ph0enix> (raw)
In-Reply-To: <20130607091043.13002.66552.stgit@Ph0enix>


---
 include/libnftables/table.h |    1 +
 src/internal.h              |    1 +
 src/table.c                 |   18 ++++++++++++++++++
 3 files changed, 20 insertions(+)

diff --git a/include/libnftables/table.h b/include/libnftables/table.h
index 658230c..19f322c 100644
--- a/include/libnftables/table.h
+++ b/include/libnftables/table.h
@@ -31,6 +31,7 @@ void nft_table_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_table
 enum {
 	NFT_TABLE_O_DEFAULT	= 0,
 	NFT_TABLE_O_XML,
+	NFT_TABLE_O_JSON,
 };
 
 enum nft_table_parse_type {
diff --git a/src/internal.h b/src/internal.h
index 3ad5e89..0c5de21 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -20,6 +20,7 @@
 #define NFT_TABLE_XML_VERSION 0
 #define NFT_CHAIN_XML_VERSION 0
 #define NFT_RULE_XML_VERSION 0
+#define NFT_TABLE_JSON_VERSION 0
 
 struct expr_ops;
 
diff --git a/src/table.c b/src/table.c
index a868da4..de106bb 100644
--- a/src/table.c
+++ b/src/table.c
@@ -300,6 +300,22 @@ int nft_table_parse(struct nft_table *t, enum nft_table_parse_type type,
 }
 EXPORT_SYMBOL(nft_table_parse);
 
+static int nft_table_snprintf_json(char *buf, size_t size, struct nft_table *t)
+{
+	return snprintf(buf, size,
+			"{\"table\" : {"
+			"\"name\" : \"%s\","
+			"\"version\" : %d,"
+			"\"properties\" : {"
+				"\"family\" : %u,"
+				"\"table_flags\" : %d"
+				"}"
+			"}"
+			"}" ,
+			t->name, NFT_TABLE_JSON_VERSION,
+			t->family, t->table_flags);
+}
+
 static int nft_table_snprintf_xml(char *buf, size_t size, struct nft_table *t)
 {
 	return snprintf(buf, size,
@@ -325,6 +341,8 @@ int nft_table_snprintf(char *buf, size_t size, struct nft_table *t,
 	switch(type) {
 	case NFT_TABLE_O_XML:
 		return nft_table_snprintf_xml(buf, size, t);
+	case NFT_TABLE_O_JSON:
+		return nft_table_snprintf_json(buf, size, t);
 	case NFT_TABLE_O_DEFAULT:
 		return nft_table_snprintf_default(buf, size, t);
 	default:


  reply	other threads:[~2013-06-07  9:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-07  9:14 [libnftables PATCH 0/2] Series short description Alvaro Neira
2013-06-07  9:14 ` Alvaro Neira [this message]
2013-06-07 12:02   ` [libnftables PATCH 1/2] Add functions for exporting tables to JSON format Pablo Neira Ayuso
2013-06-07  9:14 ` [libnftables PATCH 2/2] Add implementation for to proof the JSON export function Alvaro Neira
2013-06-07 12:02   ` 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=20130607091415.13002.47323.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).