MINOR: connection: pass the proxy when creating a connection

Till now it was very difficult for a mux to know what proxy it was
working for. Let's pass the proxy when the mux is instanciated at
init() time. It's not yet used but the H1 mux will definitely need
it, just like the H2 mux when dealing with backend connections.
This commit is contained in:
Willy Tarreau 2018-09-12 12:02:05 +02:00
parent eb528db60b
commit 175a2bb507
6 changed files with 12 additions and 10 deletions

View File

@ -796,11 +796,12 @@ static inline struct wait_list *wl_set_waitcb(struct wait_list *wl, struct task
/* Installs the connection's mux layer for upper context <ctx>.
* Returns < 0 on error.
*/
static inline int conn_install_mux(struct connection *conn, const struct mux_ops *mux, void *ctx)
static inline int conn_install_mux(struct connection *conn, const struct mux_ops *mux,
void *ctx, struct proxy *prx)
{
conn->mux = mux;
conn->mux_ctx = ctx;
return mux->init ? mux->init(conn) : 0;
return mux->init ? mux->init(conn, prx) : 0;
}
/* returns a human-readable error code for conn->err_code, or NULL if the code
@ -1045,7 +1046,7 @@ static inline int conn_install_mux_fe(struct connection *conn, void *ctx)
if (!mux_ops)
return -1;
}
return conn_install_mux(conn, mux_ops, ctx);
return conn_install_mux(conn, mux_ops, ctx, bind_conf->frontend);
}
/* installs the best mux for outgoing connection <conn> using the upper context
@ -1074,7 +1075,7 @@ static inline int conn_install_mux_be(struct connection *conn, void *ctx)
if (!mux_ops)
return -1;
}
return conn_install_mux(conn, mux_ops, ctx);
return conn_install_mux(conn, mux_ops, ctx, prx);
}
#endif /* _PROTO_CONNECTION_H */

View File

@ -41,6 +41,7 @@
struct connection;
struct conn_stream;
struct buffer;
struct proxy;
struct server;
struct pipe;
@ -310,7 +311,7 @@ struct xprt_ops {
* layer is not ready yet.
*/
struct mux_ops {
int (*init)(struct connection *conn); /* early initialization */
int (*init)(struct connection *conn, struct proxy *prx); /* early initialization */
int (*wake)(struct connection *conn); /* mux-layer callback to report activity, mandatory */
void (*update_poll)(struct conn_stream *cs); /* commit cs flags to mux/conn */
size_t (*rcv_buf)(struct conn_stream *cs, struct buffer *buf, size_t count, int flags); /* Called from the upper layer to get data */

View File

@ -1611,7 +1611,7 @@ static int connect_conn_chk(struct task *t)
clear_addr(&conn->addr.from);
conn_prepare(conn, proto, check->xprt);
conn_install_mux(conn, &mux_pt_ops, cs);
conn_install_mux(conn, &mux_pt_ops, cs, s->proxy);
cs_attach(cs, check, &check_conn_cb);
/* only plain tcp-check supports quick ACK */
@ -2806,7 +2806,7 @@ static int tcpcheck_main(struct check *check)
}
conn_prepare(conn, proto, xprt);
conn_install_mux(conn, &mux_pt_ops, cs);
conn_install_mux(conn, &mux_pt_ops, cs, s->proxy);
cs_attach(cs, check, &check_conn_cb);
ret = SF_ERR_INTERNAL;

View File

@ -438,7 +438,7 @@ static int h2c_frt_init(struct connection *conn)
* connections from the fact that the context is still NULL. Returns < 0 on
* error.
*/
static int h2_init(struct connection *conn)
static int h2_init(struct connection *conn, struct proxy *prx)
{
if (conn->mux_ctx) {
/* we don't support outgoing connections for now */

View File

@ -19,7 +19,7 @@
* 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)
static int mux_pt_init(struct connection *conn, struct proxy *prx)
{
struct conn_stream *cs = conn->mux_ctx;

View File

@ -1971,7 +1971,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
memcpy(&conn->addr.to, &peer->addr, sizeof(conn->addr.to));
conn_prepare(conn, peer->proto, peer->xprt);
conn_install_mux(conn, &mux_pt_ops, cs);
conn_install_mux(conn, &mux_pt_ops, cs, s->be);
si_attach_cs(&s->si[1], cs);
s->do_log = NULL;