]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
json: Simplify non-tcpopt exthdr printing a bit
authorPhil Sutter <phil@nwl.cc>
Tue, 4 May 2021 11:18:11 +0000 (13:18 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 19 May 2021 09:51:43 +0000 (11:51 +0200)
This was just duplicate code apart from the object's name.

Signed-off-by: Phil Sutter <phil@nwl.cc>
src/json.c

index 69ca9697d97d3d50b8134a4cb206e62fbce42505..b611c3e0e453965136e4d1886c9fe5b85eeaeb9d 100644 (file)
@@ -711,21 +711,17 @@ json_t *exthdr_expr_json(const struct expr *expr, struct output_ctx *octx)
 
                return json_pack("{s:o}", "tcp option", root);
        }
-       if (expr->exthdr.op == NFT_EXTHDR_OP_IPV4) {
-               root = json_pack("{s:s}", "name", desc);
 
-               if (!is_exists)
-                       json_object_set_new(root, "field", json_string(field));
-
-               return json_pack("{s:o}", "ip option", root);
-       }
-
-       root = json_pack("{s:s}",
-                        "name", desc);
+       root = json_pack("{s:s}", "name", desc);
        if (!is_exists)
                json_object_set_new(root, "field", json_string(field));
 
-       return json_pack("{s:o}", "exthdr", root);
+       switch (expr->exthdr.op) {
+       case NFT_EXTHDR_OP_IPV4:
+               return json_pack("{s:o}", "ip option", root);
+       default:
+               return json_pack("{s:o}", "exthdr", root);
+       }
 }
 
 json_t *verdict_expr_json(const struct expr *expr, struct output_ctx *octx)