Skip to contentSkip to conversation

json: remove the rule flags in ruleset file

PATCH In review Alvaro Neira 2 participants 4 messages Nov 11, 2013 – Nov 13, 2013 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 json: remove the rule flags in ruleset file

From: Álvaro Neira Ayuso <[email protected]>

This patch fix the unconsistence of this file with the commit 2cba09966c77e946f6f32e860a368a0c5a9830a0

rule: remove NFT_RULE_ATTR_FLAGS

---
 tests/jsonfiles/64-ruleset.json |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/jsonfiles/64-ruleset.json +1 -1
index a1baec8..533d7fa 100644
@@ -1,2 +1,2 @@
-{"nftables":[{"table":{"name":"filter","family":"ip","flags":0}},{"table":{"name":"filter2","family":"ip6","flags":0}},{"chain":{"name":"input","handle":1,"bytes":10681449,"packets":16216,"family":"ip","table":"filter","use":0,"type":"filter","hooknum":"input","prio":0,"policy":"accept"}},{"chain":{"name":"forward","handle":2,"bytes":0,"packets":0,"family":"ip","table":"filter","use":0,"type":"filter","hooknum":"forward","prio":0,"policy":"accept"}},{"chain":{"name":"output","handle":3,"bytes":2375830,"packets":15184,"family":"ip","table":"filter","use":0,"type":"filter","hooknum":"output","prio":0,"policy":"accept"}},{"chain":{"name":"chain1","handle":4,"bytes":0,"packets":0,"family":"ip","table":"filter","use":0}},{"set":{"name":"set0","table":"filter","flags":3,"family":"ip","key_type":12,"key_len":2}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":6,"flags":0,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0},{"type":"immediate","dreg":0,"immediatedata":{"data_reg":{"type":"verdict","verdict":"drop"}}}]}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":9,"flags":0,"expr":[{"type":"payload","dreg":1,"offset":9,"len":1,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":1,"data0":"0x00000006"}}},{"type":"payload","dreg":1,"offset":2,"len":2,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":2,"data0":"0x00001600"}}},{"type":"counter","pkts":0,"bytes":0}]}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":10,"flags":0,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0}]}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":11,"flags":0,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0},{"type":"immediate","dreg":0,"immediatedata":{"data_reg":{"type":"verdict","verdict":"drop"}}}]}}]}
+{"nftables":[{"table":{"name":"filter","family":"ip","flags":0}},{"table":{"name":"filter2","family":"ip6","flags":0}},{"chain":{"name":"input","handle":1,"bytes":10681449,"packets":16216,"family":"ip","table":"filter","use":0,"type":"filter","hooknum":"input","prio":0,"policy":"accept"}},{"chain":{"name":"forward","handle":2,"bytes":0,"packets":0,"family":"ip","table":"filter","use":0,"type":"filter","hooknum":"forward","prio":0,"policy":"accept"}},{"chain":{"name":"output","handle":3,"bytes":2375830,"packets":15184,"family":"ip","table":"filter","use":0,"type":"filter","hooknum":"output","prio":0,"policy":"accept"}},{"chain":{"name":"chain1","handle":4,"bytes":0,"packets":0,"family":"ip","table":"filter","use":0}},{"set":{"name":"set0","table":"filter","flags":3,"family":"ip","key_type":12,"key_len":2}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":6,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0},{"type":"immediate","dreg":0,"immediatedata":{"data_reg":{"type":"verdict","verdict":"drop"}}}]}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":9,"expr":[{"type":"payload","dreg":1,"offset":9,"len":1,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":1,"data0":"0x00000006"}}},{"type":"payload","dreg":1,"offset":2,"len":2,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":2,"data0":"0x00001600"}}},{"type":"counter","pkts":0,"bytes":0}]}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":10,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0}]}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":11,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0},{"type":"immediate","dreg":0,"immediatedata":{"data_reg":{"type":"verdict","verdict":"drop"}}}]}}]}
 

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

#1 lore raw

PATCH 2/2 json: Refactor of exporting and parsing support flags

From: Álvaro Neira Ayuso <[email protected]>

Remove the different flag definition for using the snprinf and parsing support and create a new flags for joining in general flags.

Now for printing or parsing tables or chains, we needed to use:
NFT_TABLE_O_JSON
NFT_TABLE_O_XML
NFT_CHAIN_O_JSON
NFT_CHAIN_O_XML
NFT_CHAIN_PARSE_JSON
NFT_TABLE_PARSE_JSON
NFT_CHAIN_PARSE_XML
NFT_TABLE_PARSE_XML

Now for exporting and parsing rules and chains, we only use:
NFT_FORMAT_JSON
NFT_FORMAT_XML
NFT_PARSE_FORMAT_JSON
NFT_PARSE_FORMAT_XML

---
 examples/nft-chain-get.c      |    6 +++---
 examples/nft-chain-json-add.c |    4 ++--
 examples/nft-chain-xml-add.c  |    4 ++--
 examples/nft-events.c         |    6 +++---
 examples/nft-rule-get.c       |    6 +++---
 examples/nft-rule-json-add.c  |    4 ++--
 examples/nft-rule-xml-add.c   |    4 ++--
 examples/nft-set-elem-get.c   |    6 +++---
 examples/nft-set-get.c        |    6 +++---
 examples/nft-set-json-add.c   |    4 ++--
 examples/nft-table-get.c      |    6 +++---
 examples/nft-table-json-add.c |    4 ++--
 examples/nft-table-xml-add.c  |    4 ++--
 include/libnftables/chain.h   |   17 +++--------------
 include/libnftables/common.h  |   16 ++++++++++++++++
 include/libnftables/rule.h    |   17 +++--------------
 include/libnftables/ruleset.h |   17 +++--------------
 include/libnftables/set.h     |   19 ++++---------------
 include/libnftables/table.h   |   17 +++--------------
 src/chain.c                   |   12 ++++++------
 src/expr/bitwise.c            |   18 +++++++++---------
 src/expr/byteorder.c          |    6 +++---
 src/expr/cmp.c                |   12 ++++++------
 src/expr/counter.c            |    6 +++---
 src/expr/ct.c                 |    6 +++---
 src/expr/data_reg.c           |   18 +++++++++---------
 src/expr/exthdr.c             |    6 +++---
 src/expr/immediate.c          |   24 ++++++++++++------------
 src/expr/limit.c              |    6 +++---
 src/expr/log.c                |    6 +++---
 src/expr/lookup.c             |    6 +++---
 src/expr/match.c              |    6 +++---
 src/expr/meta.c               |    6 +++---
 src/expr/nat.c                |    6 +++---
 src/expr/payload.c            |    6 +++---
 src/expr/reject.c             |    6 +++---
 src/expr/target.c             |    6 +++---
 src/rule.c                    |   12 ++++++------
 src/ruleset.c                 |   24 ++++++++++++------------
 src/set.c                     |   14 +++++++-------
 src/set_elem.c                |   18 +++++++++---------
 src/table.c                   |   12 ++++++------
 tests/nft-parsing-test.c      |   40 ++++++++++++++++++++--------------------
 43 files changed, 205 insertions(+), 244 deletions(-)
 create mode 100644 include/libnftables/common.h
examples/nft-chain-get.c +3 -3
index e466e8b..56b903a 100644
@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
 	struct mnl_socket *nl;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct nlmsghdr *nlh;
-	uint32_t portid, seq, type = NFT_CHAIN_O_DEFAULT;
+	uint32_t portid, seq, type = NFT_FORMAT_DEFAULT;
 	struct nft_chain *t = NULL;
 	int ret, family;
 
@@ -96,9 +96,9 @@ int main(int argc, char *argv[])
 	}
 
 	if (strcmp(argv[argc-1], "xml") == 0){
-		type = NFT_CHAIN_O_XML;
+		type = NFT_FORMAT_XML;
 	}else if (strcmp(argv[argc-1], "json") == 0){
-		type = NFT_CHAIN_O_JSON;
+		type = NFT_FORMAT_JSON;
 	}
 
 	nl = mnl_socket_open(NETLINK_NETFILTER);
