netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 1/3] evaluate: move default op lookup into helper
Date: Tue,  2 Feb 2016 00:18:59 +0100	[thread overview]
Message-ID: <1454368741-16368-2-git-send-email-fw@strlen.de> (raw)
In-Reply-To: <1454368741-16368-1-git-send-email-fw@strlen.de>

Split it into its own function, caller is already quite big.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/evaluate.c | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/src/evaluate.c b/src/evaluate.c
index ed78896..4d741e3 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -1119,6 +1119,26 @@ static int binop_transfer(struct eval_ctx *ctx, struct expr **expr)
 	return 0;
 }
 
+static enum ops expr_defaultop(const struct expr *e)
+{
+	switch (e->ops->type) {
+	case EXPR_RANGE:
+		return OP_RANGE;
+	case EXPR_SET:
+	case EXPR_SET_REF:
+		return OP_LOOKUP;
+	case EXPR_LIST:
+		return OP_FLAGCMP;
+	default:
+		if (e->dtype->basetype != NULL &&
+		    e->dtype->basetype->type == TYPE_BITMASK)
+			return OP_FLAGCMP;
+		break;
+	}
+
+	return OP_EQ;
+}
+
 static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 {
 	struct expr *rel = *expr, *left, *right;
@@ -1131,27 +1151,8 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr)
 		return -1;
 	right = rel->right;
 
-	if (rel->op == OP_IMPLICIT) {
-		switch (right->ops->type) {
-		case EXPR_RANGE:
-			rel->op = OP_RANGE;
-			break;
-		case EXPR_SET:
-		case EXPR_SET_REF:
-			rel->op = OP_LOOKUP;
-			break;
-		case EXPR_LIST:
-			rel->op = OP_FLAGCMP;
-			break;
-		default:
-			if (right->dtype->basetype != NULL &&
-			    right->dtype->basetype->type == TYPE_BITMASK)
-				rel->op = OP_FLAGCMP;
-			else
-				rel->op = OP_EQ;
-			break;
-		}
-	}
+	if (rel->op == OP_IMPLICIT)
+		rel->op = expr_defaultop(rel->right);
 
 	if (!expr_is_constant(right))
 		return expr_binary_error(ctx->msgs, right, rel,
-- 
2.4.10


  reply	other threads:[~2016-02-01 23:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-01 23:18 [PATCH nft 0/3] meta: random match for statistic sampling Florian Westphal
2016-02-01 23:18 ` Florian Westphal [this message]
2016-02-01 23:19 ` [PATCH nft 2/3] meta: add prandom matching Florian Westphal
2016-02-04 14:39   ` Patrick McHardy
2016-02-04 14:46     ` Florian Westphal
2016-02-04 15:27       ` Patrick McHardy
2016-02-04 15:32         ` Florian Westphal
2016-02-04 16:09           ` Florian Westphal
2016-02-04 16:42             ` Florian Westphal
2016-02-04 17:40               ` Patrick McHardy
2016-02-15 12:54                 ` Florian Westphal
2016-02-16 11:45                   ` Pablo Neira Ayuso
2016-02-16 12:00                     ` Florian Westphal
2016-02-16 16:28                       ` Pablo Neira Ayuso
2016-02-04 17:38             ` Patrick McHardy
2016-02-01 23:19 ` [PATCH nft 3/3] tests: add test cases for meta random Florian Westphal
2016-02-03 20:23 ` [PATCH nft 0/3] meta: random match for statistic sampling 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=1454368741-16368-2-git-send-email-fw@strlen.de \
    --to=fw@strlen.de \
    --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).