]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: add small helper to check if payload expr needs binop adjustment
authorFlorian Westphal <fw@strlen.de>
Mon, 1 Aug 2016 15:11:41 +0000 (17:11 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 1 Aug 2016 15:11:41 +0000 (17:11 +0200)
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>
src/evaluate.c

index 8116735d4ebf487acb8f9625462fd9396aeb1c2f..7962e9e428df82e05b3feef4e52908d0fcfcd086 100644 (file)
@@ -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;