From: Florian Westphal <fw@strlen.de>
To: <netfilter-devel@vger.kernel.org>
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nft 1/3] expression: add helper to decide if operator needs to be shown
Date: Thu, 3 Mar 2016 18:56:52 +0100 [thread overview]
Message-ID: <1457027814-14795-1-git-send-email-fw@strlen.de> (raw)
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
next reply other threads:[~2016-03-03 17:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-03 17:56 Florian Westphal [this message]
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
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=1457027814-14795-1-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).