summaryrefslogtreecommitdiffstats
path: root/src/rule.c
diff options
context:
space:
mode:
authorArturo Borrero <arturo.borrero.glez@gmail.com>2013-06-27 18:56:38 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-06-27 19:36:24 +0200
commit8e7acbfae3017cd5f30e3b17ca16354f76b81b8a (patch)
tree88164946f76b50c96ad9a08308988e434af429de /src/rule.c
parent04604b0373d907fefde0c3e13af68868f03e5d58 (diff)
src: xml: convert family values to string
This patch translates family values to display a string: * ip if AF_INET * ip6 if AF_INET6 * bridge if AF_BRIDGE * arp if 0 Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/rule.c')
-rw-r--r--src/rule.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/rule.c b/src/rule.c
index 00f1026..e792169 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -486,6 +486,7 @@ static int nft_rule_xml_parse(struct nft_rule *r, char *xml)
struct expr_ops *ops;
char *endptr = NULL;
uint64_t tmp;
+ int family;
/* Load the tree */
tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK);
@@ -509,13 +510,13 @@ static int nft_rule_xml_parse(struct nft_rule *r, char *xml)
return -1;
}
- tmp = strtoull(mxmlElementGetAttr(tree, "family"), &endptr, 10);
- if (tmp > UINT8_MAX || tmp < 0 || *endptr) {
+ family = nft_str2family(mxmlElementGetAttr(tree, "family"));
+ if (family < 0) {
mxmlDelete(tree);
return -1;
}
- r->family = (uint8_t)tmp;
+ r->family = family;
r->flags |= (1 << NFT_RULE_ATTR_FAMILY);
/* get and set <rule ... table=X ...> */
@@ -674,9 +675,9 @@ static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r,
struct nft_rule_expr *expr;
ret = snprintf(buf, size,
- "<rule family=\"%u\" table=\"%s\" "
+ "<rule family=\"%s\" table=\"%s\" "
"chain=\"%s\" handle=\"%llu\" version=\"%d\">",
- r->family, r->table, r->chain,
+ nft_family2str(r->family), r->table, r->chain,
(unsigned long long)r->handle,
NFT_RULE_XML_VERSION);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
@@ -717,9 +718,9 @@ static int nft_rule_snprintf_default(char *buf, size_t size, struct nft_rule *r,
struct nft_rule_expr *expr;
int ret, len = size, offset = 0;
- ret = snprintf(buf, size, "family=%u table=%s chain=%s handle=%llu "
+ ret = snprintf(buf, size, "family=%s table=%s chain=%s handle=%llu "
"flags=%x ",
- r->family, r->table, r->chain,
+ nft_family2str(r->family), r->table, r->chain,
(unsigned long long)r->handle, r->rule_flags);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);