From: Willy Tarreau Date: Wed, 12 Sep 2018 10:02:05 +0000 (+0200) Subject: MINOR: connection: pass the proxy when creating a connection X-Git-Tag: v1.9-dev2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=175a2bb507cd8f8c6570e0660d7f3eb574cdda89;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/proto/connection.h b/include/proto/connection.h index 2a45677b70..85c5b633fc 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -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 . * 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 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 */ diff --git a/include/types/connection.h b/include/types/connection.h index 59bb27d1ba..27ae76e21c 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -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 */ diff --git a/src/checks.c b/src/checks.c index 96374301c5..6d19eef3f3 100644 --- a/src/checks.c +++ b/src/checks.c @@ -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; diff --git a/src/mux_h2.c b/src/mux_h2.c index 780bc57f60..3faf5aeef8 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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 */ diff --git a/src/mux_pt.c b/src/mux_pt.c index 466ac21b92..5b864199ec 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -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; diff --git a/src/peers.c b/src/peers.c index 50aee870db..e61caaf93f 100644 --- a/src/peers.c +++ b/src/peers.c @@ -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;