]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: spoe: Always link a SPOE context with the applet processing it
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 24 Jan 2018 14:59:32 +0000 (15:59 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 2 Feb 2018 15:00:32 +0000 (16:00 +0100)
This was already done for fragmented frames. Now, this is true for all
frames.

include/types/spoe.h
src/flt_spoe.c

index 3e819448c547050b386872fd126e35bb4b0d6bc7..30510565d25b30c67549cee6c6bde438857aea66 100644 (file)
@@ -305,8 +305,8 @@ struct spoe_context {
        unsigned int        frame_id;     /* to map NOTIFY and ACK frames */
        unsigned int        process_exp;  /* expiration date to process an event */
 
+       struct spoe_appctx *spoe_appctx; /* SPOE appctx sending the current frame */
        struct {
-               struct spoe_appctx  *spoe_appctx; /* SPOE appctx sending the fragmented frame */
                struct spoe_message *curmsg;      /* SPOE message from which to resume encoding */
                struct spoe_arg     *curarg;      /* SPOE arg in <curmsg> from which to resume encoding */
                unsigned int         curoff;      /* offset in <curarg> from which to resume encoding */
index 0c221f3f1ddd7f371a4349bdf9e19ce8372a97e8..1d8e4e9ffb1a9e8610b5d06501ba5e9044918a87 100644 (file)
@@ -981,7 +981,6 @@ spoe_handle_agentack_frame(struct appctx *appctx, struct spoe_context **ctx,
                /* ABRT bit is set for an unfinished fragmented frame */
                if (flags & SPOE_FRM_FL_ABRT) {
                        *ctx = SPOE_APPCTX(appctx)->frag_ctx.ctx;
-                       (*ctx)->frag_ctx.spoe_appctx = NULL;
                        (*ctx)->state = SPOE_CTX_ST_ERROR;
                        (*ctx)->status_code = SPOE_CTX_ERR_FRAG_FRAME_ABRT;
                        /* Ignore the payload */
@@ -1252,7 +1251,7 @@ spoe_release_appctx(struct appctx *appctx)
         * corresponding stream. */
        if (spoe_appctx->frag_ctx.ctx) {
                ctx = spoe_appctx->frag_ctx.ctx;
-               ctx->frag_ctx.spoe_appctx = NULL;
+               ctx->spoe_appctx = NULL;
                ctx->state = SPOE_CTX_ST_ERROR;
                ctx->status_code = (spoe_appctx->status_code + 0x100);
                task_wakeup(ctx->strm->task, TASK_WOKEN_MSG);
@@ -1471,6 +1470,7 @@ spoe_handle_sending_frame_appctx(struct appctx *appctx, int *skip)
                        spoe_release_buffer(&ctx->buffer, &ctx->buffer_wait);
                        LIST_DEL(&ctx->list);
                        LIST_INIT(&ctx->list);
+                       ctx->spoe_appctx = NULL;
                        ctx->state = SPOE_CTX_ST_ERROR;
                        ctx->status_code = (SPOE_APPCTX(appctx)->status_code + 0x100);
                        task_wakeup(ctx->strm->task, TASK_WOKEN_MSG);
@@ -1487,6 +1487,7 @@ spoe_handle_sending_frame_appctx(struct appctx *appctx, int *skip)
                        spoe_release_buffer(&ctx->buffer, &ctx->buffer_wait);
                        LIST_DEL(&ctx->list);
                        LIST_INIT(&ctx->list);
+                       ctx->spoe_appctx = SPOE_APPCTX(appctx);
                        if (!(ctx->flags & SPOE_CTX_FL_FRAGMENTED) ||
                            (ctx->frag_ctx.flags & SPOE_FRM_FL_FIN))
                                goto no_frag_frame_sent;
@@ -1502,8 +1503,6 @@ spoe_handle_sending_frame_appctx(struct appctx *appctx, int *skip)
        SPOE_APPCTX(appctx)->frag_ctx.ctx    = ctx;
        SPOE_APPCTX(appctx)->frag_ctx.cursid = ctx->stream_id;
        SPOE_APPCTX(appctx)->frag_ctx.curfid = ctx->frame_id;
-
-       ctx->frag_ctx.spoe_appctx = SPOE_APPCTX(appctx);
        ctx->state = SPOE_CTX_ST_ENCODING_MSGS;
        task_wakeup(ctx->strm->task, TASK_WOKEN_MSG);
        goto end;
@@ -1525,7 +1524,6 @@ spoe_handle_sending_frame_appctx(struct appctx *appctx, int *skip)
        SPOE_APPCTX(appctx)->frag_ctx.cursid = 0;
        SPOE_APPCTX(appctx)->frag_ctx.curfid = 0;
 
-       ctx->frag_ctx.spoe_appctx = NULL;
        ctx->state = SPOE_CTX_ST_WAITING_ACK;
        goto end;
 
@@ -1573,7 +1571,8 @@ spoe_handle_receiving_frame_appctx(struct appctx *appctx, int *skip)
                default:
                        LIST_DEL(&ctx->list);
                        LIST_INIT(&ctx->list);
-
+                       if (ctx->spoe_appctx)
+                               ctx->spoe_appctx = NULL;
                        if (appctx->st0 == SPOE_APPCTX_ST_SENDING_FRAG_NOTIFY &&
                            ctx == SPOE_APPCTX(appctx)->frag_ctx.ctx) {
                                appctx->st0 = SPOE_APPCTX_ST_PROCESSING;
@@ -2221,7 +2220,7 @@ spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
                    (int)now.tv_sec, (int)now.tv_usec,
                    agent->id, __FUNCTION__, s,
                    ((ctx->flags & SPOE_CTX_FL_FRAGMENTED) ? "last fragment of" : "unfragmented"),
-                   ctx->frag_ctx.spoe_appctx, (agent->rt[tid].frame_size - FRAME_HDR_SIZE),
+                   ctx->spoe_appctx, (agent->rt[tid].frame_size - FRAME_HDR_SIZE),
                    p - ctx->buffer->p);
 
        ctx->buffer->i = p - ctx->buffer->p;
@@ -2243,7 +2242,7 @@ spoe_encode_messages(struct stream *s, struct spoe_context *ctx,
                    " - curmsg=%p - curarg=%p - curoff=%u"
                    " - max_size=%u - encoded=%ld\n",
                    (int)now.tv_sec, (int)now.tv_usec,
-                   agent->id, __FUNCTION__, s, ctx->frag_ctx.spoe_appctx,
+                   agent->id, __FUNCTION__, s, ctx->spoe_appctx,
                    ctx->frag_ctx.curmsg, ctx->frag_ctx.curarg, ctx->frag_ctx.curoff,
                    (agent->rt[tid].frame_size - FRAME_HDR_SIZE), p - ctx->buffer->p);
 
@@ -2455,9 +2454,9 @@ spoe_start_processing(struct spoe_context *ctx, int dir)
 static inline void
 spoe_stop_processing(struct spoe_context *ctx)
 {
-       struct spoe_appctx *sa = ctx->frag_ctx.spoe_appctx;
+       struct spoe_appctx *sa = ctx->spoe_appctx;
 
-       if (sa) {
+       if (sa && sa->frag_ctx.ctx == ctx) {
                sa->frag_ctx.ctx = NULL;
                spoe_wakeup_appctx(sa->owner);
        }
@@ -2472,7 +2471,7 @@ spoe_stop_processing(struct spoe_context *ctx)
 
        spoe_release_buffer(&ctx->buffer, &ctx->buffer_wait);
 
-       ctx->frag_ctx.spoe_appctx = NULL;
+       ctx->spoe_appctx          = NULL;
        ctx->frag_ctx.curmsg      = NULL;
        ctx->frag_ctx.curarg      = NULL;
        ctx->frag_ctx.curoff      = 0;
@@ -2578,8 +2577,8 @@ spoe_process_messages(struct stream *s, struct spoe_context *ctx,
        }
 
        if (ctx->state == SPOE_CTX_ST_SENDING_MSGS) {
-               if (ctx->frag_ctx.spoe_appctx)
-                       spoe_wakeup_appctx(ctx->frag_ctx.spoe_appctx->owner);
+               if (ctx->spoe_appctx)
+                       spoe_wakeup_appctx(ctx->spoe_appctx->owner);
                ret = 0;
                goto out;
        }