]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: muxes: Add an optional input buffer during mux initialization
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 8 Apr 2019 09:22:47 +0000 (11:22 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 12 Apr 2019 20:06:53 +0000 (22:06 +0200)
The mux's callback init() now take a pointer to a buffer as extra argument. It
must be used by the multiplexer as its input buffer. This buffer is always NULL
when a multiplexer is initialized with a fresh connection. But if a mux upgrade
is performed, it may be filled with existing data. Note that, for now, mux
upgrades are not supported. But this commit is mandatory to do so.

include/proto/connection.h
include/types/connection.h
src/mux_h1.c
src/mux_h2.c
src/mux_pt.c

index dba8dea1e1ce168e5ef55ccbe374c5b62f9f7582..3a98b349f2312f798bf4d83a3491fa124836d2cc 100644 (file)
@@ -836,7 +836,7 @@ static inline int conn_install_mux(struct connection *conn, const struct mux_ops
 
        conn->mux = mux;
        conn->ctx = ctx;
-       ret = mux->init ? mux->init(conn, prx, sess) : 0;
+       ret = mux->init ? mux->init(conn, prx, sess, &BUF_NULL) : 0;
        if (ret < 0) {
                conn->mux = NULL;
                conn->ctx = NULL;
index 1a1409b023a4bd2cd4a136de7b87963abab41b72..af27d0cd10f25f177204a079687e484e9da06841 100644 (file)
@@ -329,7 +329,7 @@ struct xprt_ops {
  * layer is not ready yet.
  */
 struct mux_ops {
-       int  (*init)(struct connection *conn, struct proxy *prx, struct session *sess);  /* early initialization */
+       int  (*init)(struct connection *conn, struct proxy *prx, struct session *sess, struct buffer *input);  /* early initialization */
        int  (*wake)(struct connection *conn);        /* mux-layer callback to report activity, mandatory */
        size_t (*rcv_buf)(struct conn_stream *cs, struct buffer *buf, size_t count, int flags); /* Called from the upper layer to get data */
        size_t (*snd_buf)(struct conn_stream *cs, struct buffer *buf, size_t count, int flags); /* Called from the upper layer to send data */
index a40ef3f4ae1603c28d0b9936733f7c4bf8a3e5d7..50afbc20f4689accc82fe3d6d8091426df238586 100644 (file)
@@ -356,11 +356,15 @@ static const struct cs_info *h1_get_cs_info(struct conn_stream *cs)
 }
 
 /*
- * Initialize the mux once it's attached. It is expected that conn->ctx
- * points to the existing conn_stream (for outgoing connections) or NULL (for
- * incoming ones). Returns < 0 on error.
+ * Initialize the mux once it's attached. It is expected that conn->ctx points
+ * to the existing conn_stream (for outgoing connections or for incoming onces
+ * during a mux upgrade) or NULL (for incoming ones during the connexion
+ * establishment). <input> is always used as Input buffer and may contain
+ * data. It is the caller responsibility to not reuse it anymore. Returns < 0 on
+ * error.
  */
-static int h1_init(struct connection *conn, struct proxy *proxy, struct session *sess)
+static int h1_init(struct connection *conn, struct proxy *proxy, struct session *sess,
+                  struct buffer *input)
 {
        struct h1c *h1c;
        struct task *t = NULL;
@@ -372,10 +376,10 @@ static int h1_init(struct connection *conn, struct proxy *proxy, struct session
        h1c->px   = proxy;
 
        h1c->flags = H1C_F_NONE;
-       h1c->ibuf  = BUF_NULL;
+       h1c->ibuf  = *input;
        h1c->obuf  = BUF_NULL;
        h1c->h1s   = NULL;
-       h1c->task = NULL;
+       h1c->task  = NULL;
 
        LIST_INIT(&h1c->buf_wait.list);
        h1c->wait_event.task = tasklet_new();
index 5448ea820a8ba3bfcef732f9763ea71eb07f92e5..e44042481364485ca12e078177c75c84095bef08 100644 (file)
@@ -472,10 +472,12 @@ static int h2_avail_streams(struct connection *conn)
 
 /* Initialize the mux once it's attached. For outgoing connections, the context
  * is already initialized before installing the mux, so we detect incoming
- * connections from the fact that the context is still NULL. Returns < 0 on
- * error.
+ * connections from the fact that the context is still NULL (even during mux
+ * upgrades). <input> is always used as Input buffer and may contain data. It is
+ * the caller responsibility to not reuse it anymore. Returns < 0 on error.
  */
-static int h2_init(struct connection *conn, struct proxy *prx, struct session *sess)
+static int h2_init(struct connection *conn, struct proxy *prx, struct session *sess,
+                  struct buffer *input)
 {
        struct h2c *h2c;
        struct task *t = NULL;
@@ -533,7 +535,7 @@ static int h2_init(struct connection *conn, struct proxy *prx, struct session *s
        h2c->nb_reserved = 0;
        h2c->stream_cnt = 0;
 
-       h2c->dbuf = BUF_NULL;
+       h2c->dbuf = *input;
        h2c->dsi = -1;
        h2c->msi = -1;
 
index 4f53920c418579de034ecc69289c411b195d2af0..2086d5fd0a7523c888b08f946f15a9d054afc4f6 100644 (file)
@@ -62,7 +62,8 @@ static struct task *mux_pt_io_cb(struct task *t, void *tctx, unsigned short stat
  * incoming ones, in which case one will be allocated and a new stream will be
  * instanciated). Returns < 0 on error.
  */
-static int mux_pt_init(struct connection *conn, struct proxy *prx, struct session *sess)
+static int mux_pt_init(struct connection *conn, struct proxy *prx, struct session *sess,
+                      struct buffer *input)
 {
        struct conn_stream *cs = conn->ctx;
        struct mux_pt_ctx *ctx = pool_alloc(pool_head_pt_ctx);