diff options
author | Phil Sutter <phil@nwl.cc> | 2019-05-09 13:35:41 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2019-05-09 17:19:50 +0200 |
commit | 1b8953e75c20437b5c563d86c3ba11d1b24e3ec4 (patch) | |
tree | 6d71a2ffbede3d03f74d350a0a9feb81551f7b7d /src/json.c | |
parent | 43cb4f27da74184da350c62cad8dd573590b09c6 (diff) |
json: Fix tproxy support regarding latest changes
Family may be specified also if no address is given at the same time,
make parser/printer tolerant to that. Also fix for missing/incorrect
JSON equivalents in tests/py.
While being at it, fix two issues in non-JSON tests:
* Ruleset is printed in numeric mode, so use 'l4proto 6' instead of
'l4proto tcp' in rules to avoid having to specify expected output for
that unrelated bit.
* In ip and ip6 family tables, family parameter is not deserialized on
output.
Fixes: 3edb96200690b ("parser_bison: missing tproxy syntax with port only for inet family")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 23 |
1 files changed, 10 insertions, 13 deletions
@@ -1437,26 +1437,23 @@ json_t *connlimit_stmt_json(const struct stmt *stmt, struct output_ctx *octx) json_t *tproxy_stmt_json(const struct stmt *stmt, struct output_ctx *octx) { - json_t *root = json_object(); - - if (stmt->tproxy.addr) { - int family; - json_t *tmp; - - family = stmt->tproxy.table_family; - if (family == NFPROTO_INET) - family = stmt->tproxy.family; + json_t *tmp, *root = json_object(); - tmp = json_string(family2str(family)); + if (stmt->tproxy.table_family == NFPROTO_INET && + stmt->tproxy.family != NFPROTO_UNSPEC) { + tmp = json_string(family2str(stmt->tproxy.family)); json_object_set_new(root, "family", tmp); + } + if (stmt->tproxy.addr) { tmp = expr_print_json(stmt->tproxy.addr, octx); json_object_set_new(root, "addr", tmp); } - if (stmt->tproxy.port) - json_object_set_new(root, "port", - expr_print_json(stmt->tproxy.port, octx)); + if (stmt->tproxy.port) { + tmp = expr_print_json(stmt->tproxy.port, octx); + json_object_set_new(root, "port", tmp); + } return json_pack("{s:o}", "tproxy", root); } |