The negation was introduced to provide a simple shortcut. Extend e6c32b2fa0b8 ("src: add negation match on singleton bitmask value") to disallow negation with binary operations too. # nft add rule meh tcp_flags 'tcp flags & (fin | syn | rst | ack) ! syn' Error: cannot combine negation with binary expression add rule meh tcp_flags tcp flags & (fin | syn | rst | ack) ! syn ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ~~~ Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx> --- src/evaluate.c | 16 ++++++++++------ tests/py/inet/tcp.t | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/evaluate.c b/src/evaluate.c index 4609576b2a61..8b5f51cee01c 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -2016,12 +2016,16 @@ static int expr_evaluate_relational(struct eval_ctx *ctx, struct expr **expr) /* fall through */ case OP_NEQ: case OP_NEG: - if (rel->op == OP_NEG && - (right->etype != EXPR_VALUE || - right->dtype->basetype == NULL || - right->dtype->basetype->type != TYPE_BITMASK)) - return expr_binary_error(ctx->msgs, left, right, - "negation can only be used with singleton bitmask values"); + if (rel->op == OP_NEG) { + if (left->etype == EXPR_BINOP) + return expr_binary_error(ctx->msgs, left, right, + "cannot combine negation with binary expression"); + if (right->etype != EXPR_VALUE || + right->dtype->basetype == NULL || + right->dtype->basetype->type != TYPE_BITMASK) + return expr_binary_error(ctx->msgs, left, right, + "negation can only be used with singleton bitmask values"); + } switch (right->etype) { case EXPR_RANGE: diff --git a/tests/py/inet/tcp.t b/tests/py/inet/tcp.t index 983564ec5b75..13b84215bd86 100644 --- a/tests/py/inet/tcp.t +++ b/tests/py/inet/tcp.t @@ -75,6 +75,7 @@ tcp flags & (fin | syn | rst | psh | ack | urg | ecn | cwr) == fin | syn | rst | tcp flags { syn, syn | ack };ok tcp flags & (fin | syn | rst | psh | ack | urg) == { fin, ack, psh | ack, fin | psh | ack };ok tcp flags ! fin,rst;ok +tcp flags & (fin | syn | rst | ack) ! syn;fail tcp window 22222;ok tcp window 22;ok -- 2.20.1