summaryrefslogtreecommitdiffstats
path: root/src/evaluate.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2016-08-01 17:11:41 +0200
committerFlorian Westphal <fw@strlen.de>2016-08-01 17:11:41 +0200
commitfc2f5c4418283dbfc2e008bc4268e9d3b6f313ba (patch)
tree66663bbba5738bddd900bd81b2b3e24af79c9300 /src/evaluate.c
parentca6fd0a94fc2d2c6d662b76c22ffaa4f3ffc7a1f (diff)
evaluate: add small helper to check if payload expr needs binop adjustment
kernel can only deal with byte-sized and byte-aligned payload expressions. If the payload expression doesn't fit this requirement userspace has to add explicit binop masks to remove the unwanted part(s). Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src/evaluate.c')
-rw-r--r--src/evaluate.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/evaluate.c b/src/evaluate.c
index 8116735d..7962e9e4 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -575,6 +575,12 @@ static int __expr_evaluate_payload(struct eval_ctx *ctx, struct expr *expr)
return 0;
}
+static bool payload_needs_adjustment(const struct expr *expr)
+{
+ return expr->payload.offset % BITS_PER_BYTE != 0 ||
+ expr->len % BITS_PER_BYTE != 0;
+}
+
static int expr_evaluate_payload(struct eval_ctx *ctx, struct expr **exprp)
{
struct expr *expr = *exprp;
@@ -585,8 +591,7 @@ static int expr_evaluate_payload(struct eval_ctx *ctx, struct expr **exprp)
if (expr_evaluate_primary(ctx, exprp) < 0)
return -1;
- if (expr->payload.offset % BITS_PER_BYTE != 0 ||
- expr->len % BITS_PER_BYTE != 0)
+ if (payload_needs_adjustment(expr))
expr_evaluate_bits(ctx, exprp);
return 0;