examples/nft-chain-json-add.c +2 -2
index 42e2d82..4b39327 100644
@@ -65,12 +65,12 @@ int main(int argc, char *argv[])
 
 	close(fd);
 
-	if (nft_chain_parse(c, NFT_CHAIN_PARSE_JSON, json) < 0) {
+	if (nft_chain_parse(c, NFT_PARSE_FORMAT_JSON, json) < 0) {
 		printf("E: Unable to parse JSON file: %s\n", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
 
-	nft_chain_snprintf(reprint, sizeof(reprint), c, NFT_CHAIN_O_JSON, 0);
+	nft_chain_snprintf(reprint, sizeof(reprint), c, NFT_FORMAT_JSON, 0);
 	printf("Parsed:\n%s\n", reprint);
 
 	nft_chain_attr_unset(c, NFT_CHAIN_ATTR_HANDLE);
examples/nft-chain-xml-add.c +2 -2
index 2e2fe11..42529a1 100644
@@ -63,12 +63,12 @@ int main(int argc, char *argv[])
 
 	close(fd);
 
-	if (nft_chain_parse(c, NFT_CHAIN_PARSE_XML, xml) < 0) {
+	if (nft_chain_parse(c, NFT_PARSE_FORMAT_XML, xml) < 0) {
 		printf("E: Unable to parse XML file: %s\n", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
 
-	nft_chain_snprintf(reprint, sizeof(reprint), c, NFT_CHAIN_O_XML, 0);
+	nft_chain_snprintf(reprint, sizeof(reprint), c, NFT_FORMAT_XML, 0);
 	printf("Parsed:\n%s\n", reprint);
 
 	nft_chain_attr_unset(c, NFT_CHAIN_ATTR_HANDLE);
examples/nft-events.c +3 -3
index 5550c70..8ba98a2 100644
@@ -38,7 +38,7 @@ static int table_cb(const struct nlmsghdr *nlh, int type)
 		goto err_free;
 	}
 
-	nft_table_snprintf(buf, sizeof(buf), t, NFT_TABLE_O_DEFAULT, 0);
+	nft_table_snprintf(buf, sizeof(buf), t, NFT_FORMAT_DEFAULT, 0);
 	printf("[%s]\t%s\n", type == NFT_MSG_NEWTABLE ? "NEW" : "DEL", buf);
 
 err_free:
@@ -63,7 +63,7 @@ static int rule_cb(const struct nlmsghdr *nlh, int type)
 		goto err_free;
 	}
 
-	nft_rule_snprintf(buf, sizeof(buf), t, NFT_RULE_O_DEFAULT, 0);
+	nft_rule_snprintf(buf, sizeof(buf), t, NFT_FORMAT_DEFAULT, 0);
 	printf("[%s]\t%s\n", type == NFT_MSG_NEWRULE ? "NEW" : "DEL", buf);
 
 err_free:
@@ -88,7 +88,7 @@ static int chain_cb(const struct nlmsghdr *nlh, int type)
 		goto err_free;
 	}
 
-	nft_chain_snprintf(buf, sizeof(buf), t, NFT_CHAIN_O_DEFAULT, 0);
+	nft_chain_snprintf(buf, sizeof(buf), t, NFT_FORMAT_DEFAULT, 0);
 	printf("[%s]\t%s\n", type == NFT_MSG_NEWCHAIN ? "NEW" : "DEL", buf);
 
 err_free:
examples/nft-rule-get.c +3 -3
index cd0f8dc..23448f1 100644
@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
 	struct mnl_socket *nl;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct nlmsghdr *nlh;
-	uint32_t portid, seq, type = NFT_RULE_O_DEFAULT;
+	uint32_t portid, seq, type = NFT_FORMAT_DEFAULT;
 	struct nft_rule *t = NULL;
 	int ret, family;
 
@@ -78,9 +78,9 @@ int main(int argc, char *argv[])
 
 	if (argc == 3) {
 		if (strcmp(argv[2], "xml") == 0)
-			type = NFT_RULE_O_XML;
+			type = NFT_FORMAT_XML;
 		else if (strcmp(argv[2], "json") == 0)
-			type = NFT_RULE_O_JSON;
+			type = NFT_FORMAT_JSON;
 	}
 
 	/* XXX requires table, chain and handle attributes for selective get */
examples/nft-rule-json-add.c +2 -2
index 83dec3e..2aa236b 100644
@@ -63,12 +63,12 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
-	if (nft_rule_parse(r, NFT_RULE_PARSE_JSON, json) < 0) {
+	if (nft_rule_parse(r, NFT_PARSE_FORMAT_JSON, json) < 0) {
 		printf("E: Unable to parse JSON file: %s\n", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
 
-	nft_rule_snprintf(reprint, sizeof(reprint), r, NFT_RULE_O_JSON, 0);
+	nft_rule_snprintf(reprint, sizeof(reprint), r, NFT_FORMAT_JSON, 0);
 	printf("Parsed:\n%s\n", reprint);
 
 	nft_rule_attr_unset(r, NFT_RULE_ATTR_HANDLE);
examples/nft-rule-xml-add.c +2 -2
index 4de7a69..bfca7e1 100644
@@ -63,12 +63,12 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
-	if (nft_rule_parse(r, NFT_RULE_PARSE_XML, xml) < 0) {
+	if (nft_rule_parse(r, NFT_PARSE_FORMAT_XML, xml) < 0) {
 		printf("E: Unable to parse XML file: %s\n", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
 
-	nft_rule_snprintf(reprint, sizeof(reprint), r, NFT_RULE_O_XML, 0);
+	nft_rule_snprintf(reprint, sizeof(reprint), r, NFT_FORMAT_XML, 0);
 	printf("Parsed:\n%s\n", reprint);
 
 	nft_rule_attr_unset(r, NFT_RULE_ATTR_HANDLE);
examples/nft-set-elem-get.c +3 -3
index aeba400..c5ae6d3 100644
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct nlmsghdr *nlh;
 	uint32_t portid, seq, family;
-	uint32_t type = NFT_SET_O_DEFAULT;
+	uint32_t type = NFT_FORMAT_DEFAULT;
 	struct nft_set *t = NULL;
 	int ret;
 
@@ -81,9 +81,9 @@ int main(int argc, char *argv[])
 	}
 
 	if (argc == 5 && strcmp(argv[4], "json") == 0 )
-		type = NFT_SET_O_JSON;
+		type = NFT_FORMAT_JSON;
 	else if (argc == 5 && strcmp(argv[4], "xml") == 0)
-		type = NFT_SET_O_XML;
+		type = NFT_FORMAT_XML;
 
 	nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_GETSETELEM, family,
 					NLM_F_DUMP|NLM_F_ACK, seq);
examples/nft-set-get.c +3 -3
index 4bc585c..6567ef6 100644
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
 	char buf[MNL_SOCKET_BUFFER_SIZE];
 	struct nlmsghdr *nlh;
 	uint32_t portid, seq, family;
-	uint32_t type = NFT_SET_O_DEFAULT;
+	uint32_t type = NFT_FORMAT_DEFAULT;
 	struct nft_set *t = NULL;
 	int ret;
 
@@ -80,9 +80,9 @@ int main(int argc, char *argv[])
 	}
 
 	if (argc == 3 && strcmp(argv[2], "json") == 0)
-		type = NFT_SET_O_JSON;
+		type = NFT_FORMAT_JSON;
 	else if (argc == 3 && strcmp(argv[2], "xml") == 0)
-		type = NFT_SET_O_XML;
+		type = NFT_FORMAT_XML;
 
 	nlh = nft_set_nlmsg_build_hdr(buf, NFT_MSG_GETSET, family,
 					NLM_F_DUMP|NLM_F_ACK, seq);
examples/nft-set-json-add.c +2 -2
index 33c3acd..191ce91 100644
@@ -64,12 +64,12 @@ int main(int argc, char *argv[])
 
 	close(fd);
 
-	if (nft_set_parse(s, NFT_SET_PARSE_JSON, json) < 0) {
+	if (nft_set_parse(s, NFT_PARSE_FORMAT_JSON, json) < 0) {
 		printf("E: Unable to parse JSON file: %s\n", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
 
-	nft_set_snprintf(reprint, sizeof(reprint), s, NFT_SET_O_JSON, 0);
+	nft_set_snprintf(reprint, sizeof(reprint), s, NFT_FORMAT_JSON, 0);
 	printf("Parsed:\n%s\n", reprint);
 
 	family = nft_set_attr_get_u32(s, NFT_SET_ATTR_FAMILY);
examples/nft-table-get.c +3 -3
index f57423b..78c19f3 100644
@@ -54,7 +54,7 @@ int main(int argc, char *argv[])
 	uint32_t portid, seq, family;
 	struct nft_table *t = NULL;
 	int ret;
-	uint32_t type = NFT_TABLE_O_DEFAULT;
+	uint32_t type = NFT_FORMAT_DEFAULT;
 
 	if (argc < 2 || argc > 4) {
 		fprintf(stderr, "%s <family> [<table>] [<default|xml|json>]\n",
@@ -78,11 +78,11 @@ int main(int argc, char *argv[])
 	}
 
 	if (strcmp(argv[argc-1], "xml") == 0) {
-		type = NFT_TABLE_O_XML;
+		type = NFT_FORMAT_XML;
 		argv[argc-1] = NULL;
 		argc--;
 	}else if (strcmp(argv[argc-1], "json") == 0) {
-		type = NFT_TABLE_O_JSON;
+		type = NFT_FORMAT_JSON;
 		argv[argc-1] = NULL;
 		argc--;
 	} else if (strcmp(argv[argc - 1], "default") == 0) {
examples/nft-table-json-add.c +2 -2
index 5526c91..18f94c1 100644
@@ -64,12 +64,12 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
-	if (nft_table_parse(t, NFT_TABLE_PARSE_JSON, json) < 0) {
+	if (nft_table_parse(t, NFT_PARSE_FORMAT_JSON, json) < 0) {
 		printf("E: Unable to parse JSON file: %s\n", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
 
-	nft_table_snprintf(reprint, sizeof(reprint), t, NFT_TABLE_O_JSON, 0);
+	nft_table_snprintf(reprint, sizeof(reprint), t, NFT_FORMAT_JSON, 0);
 	printf("Parsed:\n%s\n", reprint);
 
 	family = nft_table_attr_get_u32(t, NFT_TABLE_ATTR_FAMILY);
examples/nft-table-xml-add.c +2 -2
index 6de0855..d231a9d 100644
@@ -60,12 +60,12 @@ int main(int argc, char *argv[])
 		exit(EXIT_FAILURE);
 	}
 
-	if (nft_table_parse(t, NFT_TABLE_PARSE_XML, xml) < 0) {
+	if (nft_table_parse(t, NFT_PARSE_FORMAT_XML, xml) < 0) {
 		printf("E: Unable to parse XML file: %s\n", strerror(errno));
 		exit(EXIT_FAILURE);
 	}
 
-	nft_table_snprintf(reprint, sizeof(reprint), t, NFT_TABLE_O_XML, 0);
+	nft_table_snprintf(reprint, sizeof(reprint), t, NFT_FORMAT_XML, 0);
 	printf("Parsed:\n%s\n", reprint);
 
 	family = nft_table_attr_get_u32(t, NFT_TABLE_ATTR_FAMILY);
include/libnftables/chain.h +3 -14
index 5de7318..d959f7d 100644
@@ -6,6 +6,8 @@
 #include <stdbool.h>
 #include <sys/types.h>
 
+#include <libnftables/common.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -47,20 +49,7 @@ struct nlmsghdr;
 
 void nft_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_chain *t);
 
-enum {
-	NFT_CHAIN_O_DEFAULT	= 0,
-	NFT_CHAIN_O_XML,
-	NFT_CHAIN_O_JSON,
-};
-
-enum nft_chain_parse_type {
-	NFT_CHAIN_PARSE_NONE	= 0,
-	NFT_CHAIN_PARSE_XML,
-	NFT_CHAIN_PARSE_JSON,
-	NFT_CHAIN_PARSE_MAX
-};
-
-int nft_chain_parse(struct nft_chain *c, enum nft_chain_parse_type type, const char *data);
+int nft_chain_parse(struct nft_chain *c, enum nft_parse_format_type type, const char *data);
 int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *t, uint32_t type, uint32_t flags);
 int nft_chain_fprintf(FILE *fp, struct nft_chain *c, uint32_t type, uint32_t flags);
 
include/libnftables/common.h new file +16 -0
new file mode 100644
index 0000000..5055834
@@ -0,0 +1,16 @@
+#ifndef _COMMON_H_
+#define _COMMON_H_
+
+enum {
+	NFT_FORMAT_DEFAULT	= 0,
+	NFT_FORMAT_XML,
+	NFT_FORMAT_JSON,
+};
+
+enum nft_parse_format_type {
+	NFT_PARSE_FORMAT_NONE	= 0,
+	NFT_PARSE_FORMAT_XML,
+	NFT_PARSE_FORMAT_JSON,
+	NFT_PARSE_FORMAT_MAX,
+};
+#endif
include/libnftables/rule.h +3 -14
index b61afb0..c67b114 100644
@@ -6,6 +6,8 @@
 #include <stdbool.h>
 #include <sys/types.h>
 
+#include <libnftables/common.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -45,20 +47,7 @@ struct nlmsghdr;
 
 void nft_rule_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_rule *t);
 
-enum {
-	NFT_RULE_O_DEFAULT	= 0,
-	NFT_RULE_O_XML,
-	NFT_RULE_O_JSON,
-};
-
-enum nft_rule_parse_type {
-	NFT_RULE_PARSE_NONE	= 0,
-	NFT_RULE_PARSE_XML,
-	NFT_RULE_PARSE_JSON,
-	NFT_RULE_PARSE_MAX,
-};
-
-int nft_rule_parse(struct nft_rule *r, enum nft_rule_parse_type type, const char *data);
+int nft_rule_parse(struct nft_rule *r, enum nft_parse_format_type type, const char *data);
 int nft_rule_snprintf(char *buf, size_t size, struct nft_rule *t, uint32_t type, uint32_t flags);
 int nft_rule_fprintf(FILE *fp, struct nft_rule *r, uint32_t type, uint32_t flags);
 
include/libnftables/ruleset.h +3 -14
index 3b20bfa..2f44c5b 100644
@@ -7,6 +7,8 @@
 #include <stdint.h>
 #include <sys/types.h>
 
+#include <libnftables/common.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -28,20 +30,7 @@ void nft_ruleset_attr_unset(struct nft_ruleset *r, uint16_t attr);
 void nft_ruleset_attr_set(struct nft_ruleset *r, uint16_t attr, void *data);
 const void *nft_ruleset_attr_get(const struct nft_ruleset *r, uint16_t attr);
 
-enum {
-	NFT_RULESET_O_DEFAULT	= 0,
-	NFT_RULESET_O_XML,
-	NFT_RULESET_O_JSON,
-};
-
-enum nft_ruleset_parse_type {
-	NFT_RULESET_PARSE_NONE	= 0,
-	NFT_RULESET_PARSE_XML,
-	NFT_RULESET_PARSE_JSON,
-	NFT_RULESET_PARSE_MAX,
-};
-
-int nft_ruleset_parse(struct nft_ruleset *rs, enum nft_ruleset_parse_type type, const char *data);
+int nft_ruleset_parse(struct nft_ruleset *rs, enum nft_parse_format_type type, const char *data);
 int nft_ruleset_snprintf(char *buf, size_t size, const struct nft_ruleset *rs, uint32_t type, uint32_t flags);
 int nft_ruleset_fprintf(FILE *fp, const struct nft_ruleset *rs, uint32_t type, uint32_t flags);
 
include/libnftables/set.h +4 -15
index cf63b9b..24bbb0d 100644
@@ -6,6 +6,8 @@
 #include <stdbool.h>
 #include <sys/types.h>
 
+#include <libnftables/common.h>
+
 enum {
 	NFT_SET_ATTR_TABLE,
 	NFT_SET_ATTR_NAME,
@@ -58,14 +60,7 @@ struct nft_set *nft_set_list_iter_cur(struct nft_set_list_iter *iter);
 struct nft_set *nft_set_list_iter_next(struct nft_set_list_iter *iter);
 void nft_set_list_iter_destroy(struct nft_set_list_iter *iter);
 
-enum nft_set_parse_type {
-	NFT_SET_PARSE_NONE	= 0,
-	NFT_SET_PARSE_XML,
-	NFT_SET_PARSE_JSON,
-	NFT_SET_PARSE_MAX,
-};
-
-int nft_set_parse(struct nft_set *s, enum nft_set_parse_type type, const char *data);
+int nft_set_parse(struct nft_set *s, enum nft_parse_format_type type, const char *data);
 
 /*
  * Set elements
@@ -79,12 +74,6 @@ enum {
 	NFT_SET_ELEM_ATTR_DATA,
 };
 
-enum {
-	NFT_SET_O_DEFAULT	= 0,
-	NFT_SET_O_XML,
-	NFT_SET_O_JSON,
-};
-
 struct nft_set_elem;
 
 struct nft_set_elem *nft_set_elem_alloc(void);
@@ -109,7 +98,7 @@ void nft_set_elem_nlmsg_build_payload(struct nlmsghdr *nlh, struct nft_set_elem
 
 int nft_set_elem_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set_elem *s);
 
-int nft_set_elem_parse(struct nft_set_elem *e, enum nft_set_parse_type type, const char *data);
+int nft_set_elem_parse(struct nft_set_elem *e, enum nft_parse_format_type type, const char *data);
 int nft_set_elem_snprintf(char *buf, size_t size, struct nft_set_elem *s, uint32_t type, uint32_t flags);
 int nft_set_elem_fprintf(FILE *fp, struct nft_set_elem *se, uint32_t type, uint32_t flags);
 
include/libnftables/table.h +3 -14
index e3b4888..7a07726 100644
@@ -6,6 +6,8 @@
 #include <stdbool.h>
 #include <sys/types.h>
 
+#include <libnftables/common.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -35,20 +37,7 @@ struct nlmsghdr;
 
 void nft_table_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_table *t);
 
-enum {
-	NFT_TABLE_O_DEFAULT	= 0,
-	NFT_TABLE_O_XML,
-	NFT_TABLE_O_JSON,
-};
-
-enum nft_table_parse_type {
-	NFT_TABLE_PARSE_NONE	= 0,
-	NFT_TABLE_PARSE_XML,
-	NFT_TABLE_PARSE_JSON,
-	NFT_TABLE_PARSE_MAX,
-};
-
-int nft_table_parse(struct nft_table *t, enum nft_table_parse_type type, const char *data);
+int nft_table_parse(struct nft_table *t, enum nft_parse_format_type type, const char *data);
 int nft_table_snprintf(char *buf, size_t size, struct nft_table *t, uint32_t type, uint32_t flags);
 int nft_table_fprintf(FILE *fp, struct nft_table *t, uint32_t type, uint32_t flags);
 
src/chain.c +6 -6
index cdb398f..057373a 100644
@@ -727,16 +727,16 @@ static int nft_chain_xml_parse(struct nft_chain *c, const char *xml)
 #endif
 }
 
-int nft_chain_parse(struct nft_chain *c, enum nft_chain_parse_type type,
+int nft_chain_parse(struct nft_chain *c, enum nft_parse_format_type type,
 		    const char *data)
 {
 	int ret;
 
 	switch (type) {
-	case NFT_CHAIN_PARSE_XML:
+	case NFT_PARSE_FORMAT_XML:
 		ret = nft_chain_xml_parse(c, data);
 		break;
-	case NFT_CHAIN_PARSE_JSON:
+	case NFT_PARSE_FORMAT_JSON:
 		ret = nft_chain_json_parse(c, data);
 		break;
 	default:
@@ -838,11 +838,11 @@ 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_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_chain_snprintf_default(buf, size, c);
-	case NFT_CHAIN_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_chain_snprintf_xml(buf, size, c);
-	case NFT_CHAIN_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_chain_snprintf_json(buf, size, c);
 	default:
 		break;
src/expr/bitwise.c +9 -9
index 0be1593..08de7a8 100644
@@ -293,14 +293,14 @@ nft_rule_expr_bitwise_snprintf_json(char *buf, size_t size,
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &bitwise->mask,
-				    NFT_RULE_O_JSON, 0, DATA_VALUE);
+				    NFT_FORMAT_JSON, 0, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = snprintf(buf+offset, len, "},\"xor\":{");
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &bitwise->xor,
-				    NFT_RULE_O_JSON, 0, DATA_VALUE);
+				    NFT_FORMAT_JSON, 0, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = snprintf(buf+offset, len, "}");
@@ -325,14 +325,14 @@ nft_rule_expr_bitwise_snprintf_xml(char *buf, size_t size,
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &bitwise->mask,
-				    NFT_RULE_O_XML, 0, DATA_VALUE);
+				    NFT_FORMAT_XML, 0, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = snprintf(buf+offset, len, "</mask><xor>");
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &bitwise->xor,
-				    NFT_RULE_O_XML, 0, DATA_VALUE);
+				    NFT_FORMAT_XML, 0, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = snprintf(buf+offset, len, "</xor>");
@@ -352,14 +352,14 @@ nft_rule_expr_bitwise_snprintf_default(char *buf, size_t size,
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &bitwise->mask,
-				    NFT_RULE_O_DEFAULT, 0, DATA_VALUE);
+				    NFT_FORMAT_DEFAULT, 0, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = snprintf(buf+offset, len, ") ^ ");
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &bitwise->xor,
-				    NFT_RULE_O_DEFAULT, 0, DATA_VALUE);
+				    NFT_FORMAT_DEFAULT, 0, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	return offset;
@@ -372,12 +372,12 @@ nft_rule_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type,
 	struct nft_expr_bitwise *bitwise = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_rule_expr_bitwise_snprintf_default(buf, size,
 							      bitwise);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_expr_bitwise_snprintf_xml(buf, size, bitwise);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_expr_bitwise_snprintf_json(buf, size, bitwise);
 	default:
 		break;
src/expr/byteorder.c +3 -3
index 7012452..95d941d 100644
@@ -351,13 +351,13 @@ nft_rule_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type,
 	struct nft_expr_byteorder *byteorder = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_rule_expr_byteorder_snprintf_default(buf, size,
 								byteorder);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_expr_byteorder_snprintf_xml(buf, size,
 							    byteorder);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_expr_byteorder_snprintf_json(buf, size,
 							    byteorder);
 	default:
src/expr/cmp.c +6 -6
index 7de7226..bc29181 100644
@@ -258,7 +258,7 @@ nft_rule_expr_cmp_snprintf_json(char *buf, size_t size, struct nft_expr_cmp *cmp
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &cmp->data,
-				    NFT_RULE_O_JSON, 0, DATA_VALUE);
+				    NFT_FORMAT_JSON, 0, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = snprintf(buf+offset, len, "}");
@@ -277,7 +277,7 @@ nft_rule_expr_cmp_snprintf_xml(char *buf, size_t size, struct nft_expr_cmp *cmp)
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &cmp->data,
-				    NFT_RULE_O_XML, 0, DATA_VALUE);
+				    NFT_FORMAT_XML, 0, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = snprintf(buf+offset, len, "</cmpdata>");
@@ -297,7 +297,7 @@ nft_rule_expr_cmp_snprintf_default(char *buf, size_t size,
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &cmp->data,
-				    NFT_RULE_O_DEFAULT, 0, DATA_VALUE);
+				    NFT_FORMAT_DEFAULT, 0, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	return offset;
@@ -310,11 +310,11 @@ nft_rule_expr_cmp_snprintf(char *buf, size_t size, uint32_t type,
 	struct nft_expr_cmp *cmp = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_rule_expr_cmp_snprintf_default(buf, size, cmp);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_expr_cmp_snprintf_xml(buf, size, cmp);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_expr_cmp_snprintf_json(buf, size, cmp);
 	default:
 		break;
src/expr/counter.c +3 -3
index 561f26c..b227aa0 100644
@@ -173,13 +173,13 @@ nft_rule_expr_counter_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_counter *ctr = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "pkts %"PRIu64" bytes %"PRIu64" ",
 				ctr->pkts, ctr->bytes);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return snprintf(buf, len, "<pkts>%"PRIu64"</pkts><bytes>%"PRIu64"</bytes>",
 				ctr->pkts, ctr->bytes);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return snprintf(buf, len, "\"pkts\":%"PRIu64",\"bytes\":%"PRIu64"",
 				ctr->pkts, ctr->bytes);
 	default:
src/expr/ct.c +3 -3
index e84d996..0fe8368 100644
@@ -304,15 +304,15 @@ nft_rule_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_ct *ct = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "load %s => reg %u dir %u ",
 				ctkey2str(ct->key), ct->dreg, ct->dir);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return snprintf(buf, len, "<dreg>%u</dreg>"
 					  "<key>%s</key>"
 					  "<dir>%u</dir>",
 				ct->dreg, ctkey2str(ct->key), ct->dir);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_expr_ct_snprintf_json(buf, len, e);
 	default:
 		break;
src/expr/data_reg.c +9 -9
index 193f3ab..51d6daf 100644
@@ -300,13 +300,13 @@ int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg,
 	switch(reg_type) {
 	case DATA_VALUE:
 		switch(output_format) {
-		case NFT_RULE_O_DEFAULT:
+		case NFT_FORMAT_DEFAULT:
 			return nft_data_reg_value_snprintf_default(buf, size,
 								   reg, flags);
-		case NFT_RULE_O_XML:
+		case NFT_FORMAT_XML:
 			return nft_data_reg_value_snprintf_xml(buf, size,
 							       reg, flags);
-		case NFT_RULE_O_JSON:
+		case NFT_FORMAT_JSON:
 			return nft_data_reg_value_snprintf_json(buf, size,
 							       reg, flags);
 		default:
@@ -314,15 +314,15 @@ int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg,
 		}
 	case DATA_VERDICT:
 		switch(output_format) {
-		case NFT_RULE_O_DEFAULT:
+		case NFT_FORMAT_DEFAULT:
 			return snprintf(buf, size, "%d ", reg->verdict);
-		case NFT_RULE_O_XML:
+		case NFT_FORMAT_XML:
 			return snprintf(buf, size,
 					"<data_reg type=\"verdict\">"
 						"<verdict>%s</verdict>"
 					"</data_reg>",
 					nft_verdict2str(reg->verdict));
-		case NFT_RULE_O_JSON:
+		case NFT_FORMAT_JSON:
 			return snprintf(buf, size,
 					"\"data_reg\":{"
 					"\"type\":\"verdict\","
@@ -333,14 +333,14 @@ int nft_data_reg_snprintf(char *buf, size_t size, union nft_data_reg *reg,
 		}
 	case DATA_CHAIN:
 		switch(output_format) {
-		case NFT_RULE_O_DEFAULT:
+		case NFT_FORMAT_DEFAULT:
 			return snprintf(buf, size, "%s ", reg->chain);
-		case NFT_RULE_O_XML:
+		case NFT_FORMAT_XML:
 			return snprintf(buf, size,
 					"<data_reg type=\"chain\">"
 						"<chain>%s</chain>"
 					"</data_reg>", reg->chain);
-		case NFT_RULE_O_JSON:
+		case NFT_FORMAT_JSON:
 			return snprintf(buf, size,
 					"\"data_reg\":{\"type\":\"chain\","
 					"\"chain\":\"%s\""
src/expr/exthdr.c +3 -3
index 32791d0..c297ea5 100644
@@ -289,11 +289,11 @@ nft_rule_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_exthdr *exthdr = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "load %ub @ %u + %u => reg %u ",
 				exthdr->len, exthdr->type,
 				exthdr->offset, exthdr->dreg);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return snprintf(buf, len, "<dreg>%u</dreg>"
 					  "<exthdr_type>%s</exthdr_type>"
 					  "<offset>%u</offset>"
@@ -301,7 +301,7 @@ nft_rule_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
 					exthdr->dreg,
 					exthdr_type2str(exthdr->type),
 					exthdr->offset, exthdr->len);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return snprintf(buf, len, "\"dreg\":%u,"
 					  "\"exthdr_type\":\"%s\",\"offset\":%u,"
 					  "\"len\":%u",
src/expr/immediate.c +12 -12
index cb3b209..3b963da 100644
@@ -268,17 +268,17 @@ nft_rule_expr_immediate_snprintf_json(char *buf, size_t len,
 
 	if (e->flags & (1 << NFT_EXPR_IMM_DATA)) {
 		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
-					    NFT_RULE_O_JSON, flags, DATA_VALUE);
+					    NFT_FORMAT_JSON, flags, DATA_VALUE);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	} else if (e->flags & (1 << NFT_EXPR_IMM_VERDICT)) {
 		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
-					  NFT_RULE_O_JSON, flags, DATA_VERDICT);
+					  NFT_FORMAT_JSON, flags, DATA_VERDICT);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	} else if (e->flags & (1 << NFT_EXPR_IMM_CHAIN)) {
 		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
-					    NFT_RULE_O_JSON, flags, DATA_CHAIN);
+					    NFT_FORMAT_JSON, flags, DATA_CHAIN);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 	}
 
@@ -302,17 +302,17 @@ nft_rule_expr_immediate_snprintf_xml(char *buf, size_t len,
 
 	if (e->flags & (1 << NFT_EXPR_IMM_DATA)) {
 		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
-					    NFT_RULE_O_XML, flags, DATA_VALUE);
+					    NFT_FORMAT_XML, flags, DATA_VALUE);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	} else if (e->flags & (1 << NFT_EXPR_IMM_VERDICT)) {
 		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
-					  NFT_RULE_O_XML, flags, DATA_VERDICT);
+					  NFT_FORMAT_XML, flags, DATA_VERDICT);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	} else if (e->flags & (1 << NFT_EXPR_IMM_CHAIN)) {
 		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
-					    NFT_RULE_O_XML, flags, DATA_CHAIN);
+					    NFT_FORMAT_XML, flags, DATA_CHAIN);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 	}
 
@@ -334,17 +334,17 @@ nft_rule_expr_immediate_snprintf_default(char *buf, size_t len,
 
 	if (e->flags & (1 << NFT_EXPR_IMM_DATA)) {
 		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
-					NFT_RULE_O_DEFAULT, flags, DATA_VALUE);
+					NFT_FORMAT_DEFAULT, flags, DATA_VALUE);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	} else if (e->flags & (1 << NFT_EXPR_IMM_VERDICT)) {
 		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
-				NFT_RULE_O_DEFAULT, flags, DATA_VERDICT);
+				NFT_FORMAT_DEFAULT, flags, DATA_VERDICT);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	} else if (e->flags & (1 << NFT_EXPR_IMM_CHAIN)) {
 		ret = nft_data_reg_snprintf(buf+offset, len, &imm->data,
-					NFT_RULE_O_DEFAULT, flags, DATA_CHAIN);
+					NFT_FORMAT_DEFAULT, flags, DATA_CHAIN);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 	}
 
@@ -356,11 +356,11 @@ nft_rule_expr_immediate_snprintf(char *buf, size_t len, uint32_t type,
 				 uint32_t flags, struct nft_rule_expr *e)
 {
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_rule_expr_immediate_snprintf_default(buf, len, e, flags);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_expr_immediate_snprintf_xml(buf, len, e, flags);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_expr_immediate_snprintf_json(buf, len, e, flags);
 	default:
 		break;
src/expr/limit.c +3 -3
index 4fcf798..cb2ade5 100644
@@ -183,14 +183,14 @@ nft_rule_expr_limit_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_limit *limit = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "rate %"PRIu64"/%s ",
 				limit->rate, get_unit(limit->unit));
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return snprintf(buf, len, "<rate>%"PRIu64"</rate>"
 					  "<unit>%"PRIu64"</unit>",
 				limit->rate, limit->unit);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return snprintf(buf, len, "\"rate\":%"PRIu64","
 					  "\"unit\":%"PRIu64"",
 				limit->rate, limit->unit);
src/expr/log.c +3 -3
index 7722d62..62ee0a2 100644
@@ -243,19 +243,19 @@ nft_rule_expr_log_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_log *log = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "prefix '%s' group %u "
 					  "snaplen %u qthreshold %u ",
 				log->prefix, log->group,
 				log->snaplen, log->qthreshold);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return snprintf(buf, len, "<prefix>%s</prefix>"
 					  "<group>%u</group>"
 					  "<snaplen>%u</snaplen>"
 					  "<qthreshold>%u</qthreshold>",
 				log->prefix, log->group,
 				log->snaplen, log->qthreshold);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return snprintf(buf, len, "\"prefix\":\"%s\","
 					  "\"group\":%u,"
 					  "\"snaplen\":%u,"
src/expr/lookup.c +3 -3
index e37e295..789c61d 100644
@@ -257,11 +257,11 @@ nft_rule_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
 	struct nft_expr_lookup *lookup = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_rule_expr_lookup_snprintf_default(buf, size, lookup);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_expr_lookup_snprintf_xml(buf, size, lookup);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_expr_lookup_snprintf_json(buf, size, lookup);
 	default:
 		break;
src/expr/match.c +3 -3
index c03ab12..6b2fb74 100644
@@ -245,12 +245,12 @@ nft_rule_expr_match_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_match *match = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "name %s rev %u ",
 				match->name, match->rev);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_expr_match_snprintf_xml(buf, len, match);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_expr_match_snprintf_json(buf, len, match);
 	default:
 		break;
src/expr/meta.c +3 -3
index beeb8ca..535642d 100644
@@ -231,14 +231,14 @@ nft_rule_expr_meta_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_meta *meta = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "load %s => reg %u ",
 				meta_key2str(meta->key), meta->dreg);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return snprintf(buf, len, "<dreg>%u</dreg>"
 					  "<key>%s</key>",
 				meta->dreg, meta_key2str(meta->key));
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return snprintf(buf, len, "\"dreg\":%u,"
 					  "\"key\":\"%s\"",
 				meta->dreg, meta_key2str(meta->key));
src/expr/nat.c +3 -3
index 7150eec..e8f6351 100644
@@ -438,11 +438,11 @@ nft_rule_expr_nat_snprintf(char *buf, size_t size, uint32_t type,
 			   uint32_t flags, struct nft_rule_expr *e)
 {
 	switch (type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_rule_expr_nat_snprintf_default(buf, size, e);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_expr_nat_snprintf_xml(buf, size, e);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_expr_nat_snprintf_json(buf, size, e);
 	default:
 		break;
src/expr/payload.c +3 -3
index 390b8ef..12c8781 100644
@@ -302,14 +302,14 @@ nft_rule_expr_payload_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_payload *payload = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "load %ub @ %s header + %u => reg %u ",
 				payload->len, base2str(payload->base),
 				payload->offset, payload->dreg);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_expr_payload_snprintf_xml(buf, len, flags,
 							  payload);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_expr_payload_snprintf_json(buf, len, flags,
 							  payload);
 	default:
src/expr/reject.c +3 -3
index ca008ef..26b0734 100644
@@ -177,14 +177,14 @@ nft_rule_expr_reject_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_reject *reject = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "type %u code %u  ",
 				reject->type, reject->icmp_code);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return snprintf(buf, len, "<type>%u</type>"
 					  "<code>%u</code>",
 				reject->type, reject->icmp_code);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return snprintf(buf, len, "\"type\":%u,"
 					  "\"code\":%u,",
 				reject->type, reject->icmp_code);
src/expr/target.c +3 -3
index 43fb666..40274a7 100644
@@ -247,12 +247,12 @@ nft_rule_expr_target_snprintf(char *buf, size_t len, uint32_t type,
 	struct nft_expr_target *target = nft_expr_data(e);
 
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return snprintf(buf, len, "name %s rev %u ",
 				target->name, target->rev);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_exp_target_snprintf_xml(buf, len, target);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_exp_target_snprintf_json(buf, len, target);
 	default:
 		break;
src/rule.c +6 -6
index 3b45dc7..68e0b2f 100644
@@ -658,16 +658,16 @@ static int nft_rule_xml_parse(struct nft_rule *r, const char *xml)
 #endif
 }
 
-int nft_rule_parse(struct nft_rule *r, enum nft_rule_parse_type type,
+int nft_rule_parse(struct nft_rule *r, enum nft_parse_format_type type,
 		   const char *data)
 {
 	int ret;
 
 	switch (type) {
-	case NFT_RULE_PARSE_XML:
+	case NFT_PARSE_FORMAT_XML:
 		ret = nft_rule_xml_parse(r, data);
 		break;
-	case NFT_RULE_PARSE_JSON:
+	case NFT_PARSE_FORMAT_JSON:
 		ret = nft_rule_json_parse(r, data);
 		break;
 	default:
@@ -806,11 +806,11 @@ int nft_rule_snprintf(char *buf, size_t size, struct nft_rule *r,
 		       uint32_t type, uint32_t flags)
 {
 	switch(type) {
-	case NFT_RULE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_rule_snprintf_default(buf, size, r, type, flags);
-	case NFT_RULE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_rule_snprintf_xml(buf, size, r, type, flags);
-	case NFT_RULE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_rule_snprintf_json(buf, size, r, type, flags);
 	default:
 		break;
src/ruleset.c +12 -12
index ee2c60a..838123a 100644
@@ -557,16 +557,16 @@ err:
 #endif
 }
 
-int nft_ruleset_parse(struct nft_ruleset *r, enum nft_ruleset_parse_type type,
+int nft_ruleset_parse(struct nft_ruleset *r, enum nft_parse_format_type type,
 		      const char *data)
 {
 	int ret;
 
 	switch (type) {
-	case NFT_RULESET_PARSE_XML:
+	case NFT_PARSE_FORMAT_XML:
 		ret = nft_ruleset_xml_parse(r, data);
 		break;
-	case NFT_RULESET_PARSE_JSON:
+	case NFT_PARSE_FORMAT_JSON:
 		ret = nft_ruleset_json_parse(r, data);
 		break;
 	default:
@@ -582,9 +582,9 @@ EXPORT_SYMBOL(nft_ruleset_parse);
 static const char *nft_ruleset_o_opentag(uint32_t type)
 {
 	switch (type) {
-	case NFT_RULESET_O_XML:
+	case NFT_FORMAT_XML:
 		return "<nftables>";
-	case NFT_RULESET_O_JSON:
+	case NFT_FORMAT_JSON:
 		return "{\"nftables\":[";
 	default:
 		return "";
@@ -597,9 +597,9 @@ static const char *nft_ruleset_o_separator(void *obj, uint32_t type)
 		return "";
 
 	switch (type) {
-	case NFT_RULESET_O_JSON:
+	case NFT_FORMAT_JSON:
 		return ",";
-	case NFT_RULESET_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return "\n";
 	default:
 		return "";
@@ -609,9 +609,9 @@ static const char *nft_ruleset_o_separator(void *obj, uint32_t type)
 static const char *nft_ruleset_o_closetag(uint32_t type)
 {
 	switch (type) {
-	case NFT_RULESET_O_XML:
+	case NFT_FORMAT_XML:
 		return "</nftables>";
-	case NFT_RULESET_O_JSON:
+	case NFT_FORMAT_JSON:
 		return "]}";
 	default:
 		return "";
@@ -803,9 +803,9 @@ int nft_ruleset_snprintf(char *buf, size_t size, const struct nft_ruleset *r,
 			 uint32_t type, uint32_t flags)
 {
 	switch (type) {
-	case NFT_RULESET_O_DEFAULT:
-	case NFT_RULESET_O_XML:
-	case NFT_RULESET_O_JSON:
+	case NFT_FORMAT_DEFAULT:
+	case NFT_FORMAT_XML:
+	case NFT_FORMAT_JSON:
 		return nft_ruleset_do_snprintf(buf, size, r, type, flags);
 	default:
 		errno = EOPNOTSUPP;
src/set.c +7 -7
index 9620006..8e1a332 100644
@@ -515,16 +515,16 @@ static int nft_set_xml_parse(struct nft_set *s, const char *xml)
 #endif
 }
 
-int nft_set_parse(struct nft_set *s, enum nft_set_parse_type type,
+int nft_set_parse(struct nft_set *s, enum nft_parse_format_type type,
 		  const char *data)
 {
 	int ret;
 
 	switch (type) {
-	case NFT_SET_PARSE_XML:
+	case NFT_PARSE_FORMAT_XML:
 		ret = nft_set_xml_parse(s, data);
 		break;
-	case NFT_SET_PARSE_JSON:
+	case NFT_PARSE_FORMAT_JSON:
 		ret = nft_set_json_parse(s, data);
 		break;
 	default:
@@ -640,7 +640,7 @@ static int nft_set_snprintf_xml(char *buf, size_t size, struct nft_set *s,
 	if (!list_empty(&s->element_list)) {
 		list_for_each_entry(elem, &s->element_list, head) {
 			ret = nft_set_elem_snprintf(buf+offset, len, elem,
-						    NFT_SET_O_XML, flags);
+						    NFT_FORMAT_XML, flags);
 			SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 		}
 	}
@@ -655,11 +655,11 @@ int nft_set_snprintf(char *buf, size_t size, struct nft_set *s,
 		     uint32_t type, uint32_t flags)
 {
 	switch(type) {
-	case NFT_SET_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_set_snprintf_default(buf, size, s, type, flags);
-	case NFT_SET_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_set_snprintf_xml(buf, size, s, flags);
-	case NFT_SET_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_set_snprintf_json(buf, size, s, type, flags);
 	default:
 		break;
src/set_elem.c +9 -9
index 516905d..3d09bb7 100644
@@ -434,11 +434,11 @@ static int nft_set_elem_xml_parse(struct nft_set_elem *e, const char *xml)
 }
 
 int nft_set_elem_parse(struct nft_set_elem *e,
-		       enum nft_set_parse_type type, const char *data) {
+		       enum nft_parse_format_type type, const char *data) {
 	int ret;
 
 	switch (type) {
-	case NFT_SET_PARSE_XML:
+	case NFT_PARSE_FORMAT_XML:
 		ret = nft_set_elem_xml_parse(e, data);
 		break;
 	default:
@@ -463,7 +463,7 @@ static int nft_set_elem_snprintf_json(char *buf, size_t size,
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &e->key,
-				    NFT_RULE_O_JSON, flags, DATA_VALUE);
+				    NFT_FORMAT_JSON, flags, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = snprintf(buf+offset, len, "}");
@@ -481,7 +481,7 @@ static int nft_set_elem_snprintf_json(char *buf, size_t size,
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 		ret = nft_data_reg_snprintf(buf+offset, len, &e->data,
-				    NFT_RULE_O_JSON, flags, type);
+				    NFT_FORMAT_JSON, flags, type);
 			SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 		ret = snprintf(buf+offset, len, "}");
@@ -529,7 +529,7 @@ static int nft_set_elem_snprintf_xml(char *buf, size_t size,
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = nft_data_reg_snprintf(buf+offset, len, &e->key,
-				    NFT_RULE_O_XML, flags, DATA_VALUE);
+				    NFT_FORMAT_XML, flags, DATA_VALUE);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	ret = snprintf(buf+offset, len, "</key>");
@@ -547,7 +547,7 @@ static int nft_set_elem_snprintf_xml(char *buf, size_t size,
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 		ret = nft_data_reg_snprintf(buf+offset, len, &e->data,
-					    NFT_RULE_O_XML, flags, type);
+					    NFT_FORMAT_XML, flags, type);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 		ret = snprintf(buf+offset, len, "</data>");
@@ -564,11 +564,11 @@ int nft_set_elem_snprintf(char *buf, size_t size, struct nft_set_elem *e,
 			   uint32_t type, uint32_t flags)
 {
 	switch(type) {
-	case NFT_SET_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_set_elem_snprintf_default(buf, size, e);
-	case NFT_SET_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_set_elem_snprintf_xml(buf, size, e, flags);
-	case NFT_SET_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_set_elem_snprintf_json(buf, size, e, flags);
 	default:
 		break;
src/table.c +6 -6
index d1acc7c..ec188ed 100644
@@ -324,16 +324,16 @@ static int nft_table_json_parse(struct nft_table *t, const char *json)
 #endif
 }
 
-int nft_table_parse(struct nft_table *t, enum nft_table_parse_type type,
+int nft_table_parse(struct nft_table *t, enum nft_parse_format_type type,
 		    const char *data)
 {
 	int ret;
 
 	switch (type) {
-	case NFT_TABLE_PARSE_XML:
+	case NFT_PARSE_FORMAT_XML:
 		ret = nft_table_xml_parse(t, data);
 		break;
-	case NFT_TABLE_PARSE_JSON:
+	case NFT_PARSE_FORMAT_JSON:
 		ret = nft_table_json_parse(t, data);
 		break;
 	default:
@@ -375,11 +375,11 @@ int nft_table_snprintf(char *buf, size_t size, struct nft_table *t,
 		       uint32_t type, uint32_t flags)
 {
 	switch(type) {
-	case NFT_TABLE_O_DEFAULT:
+	case NFT_FORMAT_DEFAULT:
 		return nft_table_snprintf_default(buf, size, t);
-	case NFT_TABLE_O_XML:
+	case NFT_FORMAT_XML:
 		return nft_table_snprintf_xml(buf, size, t);
-	case NFT_TABLE_O_JSON:
+	case NFT_FORMAT_JSON:
 		return nft_table_snprintf_json(buf, size, t);
 	default:
 		break;
tests/nft-parsing-test.c +20 -20
index 9fa69ae..0a15dd6 100644
@@ -112,36 +112,36 @@ static int compare_test(uint32_t type, void *input, const char *filename)
 
 	switch (type) {
 	case TEST_XML_TABLE:
-		nft_table_snprintf(out, sizeof(out), t, NFT_TABLE_O_XML, 0);
+		nft_table_snprintf(out, sizeof(out), t, NFT_FORMAT_XML, 0);
 		break;
 	case TEST_JSON_TABLE:
-		nft_table_snprintf(out, sizeof(out), t, NFT_TABLE_O_JSON, 0);
+		nft_table_snprintf(out, sizeof(out), t, NFT_FORMAT_JSON, 0);
 		break;
 	case TEST_XML_CHAIN:
-		nft_chain_snprintf(out, sizeof(out), c, NFT_CHAIN_O_XML, 0);
+		nft_chain_snprintf(out, sizeof(out), c, NFT_FORMAT_XML, 0);
 		break;
 	case TEST_JSON_CHAIN:
-		nft_chain_snprintf(out, sizeof(out), c, NFT_CHAIN_O_JSON, 0);
+		nft_chain_snprintf(out, sizeof(out), c, NFT_FORMAT_JSON, 0);
 		break;
 	case TEST_XML_RULE:
-		nft_rule_snprintf(out, sizeof(out), r, NFT_RULE_O_XML, 0);
+		nft_rule_snprintf(out, sizeof(out), r, NFT_FORMAT_XML, 0);
 		break;
 	case TEST_JSON_RULE:
-		nft_rule_snprintf(out, sizeof(out), r, NFT_RULE_O_JSON, 0);
+		nft_rule_snprintf(out, sizeof(out), r, NFT_FORMAT_JSON, 0);
 		break;
 	case TEST_XML_SET:
-		nft_set_snprintf(out, sizeof(out), s, NFT_SET_O_XML, 0);
+		nft_set_snprintf(out, sizeof(out), s, NFT_FORMAT_XML, 0);
 		break;
 	case TEST_JSON_SET:
-		nft_set_snprintf(out, sizeof(out), s, NFT_SET_O_JSON, 0);
+		nft_set_snprintf(out, sizeof(out), s, NFT_FORMAT_JSON, 0);
 		break;
 	case TEST_XML_RULESET:
 		nft_ruleset_snprintf(out, sizeof(out), rs,
-				     NFT_RULESET_O_XML, 0);
+				     NFT_FORMAT_XML, 0);
 		break;
 	case TEST_JSON_RULESET:
 		nft_ruleset_snprintf(out, sizeof(out), rs,
-				     NFT_RULESET_O_JSON, 0);
+				     NFT_FORMAT_JSON, 0);
 		break;
 	default:
 		errno = EINVAL;
@@ -191,7 +191,7 @@ static int test_json(const char *filename)
 	if (json_object_get(root, "table") != NULL) {
 		t = nft_table_alloc();
 		if (t != NULL) {
-			if (nft_table_parse(t, NFT_TABLE_PARSE_JSON, json) == 0)
+			if (nft_table_parse(t, NFT_PARSE_FORMAT_JSON, json) == 0)
 				ret = compare_test(TEST_JSON_TABLE, t, filename);
 			else
 				goto failparsing;
@@ -201,7 +201,7 @@ static int test_json(const char *filename)
 	} 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)
+			if (nft_chain_parse(c, NFT_PARSE_FORMAT_JSON, json) == 0)
 				ret = compare_test(TEST_JSON_CHAIN, c, filename);
 			else
 				goto failparsing;
@@ -211,7 +211,7 @@ static int test_json(const char *filename)
 	} else if (json_object_get(root, "rule") != NULL) {
 		r = nft_rule_alloc();
 		if (r != NULL) {
-			if (nft_rule_parse(r, NFT_RULE_PARSE_JSON, json) == 0)
+			if (nft_rule_parse(r, NFT_PARSE_FORMAT_JSON, json) == 0)
 				ret = compare_test(TEST_JSON_RULE, r, filename);
 			else
 				goto failparsing;
@@ -221,7 +221,7 @@ static int test_json(const char *filename)
 	} else if (json_object_get(root, "set") != NULL) {
 		s = nft_set_alloc();
 		if (s != NULL) {
-			if (nft_set_parse(s, NFT_SET_PARSE_JSON, json) == 0)
+			if (nft_set_parse(s, NFT_PARSE_FORMAT_JSON, json) == 0)
 				ret = compare_test(TEST_JSON_SET, s, filename);
 			else
 				goto failparsing;
@@ -231,7 +231,7 @@ static int test_json(const char *filename)
 	} else if (json_object_get(root, "nftables") != NULL) {
 		rs = nft_ruleset_alloc();
 		if (rs != NULL) {
-			if (nft_ruleset_parse(rs, NFT_RULESET_PARSE_JSON, json) == 0)
+			if (nft_ruleset_parse(rs, NFT_PARSE_FORMAT_JSON, json) == 0)
 				ret = compare_test(TEST_JSON_RULESET, rs, filename);
 			else
 				goto failparsing;
@@ -290,7 +290,7 @@ static int test_xml(const char *filename)
 	if (strcmp(tree->value.opaque, "table") == 0) {
 		t = nft_table_alloc();
 		if (t != NULL) {
-			if (nft_table_parse(t, NFT_TABLE_PARSE_XML, xml) == 0)
+			if (nft_table_parse(t, NFT_PARSE_FORMAT_XML, xml) == 0)
 				ret = compare_test(TEST_XML_TABLE, t, filename);
 			else
 				goto failparsing;
@@ -300,7 +300,7 @@ static int test_xml(const char *filename)
 	} else if (strcmp(tree->value.opaque, "chain") == 0) {
 		c = nft_chain_alloc();
 		if (c != NULL) {
-			if (nft_chain_parse(c, NFT_CHAIN_PARSE_XML, xml) == 0)
+			if (nft_chain_parse(c, NFT_PARSE_FORMAT_XML, xml) == 0)
 				ret = compare_test(TEST_XML_CHAIN, c, filename);
 			else
 				goto failparsing;
@@ -310,7 +310,7 @@ static int test_xml(const char *filename)
 	} else if (strcmp(tree->value.opaque, "rule") == 0) {
 		r = nft_rule_alloc();
 		if (r != NULL) {
-			if (nft_rule_parse(r, NFT_RULE_PARSE_XML, xml) == 0)
+			if (nft_rule_parse(r, NFT_PARSE_FORMAT_XML, xml) == 0)
 				ret = compare_test(TEST_XML_RULE, r, filename);
 			else
 				goto failparsing;
@@ -320,7 +320,7 @@ static int test_xml(const char *filename)
 	} else if (strcmp(tree->value.opaque, "set") == 0) {
 		s = nft_set_alloc();
 		if (s != NULL) {
-			if (nft_set_parse(s, NFT_SET_PARSE_XML, xml) == 0)
+			if (nft_set_parse(s, NFT_PARSE_FORMAT_XML, xml) == 0)
 				ret = compare_test(TEST_XML_SET, s, filename);
 			else
 				goto failparsing;
@@ -330,7 +330,7 @@ static int test_xml(const char *filename)
 	} else if (strcmp(tree->value.opaque, "nftables") == 0) {
 		rs = nft_ruleset_alloc();
 		if (rs != NULL) {
-			if (nft_ruleset_parse(rs, NFT_RULESET_PARSE_XML,
+			if (nft_ruleset_parse(rs, NFT_PARSE_FORMAT_XML,
 					      xml) == 0)
 				ret = compare_test(TEST_XML_RULESET, rs,
 						   filename);

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

#2 lore raw

Re: [libnftables PATCH 2/2] json: Refactor of exporting and parsing support flags

Quoted 16 lines · Alvaro Neira

From: Álvaro Neira Ayuso <[email protected]>

Remove the different flag definition for using the snprinf and parsing support and create a new flags for joining in general flags.

Now for printing or parsing tables or chains, we needed to use:
NFT_TABLE_O_JSON
NFT_TABLE_O_XML
NFT_CHAIN_O_JSON
NFT_CHAIN_O_XML
NFT_CHAIN_PARSE_JSON
NFT_TABLE_PARSE_JSON
NFT_CHAIN_PARSE_XML
NFT_TABLE_PARSE_XML

Quoted 5 lines

Now for exporting and parsing rules and chains, we only use:
NFT_FORMAT_JSON
NFT_FORMAT_XML
NFT_PARSE_FORMAT_JSON
NFT_PARSE_FORMAT_XML

These names are too long. I mangled your patch to use:

NFT_OUTPUT_[XML|JSON]
NFT_PARSE_[XML|JSON]

instead.

I have also reworked the patch descriptions, it says "json: " but this is not only related to it. Fixed and applied, thanks for working on this. --
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Alvaro Neira
Quoted 6 lines · Alvaro Neira

From: Álvaro Neira Ayuso <[email protected]>

This patch fix the unconsistence of this file with the commit 2cba09966c77e946f6f32e860a368a0c5a9830a0

rule: remove NFT_RULE_ATTR_FLAGS

Prefered format to refer to patches is (2cba09 rule: remove NFT_RULE_ATTR_FLAGS).

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html