MINOR: connection: Set the conncetion target during its initialisation

When a new connection is created, its target is always set just after. So the
connection target may set when it is created instead, during its initialisation
to be precise. It is the purpose of this patch. Now, conn_new() function is
called with the connection target as parameter. The target is then passed to
conn_init(). It means the target must be passed when cs_new() is called. In this
case, the target is only used when the conn-stream is created with no
connection. This only happens for tcpchecks for now.
diff --git a/src/backend.c b/src/backend.c
index 8556d4c..47f4bff 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -1368,10 +1368,8 @@
 
 	/* no reuse or failed to reuse the connection above, pick a new one */
 	if (!srv_conn) {
-		srv_conn = conn_new();
+		srv_conn = conn_new(s->target);
 		was_unused = 1;
-		if (srv_conn)
-			srv_conn->target = s->target;
 		srv_cs = NULL;
 
 		srv_conn->owner = s->sess;
diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c
index 88cc6b1..58d4923 100644
--- a/src/mux_fcgi.c
+++ b/src/mux_fcgi.c
@@ -3436,7 +3436,7 @@
 	struct fcgi_conn *fconn = conn->ctx;
 
 	TRACE_ENTER(FCGI_EV_FSTRM_NEW, conn);
-	cs = cs_new(conn);
+	cs = cs_new(conn, conn->target);
 	if (!cs) {
 		TRACE_DEVEL("leaving on CS allocation failure", FCGI_EV_FSTRM_NEW|FCGI_EV_FSTRM_ERR, conn);
 		return NULL;
diff --git a/src/mux_h1.c b/src/mux_h1.c
index a27c2d0..3268aff 100644
--- a/src/mux_h1.c
+++ b/src/mux_h1.c
@@ -473,7 +473,7 @@
 	struct conn_stream *cs;
 
 	TRACE_ENTER(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
-	cs = cs_new(h1s->h1c->conn);
+	cs = cs_new(h1s->h1c->conn, h1s->h1c->conn->target);
 	if (!cs) {
 		TRACE_DEVEL("leaving on CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
 		goto err;
@@ -2372,7 +2372,7 @@
 		goto end;
 	}
 
-	cs = cs_new(h1c->conn);
+	cs = cs_new(h1c->conn, h1c->conn->target);
 	if (!cs) {
 		TRACE_DEVEL("leaving on CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, conn);
 		goto end;
diff --git a/src/mux_h2.c b/src/mux_h2.c
index ea79371..4b790e6 100644
--- a/src/mux_h2.c
+++ b/src/mux_h2.c
@@ -1352,7 +1352,7 @@
 	if (!h2s)
 		goto out;
 
-	cs = cs_new(h2c->conn);
+	cs = cs_new(h2c->conn, h2c->conn->target);
 	if (!cs)
 		goto out_close;
 
@@ -3818,7 +3818,7 @@
 	struct h2c *h2c = conn->ctx;
 
 	TRACE_ENTER(H2_EV_H2S_NEW, conn);
-	cs = cs_new(conn);
+	cs = cs_new(conn, conn->target);
 	if (!cs) {
 		TRACE_DEVEL("leaving on CS allocation failure", H2_EV_H2S_NEW|H2_EV_H2S_ERR, conn);
 		return NULL;
diff --git a/src/mux_pt.c b/src/mux_pt.c
index 9a96fb8..a9fe009 100644
--- a/src/mux_pt.c
+++ b/src/mux_pt.c
@@ -100,7 +100,7 @@
 	ctx->conn = conn;
 
 	if (!cs) {
-		cs = cs_new(conn);
+		cs = cs_new(conn, conn->target);
 		if (!cs)
 			goto fail_free_ctx;
 
@@ -167,7 +167,7 @@
 
 	if (ctx->wait_event.events)
 		conn->xprt->unsubscribe(ctx->conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event);
-	cs = cs_new(conn);
+	cs = cs_new(conn, conn->target);
 	if (!cs)
 		goto fail;
 
diff --git a/src/session.c b/src/session.c
index 4fad934..52d3a1f 100644
--- a/src/session.c
+++ b/src/session.c
@@ -144,7 +144,7 @@
 
 	ret = -1; /* assume unrecoverable error by default */
 
-	if (unlikely((cli_conn = conn_new()) == NULL))
+	if (unlikely((cli_conn = conn_new(&l->obj_type)) == NULL))
 		goto out_close;
 
 	if (!sockaddr_alloc(&cli_conn->src))
@@ -153,7 +153,6 @@
 	cli_conn->handle.fd = cfd;
 	*cli_conn->src = *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);
diff --git a/src/tcpcheck.c b/src/tcpcheck.c
index 4e714fa..6f962cc 100644
--- a/src/tcpcheck.c
+++ b/src/tcpcheck.c
@@ -994,7 +994,7 @@
 	 */
 
 	/* 2- prepare new connection */
-	cs = cs_new(NULL);
+	cs = cs_new(NULL, (s ? &s->obj_type : &proxy->obj_type));
 	if (!cs) {
 		chunk_printf(&trash, "TCPCHK error allocating connection at step %d",
 			     tcpcheck_get_step_id(check, rule));
@@ -1028,9 +1028,7 @@
 	check->wait_list.events = 0;
 	if (s) {
 		_HA_ATOMIC_ADD(&s->curr_used_conns, 1);
-		conn->target = &s->obj_type;
-	} else
-		conn->target = &proxy->obj_type;
+	}
 
 	/* no client address */
 	if (!sockaddr_alloc(&conn->dst)) {