]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: session: automatically register the applet designated by the target
authorWilly Tarreau <w@1wt.eu>
Sun, 1 Dec 2013 11:25:52 +0000 (12:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 9 Dec 2013 14:40:23 +0000 (15:40 +0100)
Some applet users don't need to initialize their applet, they just want
to route the traffic there just as if it were a server. Since applets
are now connected to from session.c, let's simply ensure that when
connecting, the applet in si->end matches the target, and allocate
one there if it's not already done. In case of error, we force the
status code to resource and connection so that it's clear that it
happens because of a memory shortage.

src/session.c

index 3122380a3792b97d0437e21c9d9ecb9a59ad6f6e..1183d91e308a746579c74841bf11953fe5e6d3e7 100644 (file)
@@ -1162,6 +1162,29 @@ static void sess_prepare_conn_req(struct session *s, struct stream_interface *si
 
        if (unlikely(obj_type(s->target) == OBJ_TYPE_APPLET)) {
                /* the applet directly goes to the EST state */
+               struct appctx *appctx = objt_appctx(si->end);
+
+               if (!appctx || appctx->applet != __objt_applet(s->target))
+                       appctx = stream_int_register_handler(si, objt_applet(s->target));
+
+               if (!appctx) {
+                       /* No more memory, let's immediately abort. Force the
+                        * error code to ignore the ERR_LOCAL which is not a
+                        * real error.
+                        */
+                       s->flags = (s->flags & ~SN_ERR_MASK) | SN_ERR_RESOURCE;
+                       s->flags = (s->flags & ~SN_FINST_MASK) | SN_FINST_C;
+
+                       si_shutr(si);
+                       si_shutw(si);
+                       si->ob->flags |= CF_WRITE_ERROR;
+                       si->err_type = SI_ET_CONN_OTHER;
+                       si->state = SI_ST_CLO;
+                       if (s->srv_error)
+                               s->srv_error(s, si);
+                       return;
+               }
+
                s->logs.t_queue   = tv_ms_elapsed(&s->logs.tv_accept, &now);
                s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now);
                si->state         = SI_ST_EST;