From e8b5419b94e230d008d6701b66d02434a7cb1152 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 8 Jun 2018 17:27:16 +0200 Subject: JSON: Add support for socket expression Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/parser_json.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/parser_json.c') diff --git a/src/parser_json.c b/src/parser_json.c index e340bebc..d60cbad8 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -345,6 +346,27 @@ static struct expr *json_parse_meta_expr(struct json_ctx *ctx, return meta_expr_alloc(int_loc, key); } +static struct expr *json_parse_socket_expr(struct json_ctx *ctx, + const char *type, json_t *root) +{ + const char *key; + int keyval = -1; + + + if (json_unpack_err(ctx, root, "{s:s}", "key", &key)) + return NULL; + + if (!strcmp(key, "transparent")) + keyval = NFT_SOCKET_TRANSPARENT; + + if (keyval == -1) { + json_error(ctx, "Invalid socket key value."); + return NULL; + } + + return socket_expr_alloc(int_loc, keyval); +} + static int json_parse_payload_field(const struct proto_desc *desc, const char *name, int *field) { @@ -1157,6 +1179,7 @@ static struct expr *json_parse_expr(struct json_ctx *ctx, json_t *root) { "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 }, { "meta", json_parse_meta_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_MAP }, + { "socket", json_parse_socket_expr, CTX_F_PRIMARY }, { "rt", json_parse_rt_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_SES | CTX_F_MAP }, { "ct", json_parse_ct_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_MAP }, { "numgen", json_parse_numgen_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_SES | CTX_F_MAP }, -- cgit v1.2.3