diff options
author | Arturo Borrero <arturo.borrero.glez@gmail.com> | 2013-06-27 18:56:38 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-06-27 19:36:24 +0200 |
commit | 8e7acbfae3017cd5f30e3b17ca16354f76b81b8a (patch) | |
tree | 88164946f76b50c96ad9a08308988e434af429de /src/expr | |
parent | 04604b0373d907fefde0c3e13af68868f03e5d58 (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/expr')
-rw-r--r-- | src/expr/nat.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/expr/nat.c b/src/expr/nat.c index 7c4cf37..2061618 100644 --- a/src/expr/nat.c +++ b/src/expr/nat.c @@ -213,6 +213,7 @@ static int nft_rule_expr_nat_xml_parse(struct nft_rule_expr *e, char *xml) mxml_node_t *node = NULL; uint64_t tmp; char *endptr; + int family; tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK); if (tree == NULL) @@ -254,15 +255,13 @@ static int nft_rule_expr_nat_xml_parse(struct nft_rule_expr *e, char *xml) return -1; } - if (strcmp(node->child->value.opaque, "AF_INET") == 0) { - nat->family = AF_INET; - } else if (strcmp(node->child->value.opaque, "AF_INET6") == 0) { - nat->family = AF_INET6; - } else { + family = nft_str2family(node->child->value.opaque); + if (family < 0) { mxmlDelete(tree); return -1; } + nat->family = family; e->flags |= (1 << NFT_EXPR_NAT_FAMILY); /* Get and set <sreg_addr_min_v4>. Not mandatory */ @@ -349,7 +348,7 @@ nft_rule_expr_nat_snprintf_xml(char *buf, size_t size, } ret = snprintf(buf+offset, len, "<family>%s</family>", - nat->family == AF_INET ? "AF_INET" : "AF_INET6"); + nft_family2str(nat->family)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); if (e->flags & (1 << NFT_EXPR_NAT_REG_ADDR_MIN)) { @@ -389,8 +388,7 @@ nft_rule_expr_nat_snprintf_default(char *buf, size_t size, break; } - ret = snprintf(buf, len, "family=%s ", - nat->family == AF_INET ? "AF_INET" : "AF_INET6"); + ret = snprintf(buf, len, "family=%s ", nft_family2str(nat->family)); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); if (e->flags & (1 << NFT_EXPR_NAT_REG_ADDR_MIN)) { |