]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Save the "use-service" rule in the stream to init a service applet
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Apr 2025 14:08:48 +0000 (16:08 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Apr 2025 14:22:24 +0000 (16:22 +0200)
When a service is initialized, the "use-service" rule that was executed is
now saved in the stream, using "current_rule" field, instead of saving it
into the applet context. It is safe to do so becaues this field is unused at
this stage. To avoid any issue, it is reset after the service
initialization. Doing so, it is no longer necessary to save it in the applet
context. It was the last usage of the rule pointer in the applet context.

The init functions for TCP and HTTP lua services were updated accordingly.

src/hlua.c
src/stream.c

index 53ed8952170a185f94985f205bfa6c97390f8c03..b15e416f938882c39be69a690111030196900203 100644 (file)
@@ -10925,6 +10925,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
        struct hlua_tcp_ctx *tcp_ctx = applet_reserve_svcctx(ctx, sizeof(*tcp_ctx));
        struct stconn *sc = appctx_sc(ctx);
        struct stream *strm = __sc_strm(sc);
+       struct act_rule *rule = strm->current_rule;
        struct hlua *hlua;
        struct task *task;
        char **arg;
@@ -10957,7 +10958,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
         * permits to save performances because a systematic
         * Lua initialization cause 5% performances loss.
         */
-       if (!hlua_ctx_init(hlua, fcn_ref_to_stack_id(ctx->rule->arg.hlua_rule->fcn), task)) {
+       if (!hlua_ctx_init(hlua, fcn_ref_to_stack_id(rule->arg.hlua_rule->fcn), task)) {
                SEND_ERR(strm->be, "Lua applet tcp '%s': can't initialize Lua context.\n",
                         ctx->applet->name);
                return -1;
@@ -10988,7 +10989,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
        }
 
        /* Restore the function in the stack. */
-       hlua_pushref(hlua->T, ctx->rule->arg.hlua_rule->fcn->function_ref[hlua->state_id]);
+       hlua_pushref(hlua->T, rule->arg.hlua_rule->fcn->function_ref[hlua->state_id]);
 
        /* Create and and push object stream in the stack. */
        if (!hlua_applet_tcp_new(hlua->T, ctx)) {
@@ -11000,7 +11001,7 @@ static int hlua_applet_tcp_init(struct appctx *ctx)
        hlua->nargs = 1;
 
        /* push keywords in the stack. */
-       for (arg = ctx->rule->arg.hlua_rule->args; arg && *arg; arg++) {
+       for (arg = rule->arg.hlua_rule->args; arg && *arg; arg++) {
                if (!lua_checkstack(hlua->T, 1)) {
                        SEND_ERR(strm->be, "Lua applet tcp '%s': full stack.\n",
                                 ctx->applet->name);
@@ -11128,6 +11129,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
        struct hlua_http_ctx *http_ctx = applet_reserve_svcctx(ctx, sizeof(*http_ctx));
        struct stconn *sc = appctx_sc(ctx);
        struct stream *strm = __sc_strm(sc);
+       struct act_rule *rule = strm->current_rule;
        struct http_txn *txn;
        struct hlua *hlua;
        char **arg;
@@ -11166,7 +11168,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
         * permits to save performances because a systematic
         * Lua initialization cause 5% performances loss.
         */
-       if (!hlua_ctx_init(hlua, fcn_ref_to_stack_id(ctx->rule->arg.hlua_rule->fcn), task)) {
+       if (!hlua_ctx_init(hlua, fcn_ref_to_stack_id(rule->arg.hlua_rule->fcn), task)) {
                SEND_ERR(strm->be, "Lua applet http '%s': can't initialize Lua context.\n",
                         ctx->applet->name);
                return -1;
@@ -11197,7 +11199,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
        }
 
        /* Restore the function in the stack. */
-       hlua_pushref(hlua->T, ctx->rule->arg.hlua_rule->fcn->function_ref[hlua->state_id]);
+       hlua_pushref(hlua->T, rule->arg.hlua_rule->fcn->function_ref[hlua->state_id]);
 
        /* Create and and push object stream in the stack. */
        if (!hlua_applet_http_new(hlua->T, ctx)) {
@@ -11209,7 +11211,7 @@ static int hlua_applet_http_init(struct appctx *ctx)
        hlua->nargs = 1;
 
        /* push keywords in the stack. */
-       for (arg = ctx->rule->arg.hlua_rule->args; arg && *arg; arg++) {
+       for (arg = rule->arg.hlua_rule->args; arg && *arg; arg++) {
                if (!lua_checkstack(hlua->T, 1)) {
                        SEND_ERR(strm->be, "Lua applet http '%s': full stack.\n",
                                 ctx->applet->name);
index ab479f0624e779d9f7690fd56829d71684b3476e..46f77cc98cdaabf343b1bb1926ab9f6de1d92aac 100644 (file)
@@ -1051,9 +1051,10 @@ enum act_return process_use_service(struct act_rule *rule, struct proxy *px,
                        return ACT_RET_ERR;
 
                /* Finish initialisation of the context. */
-               appctx->rule = rule;
+               s->current_rule = rule;
                if (appctx_init(appctx) == -1)
                        return ACT_RET_ERR;
+               s->current_rule = NULL;
        }
        else
                appctx = __sc_appctx(s->scb);