From 26db6cd9061757d9548cfadc4f921caa1aa6aff7 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 19 Oct 2020 23:51:16 +0200 Subject: src: constify location parameter in cmd_add_loc() Constify pointer to location object to compile check for unintentional updates. Signed-off-by: Pablo Neira Ayuso --- include/rule.h | 6 +++--- src/cmd.c | 17 +++++++++-------- src/rule.c | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/rule.h b/include/rule.h index 10e71047..119fc19d 100644 --- a/include/rule.h +++ b/include/rule.h @@ -704,8 +704,8 @@ struct cmd { struct obj *object; }; struct { - uint16_t offset; - struct location *location; + uint16_t offset; + const struct location *location; } attr[NFT_NLATTR_LOC_MAX]; int num_attrs; const void *arg; @@ -720,7 +720,7 @@ extern struct cmd *cmd_alloc_obj_ct(enum cmd_ops op, int type, const struct location *loc, struct obj *obj); extern void cmd_free(struct cmd *cmd); -void cmd_add_loc(struct cmd *cmd, uint16_t offset, struct location *loc); +void cmd_add_loc(struct cmd *cmd, uint16_t offset, const struct location *loc); #include #include diff --git a/src/cmd.c b/src/cmd.c index e0cf3e77..9cb5b6a3 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -10,7 +10,7 @@ #include static int nft_cmd_enoent_table(struct netlink_ctx *ctx, const struct cmd *cmd, - struct location *loc) + const struct location *loc) { struct table *table; @@ -25,7 +25,7 @@ static int nft_cmd_enoent_table(struct netlink_ctx *ctx, const struct cmd *cmd, } static int nft_cmd_enoent_chain(struct netlink_ctx *ctx, const struct cmd *cmd, - struct location *loc) + const struct location *loc) { const struct table *table; struct chain *chain; @@ -42,7 +42,7 @@ static int nft_cmd_enoent_chain(struct netlink_ctx *ctx, const struct cmd *cmd, } static int nft_cmd_enoent_rule(struct netlink_ctx *ctx, const struct cmd *cmd, - struct location *loc) + const struct location *loc) { unsigned int flags = NFT_CACHE_TABLE | NFT_CACHE_CHAIN; @@ -76,7 +76,7 @@ static int nft_cmd_enoent_rule(struct netlink_ctx *ctx, const struct cmd *cmd, } static int nft_cmd_enoent_set(struct netlink_ctx *ctx, const struct cmd *cmd, - struct location *loc) + const struct location *loc) { const struct table *table; struct set *set; @@ -95,7 +95,7 @@ static int nft_cmd_enoent_set(struct netlink_ctx *ctx, const struct cmd *cmd, } static int nft_cmd_enoent_obj(struct netlink_ctx *ctx, const struct cmd *cmd, - struct location *loc) + const struct location *loc) { const struct table *table; struct obj *obj; @@ -112,7 +112,8 @@ static int nft_cmd_enoent_obj(struct netlink_ctx *ctx, const struct cmd *cmd, } static int nft_cmd_enoent_flowtable(struct netlink_ctx *ctx, - const struct cmd *cmd, struct location *loc) + const struct cmd *cmd, + const struct location *loc) { const struct table *table; struct flowtable *ft; @@ -130,7 +131,7 @@ static int nft_cmd_enoent_flowtable(struct netlink_ctx *ctx, } static void nft_cmd_enoent(struct netlink_ctx *ctx, const struct cmd *cmd, - struct location *loc, int err) + const struct location *loc, int err) { int ret = 0; @@ -173,7 +174,7 @@ static void nft_cmd_enoent(struct netlink_ctx *ctx, const struct cmd *cmd, void nft_cmd_error(struct netlink_ctx *ctx, struct cmd *cmd, struct mnl_err *err) { - struct location *loc = NULL; + const struct location *loc = NULL; int i; for (i = 0; i < cmd->num_attrs; i++) { diff --git a/src/rule.c b/src/rule.c index e57009b2..dddfdf51 100644 --- a/src/rule.c +++ b/src/rule.c @@ -1473,7 +1473,7 @@ struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj, return cmd; } -void cmd_add_loc(struct cmd *cmd, uint16_t offset, struct location *loc) +void cmd_add_loc(struct cmd *cmd, uint16_t offset, const struct location *loc) { if (cmd->num_attrs > NFT_NLATTR_LOC_MAX) return; -- cgit v1.2.3