diff options
-rw-r--r-- | src/netlink_delinearize.c | 21 | ||||
-rw-r--r-- | tests/shell/testcases/sets/dumps/typeof_sets_0.nft | 8 | ||||
-rwxr-xr-x | tests/shell/testcases/sets/typeof_sets_0 | 8 |
3 files changed, 37 insertions, 0 deletions
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c index e37a34f3..323e9150 100644 --- a/src/netlink_delinearize.c +++ b/src/netlink_delinearize.c @@ -2322,6 +2322,20 @@ static void map_binop_postprocess(struct rule_pp_ctx *ctx, struct expr *expr) binop_postprocess(ctx, expr, &expr->map); } +static bool is_shift_by_zero(const struct expr *binop) +{ + struct expr *rhs; + + if (binop->op != OP_RSHIFT && binop->op != OP_LSHIFT) + return false; + + rhs = binop->right; + if (rhs->etype != EXPR_VALUE || rhs->len > 64) + return false; + + return mpz_get_uint64(rhs->value) == 0; +} + static void relational_binop_postprocess(struct rule_pp_ctx *ctx, struct expr **exprp) { @@ -2421,6 +2435,13 @@ static void relational_binop_postprocess(struct rule_pp_ctx *ctx, */ binop_postprocess(ctx, binop, &binop->left); + if (is_shift_by_zero(binop)) { + struct expr *lhs = binop->left; + + expr_get(lhs); + expr_free(binop); + expr->left = lhs; + } } } diff --git a/tests/shell/testcases/sets/dumps/typeof_sets_0.nft b/tests/shell/testcases/sets/dumps/typeof_sets_0.nft index ad442713..e397a634 100644 --- a/tests/shell/testcases/sets/dumps/typeof_sets_0.nft +++ b/tests/shell/testcases/sets/dumps/typeof_sets_0.nft @@ -53,6 +53,10 @@ table inet t { vlan id @s2 accept } + chain c4 { + frag frag-off @s4 accept + } + chain c5 { ip option ra value @s5 accept } @@ -65,6 +69,10 @@ table inet t { sctp chunk init num-inbound-streams @s7 accept } + chain c8 { + ip version @s8 accept + } + chain c9 { ip hdrlength @s9 accept } diff --git a/tests/shell/testcases/sets/typeof_sets_0 b/tests/shell/testcases/sets/typeof_sets_0 index 2102789e..be906cdc 100755 --- a/tests/shell/testcases/sets/typeof_sets_0 +++ b/tests/shell/testcases/sets/typeof_sets_0 @@ -58,6 +58,10 @@ EXPECTED="table inet t { ether type vlan vlan id @s2 accept } + chain c4 { + frag frag-off @s4 accept + } + chain c5 { ip option ra value @s5 accept } @@ -70,6 +74,10 @@ EXPECTED="table inet t { sctp chunk init num-inbound-streams @s7 accept } + chain c8 { + ip version @s8 accept + } + chain c9 { ip hdrlength @s9 accept } |