]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
JSON: Simplify tcp option expression parsing a bit
authorPhil Sutter <phil@nwl.cc>
Mon, 28 May 2018 16:51:03 +0000 (18:51 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 1 Jun 2018 07:16:48 +0000 (09:16 +0200)
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 <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/parser_json.c

index f3d2c0f1d3dfcf020b34a43411e8b66e229b6429..bd1c0a04993c830c1e2034f5a6102d49a877ad90 100644 (file)
@@ -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,
                                         TCPOPTHDR_FIELD_KIND);
                expr->exthdr.flags = NFT_EXTHDR_F_PRESENT;