]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: json: support json restore for "th" pseudoheader
authorFlorian Westphal <fw@strlen.de>
Wed, 14 Aug 2019 11:34:52 +0000 (13:34 +0200)
committerFlorian Westphal <fw@strlen.de>
Wed, 14 Aug 2019 13:26:30 +0000 (15:26 +0200)
Json output could not be restored back by nft because it did
not recognize the new "th" pseudoheader.

Fixes: a43a696443a150f44 ("proto: add pseudo th protocol to match d/sport in generic way")
Signed-off-by: Florian Westphal <fw@strlen.de>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/parser_json.c

index 956233b92b92ee961ee6eca822930223c6360758..d42bab704f7cde1884330c0027a240088e27902d 100644 (file)
@@ -503,7 +503,8 @@ static const struct proto_desc *proto_lookup_byname(const char *name)
                &proto_udplite,
                &proto_tcp,
                &proto_dccp,
-               &proto_sctp
+               &proto_sctp,
+               &proto_th,
        };
        unsigned int i;
 
@@ -519,11 +520,10 @@ static struct expr *json_parse_payload_expr(struct json_ctx *ctx,
 {
        const char *protocol, *field, *base;
        int offset, len, val;
+       struct expr *expr;
 
        if (!json_unpack(root, "{s:s, s:i, s:i}",
                         "base", &base, "offset", &offset, "len", &len)) {
-               struct expr *expr;
-
                if (!strcmp(base, "ll")) {
                        val = PROTO_BASE_LL_HDR;
                } else if (!strcmp(base, "nh")) {
@@ -553,7 +553,12 @@ static struct expr *json_parse_payload_expr(struct json_ctx *ctx,
                                   protocol, field);
                        return NULL;
                }
-               return payload_expr_alloc(int_loc, proto, val);
+               expr = payload_expr_alloc(int_loc, proto, val);
+
+               if (proto == &proto_th)
+                       expr->payload.is_raw = true;
+
+               return expr;
        }
        json_error(ctx, "Invalid payload expression properties.");
        return NULL;