From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: kaber@trash.net, fw@strlen.de
Subject: [PATCH nft 4/7] evaluate: transfer right shifts to constant side
Date: Sat, 5 Dec 2015 20:04:23 +0100 [thread overview]
Message-ID: <1449342266-2756-4-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1449342266-2756-1-git-send-email-pablo@netfilter.org>
From: Patrick McHardy <kaber@trash.net>
This provides a generic way to transfer shifts from the left hand side
to the right hand constant side of a relational expression when
performing transformations from the evaluation step.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/evaluate.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index 7aab6aa..d62870a 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -646,6 +646,7 @@ static int constant_binop_simplify(struct eval_ctx *ctx, struct expr **expr)
break;
case OP_LSHIFT:
assert(left->byteorder == BYTEORDER_HOST_ENDIAN);
+ mpz_set(val, left->value);
mpz_lshift_ui(val, mpz_get_uint32(right->value));
mpz_and(val, val, mask);
break;
@@ -1021,6 +1022,8 @@ static int binop_can_transfer(struct eval_ctx *ctx,
return expr_binary_error(ctx->msgs, right, left,
"Comparison is always false");
return 1;
+ case OP_RSHIFT:
+ return 1;
case OP_XOR:
return 1;
default:
@@ -1038,6 +1041,10 @@ static int binop_transfer_one(struct eval_ctx *ctx,
(*right) = binop_expr_alloc(&(*right)->location, OP_RSHIFT,
*right, expr_get(left->right));
break;
+ case OP_RSHIFT:
+ (*right) = binop_expr_alloc(&(*right)->location, OP_LSHIFT,
+ *right, expr_get(left->right));
+ break;
case OP_XOR:
(*right) = binop_expr_alloc(&(*right)->location, OP_XOR,
*right, expr_get(left->right));
@@ -1052,6 +1059,7 @@ static int binop_transfer_one(struct eval_ctx *ctx,
static int binop_transfer(struct eval_ctx *ctx, struct expr **expr)
{
struct expr *left = (*expr)->left, *i, *next;
+ unsigned int shift;
int err;
if (left->ops->type != EXPR_BINOP)
@@ -1083,10 +1091,24 @@ static int binop_transfer(struct eval_ctx *ctx, struct expr **expr)
return 0;
}
- left = expr_get((*expr)->left->left);
- left->dtype = (*expr)->left->dtype;
- expr_free((*expr)->left);
- (*expr)->left = left;
+ switch (left->op) {
+ case OP_RSHIFT:
+ /* Mask out the bits the shift would have masked out */
+ shift = mpz_get_uint8(left->right->value);
+ mpz_bitmask(left->right->value, left->left->len);
+ mpz_lshift_ui(left->right->value, shift);
+ left->op = OP_AND;
+ break;
+ case OP_LSHIFT:
+ case OP_XOR:
+ left = expr_get((*expr)->left->left);
+ left->dtype = (*expr)->left->dtype;
+ expr_free((*expr)->left);
+ (*expr)->left = left;
+ break;
+ default:
+ BUG("invalid binop operation %u", left->op);
+ }
return 0;
}
--
2.1.4
next prev parent reply other threads:[~2015-12-05 19:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-05 19:04 [PATCH nft 1/7,v2] tests: vlan pcp and cfi are located in the first byte Pablo Neira Ayuso
2015-12-05 19:04 ` [PATCH nft 2/7,v2] src: fix sub-byte protocol header definitions Pablo Neira Ayuso
2015-12-14 17:38 ` Pablo Neira Ayuso
2015-12-05 19:04 ` [PATCH nft 3/7] netlink_delinearize: postprocess expression before range merge Pablo Neira Ayuso
2015-12-05 19:04 ` Pablo Neira Ayuso [this message]
2015-12-05 19:04 ` [PATCH nft 5/7] evaluate: transfer right shifts to range side Pablo Neira Ayuso
2015-12-05 19:04 ` [PATCH nft 6/7] evaluate: transfer right shifts to set reference side Pablo Neira Ayuso
2015-12-05 19:04 ` [PATCH nft 7/7] src: move payload sub-byte matching to the evaluation step 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=1449342266-2756-4-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=kaber@trash.net \
--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).