]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: make the initialization more consistent
authorWilly Tarreau <w@1wt.eu>
Thu, 6 Sep 2018 09:45:30 +0000 (11:45 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 6 Sep 2018 09:45:30 +0000 (11:45 +0200)
Sometimes a connection is prepared before the target is set, sometimes
after. There's no real rule since the few functions involved operate on
different and independent fields. Soon we'll benefit from knowing the
target at the connection layer, in order to figure the associated proxy
and retrieve the various parameters (timeouts etc). This patch slightly
reorders a few calls to conn_prepare() so that we can make sure that the
target is always known to the mux.

include/proto/connection.h
src/checks.c
src/peers.c
src/session.c

index dfaaad78d2426a279a7b36024447cee04b7073c4..a683926566a1d63f3959bf008a9db192db9d6529 100644 (file)
@@ -579,7 +579,9 @@ static inline int conn_xprt_read0_pending(struct connection *c)
 
 /* prepares a connection to work with protocol <proto> and transport <xprt>.
  * The transport's is initialized as well, and the mux and its context are
- * cleared.
+ * cleared. The target is not reinitialized and it is recommended that it is
+ * set prior to calling this function so that the function may make use of it
+ * in the future to refine the mux choice if needed.
  */
 static inline void conn_prepare(struct connection *conn, const struct protocol *proto, const struct xprt_ops *xprt)
 {
index fc1384580f71a0b8c05415c419f045ae95b85b55..28ee4c473c9e639d12a9640533816544d5f9d20c 100644 (file)
@@ -1588,13 +1588,9 @@ static int connect_conn_chk(struct task *t)
        }
 
        proto = protocol_by_family(conn->addr.to.ss_family);
-
-       conn_prepare(conn, proto, check->xprt);
-       conn_install_mux(conn, &mux_pt_ops, cs);
-       cs_attach(cs, check, &check_conn_cb);
        conn->target = &s->obj_type;
 
-       if ((conn->addr.to.ss_family == AF_INET) || (conn->addr.to.ss_family == AF_INET6)) {
+       if ((conn->addr.to.ss_family == AF_INET) || (conn->addr.to.ss_family == AF_INET6)) {
                int i = 0;
 
                i = srv_check_healthcheck_port(check);
@@ -1607,6 +1603,10 @@ static int connect_conn_chk(struct task *t)
        /* no client address */
        clear_addr(&conn->addr.from);
 
+       conn_prepare(conn, proto, check->xprt);
+       conn_install_mux(conn, &mux_pt_ops, cs);
+       cs_attach(cs, check, &check_conn_cb);
+
        /* only plain tcp-check supports quick ACK */
        quickack = check->type == 0 || check->type == PR_O2_TCPCHK_CHK;
 
@@ -2766,7 +2766,6 @@ static int tcpcheck_main(struct check *check)
 
                        check->cs = cs;
                        conn = cs->conn;
-                       cs_attach(cs, check, &check_conn_cb);
                        conn->target = &s->obj_type;
 
                        /* no client address */
@@ -2796,8 +2795,10 @@ static int tcpcheck_main(struct check *check)
                        else {
                                xprt = xprt_get(XPRT_RAW);
                        }
+
                        conn_prepare(conn, proto, xprt);
                        conn_install_mux(conn, &mux_pt_ops, cs);
+                       cs_attach(cs, check, &check_conn_cb);
 
                        ret = SF_ERR_INTERNAL;
                        if (proto->connect)
index f26c3dfb9edda103b0055e4cf7733fd69c2f4613..1fefa9431c4338b6ec1a50c616aca73ffefcba80 100644 (file)
@@ -1969,12 +1969,13 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer
        if (unlikely((cs = cs_new(conn)) == NULL))
                goto out_free_conn;
 
+       conn->target = s->target = &s->be->obj_type;
+       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);
        si_attach_cs(&s->si[1], cs);
 
-       conn->target = s->target = &s->be->obj_type;
-       memcpy(&conn->addr.to, &peer->addr, sizeof(conn->addr.to));
        s->do_log = NULL;
        s->uniq_id = 0;
 
index c40e4f60e18220d47116cf6c5d5346a463f75a51..c9d50df5b76eaca47320b245a8cb8a7e0ddd9b1b 100644 (file)
@@ -135,14 +135,13 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
        if (unlikely((cli_conn = conn_new()) == NULL))
                goto out_close;
 
-       conn_prepare(cli_conn, l->proto, l->bind_conf->xprt);
-
        cli_conn->handle.fd = cfd;
        cli_conn->addr.from = *addr;
        cli_conn->flags |= CO_FL_ADDR_FROM_SET;
        cli_conn->target = &l->obj_type;
        cli_conn->proxy_netns = l->netns;
 
+       conn_prepare(cli_conn, l->proto, l->bind_conf->xprt);
        conn_ctrl_init(cli_conn);
 
        /* wait for a PROXY protocol header */