]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
src: add queue expr and flags to queue_stmt_alloc
authorFlorian Westphal <fw@strlen.de>
Tue, 15 Jun 2021 23:45:29 +0000 (01:45 +0200)
committerFlorian Westphal <fw@strlen.de>
Mon, 21 Jun 2021 12:44:58 +0000 (14:44 +0200)
Preparation patch to avoid too much $<stmt>$ references in the parser.

Signed-off-by: Florian Westphal <fw@strlen.de>
include/statement.h
src/netlink_delinearize.c
src/parser_bison.y
src/parser_json.c
src/statement.c

index 7637a82e4e00295dcabf9541f08d2486aaab30c8..06221040fa0c5aa2f4b66532b9995d56b7b82db0 100644 (file)
@@ -159,7 +159,8 @@ struct queue_stmt {
        uint16_t                flags;
 };
 
-extern struct stmt *queue_stmt_alloc(const struct location *loc);
+extern struct stmt *queue_stmt_alloc(const struct location *loc,
+                                    struct expr *e, uint16_t flags);
 
 struct quota_stmt {
        uint64_t                bytes;
index 58daa4e0a265a9c39ffbf7645244f97128b30bdd..5849780996a6e250cae7255fe6fa11e82613893c 100644 (file)
@@ -1467,9 +1467,8 @@ static void netlink_parse_queue(struct netlink_parse_ctx *ctx,
                              const struct location *loc,
                              const struct nftnl_expr *nle)
 {
+       uint16_t num, total, flags;
        struct expr *expr, *high;
-       struct stmt *stmt;
-       uint16_t num, total;
 
        num   = nftnl_expr_get_u16(nle, NFTNL_EXPR_QUEUE_NUM);
        total = nftnl_expr_get_u16(nle, NFTNL_EXPR_QUEUE_TOTAL);
@@ -1483,11 +1482,8 @@ static void netlink_parse_queue(struct netlink_parse_ctx *ctx,
                expr = range_expr_alloc(loc, expr, high);
        }
 
-       stmt = queue_stmt_alloc(loc);
-       stmt->queue.queue = expr;
-       stmt->queue.flags = nftnl_expr_get_u16(nle, NFTNL_EXPR_QUEUE_FLAGS);
-
-       ctx->stmt = stmt;
+       flags = nftnl_expr_get_u16(nle, NFTNL_EXPR_QUEUE_FLAGS);
+       ctx->stmt = queue_stmt_alloc(loc, expr, flags);
 }
 
 struct dynset_parse_ctx {
index a329538a5ca889bf7debcc5705566bd064931c6d..7883437f4cca432194b8746e0f12ac0e3143b3fd 100644 (file)
@@ -3744,7 +3744,7 @@ queue_stmt                :       queue_stmt_alloc        close_scope_queue
 
 queue_stmt_alloc       :       QUEUE
                        {
-                               $$ = queue_stmt_alloc(&@$);
+                               $$ = queue_stmt_alloc(&@$, NULL, 0);
                        }
                        ;
 
index bb0e4169b477d296f82dc2f2fc433b74d334a2d2..e03b51697cb7bbc90aab008de43cae96ded3b1db 100644 (file)
@@ -2559,14 +2559,14 @@ static int queue_flag_parse(const char *name, uint16_t *flags)
 static struct stmt *json_parse_queue_stmt(struct json_ctx *ctx,
                                          const char *key, json_t *value)
 {
-       struct stmt *stmt = queue_stmt_alloc(int_loc);
+       struct expr *qexpr = NULL;
+       uint16_t flags = 0;
        json_t *tmp;
 
        if (!json_unpack(value, "{s:o}", "num", &tmp)) {
-               stmt->queue.queue = json_parse_stmt_expr(ctx, tmp);
-               if (!stmt->queue.queue) {
+               qexpr = json_parse_stmt_expr(ctx, tmp);
+               if (!qexpr) {
                        json_error(ctx, "Invalid queue num.");
-                       stmt_free(stmt);
                        return NULL;
                }
        }
@@ -2578,15 +2578,15 @@ static struct stmt *json_parse_queue_stmt(struct json_ctx *ctx,
                if (json_is_string(tmp)) {
                        flag = json_string_value(tmp);
 
-                       if (queue_flag_parse(flag, &stmt->queue.flags)) {
+                       if (queue_flag_parse(flag, &flags)) {
                                json_error(ctx, "Invalid queue flag '%s'.",
                                           flag);
-                               stmt_free(stmt);
+                               expr_free(qexpr);
                                return NULL;
                        }
                } else if (!json_is_array(tmp)) {
                        json_error(ctx, "Unexpected object type in queue flags.");
-                       stmt_free(stmt);
+                       expr_free(qexpr);
                        return NULL;
                }
 
@@ -2594,20 +2594,20 @@ static struct stmt *json_parse_queue_stmt(struct json_ctx *ctx,
                        if (!json_is_string(val)) {
                                json_error(ctx, "Invalid object in queue flag array at index %zu.",
                                           index);
-                               stmt_free(stmt);
+                               expr_free(qexpr);
                                return NULL;
                        }
                        flag = json_string_value(val);
 
-                       if (queue_flag_parse(flag, &stmt->queue.flags)) {
+                       if (queue_flag_parse(flag, &flags)) {
                                json_error(ctx, "Invalid queue flag '%s'.",
                                           flag);
-                               stmt_free(stmt);
+                               expr_free(qexpr);
                                return NULL;
                        }
                }
        }
-       return stmt;
+       return queue_stmt_alloc(int_loc, qexpr, flags);
 }
 
 static struct stmt *json_parse_connlimit_stmt(struct json_ctx *ctx,
index 7537c07f495c502f763373e0e3c40da3d03f6112..a713952c0af7247d5e6b86a91f3849c91da3eca2 100644 (file)
@@ -522,9 +522,15 @@ static const struct stmt_ops queue_stmt_ops = {
        .destroy        = queue_stmt_destroy,
 };
 
-struct stmt *queue_stmt_alloc(const struct location *loc)
+struct stmt *queue_stmt_alloc(const struct location *loc, struct expr *e, uint16_t flags)
 {
-       return stmt_alloc(loc, &queue_stmt_ops);
+       struct stmt *stmt;
+
+       stmt = stmt_alloc(loc, &queue_stmt_ops);
+       stmt->queue.queue = e;
+       stmt->queue.flags = flags;
+
+       return stmt;
 }
 
 static void quota_stmt_print(const struct stmt *stmt, struct output_ctx *octx)