summaryrefslogtreecommitdiffstats
path: root/src/expr/lookup.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2013-07-04 16:10:24 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-07-04 16:47:58 +0200
commit556fb7ee694a0f18cbd3d73ac96b27c74081bd6d (patch)
treea5148ca080d15ea122473186baacc3fd5bd2138c /src/expr/lookup.c
parentd844fa06e43bc80487acfe5647cef4d4994c95fd (diff)
src: consolidate XML parsing of expressions via nft_mxml_reg_parse
This patch reduces the XML code in 100 LOC.
Diffstat (limited to 'src/expr/lookup.c')
-rw-r--r--src/expr/lookup.c37
1 files changed, 9 insertions, 28 deletions
diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index ca10cab..e083372 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -158,8 +158,7 @@ nft_rule_expr_lookup_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
#ifdef XML_PARSING
struct nft_expr_lookup *lookup = (struct nft_expr_lookup *)e->data;
mxml_node_t *node = NULL;
- uint64_t tmp;
- char *endptr;
+ int32_t reg;
/* get and set <set>. Is mandatory */
node = mxmlFindElement(tree, tree, "set", NULL, NULL,
@@ -171,38 +170,20 @@ nft_rule_expr_lookup_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
lookup->set_name[IFNAMSIZ-1] = '\0';
e->flags |= (1 << NFT_EXPR_LOOKUP_SET);
- /* get and set <sreg>. Is mandatory */
- node = mxmlFindElement(tree, tree, "sreg", NULL, NULL,
- MXML_DESCEND);
- if (node == NULL)
+ reg = nft_mxml_reg_parse(tree, "sreg", MXML_DESCEND);
+ if (reg < 0)
return -1;
- errno = 0;
-
- tmp = strtoull(node->child->value.opaque, &endptr, 10);
- if (tmp > UINT32_MAX || tmp < 0 || *endptr)
- return -1;
-
- if (tmp > NFT_REG_MAX)
- return -1;
-
- lookup->sreg = (uint32_t)tmp;
+ lookup->sreg = reg;
e->flags |= (1 << NFT_EXPR_LOOKUP_SREG);
- /* get and set <dreg>. Isn't mandatory */
- node = mxmlFindElement(tree, tree, "dreg", NULL, NULL,
- MXML_DESCEND);
- if (node != NULL) {
- tmp = strtoull(node->child->value.opaque, &endptr, 10);
- if (tmp > UINT32_MAX || tmp < 0 || *endptr)
- return -1;
+ reg = nft_mxml_reg_parse(tree, "dreg", MXML_DESCEND);
+ if (reg < 0)
+ return -1;
- if (tmp > NFT_REG_MAX)
- return -1;
+ lookup->dreg = reg;
+ e->flags |= (1 << NFT_EXPR_LOOKUP_DREG);
- lookup->dreg = (uint32_t)tmp;
- e->flags |= (1 << NFT_EXPR_LOOKUP_DREG);
- }
return 0;
#else
errno = EOPNOTSUPP;