expr: do not suppress OP_EQ when RHS is bitmask type
Florian Westphal
maintainerPATCH 1/1 expr: do not suppress OP_EQ when RHS is bitmask type
bitmask types default to flagcmp now, thus do not suppress OP_EQ. Else,
rule filter output tcp flags syn
rule filter output tcp flags == syn
are both displayed as 'flags syn'.
--- src/expression.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
src/expression.c +10 -2
@@ -514,13 +514,21 @@ static void binop_arg_print(const struct expr *op, const struct expr *arg)printf (")" ); } +static bool must_print_eq_op (const struct expr *expr) +{ +if (expr->right->dtype->basetype !=NULL && + expr->right->dtype->basetype->type ==TYPE_BITMASK ) +return true; + +return expr->left->ops->type ==EXPR_BINOP ; +} +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 || - expr->left->ops->type ==EXPR_BINOP )) + (expr->op !=OP_EQ ||must_print_eq_op (expr)))printf (" %s " , expr_op_symbols[expr->op]);else printf (" " );
Signature · 1 line
1.8.1.5
Pablo Neira Ayuso
maintainerQuoted 6 lines · Florian Westphal
bitmask types default to flagcmp now, thus do not suppress
OP_EQ. Else,rule filter output tcp flags syn
rule filter output tcp flags == synare both displayed as 'flags syn'.
I believe that in other selectors:
selector == value
selector valueare equivalent.
I think it's not just that we have to fix the printing, but make it consistent.
Quoted 40 lines
Signed-off-by Florian Westphal <[email protected]>--- src/expression.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)src/expression.c +10
-2@@ -514,13 +514,21 @@ static void binop_arg_print(const struct expr *op, const struct expr *arg)printf (")" ); } +static bool must_print_eq_op (const struct expr *expr) +{ +if (expr->right->dtype->basetype !=NULL && + expr->right->dtype->basetype->type ==TYPE_BITMASK ) +return true; + +return expr->left->ops->type ==EXPR_BINOP ; +} +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 || - expr->left->ops->type ==EXPR_BINOP )) + (expr->op !=OP_EQ ||must_print_eq_op (expr)))printf (" %s " , expr_op_symbols[expr->op]);else printf (" " );Signature · 6 lines
1.8.1.5 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Florian Westphal
maintainerQuoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
bitmask types default to flagcmp now, thus do not suppress
OP_EQ. Else,rule filter output tcp flags syn
rule filter output tcp flags == syn
Quoted 8 lines
Quoted 1 line
are both displayed as 'flags syn'.
I believe that in other selectors:
selector == value selector valueare equivalent.
Yes, thats true.
Quoted 2 lines
I think it's not just that we have to fix the printing, but make it consistent.
Not sure, this was changed recently, see 6bad82aba5d304c7a2dd1b19fe57464dca327f4a (evaluate: use flagcmp for single RHS bitmask expression).
Pablo Neira Ayuso
maintainerQuoted 16 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
bitmask types default to flagcmp now, thus do not suppress
OP_EQ. Else,rule filter output tcp flags syn
rule filter output tcp flags == synQuoted 8 lines
Quoted 1 line
are both displayed as 'flags syn'.
I believe that in other selectors:
selector == value selector valueare equivalent.
Quoted 8 lines
Yes, thats true.
Quoted 2 lines
I think it's not just that we have to fix the printing, but make it consistent.
Not sure, this was changed recently, see
6bad82aba5d304c7a2dd1b19fe57464dca327f4a(evaluate: use flagcmp for single RHS bitmask expression).
That change is fine, I think we only have to fix tcp flags == syn to make it equivalent to tcp flags syn. I don't find a good reason why the should behave in a different way.
Quoted 22 lines · Pablo Neira Ayuso
Quoted 21 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
bitmask types default to flagcmp now, thus do not suppress
OP_EQ. Else,rule filter output tcp flags syn
rule filter output tcp flags == synQuoted 8 lines
Quoted 1 line
are both displayed as 'flags syn'.
I believe that in other selectors:
selector == value selector valueare equivalent.
Yes, thats true.
Quoted 2 lines
I think it's not just that we have to fix the printing, but make it consistent.
Quoted 7 lines
Quoted 3 lines
Not sure, this was changed recently, see
6bad82aba5d304c7a2dd1b19fe57464dca327f4a(evaluate: use flagcmp for single RHS bitmask expression).That change is fine, I think we only have to fix tcp flags == syn to make it equivalent to tcp flags syn. I don't find a good reason why the should behave in a different way.
Because the implicit op for bitmasks is to test for any of the given bits. tcp flags syn really should match on syn and syn/ack.
If an equality relation is explicitly specified by the user, it also needs to be printed. Florian's change is all we need from what I can tell.
Pablo Neira Ayuso
maintainerQuoted 27 lines · Patrick McHardy
Quoted 26 lines · Pablo Neira Ayuso
Quoted 24 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
bitmask types default to flagcmp now, thus do not suppress
OP_EQ. Else,rule filter output tcp flags syn
rule filter output tcp flags == synQuoted 8 lines
Quoted 1 line
are both displayed as 'flags syn'.
I believe that in other selectors:
selector == value selector valueare equivalent.
Yes, thats true.
Quoted 2 lines
I think it's not just that we have to fix the printing, but make it consistent.
Not sure, this was changed recently, see
6bad82aba5d304c7a2dd1b19fe57464dca327f4a(evaluate: use flagcmp for single RHS bitmask expression).
Quoted 6 lines
Quoted 3 lines
That change is fine, I think we only have to fix tcp flags == syn to make it equivalent to tcp flags syn. I don't find a good reason why the should behave in a different way.
Because the implicit op for bitmasks is to test for any of the given bits. tcp flags syn really should match on syn and syn/ack.
That's fine with me. The problem that I see is the inconsistent interpretation depending on if the value is a flag or not.
Quoted 2 lines
If an equality relation is explicitly specified by the user, it also needs to be printed. Florian's change is all we need from what I can tell.
Then we have to document that in some cases key == value and key value are equivalent, and when it comes to flags it is not, which is still rare to me.
nft --debug=netlink add rule filter output tcp flags == syn ip filter output
[ payload load 1b @ network header + 9 => reg 1 ]
[ cmp eq reg 1 0x00000006 ]
[ payload load 1b @ transport header + 13 => reg 1 ]
[ cmp eq reg 1 0x00000002 ]
nft --debug=netlink add rule filter output tcp flags syn ip filter output
[ payload load 1b @ network header + 9 => reg 1 ]
[ cmp eq reg 1 0x00000006 ]
[ payload load 1b @ transport header + 13 => reg 1 ]
[ bitwise reg 1 = (reg=1 & 0x00000002 ) ^ 0x00000000 ]
[ cmp neq reg 1 0x00000000 ]
Quoted 32 lines · Pablo Neira Ayuso
Quoted 31 lines · Patrick McHardy
Quoted 29 lines · Pablo Neira Ayuso
Quoted 16 lines · Florian Westphal
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
bitmask types default to flagcmp now, thus do not suppress
OP_EQ. Else,rule filter output tcp flags syn
rule filter output tcp flags == synQuoted 8 lines
Quoted 1 line
are both displayed as 'flags syn'.
I believe that in other selectors:
selector == value selector valueare equivalent.
Quoted 8 lines
Yes, thats true.
Quoted 2 lines
I think it's not just that we have to fix the printing, but make it consistent.
Not sure, this was changed recently, see
6bad82aba5d304c7a2dd1b19fe57464dca327f4a(evaluate: use flagcmp for single RHS bitmask expression).That change is fine, I think we only have to fix tcp flags == syn to make it equivalent to tcp flags syn. I don't find a good reason why the should behave in a different way.
Quoted 5 lines
Quoted 2 lines
Because the implicit op for bitmasks is to test for any of the given bits. tcp flags syn really should match on syn and syn/ack.
That's fine with me. The problem that I see is the inconsistent interpretation depending on if the value is a flag or not.
I don't see it as inconsistent, its just that the implicit op can mean different things. Its basically meant to "do the right thing", which IMO is the current behaviour. For me tcp flags syn also matching on syn/ack is what I'd expect.
Quoted 6 lines
Quoted 2 lines
If an equality relation is explicitly specified by the user, it also needs to be printed. Florian's change is all we need from what I can tell.
Then we have to document that in some cases key == value and key value are equivalent, and when it comes to flags it is not, which is still rare to me.
Sure. I think I already have it in my documentation. Its basically simply documenting what the implicit op means in which context.
Pablo Neira Ayuso
maintainerQuoted 9 lines · Patrick McHardy
Quoted 6 lines
Quoted 2 lines
If an equality relation is explicitly specified by the user, it also needs to be printed. Florian's change is all we need from what I can tell.
Then we have to document that in some cases key == value and key value are equivalent, and when it comes to flags it is not, which is still rare to me.
Sure. I think I already have it in my documentation. Its basically simply documenting what the implicit op means in which context.
OK, please go ahead push it, thanks.
Florian Westphal
maintainerQuoted 4 lines · Pablo Neira Ayuso
Quoted 3 lines · Patrick McHardy
Quoted 3 lines
Quoted 2 lines
If an equality relation is explicitly specified by the user, it also needs to be printed. Florian's change is all we need from what I can tell.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Then we have to document that in some cases key == value and key value are equivalent, and when it comes to flags it is not, which is still rare to me.
Sure. I think I already have it in my documentation. Its basically simply documenting what the implicit op means in which context.
OK, please go ahead push it, thanks.
done.
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
bitmask types default to flagcmp now, thus do not suppress
OP_EQ. Else,rule filter output tcp flags syn
rule filter output tcp flags == syn
Quoted 8 lines
Quoted 1 line
are both displayed as 'flags syn'.
I believe that in other selectors:
selector == value selector valueare equivalent.
No, it really depends on the base type. For bitmasks the equality relation should be printed explicitly.
Quoted 2 lines
I think it's not just that we have to fix the printing, but make it consistent.
What do you propose to change?