diff options
author | Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> | 2013-08-05 14:01:39 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-08-05 14:43:21 +0200 |
commit | 19925e0fbc1d709212ed82fe4e43fe6ef1ec3539 (patch) | |
tree | 7fde73686ad46c0ca68ad642a27bfdcc0e49fae5 | |
parent | fa8911fb884537221b0993dff88df6013e5654e0 (diff) |
chain: Use nft_str2hooknum() in the XML parsing code.
Note: I've used MXML_DESCEND_FIRST flag when calling nft_mxml_str_parse()
to ensure that the parsing travels from the top of the chain XML tree.
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
-rw-r--r-- | src/chain.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/chain.c b/src/chain.c index 4f07bf8..69ea68f 100644 --- a/src/chain.c +++ b/src/chain.c @@ -589,7 +589,8 @@ static int nft_chain_xml_parse(struct nft_chain *c, char *xml) mxml_node_t *node = NULL; char *endptr = NULL; uint64_t utmp; - int family; + const char *hooknum_str; + int family, hooknum; /* NOTE: all XML nodes are mandatory */ @@ -686,29 +687,24 @@ static int nft_chain_xml_parse(struct nft_chain *c, char *xml) /* Ignore <use> (cannot be set)*/ node = mxmlFindElement(tree, tree, "use", NULL, NULL, MXML_DESCEND); - /* Get and set <hooknum> */ - node = mxmlFindElement(tree, tree, "hooknum", NULL, NULL, - MXML_DESCEND); - if (node == NULL) { + + hooknum_str = nft_mxml_str_parse(tree, "hooknum", MXML_DESCEND_FIRST); + if (hooknum_str == NULL) { mxmlDelete(tree); return -1; } - /* iterate the list of hooks until a match is found */ - for (utmp = 0; utmp < NF_INET_NUMHOOKS; utmp++) { - if (strcmp(node->child->value.opaque, hooknum2str_array[utmp]) == 0) { - c->hooknum = utmp; - c->flags |= (1 << NFT_CHAIN_ATTR_HOOKNUM); - break; - } - } + hooknum = nft_str2hooknum(hooknum_str); + free((char *)hooknum_str); - /* if no hook was found, error */ - if (!(c->flags & (1 << NFT_CHAIN_ATTR_HOOKNUM))) { + if (hooknum < 0) { mxmlDelete(tree); return -1; } + c->hooknum = hooknum; + c->flags |= (1 << NFT_CHAIN_ATTR_HOOKNUM); + /* Get and set <policy> */ node = mxmlFindElement(tree, tree, "policy", NULL, NULL, MXML_DESCEND); if (node == NULL) { |