path: root/src/parser_json.c
diff options
authorPhil Sutter <>2018-05-28 18:51:03 +0200
committerPablo Neira Ayuso <>2018-06-01 09:16:48 +0200
commitbc3e9adc19bc1624010dd478b5e9f006b072298c (patch)
treeeccfeecca63893e5724c6cc960bc390accb2459e /src/parser_json.c
parentc36288dbe2ba363586424c2951fd715873608581 (diff)
JSON: Simplify tcp option expression parsing a bit
When parsing the optional "field" property, use return code of json_unpack() directly to check if it was present or not. Signed-off-by: Phil Sutter <> Signed-off-by: Pablo Neira Ayuso <>
Diffstat (limited to 'src/parser_json.c')
1 files changed, 2 insertions, 3 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index f3d2c0f1..bd1c0a04 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -479,20 +479,19 @@ static struct expr *json_parse_payload_expr(struct json_ctx *ctx,
static struct expr *json_parse_tcp_option_expr(struct json_ctx *ctx,
const char *type, json_t *root)
- const char *desc, *field = NULL;
+ const char *desc, *field;
int descval, fieldval;
struct expr *expr;
if (json_unpack_err(ctx, root, "{s:s}", "name", &desc))
return NULL;
- json_unpack(root, "{s:s}", "field", &field);
if (json_parse_tcp_option_type(desc, &descval)) {
json_error(ctx, "Unknown tcp option name '%s'.", desc);
return NULL;
- if (!field) {
+ if (json_unpack(root, "{s:s}", "field", &field)) {
expr = tcpopt_expr_alloc(int_loc, descval,
expr->exthdr.flags = NFT_EXTHDR_F_PRESENT;