diff options
author | Phil Sutter <phil@nwl.cc> | 2018-06-01 17:32:08 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-06-03 11:47:22 +0200 |
commit | d1057a5feb5fde589c6505cf94f89fbdce91351b (patch) | |
tree | 6d66a5c92ab0a061dc901979af328fde8adf7576 | |
parent | 7a5d1b3d8bef8d29c55632f363573cdb69328df0 (diff) |
JSON: Simplify verdict statement parsing
Reuse verdict expression parsing routine. Since the statement simply
wraps an expression, this change is an obvious one.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | src/parser_json.c | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/src/parser_json.c b/src/parser_json.c index 1d60db47..394e5039 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -1403,45 +1403,12 @@ static struct stmt *json_parse_counter_stmt(struct json_ctx *ctx, static struct stmt *json_parse_verdict_stmt(struct json_ctx *ctx, const char *key, json_t *value) { - struct { - const char *name; - int val; - } verdict_type_tbl[] = { - { "accept", NF_ACCEPT }, - { "drop", NF_DROP }, - { "continue", NFT_CONTINUE }, - { "jump", NFT_JUMP }, - { "goto", NFT_GOTO }, - { "return", NFT_RETURN }, - }; - const char *identifier = NULL; struct expr *expr; - unsigned int i; - int type = 255; /* NFT_* are negative, NF_* are max 5 (NF_STOP) */ - for (i = 0; i < array_size(verdict_type_tbl); i++) { - if (!strcmp(verdict_type_tbl[i].name, key)) { - type = verdict_type_tbl[i].val; - break; - } - } - switch(type) { - case NFT_JUMP: - case NFT_GOTO: - if (!json_is_string(value)) { - json_error(ctx, "Verdict '%s' requires destination.", key); - return NULL; - } - identifier = xstrdup(json_string_value(value)); - /* fall through */ - case NF_ACCEPT: - case NF_DROP: - case NFT_CONTINUE: - case NFT_RETURN: - expr = verdict_expr_alloc(int_loc, type, identifier); + expr = json_parse_verdict_expr(ctx, key, value); + if (expr) return verdict_stmt_alloc(int_loc, expr); - } - json_error(ctx, "Unknown verdict '%s'.", key); + return NULL; } |