summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/json.c13
-rw-r--r--src/parser_json.c40
2 files changed, 49 insertions, 4 deletions
diff --git a/src/json.c b/src/json.c
index a871c934..c1cd0fbf 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1008,9 +1008,18 @@ json_t *limit_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
json_t *fwd_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
{
- json_t *root;
+ json_t *root, *tmp;
+
+ root = json_pack("{s:o}", "dev", expr_print_json(stmt->fwd.dev, octx));
+
+ if (stmt->fwd.addr) {
+ tmp = json_string(family2str(stmt->fwd.family));
+ json_object_set_new(root, "family", tmp);
+
+ tmp = expr_print_json(stmt->fwd.addr, octx);
+ json_object_set_new(root, "addr", tmp);
+ }
- root = expr_print_json(stmt->fwd.dev, octx);
return json_pack("{s:o}", "fwd", root);
}
diff --git a/src/parser_json.c b/src/parser_json.c
index bc36136f..2fd0ef83 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1584,11 +1584,47 @@ static struct stmt *json_parse_limit_stmt(struct json_ctx *ctx,
static struct stmt *json_parse_fwd_stmt(struct json_ctx *ctx,
const char *key, json_t *value)
{
- struct stmt *stmt = fwd_stmt_alloc(int_loc);
+ json_t *jaddr, *jdev;
+ const char *family;
+ struct stmt *stmt;
+ int familyval;
+
+ if (json_unpack_err(ctx, value, "{s:o}", "dev", &jdev))
+ return NULL;
- stmt->fwd.dev = json_parse_expr(ctx, value);
+ stmt = fwd_stmt_alloc(int_loc);
+
+ stmt->fwd.dev = json_parse_stmt_expr(ctx, jdev);
+ if (!stmt->fwd.dev) {
+ json_error(ctx, "Invalid fwd dev value.");
+ goto out_err;
+ }
+
+ if (json_unpack(value, "{s:s, s:o}",
+ "family", &family, "addr", &jaddr))
+ return stmt;
+
+ familyval = parse_family(family);
+ switch (familyval) {
+ case NFPROTO_IPV4:
+ case NFPROTO_IPV6:
+ stmt->fwd.family = familyval;
+ break;
+ default:
+ json_error(ctx, "Invalid fwd family value '%s'.", family);
+ goto out_err;
+ }
+
+ stmt->fwd.addr = json_parse_stmt_expr(ctx, jaddr);
+ if (!stmt->fwd.addr) {
+ json_error(ctx, "Invalid fwd addr value.");
+ goto out_err;
+ }
return stmt;
+out_err:
+ stmt_free(stmt);
+ return NULL;
}
static struct stmt *json_parse_notrack_stmt(struct json_ctx *ctx,