Patchwork [libnftables,6/7] test:chain:test json parsing support

login
register
mail settings
Submitter Alvaro Neira
Date July 31, 2013, 1:21 p.m.
Message ID <20130731132127.29730.40714.stgit@Ph0enix>
Download mbox | patch
Permalink /patch/263700/
State Accepted
Headers show

Comments

Alvaro Neira - July 31, 2013, 1:21 p.m.
From: Álvaro Neira Ayuso <alvaroneay@gmail.com>

Test the functions for parsing chains in JSON Support

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
---
 tests/jsonfiles/11-chain.json |    1 +
 tests/jsonfiles/12-chain.json |    1 +
 tests/jsonfiles/13-chain.json |    1 +
 tests/jsonfiles/14-chain.json |    1 +
 tests/nft-parsing-test.c      |    9 +++++++++
 5 files changed, 13 insertions(+)
 create mode 100644 tests/jsonfiles/11-chain.json
 create mode 100644 tests/jsonfiles/12-chain.json
 create mode 100644 tests/jsonfiles/13-chain.json
 create mode 100644 tests/jsonfiles/14-chain.json


--
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

Patch

diff --git a/tests/jsonfiles/11-chain.json b/tests/jsonfiles/11-chain.json
new file mode 100644
index 0000000..0e71e8f
--- /dev/null
+++ b/tests/jsonfiles/11-chain.json
@@ -0,0 +1 @@ 
+{ "chain": {"name": "input","handle": 1,"bytes": 1375696,"packets": 4136,"family": "ip","table": "filter","use": 0,"type": "filter","hooknum": "NF_INET_LOCAL_IN","prio": 0,"policy": "accept"}}
diff --git a/tests/jsonfiles/12-chain.json b/tests/jsonfiles/12-chain.json
new file mode 100644
index 0000000..e841032
--- /dev/null
+++ b/tests/jsonfiles/12-chain.json
@@ -0,0 +1 @@ 
+{ "chain": {"name": "forward","handle": 2,"bytes": 0,"packets": 0,"family": "ip","table": "filter","use": 0,"type": "filter","hooknum": "NF_INET_FORWARD","prio": 0,"policy": "accept"}}
diff --git a/tests/jsonfiles/13-chain.json b/tests/jsonfiles/13-chain.json
new file mode 100644
index 0000000..9967233
--- /dev/null
+++ b/tests/jsonfiles/13-chain.json
@@ -0,0 +1 @@ 
+{ "chain": {"name": "output","handle": 3,"bytes": 454786,"packets": 2681,"family": "ip","table": "filter","use": 0,"type": "filter","hooknum": "NF_INET_LOCAL_OUT","prio": 0,"policy": "accept"}}
diff --git a/tests/jsonfiles/14-chain.json b/tests/jsonfiles/14-chain.json
new file mode 100644
index 0000000..716d022
--- /dev/null
+++ b/tests/jsonfiles/14-chain.json
@@ -0,0 +1 @@ 
+{ "chain": {"name": "chain1","handle": 4,"bytes": 0,"packets": 0,"family": "ip","table": "filter","use": 0}}
diff --git a/tests/nft-parsing-test.c b/tests/nft-parsing-test.c
index 0734f07..e111fd0 100644
--- a/tests/nft-parsing-test.c
+++ b/tests/nft-parsing-test.c
@@ -24,6 +24,7 @@  static int test_json(const char *filename)
 #ifdef JSON_PARSING
 	int ret = -1;
 	struct nft_table *t = NULL;
+	struct nft_chain *c = NULL;
 	json_t *root;
 	json_error_t error;
 	char *json = NULL;
@@ -47,6 +48,14 @@  static int test_json(const char *filename)
 
 			nft_table_free(t);
 		}
+	} else if (json_object_get(root, "chain") != NULL) {
+		c = nft_chain_alloc();
+		if (c != NULL) {
+			if (nft_chain_parse(c, NFT_CHAIN_PARSE_JSON, json) == 0)
+				ret = 0;
+
+			nft_chain_free(c);
+		}
 	}
 
 	return ret;