]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: move lhs fixup to a helper
authorFlorian Westphal <fw@strlen.de>
Mon, 2 Apr 2018 18:34:23 +0000 (20:34 +0200)
committerFlorian Westphal <fw@strlen.de>
Tue, 3 Apr 2018 12:27:03 +0000 (14:27 +0200)
... to reuse this in a followup patch.

Signed-off-by: Florian Westphal <fw@strlen.de>
src/evaluate.c

index 967ad162e46e579af2b42dfb1cc13e258fe005b7..189f1ea4fa6df6561bf7baeee8b497df51ec69ba 100644 (file)
@@ -1483,10 +1483,36 @@ static int binop_transfer_one(struct eval_ctx *ctx,
        return expr_evaluate(ctx, right);
 }
 
+static void binop_transfer_handle_lhs(struct expr **expr)
+{
+       struct expr *tmp, *left = *expr;
+       unsigned int shift;
+
+       assert(left->ops->type == EXPR_BINOP);
+
+       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:
+               tmp = expr_get(left->left);
+               tmp->dtype = left->dtype;
+               expr_free(left);
+               *expr = tmp;
+               break;
+       default:
+               BUG("invalid binop operation %u", left->op);
+       }
+}
+
 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)
@@ -1555,24 +1581,7 @@ static int binop_transfer(struct eval_ctx *ctx, struct expr **expr)
                return 0;
        }
 
-       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);
-       }
+       binop_transfer_handle_lhs(&(*expr)->left);
        return 0;
 }