]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream/mux: implement websocket stream flag
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 18 Oct 2021 12:45:49 +0000 (14:45 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 3 Nov 2021 15:24:48 +0000 (16:24 +0100)
Define a new stream flag SF_WEBSOCKET and a new cs flag CS_FL_WEBSOCKET.
The conn-stream flag is first set by h1/h2 muxes if the request is a
valid websocket upgrade. The flag is then converted to SF_WEBSOCKET on
the stream creation.

This will be useful to properly manage websocket streams in
connect_server().

include/haproxy/connection-t.h
include/haproxy/stream-t.h
src/mux_h1.c
src/mux_h2.c
src/stream.c

index 68ab91ae8ae5df60cab7540fedb879fb2e7b3864..6969d8c757f074c8e56355962e440a24021f4f5c 100644 (file)
@@ -86,6 +86,9 @@ enum {
         * the stream-interface :
         */
        CS_FL_NOT_FIRST     = 0x00100000,  /* this stream is not the first one */
+
+       /* flags set by the mux relayed to the stream */
+       CS_FL_WEBSOCKET     = 0x00200000,  /* websocket stream */
 };
 
 /* cs_shutr() modes */
index b8e31658f18e87a48eb69fbc4a3be0b6c83f7a1e..72b5f3a438a8c531dc5ebe8967de485477a70056 100644 (file)
@@ -80,6 +80,7 @@
 
 #define SF_SRV_REUSED   0x00100000     /* the server-side connection was reused */
 #define SF_SRV_REUSED_ANTICIPATED  0x00200000  /* the connection was reused but the mux is not ready yet */
+#define SF_WEBSOCKET    0x00400000     /* websocket stream */
 
 /* flags for the proxy of the master CLI */
 /* 0x1.. to 0x3 are reserved for ACCESS_LVL_MASK */
index 467d593c5ec66c2d3aa8305463160e9515cce4ad..63270e91495e685fc685f14d1596c8a2da2918a4 100644 (file)
@@ -589,6 +589,9 @@ static struct conn_stream *h1s_new_cs(struct h1s *h1s, struct buffer *input)
        if (h1s->flags & H1S_F_NOT_FIRST)
                cs->flags |= CS_FL_NOT_FIRST;
 
+       if (h1s->req.flags & H1_MF_UPG_WEBSOCKET)
+               cs->flags |= CS_FL_WEBSOCKET;
+
        if (stream_create_from_cs(cs, input) < 0) {
                TRACE_DEVEL("leaving on stream creation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
                goto err;
index 90373310ee8fd9632cf94bb93b2efdc2caa779dc..ff51cb59ccb3a44d24127d1d850c00b4619472f0 100644 (file)
@@ -1509,7 +1509,7 @@ static struct h2s *h2s_new(struct h2c *h2c, int id)
  * responsible of it. On error, <input> is unchanged, thus the mux must still
  * take care of it.
  */
-static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id, struct buffer *input)
+static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id, struct buffer *input, uint32_t flags)
 {
        struct session *sess = h2c->conn->owner;
        struct conn_stream *cs;
@@ -1533,6 +1533,12 @@ static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id, struct buffer *in
        cs->ctx = h2s;
        h2c->nb_cs++;
 
+       /* FIXME wrong analogy between ext-connect and websocket, this need to
+        * be refine.
+        */
+       if (flags & H2_SF_EXT_CONNECT_RCVD)
+               cs->flags |= CS_FL_WEBSOCKET;
+
        if (stream_create_from_cs(cs, input) < 0)
                goto out_free_cs;
 
@@ -2747,7 +2753,7 @@ static struct h2s *h2c_frt_handle_headers(struct h2c *h2c, struct h2s *h2s)
         * Xfer the rxbuf to the stream. On success, the new stream owns the
         * rxbuf. On error, it is released here.
         */
-       h2s = h2c_frt_stream_new(h2c, h2c->dsi, &rxbuf);
+       h2s = h2c_frt_stream_new(h2c, h2c->dsi, &rxbuf, flags);
        if (!h2s) {
                h2s = (struct h2s*)h2_refused_stream;
                goto send_rst;
index 7f57d9e09c729e894d69c4726bfab5ac169ef3ef..04d2845651f1dc1b3bee76a134cf4d27288db740 100644 (file)
@@ -465,6 +465,9 @@ struct stream *stream_new(struct session *sess, enum obj_type *origin, struct bu
                        s->si[0].flags |= SI_FL_CLEAN_ABRT;
                if (cs->conn->mux->flags & MX_FL_HTX)
                        s->flags |= SF_HTX;
+
+               if (cs->flags & CS_FL_WEBSOCKET)
+                       s->flags |= SF_WEBSOCKET;
        }
         /* Set SF_HTX flag for HTTP frontends. */
        if (sess->fe->mode == PR_MODE_HTTP)