]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: Enhance payload_gen_dependency()
authorAlvaro Neira <alvaroneay@gmail.com>
Tue, 30 Sep 2014 15:21:38 +0000 (17:21 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 9 Oct 2014 11:22:55 +0000 (13:22 +0200)
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>
include/payload.h
include/statement.h
src/evaluate.c
src/payload.c

index d47e56458f8213a1fb7b9f4e658ad7b2d07e9f54..95364af1410d478f399118b8417e71ee9d801755 100644 (file)
@@ -11,8 +11,9 @@ extern void payload_init_raw(struct expr *expr, enum proto_bases base,
                             unsigned int offset, unsigned int len);
 
 struct eval_ctx;
+struct stmt;
 extern int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr,
-                                 struct expr **res);
+                                 struct stmt **res);
 
 extern bool payload_is_adjacent(const struct expr *e1, const struct expr *e2);
 extern struct expr *payload_expr_join(const struct expr *e1,
index e2f02b8c1c1cd385d818fdba61a2e0cdc4f5576c..7a57f7ddd7ec96f73ada76e592c3ece4d7c53b6b 100644 (file)
@@ -166,6 +166,7 @@ struct stmt {
 
 extern struct stmt *stmt_alloc(const struct location *loc,
                               const struct stmt_ops *ops);
+int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt);
 extern void stmt_free(struct stmt *stmt);
 extern void stmt_list_free(struct list_head *list);
 extern void stmt_print(const struct stmt *stmt);
index 284ee72a840cddd8e84fe307b8a00e9dc05109d0..52ce5487f2f0aa678e8371bf0615412348647977 100644 (file)
@@ -26,7 +26,6 @@
 #include <utils.h>
 
 static int expr_evaluate(struct eval_ctx *ctx, struct expr **expr);
-static int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt);
 
 static const char *byteorder_names[] = {
        [BYTEORDER_INVALID]             = "invalid",
@@ -271,13 +270,9 @@ static int expr_evaluate_payload(struct eval_ctx *ctx, struct expr **expr)
        struct expr *payload = *expr;
        enum proto_bases base = payload->payload.base;
        struct stmt *nstmt;
-       struct expr *nexpr;
 
        if (ctx->pctx.protocol[base].desc == NULL) {
-               if (payload_gen_dependency(ctx, payload, &nexpr) < 0)
-                       return -1;
-               nstmt = expr_stmt_alloc(&nexpr->location, nexpr);
-               if (stmt_evaluate(ctx, nstmt) < 0)
+               if (payload_gen_dependency(ctx, payload, &nstmt) < 0)
                        return -1;
                list_add_tail(&nstmt->list, &ctx->stmt->list);
        } else if (ctx->pctx.protocol[base].desc != payload->payload.desc)
@@ -1205,7 +1200,7 @@ static int stmt_evaluate_log(struct eval_ctx *ctx, struct stmt *stmt)
        return 0;
 }
 
-static int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
+int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt)
 {
 #ifdef DEBUG
        if (debug_level & DEBUG_EVALUATION) {
index a3bbe51ebf4f84b42c15f30db8fca35e0f794d04..b7b74edd2049a88d6c8072501032688ee5cee8d6 100644 (file)
@@ -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;
 }