]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: simplify logic governing storing payload dependencies
authorJeremy Sowden <jeremy@azazel.net>
Tue, 21 Dec 2021 19:36:53 +0000 (19:36 +0000)
committerFlorian Westphal <fw@strlen.de>
Sat, 15 Jan 2022 16:38:48 +0000 (17:38 +0100)
There are several places where we check whether `ctx->pdctx.pbase`
equal to `PROTO_BASE_INVALID` and don't bother trying to free the
dependency if so.  However, these checks are redundant.

In `payload_match_expand` and `trace_gen_stmts`, we skip a call to
`payload_dependency_kill`, but that calls `payload_dependency_exists` to check a
dependency exists before doing anything else.

In `ct_meta_common_postprocess`, we skip an open-coded equivalent to
`payload_dependency_kill` which performs some different checks, but the
first is the same: a call to `payload_dependency_exists`.

Therefore, we can drop the redundant checks and simplify the flow-
control in the functions.

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/netlink.c
src/netlink_delinearize.c

index 5aad865955db4c73a8d6b4db2d7b16add8a36c8c..15b8878eb488f19f67a8588e51506bc9ae0faa7d 100644 (file)
@@ -1939,16 +1939,11 @@ next:
                if (payload_is_stacked(desc, rel))
                        b--;
 
-               if (lhs->flags & EXPR_F_PROTOCOL &&
-                   pctx->pbase == PROTO_BASE_INVALID) {
+               /* Don't strip 'icmp type' from payload dump. */
+               if (pctx->icmp_type == 0)
+                       payload_dependency_kill(pctx, lhs, ctx->family);
+               if (lhs->flags & EXPR_F_PROTOCOL)
                        payload_dependency_store(pctx, stmt, b);
-               } else {
-                       /* Don't strip 'icmp type' from payload dump. */
-                       if (pctx->icmp_type == 0)
-                               payload_dependency_kill(pctx, lhs, ctx->family);
-                       if (lhs->flags & EXPR_F_PROTOCOL)
-                               payload_dependency_store(pctx, stmt, b);
-               }
 
                goto next;
        }
index 36ead80296912ac6de919c47df783e0532a114b0..fd81e07151c2b70a2f1eae97c6a1e697fc4d0be4 100644 (file)
@@ -1899,16 +1899,10 @@ static void payload_match_expand(struct rule_pp_ctx *ctx,
                 * kill it later on if made redundant by a higher layer
                 * payload expression.
                 */
-               if (ctx->pdctx.pbase == PROTO_BASE_INVALID &&
-                   expr->op == OP_EQ &&
-                   left->flags & EXPR_F_PROTOCOL) {
+               payload_dependency_kill(&ctx->pdctx, nexpr->left,
+                                       ctx->pctx.family);
+               if (expr->op == OP_EQ && left->flags & EXPR_F_PROTOCOL)
                        payload_dependency_store(&ctx->pdctx, nstmt, base);
-               } else {
-                       payload_dependency_kill(&ctx->pdctx, nexpr->left,
-                                               ctx->pctx.family);
-                       if (expr->op == OP_EQ && left->flags & EXPR_F_PROTOCOL)
-                               payload_dependency_store(&ctx->pdctx, nstmt, base);
-               }
        }
        list_del(&ctx->stmt->list);
        stmt_free(ctx->stmt);
@@ -2125,10 +2119,7 @@ static void ct_meta_common_postprocess(struct rule_pp_ctx *ctx,
 
                relational_expr_pctx_update(&ctx->pctx, expr);
 
-               if (ctx->pdctx.pbase == PROTO_BASE_INVALID &&
-                   left->flags & EXPR_F_PROTOCOL) {
-                       payload_dependency_store(&ctx->pdctx, ctx->stmt, base);
-               } else if (ctx->pdctx.pbase < PROTO_BASE_TRANSPORT_HDR) {
+               if (ctx->pdctx.pbase < PROTO_BASE_TRANSPORT_HDR) {
                        if (payload_dependency_exists(&ctx->pdctx, base) &&
                            meta_may_dependency_kill(&ctx->pdctx,
                                                     ctx->pctx.family, expr))