[PATCH nft 1/4] evaluate: move lhs fixup to a helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



... to reuse this in a followup patch.

Signed-off-by: Florian Westphal <fw@xxxxxxxxx>
---
 src/evaluate.c | 47 ++++++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 19 deletions(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index 967ad162e46e..189f1ea4fa6d 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -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;
 }
 
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux