]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
chain: Use nft_str2hooknum() in the XML parsing code.
authorArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Mon, 5 Aug 2013 12:01:39 +0000 (14:01 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 5 Aug 2013 12:43:21 +0000 (14:43 +0200)
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>
src/chain.c

index 4f07bf8e2dd22aca1ecb4c7311a22cc9ee9d4ab5..69ea68f48c916774406cd1e90751c21361d9ee71 100644 (file)
@@ -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) {