diff options
author | Alvaro Neira <alvaroneay@gmail.com> | 2014-09-30 17:21:38 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2014-10-09 13:22:55 +0200 |
commit | ffac724a876d1fb3ae08b7da727d251a6762358c (patch) | |
tree | e3d51d13203c0cd48427fbc1fac4765f5264f3ba /src/payload.c | |
parent | 389545e6fda863f8804b513b8dca4c4db4a7c5a6 (diff) |
src: Enhance payload_gen_dependency()
With this patch, this function returns a statement with the new dependency
that we want to add, instead of an expression.
This change is needed in a follow up patch.
Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/payload.c')
-rw-r--r-- | src/payload.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/payload.c b/src/payload.c index a3bbe51e..b7b74edd 100644 --- a/src/payload.c +++ b/src/payload.c @@ -21,6 +21,7 @@ #include <rule.h> #include <expression.h> +#include <statement.h> #include <payload.h> #include <gmputil.h> #include <utils.h> @@ -160,12 +161,13 @@ void payload_init_raw(struct expr *expr, enum proto_bases base, * in the input path though. */ int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr, - struct expr **res) + struct stmt **res) { const struct hook_proto_desc *h = &hook_proto_desc[ctx->pctx.family]; const struct proto_desc *desc; const struct proto_hdr_template *tmpl; struct expr *dep, *left, *right; + struct stmt *stmt; int protocol; uint16_t type; @@ -186,7 +188,12 @@ int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr, 2 * BITS_PER_BYTE, &type); dep = relational_expr_alloc(&expr->location, OP_EQ, left, right); - *res = dep; + stmt = expr_stmt_alloc(&dep->location, dep); + if (stmt_evaluate(ctx, stmt) < 0) { + return expr_error(ctx->msgs, expr, + "dependency statement is invalid"); + } + *res = stmt; return 0; } @@ -220,8 +227,13 @@ int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr, constant_data_ptr(protocol, tmpl->len)); dep = relational_expr_alloc(&expr->location, OP_EQ, left, right); + stmt = expr_stmt_alloc(&dep->location, dep); + if (stmt_evaluate(ctx, stmt) < 0) { + return expr_error(ctx->msgs, expr, + "dependency statement is invalid"); + } left->ops->pctx_update(&ctx->pctx, dep); - *res = dep; + *res = stmt; return 0; } |