summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2013-07-25 20:34:24 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-07-25 20:34:49 +0200
commit69efde1a7f4a9640506005bd4d51b3461d3c7d53 (patch)
tree76d81861d79c4cdea78136f8ba74108363d8926a
parente13819c5f5b6138c4c7e01156d0fd9f58b11702d (diff)
expr: counter: use nft_mxml_num_parse
Put this code on a diet by using the new helper function nft_mxml_num_parse. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--src/expr/counter.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/src/expr/counter.c b/src/expr/counter.c
index 8b2542d..75ad469 100644
--- a/src/expr/counter.c
+++ b/src/expr/counter.c
@@ -123,33 +123,18 @@ nft_rule_expr_counter_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
struct nft_expr_counter *ctr = nft_expr_data(e);
- mxml_node_t *node = NULL;
- char *endptr;
- uint64_t tmp;
-
- /* get and set <pkts>. Is not mandatory*/
- node = mxmlFindElement(tree, tree, "pkts", NULL, NULL,
- MXML_DESCEND_FIRST);
- if (node != NULL) {
- tmp = strtoull(node->child->value.opaque, &endptr, 10);
- if (tmp == UINT64_MAX || tmp < 0 || *endptr )
- return -1;
-
- ctr->pkts = tmp;
- e->flags |= (1 << NFT_EXPR_CTR_PACKETS);
- }
- /* get and set <bytes> */
- node = mxmlFindElement(tree, tree, "bytes", NULL, NULL,
- MXML_DESCEND);
- if (node != NULL) {
- tmp = strtoull(node->child->value.opaque, &endptr, 10);
- if (tmp == UINT64_MAX || tmp < 0 || *endptr)
- return -1;
+ if (nft_mxml_num_parse(tree, "pkts", MXML_DESCEND_FIRST, BASE_DEC,
+ &ctr->pkts, NFT_TYPE_U64) != 0)
+ return -1;
- ctr->bytes = tmp;
- e->flags |= (1 << NFT_EXPR_CTR_BYTES);
- }
+ e->flags |= (1 << NFT_EXPR_CTR_PACKETS);
+
+ if (nft_mxml_num_parse(tree, "bytes", MXML_DESCEND_FIRST, BASE_DEC,
+ &ctr->bytes, NFT_TYPE_U64) != 0)
+ return -1;
+
+ e->flags |= (1 << NFT_EXPR_CTR_BYTES);
return 0;
#else