]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
fix printing of "tcp flags syn" and "tcp flags == syn" expressions
authorSabrina Dubroca <sd@queasysnail.net>
Fri, 25 May 2018 13:23:16 +0000 (15:23 +0200)
committerFlorian Westphal <fw@strlen.de>
Fri, 25 May 2018 15:48:55 +0000 (17:48 +0200)
Commit 6979625686ec ("relational: Eliminate meta OPs") introduced some
bugs when printing bitmask types.

First, during the post-processing phase of delinearization, the
expression for "tcp flags syn" (PAYLOAD & flag != 0) gets converted to
PAYLOAD == flag, which is not equivalent. This should be
PAYLOAD (IMPL) flag.

Then, during output, the "==" sign from "tcp flags == syn" is dropped,
because the bitmask condition in must_print_eq_op() was removed. Let's
restore it, so that "tcp flags == syn" doesn't get printed as
"tcp flags syn". An extra check for value types is added, so that we
don't start printing "==" for sets such as "tcp flags {syn,ack}"

Finally, add a regression test for this particular case.

Fixes: 6979625686ec ("relational: Eliminate meta OPs")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/expression.c
src/netlink_delinearize.c
tests/py/inet/tcp.t
tests/py/inet/tcp.t.payload

index 53fb1811f28cb4a9f05bafab40a0bcff53b0705f..bea0f4c8d9bc1f9f8c777457632d1b38a2cd01bf 100644 (file)
@@ -565,6 +565,11 @@ static void binop_arg_print(const struct expr *op, const struct expr *arg,
 
 bool must_print_eq_op(const struct expr *expr)
 {
+       if (expr->right->dtype->basetype != NULL &&
+           expr->right->dtype->basetype->type == TYPE_BITMASK &&
+           expr->right->ops->type == EXPR_VALUE)
+               return true;
+
        return expr->left->ops->type == EXPR_BINOP;
 }
 
index 8f4035a291f49da7ea104f6586066446e77a74f2..7d882ebac555a89f8b465ba6aad6580051b6fefd 100644 (file)
@@ -1733,7 +1733,7 @@ static void relational_binop_postprocess(struct rule_pp_ctx *ctx, struct expr *e
 
                expr->left  = expr_get(binop->left);
                expr->right = binop_tree_to_list(NULL, binop->right);
-               expr->op    = OP_EQ;
+               expr->op    = OP_IMPLICIT;
 
                expr_free(binop);
        } else if (binop->left->dtype->flags & DTYPE_F_PREFIX &&
index 5276516625ccef78cd85b5ba8ec0a7abc0ef6323..d66ba8438a32f9d44ea53c6f156ee34f88c0305d 100644 (file)
@@ -76,6 +76,7 @@ tcp flags { fin, syn, rst, psh, ack, urg, ecn, cwr} drop;ok
 tcp flags != { fin, urg, ecn, cwr} drop;ok
 tcp flags cwr;ok
 tcp flags != cwr;ok
+tcp flags == syn;ok
 tcp flags & (syn|fin) == (syn|fin);ok;tcp flags & (fin | syn) == fin | syn
 
 tcp window 22222;ok
index 512b42e9df0840d6e7c485cfe40f4edfc161e6c4..09538aed746c9a11278e8fb4e63110386245b103 100644 (file)
@@ -421,6 +421,13 @@ inet test-inet input
   [ payload load 1b @ transport header + 13 => reg 1 ]
   [ cmp neq reg 1 0x00000080 ]
 
+# tcp flags == syn
+inet test-inet input
+  [ meta load l4proto => reg 1 ]
+  [ cmp eq reg 1 0x00000006 ]
+  [ payload load 1b @ transport header + 13 => reg 1 ]
+  [ cmp eq reg 1 0x00000002 ]
+
 # tcp flags & (syn|fin) == (syn|fin)
 inet test-inet input
   [ meta load l4proto => reg 1 ]