From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft 5/8] evaluate: add expr_evaluate_integer()
Date: Mon, 29 Aug 2016 20:21:16 +0200 [thread overview]
Message-ID: <1472494879-16442-5-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1472494879-16442-1-git-send-email-pablo@netfilter.org>
Add a helper function to wrap the integer evaluation code.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/evaluate.c | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index 8f7824b..39573e9 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -263,27 +263,35 @@ static int expr_evaluate_string(struct eval_ctx *ctx, struct expr **exprp)
return 0;
}
-static int expr_evaluate_value(struct eval_ctx *ctx, struct expr **expr)
+static int expr_evaluate_integer(struct eval_ctx *ctx, struct expr **exprp)
{
+ struct expr *expr = *exprp;
mpz_t mask;
+ mpz_init_bitmask(mask, ctx->ectx.len);
+ if (mpz_cmp(expr->value, mask) > 0) {
+ char *valstr = mpz_get_str(NULL, 10, expr->value);
+ char *rangestr = mpz_get_str(NULL, 10, mask);
+ expr_error(ctx->msgs, expr,
+ "Value %s exceeds valid range 0-%s",
+ valstr, rangestr);
+ free(valstr);
+ free(rangestr);
+ mpz_clear(mask);
+ return -1;
+ }
+ expr->byteorder = ctx->ectx.byteorder;
+ expr->len = ctx->ectx.len;
+ mpz_clear(mask);
+ return 0;
+}
+
+static int expr_evaluate_value(struct eval_ctx *ctx, struct expr **expr)
+{
switch (expr_basetype(*expr)->type) {
case TYPE_INTEGER:
- mpz_init_bitmask(mask, ctx->ectx.len);
- if (mpz_cmp((*expr)->value, mask) > 0) {
- char *valstr = mpz_get_str(NULL, 10, (*expr)->value);
- char *rangestr = mpz_get_str(NULL, 10, mask);
- expr_error(ctx->msgs, *expr,
- "Value %s exceeds valid range 0-%s",
- valstr, rangestr);
- free(valstr);
- free(rangestr);
- mpz_clear(mask);
+ if (expr_evaluate_integer(ctx, expr) < 0)
return -1;
- }
- (*expr)->byteorder = ctx->ectx.byteorder;
- (*expr)->len = ctx->ectx.len;
- mpz_clear(mask);
break;
case TYPE_STRING:
if (expr_evaluate_string(ctx, expr) < 0)
--
2.1.4
next prev parent reply other threads:[~2016-08-29 18:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-29 18:21 [PATCH nft 1/8] tests: py: adapt this to new add element command semantics Pablo Neira Ayuso
2016-08-29 18:21 ` [PATCH nft 2/8] src: add quota statement Pablo Neira Ayuso
2016-08-29 18:21 ` [PATCH nft 3/8] src: add numgen expression Pablo Neira Ayuso
2016-08-29 18:21 ` [PATCH nft 4/8] src: add hash expression Pablo Neira Ayuso
2016-08-29 18:21 ` Pablo Neira Ayuso [this message]
2016-08-29 18:21 ` [PATCH nft 6/8] evaluate: validate maximum hash and numgen value Pablo Neira Ayuso
2016-08-29 18:21 ` [PATCH nft 7/8] parser_bison: add variable_expr rule Pablo Neira Ayuso
2016-08-29 18:21 ` [PATCH nft 8/8] parser_bison: allow variable references in set elements definition Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1472494879-16442-5-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).