netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nft 1/3] expression: add helper to decide if operator needs to be shown
@ 2016-03-03 17:56 Florian Westphal
  2016-03-03 17:56 ` [PATCH nft 3/4] meta: add probability matching Florian Westphal
  2016-03-03 17:56 ` [PATCH nft 4/4] meta: add tests for " Florian Westphal
  0 siblings, 2 replies; 9+ messages in thread
From: Florian Westphal @ 2016-03-03 17:56 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

tcp dport 22 is treated as if user had given 'tcp dport == 22'.
When printing, the implicit == is omitted.

In some other cases we use OP_AND instead, e.g.
tcp flags ack means 'tcp flags & ack != 0'.

In all of these cases, we print the rule in the short form,
without showing this implicit operator.

Future patches will add other cases where an operator
other than AND or EQ can be suppressed, so add an explicit
helper that can suppress the operator symbol.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/expression.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/expression.c b/src/expression.c
index ab195e5..c96bce4 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -514,21 +514,27 @@ static void binop_arg_print(const struct expr *op, const struct expr *arg)
 		printf(")");
 }
 
-static bool must_print_eq_op(const struct expr *expr)
+static bool must_print_op(const struct expr *binop)
 {
-	if (expr->right->dtype->basetype != NULL &&
-	    expr->right->dtype->basetype->type == TYPE_BITMASK)
-		return true;
+	switch (binop->op) {
+	case OP_EQ:
+		if (binop->right->dtype->basetype != NULL &&
+		     binop->right->dtype->basetype->type == TYPE_BITMASK)
+			return true;
 
-	return expr->left->ops->type == EXPR_BINOP;
+		return binop->left->ops->type == EXPR_BINOP;
+	default:
+		break;
+	}
+
+	return true;
 }
 
 static void binop_expr_print(const struct expr *expr)
 {
 	binop_arg_print(expr, expr->left);
 
-	if (expr_op_symbols[expr->op] &&
-	    (expr->op != OP_EQ || must_print_eq_op(expr)))
+	if (expr_op_symbols[expr->op] && must_print_op(expr))
 		printf(" %s ", expr_op_symbols[expr->op]);
 	else
 		printf(" ");
-- 
2.4.10


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-03-04 13:13 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-03 17:56 [PATCH nft 1/3] expression: add helper to decide if operator needs to be shown Florian Westphal
2016-03-03 17:56 ` [PATCH nft 3/4] meta: add probability matching Florian Westphal
2016-03-03 19:36   ` Jan Engelhardt
2016-03-03 20:32     ` Florian Westphal
2016-03-03 20:45       ` Jan Engelhardt
2016-03-04 11:12         ` Florian Westphal
2016-03-04 12:34           ` Jan Engelhardt
2016-03-04 13:13             ` Florian Westphal
2016-03-03 17:56 ` [PATCH nft 4/4] meta: add tests for " Florian Westphal

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).