diff options
author | Phil Sutter <phil@nwl.cc> | 2018-06-01 17:32:07 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-06-03 11:47:22 +0200 |
commit | 7a5d1b3d8bef8d29c55632f363573cdb69328df0 (patch) | |
tree | ba80a60b7b7bb6ada7c847d1a505495965f0bb0b /src/parser_json.c | |
parent | caf5cb10fbde15845a63e857e0639921036b3f73 (diff) |
JSON: Simplify wildcard expression
Instead of dedicating an object for it ('{ "*": null }'), just use a
string consisting of an asterisk as sole character.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/parser_json.c')
-rw-r--r-- | src/parser_json.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/src/parser_json.c b/src/parser_json.c index 336092b7..1d60db47 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -278,13 +278,21 @@ static struct expr *json_parse_constant(struct json_ctx *ctx, const char *name) return NULL; } +static struct expr *wildcard_expr_alloc(void) +{ + struct expr *expr; + + expr = constant_expr_alloc(int_loc, &integer_type, + BYTEORDER_HOST_ENDIAN, 0, NULL); + return prefix_expr_alloc(int_loc, expr, 0); +} + /* this is a combination of symbol_expr, integer_expr, boolean_expr ... */ static struct expr *json_parse_immediate(struct json_ctx *ctx, json_t *root) { enum symbol_types symtype = SYMBOL_VALUE; const char *str; char buf[64] = {}; - struct expr; switch (json_typeof(root)) { case JSON_STRING: @@ -292,6 +300,8 @@ static struct expr *json_parse_immediate(struct json_ctx *ctx, json_t *root) if (str[0] == '@') { symtype = SYMBOL_SET; str++; + } else if (str[0] == '*' && str[1] == '\0') { + return wildcard_expr_alloc(); } else if (is_keyword(str)) { return symbol_expr_alloc(int_loc, SYMBOL_VALUE, NULL, str); @@ -974,16 +984,6 @@ static struct expr *json_parse_range_expr(struct json_ctx *ctx, return range_expr_alloc(int_loc, expr_low, expr_high); } -static struct expr *json_parse_wildcard_expr(struct json_ctx *ctx, - const char *type, json_t *root) -{ - struct expr *expr; - - expr = constant_expr_alloc(int_loc, &integer_type, - BYTEORDER_HOST_ENDIAN, 0, NULL); - return prefix_expr_alloc(int_loc, expr, 0); -} - static struct expr *json_parse_verdict_expr(struct json_ctx *ctx, const char *type, json_t *root) { @@ -1153,7 +1153,6 @@ static struct expr *json_parse_expr(struct json_ctx *ctx, json_t *root) /* below three are multiton_rhs_expr */ { "prefix", json_parse_prefix_expr, CTX_F_RHS | CTX_F_STMT }, { "range", json_parse_range_expr, CTX_F_RHS | CTX_F_STMT }, - { "*", json_parse_wildcard_expr, CTX_F_RHS | CTX_F_STMT }, { "payload", json_parse_payload_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_MAP }, { "exthdr", json_parse_exthdr_expr, CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_SES | CTX_F_MAP }, { "tcp option", json_parse_tcp_option_expr, CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES }, |