* [libnftables PATCH] rule: complete print/parse position attr
@ 2013-08-23 11:35 Arturo Borrero Gonzalez
0 siblings, 0 replies; only message in thread
From: Arturo Borrero Gonzalez @ 2013-08-23 11:35 UTC (permalink / raw)
To: netfilter-devel
Do printf/parse of position attr in both XML and JSON.
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>
---
0 files changed
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);
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-08-23 11:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-23 11:35 [libnftables PATCH] rule: complete print/parse position attr Arturo Borrero Gonzalez
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).