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
conversion to big-endian hex 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 <f...@strlen.de>
---
 include/expression.h | 1 +
 src/evaluate.c       | 3 +++
 src/parser_bison.y   | 3 +++
 src/payload.c        | 2 +-
 4 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/include/expression.h b/include/expression.h
index 0a0e178fe468..26182120f63d 100644
--- a/include/expression.h
+++ b/include/expression.h
@@ -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 */
diff --git a/src/evaluate.c b/src/evaluate.c
index c98749d92a21..6be3bf031f58 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -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)
diff --git a/src/parser_bison.y b/src/parser_bison.y
index 563411155bf4..ec8b0dd894fe 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -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;
                        }
                        ;
 
diff --git a/src/payload.c b/src/payload.c
index ef437b440b28..09665a0e8156 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -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);
 }
-- 
2.16.1

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to