summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArturo Borrero <arturo.borrero.glez@gmail.com>2013-08-23 13:35:35 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-08-24 17:53:06 +0200
commit7e3c0b62f9fc3dab35b13b021618a0fcf2f25ca4 (patch)
tree9f15ca3b50910d92c1cbf6b92a68ecee28500f35
parentc15e8e5d2a1bbcb56d571b5f97ef30d1b8839d70 (diff)
rule: xml/json: support rule position attribute
Note that the position attr is optional as stated in net/netfilter/nf_tables_api.c Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/rule.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/rule.c b/src/rule.c
index 98c2022..aca88d0 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -538,6 +538,14 @@ static int nft_rule_json_parse(struct nft_rule *r, const char *json)
nft_rule_attr_set_u32(r, NFT_RULE_ATTR_COMPAT_FLAGS, uval32);
}
+ if (nft_jansson_node_exist(root, "position")) {
+ if (nft_jansson_value_parse_val(root, "position",
+ NFT_TYPE_U64, &uval64) == -1)
+ goto err;
+
+ nft_rule_attr_set_u64(r, NFT_RULE_ATTR_POSITION, uval64);
+ }
+
array = json_object_get(root, "expr");
if (array == NULL)
goto err;
@@ -636,6 +644,16 @@ static int nft_rule_xml_parse(struct nft_rule *r, const char *xml)
r->flags |= (1 << NFT_RULE_ATTR_COMPAT_FLAGS);
}
+ node = mxmlFindElement(tree, tree, "position", NULL, NULL,
+ MXML_DESCEND_FIRST);
+ if (node != NULL && node->child != NULL) {
+ if (nft_strtoi(node->child->value.opaque, BASE_DEC,
+ &r->position, NFT_TYPE_U64) != 0)
+ goto err;
+
+ r->flags |= (1 << NFT_RULE_ATTR_POSITION);
+ }
+
/* Iterating over <expr> */
for (node = mxmlFindElement(tree, tree, "expr", "type",
NULL, MXML_DESCEND);
@@ -714,6 +732,13 @@ static int nft_rule_snprintf_json(char *buf, size_t size, struct nft_rule *r,
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
+ if (r->flags & (1 << NFT_RULE_ATTR_POSITION)) {
+ ret = snprintf(buf+offset, len,
+ "\"position\" : %"PRIu64", ",
+ r->position);
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+ }
+
ret = snprintf(buf+offset, len, "\"expr\" : [");
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
@@ -756,6 +781,13 @@ static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r,
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
+ if (r->flags & (1 << NFT_RULE_ATTR_POSITION)) {
+ ret = snprintf(buf+offset, len,
+ "<position>%"PRIu64"</position>",
+ r->position);
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+ }
+
list_for_each_entry(expr, &r->expr_list, head) {
ret = snprintf(buf+offset, len,
"<expr type=\"%s\">", expr->ops->name);