]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: make raw payloads work
authorFlorian Westphal <fw@strlen.de>
Sun, 25 Feb 2018 18:46:04 +0000 (19:46 +0100)
committerFlorian Westphal <fw@strlen.de>
Mon, 26 Feb 2018 17:29:39 +0000 (18:29 +0100)
make syntax consistent between print and parse.
No dependency handling -- once you use raw expression, you need
to make sure the raw expression only sees the packets that you'd
want it to see.

based on an earlier patch from Laurent Fasnacht <l@libres.ch>.
Laurents patch added a different syntax:
   @<protocol>,<base>,<data type>,<offset>,<length>

data_type is useful to make nftables not err when
asking for "@payload,32,32 192.168.0.1", this patch still requires
manual convsersion to an integer type (hex or decimal notation).

data_type should probably be added later by adding an explicit
cast expression, independent of the raw payload syntax.

Signed-off-by: Florian Westphal <fw@strlen.de>
include/expression.h
src/evaluate.c
src/parser_bison.y
src/payload.c

index 0a0e178fe4680d73bec70d5b46cdfd61eb8fb39a..26182120f63dbd30829a53eda16c95ff1976bc24 100644 (file)
@@ -279,6 +279,7 @@ struct expr {
                        const struct proto_hdr_template *tmpl;
                        enum proto_bases                base;
                        unsigned int                    offset;
+                       bool                            is_raw;
                } payload;
                struct {
                        /* EXPR_EXTHDR */
index c98749d92a21a5238060779c093fabe922a036ab..6be3bf031f58710a9c8ad350e98888ab3cd206e8 100644 (file)
@@ -609,6 +609,9 @@ static int __expr_evaluate_payload(struct eval_ctx *ctx, struct expr *expr)
        struct stmt *nstmt;
        int err;
 
+       if (expr->ops->type == EXPR_PAYLOAD && expr->payload.is_raw)
+               return 0;
+
        desc = ctx->pctx.protocol[base].desc;
        if (desc == NULL) {
                if (payload_gen_dependency(ctx, payload, &nstmt) < 0)
index 563411155bf40313e9bad01da0f85965fe853be3..ec8b0dd894feaf9bad35aa38a20f8c13ed274f5c 100644 (file)
@@ -3465,6 +3465,9 @@ payload_raw_expr  :       AT      payload_base_spec       COMMA   NUM     COMMA   NUM
                                $$->payload.offset      = $4;
                                $$->len                 = $6;
                                $$->dtype               = &integer_type;
+                               $$->byteorder           = BYTEORDER_BIG_ENDIAN;
+                               $$->payload.is_raw      = true;
+                               $$->flags               = 0;
                        }
                        ;
 
index ef437b440b289e470370800513c22d236a87dcd5..09665a0e815689111a23415bf608ac28a1c4915c 100644 (file)
@@ -48,7 +48,7 @@ static void payload_expr_print(const struct expr *expr, struct output_ctx *octx)
        if (payload_is_known(expr))
                nft_print(octx, "%s %s", desc->name, tmpl->token);
        else
-               nft_print(octx, "payload @%s,%u,%u",
+               nft_print(octx, "@%s,%u,%u",
                          proto_base_tokens[expr->payload.base],
                          expr->payload.offset, expr->len);
 }