diff mbox

[libnftables,1/4] Add functions for to export tables to JSON format

Message ID 20130606131706.18048.11297.stgit@Ph0enix
State Superseded
Headers show

Commit Message

Alvaro Neira June 6, 2013, 1:17 p.m. UTC
---
 0 files changed


--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/src/table.c b/src/table.c
index a868da4..57ea586 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: