summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2020-05-05 20:12:46 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2020-05-05 20:21:27 +0200
commitd0d564ed1fba00cc3b2fdf4d646f080b2790b76a (patch)
tree698d17c51a94b3d82512b7ce1608a505a6e649ea
parenteea03c8fb560a8a6deede1bccbce78b52b2c2905 (diff)
src: add rule_stmt_append() and use it
This helper function adds a statement at the end of the rule statement list and it updates the rule statement counter. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/rule.h1
-rw-r--r--src/netlink_delinearize.c7
-rw-r--r--src/parser_json.c6
-rw-r--r--src/rule.c6
-rw-r--r--src/xt.c4
5 files changed, 14 insertions, 10 deletions
diff --git a/include/rule.h b/include/rule.h
index 5311b563..1a4ec3d8 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -280,6 +280,7 @@ extern void rule_print(const struct rule *rule, struct output_ctx *octx);
extern struct rule *rule_lookup(const struct chain *chain, uint64_t handle);
extern struct rule *rule_lookup_by_index(const struct chain *chain,
uint64_t index);
+void rule_stmt_append(struct rule *rule, struct stmt *stmt);
void rule_stmt_insert_at(struct rule *rule, struct stmt *nstmt,
struct stmt *stmt);
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index f721d15c..7f7ad262 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -563,8 +563,7 @@ static void netlink_parse_payload_stmt(struct netlink_parse_ctx *ctx,
payload_init_raw(expr, base, offset, len);
stmt = payload_stmt_alloc(loc, expr, val);
-
- list_add_tail(&stmt->list, &ctx->rule->stmts);
+ rule_stmt_append(ctx->rule, stmt);
}
static void netlink_parse_payload(struct netlink_parse_ctx *ctx,
@@ -615,7 +614,7 @@ static void netlink_parse_exthdr(struct netlink_parse_ctx *ctx,
expr_set_type(val, expr->dtype, expr->byteorder);
stmt = exthdr_stmt_alloc(loc, expr, val);
- list_add_tail(&stmt->list, &ctx->rule->stmts);
+ rule_stmt_append(ctx->rule, stmt);
}
}
@@ -1672,7 +1671,7 @@ static int netlink_parse_rule_expr(struct nftnl_expr *nle, void *arg)
if (err < 0)
return err;
if (ctx->stmt != NULL) {
- list_add_tail(&ctx->stmt->list, &ctx->rule->stmts);
+ rule_stmt_append(ctx->rule, ctx->stmt);
ctx->stmt = NULL;
}
return 0;
diff --git a/src/parser_json.c b/src/parser_json.c
index a1765027..4468407b 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -2731,8 +2731,7 @@ static struct cmd *json_parse_cmd_add_rule(struct json_ctx *ctx, json_t *root,
return NULL;
}
- rule->num_stmts++;
- list_add_tail(&stmt->list, &rule->stmts);
+ rule_stmt_append(rule, stmt);
}
if (op == CMD_ADD)
@@ -3404,8 +3403,7 @@ static struct cmd *json_parse_cmd_replace(struct json_ctx *ctx,
return NULL;
}
- rule->num_stmts++;
- list_add_tail(&stmt->list, &rule->stmts);
+ rule_stmt_append(rule, stmt);
}
if (op == CMD_REPLACE)
diff --git a/src/rule.c b/src/rule.c
index 0759bec5..c58aa359 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -686,6 +686,12 @@ struct rule *rule_lookup_by_index(const struct chain *chain, uint64_t index)
return NULL;
}
+void rule_stmt_append(struct rule *rule, struct stmt *stmt)
+{
+ list_add_tail(&stmt->list, &rule->stmts);
+ rule->num_stmts++;
+}
+
void rule_stmt_insert_at(struct rule *rule, struct stmt *nstmt,
struct stmt *stmt)
{
diff --git a/src/xt.c b/src/xt.c
index b0f5a30c..f39acf30 100644
--- a/src/xt.c
+++ b/src/xt.c
@@ -238,7 +238,7 @@ void netlink_parse_match(struct netlink_parse_ctx *ctx,
stmt->xt.name = strdup(name);
stmt->xt.type = NFT_XT_MATCH;
#endif
- list_add_tail(&stmt->list, &ctx->rule->stmts);
+ rule_stmt_append(ctx->rule, stmt);
}
void netlink_parse_target(struct netlink_parse_ctx *ctx,
@@ -283,7 +283,7 @@ void netlink_parse_target(struct netlink_parse_ctx *ctx,
stmt->xt.name = strdup(name);
stmt->xt.type = NFT_XT_TARGET;
#endif
- list_add_tail(&stmt->list, &ctx->rule->stmts);
+ rule_stmt_append(ctx->rule, stmt);
}
#ifdef HAVE_LIBXTABLES