diff options
author | Florian Westphal <fw@strlen.de> | 2017-02-27 15:11:42 +0100 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2017-03-16 10:09:57 +0100 |
commit | ec38e5ed61a088a1fbd2922742c9125aa1c63a7c (patch) | |
tree | a86d718b2a842c730b42ea8765b0edc064a129fd /src/evaluate.c | |
parent | 5ca4eb30d62e0ab2768d64de5c70931292213338 (diff) |
evaluate: refactor CMD_OBJ_QUOTA/COUNTER handling
... to make adding CMD_OBJ_CT_HELPER support easier.
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/evaluate.c')
-rw-r--r-- | src/evaluate.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/evaluate.c b/src/evaluate.c index 7ddbb658..ae30bc9b 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -2940,12 +2940,29 @@ static int cmd_evaluate_delete(struct eval_ctx *ctx, struct cmd *cmd) } } +static int cmd_evaluate_list_obj(struct eval_ctx *ctx, const struct cmd *cmd, + uint32_t obj_type) +{ + const struct table *table; + + if (obj_type == NFT_OBJECT_UNSPEC) + obj_type = NFT_OBJECT_COUNTER; + + table = table_lookup(&cmd->handle); + if (table == NULL) + return cmd_error(ctx, "Could not process rule: Table '%s' does not exist", + cmd->handle.table); + if (obj_lookup(table, cmd->handle.obj, obj_type) == NULL) + return cmd_error(ctx, "Could not process rule: Object '%s' does not exist", + cmd->handle.obj); + return 0; +} + static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd) { struct table *table; struct set *set; int ret; - uint32_t obj_type = NFT_OBJECT_UNSPEC; ret = cache_update(cmd->op, ctx->msgs); if (ret < 0) @@ -3001,18 +3018,9 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd) cmd->handle.chain); return 0; case CMD_OBJ_QUOTA: - obj_type = NFT_OBJECT_QUOTA; + return cmd_evaluate_list_obj(ctx, cmd, NFT_OBJECT_QUOTA); case CMD_OBJ_COUNTER: - if (obj_type == NFT_OBJECT_UNSPEC) - obj_type = NFT_OBJECT_COUNTER; - table = table_lookup(&cmd->handle); - if (table == NULL) - return cmd_error(ctx, "Could not process rule: Table '%s' does not exist", - cmd->handle.table); - if (obj_lookup(table, cmd->handle.obj, obj_type) == NULL) - return cmd_error(ctx, "Could not process rule: Object '%s' does not exist", - cmd->handle.obj); - return 0; + return cmd_evaluate_list_obj(ctx, cmd, NFT_OBJECT_COUNTER); case CMD_OBJ_COUNTERS: case CMD_OBJ_QUOTAS: if (cmd->handle.table == NULL) |