MEDIUM: stream-int/conn-stream: Move src/dst addresses in the conn-stream

The source and destination addresses at the applicative layer are moved from
the stream-interface to the conn-stream. This simplifies a bit the code and
it is a logicial step to remove the stream-interface.
diff --git a/src/backend.c b/src/backend.c
index c73b23e..941d755 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -701,7 +701,7 @@
 				const struct sockaddr_storage *src;
 
 			case BE_LB_HASH_SRC:
-				src = si_src(cs_si(s->csf));
+				src = cs_src(s->csf);
 				if (src && src->ss_family == AF_INET) {
 					srv = get_server_sh(s->be,
 							    (void *)&((struct sockaddr_in *)src)->sin_addr,
@@ -854,7 +854,7 @@
 			 * locally on multiple addresses at once. Nothing is done
 			 * for AF_UNIX addresses.
 			 */
-			dst = si_dst(cs_si(s->csf));
+			dst = cs_dst(s->csf);
 			if (dst && dst->ss_family == AF_INET) {
 				((struct sockaddr_in *)*ss)->sin_family = AF_INET;
 				((struct sockaddr_in *)*ss)->sin_addr =
@@ -871,7 +871,7 @@
 		if ((srv->flags & SRV_F_MAPPORTS)) {
 			int base_port;
 
-			dst = si_dst(cs_si(s->csf));
+			dst = cs_dst(s->csf);
 			if (dst) {
 				/* First, retrieve the port from the incoming connection */
 				base_port = get_host_port(dst);
@@ -894,7 +894,7 @@
 			return SRV_STATUS_INTERNAL;
 
 		/* in transparent mode, use the original dest addr if no dispatch specified */
-		dst = si_dst(cs_si(s->csf));
+		dst = cs_dst(s->csf);
 		if (dst && (dst->ss_family == AF_INET || dst->ss_family == AF_INET6))
 			**ss = *dst;
 	}
@@ -1069,7 +1069,7 @@
 	case CO_SRC_TPROXY_CLI:
 	case CO_SRC_TPROXY_CIP:
 		/* FIXME: what can we do if the client connects in IPv6 or unix socket ? */
-		addr = si_src(cs_si(s->csf));
+		addr = cs_src(s->csf);
 		if (!addr)
 			return SRV_STATUS_INTERNAL;
 
@@ -1271,7 +1271,7 @@
 	srv = objt_server(s->target);
 
 	if (!(s->flags & SF_ADDR_SET)) {
-		err = alloc_dst_address(&(cs_si(s->csb)->dst), srv, s);
+		err = alloc_dst_address(&s->csb->dst, srv, s);
 		if (err != SRV_STATUS_OK)
 			return SF_ERR_INTERNAL;
 
@@ -1326,7 +1326,7 @@
 
 	/* 3. destination address */
 	if (srv && (!is_addr(&srv->addr) || srv->flags & SRV_F_MAPPORTS))
-		hash_params.dst_addr = cs_si(s->csb)->dst;
+		hash_params.dst_addr = s->csb->dst;
 
 	/* 4. source address */
 	hash_params.src_addr = bind_addr;
@@ -1546,7 +1546,7 @@
 		return SF_ERR_RESOURCE;
 
 	/* copy the target address into the connection */
-	*srv_conn->dst = *(cs_si(s->csb))->dst;
+	*srv_conn->dst = *s->csb->dst;
 
 	/* Copy network namespace from client connection */
 	srv_conn->proxy_netns = cli_conn ? cli_conn->proxy_netns : NULL;
@@ -1820,7 +1820,7 @@
 		if (((s->flags & (SF_DIRECT|SF_FORCE_PRST)) == SF_DIRECT) &&
 		    (s->be->options & PR_O_REDISP)) {
 			s->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
-			sockaddr_free(&(cs_si(s->csb)->dst));
+			sockaddr_free(&s->csb->dst);
 			goto redispatch;
 		}
 
diff --git a/src/cli.c b/src/cli.c
index f3d05d8..9b53370 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -2764,7 +2764,7 @@
 			}
 		}
 
-		sockaddr_free(&(cs_si(s->csb)->dst));
+		sockaddr_free(&s->csb->dst);
 
 		cs_si(s->csb)->state = cs_si(s->csb)->prev_state = SI_ST_INI;
 		cs_si(s->csb)->err_type = SI_ET_NONE;
diff --git a/src/conn_stream.c b/src/conn_stream.c
index 45c82ef..55dd86c 100644
--- a/src/conn_stream.c
+++ b/src/conn_stream.c
@@ -60,7 +60,8 @@
 	cs->app = NULL;
 	cs->si = NULL;
 	cs->data_cb = NULL;
-
+	cs->src = NULL;
+	cs->dst = NULL;
 	if (!endp) {
 		endp = cs_endpoint_new();
 		if (unlikely(!endp))
@@ -147,6 +148,8 @@
 void cs_free(struct conn_stream *cs)
 {
 	si_free(cs->si);
+	sockaddr_free(&cs->src);
+	sockaddr_free(&cs->dst);
 	if (cs->endp) {
 		BUG_ON(!(cs->endp->flags & CS_EP_DETACHED));
 		cs_endpoint_free(cs->endp);
@@ -282,7 +285,8 @@
 	cs->app = NULL;
 	cs->si  = NULL;
 	cs->data_cb = NULL;
-
+	sockaddr_free(&cs->src);
+	sockaddr_free(&cs->dst);
 	if (!cs->endp || (cs->endp->flags & CS_EP_DETACHED))
 		cs_free(cs);
 }
diff --git a/src/connection.c b/src/connection.c
index a14dfe7..227e9d9 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -18,6 +18,7 @@
 #include <haproxy/cfgparse.h>
 #include <haproxy/connection.h>
 #include <haproxy/conn_stream.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/fd.h>
 #include <haproxy/frontend.h>
 #include <haproxy/hash.h>
@@ -1746,8 +1747,8 @@
 	memcpy(hdr->sig, pp2_signature, PP2_SIGNATURE_LEN);
 
 	if (strm) {
-		src = si_src(strm->csf->si);
-		dst = si_dst(strm->csf->si);
+		src = cs_src(strm->csf);
+		dst = cs_dst(strm->csf);
 	}
 	else if (remote && conn_get_src(remote) && conn_get_dst(remote)) {
 		src = conn_src(remote);
@@ -1945,8 +1946,8 @@
 		const struct sockaddr_storage *dst = NULL;
 
 		if (strm) {
-			src = si_src(strm->csf->si);
-			dst = si_dst(strm->csf->si);
+			src = cs_src(strm->csf);
+			dst = cs_dst(strm->csf);
 		}
 		else if (remote && conn_get_src(remote) && conn_get_dst(remote)) {
 			src = conn_src(remote);
diff --git a/src/dns.c b/src/dns.c
index 755053a..92f37b4 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -915,7 +915,7 @@
 	}
 
 	s = DISGUISE(cs_strm(cs));
-	cs_si(s->csb)->dst = addr;
+	s->csb->dst = addr;
 	cs_si(s->csb)->flags |= SI_FL_NOLINGER;
 	s->target = &ds->dss->srv->obj_type;
 	s->flags = SF_ASSIGNED|SF_ADDR_SET;
diff --git a/src/frontend.c b/src/frontend.c
index c8fb3d2..3ae24f2 100644
--- a/src/frontend.c
+++ b/src/frontend.c
@@ -26,6 +26,8 @@
 #include <haproxy/api.h>
 #include <haproxy/arg.h>
 #include <haproxy/chunk.h>
+#include <haproxy/connection.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/fd.h>
 #include <haproxy/frontend.h>
 #include <haproxy/global.h>
@@ -62,7 +64,7 @@
 					s->do_log(s);
 		}
 		else if (conn) {
-			src = si_src(cs_si(s->csf));
+			src = cs_src(s->csf);
 			if (!src)
 				send_log(fe, LOG_INFO, "Connect from unknown source to listener %d (%s/%s)\n",
 					 l->luid, fe->id, (fe->mode == PR_MODE_HTTP) ? "HTTP" : "TCP");
@@ -73,7 +75,7 @@
 				switch (addr_to_str(src, pn, sizeof(pn))) {
 				case AF_INET:
 				case AF_INET6:
-					dst = si_dst(cs_si(s->csf));
+					dst = cs_dst(s->csf);
 					if (dst) {
 						addr_to_str(dst, sn, sizeof(sn));
 						port = get_host_port(dst);
@@ -113,7 +115,7 @@
 			}
 		}
 
-		src = si_src(cs_si(s->csf));
+		src = cs_src(s->csf);
 		if (!src) {
 			chunk_printf(&trash, "%08x:%s.accept(%04x)=%04x from [listener:%d] ALPN=%s\n",
 			             s->uniq_id, fe->id, (unsigned short)l->rx.fd, (unsigned short)conn->handle.fd,
diff --git a/src/hlua.c b/src/hlua.c
index 380e61b..60b9923 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2576,7 +2576,7 @@
 	}
 	appctx = container_of(peer, struct appctx, ctx.hlua_cosocket.xref);
 	cs = appctx->owner;
-	dst = si_dst(cs_opposite(cs)->si);
+	dst = cs_dst(cs_opposite(cs));
 	if (!dst) {
 		xref_unlock(&socket->xref, peer);
 		lua_pushnil(L);
@@ -2778,7 +2778,7 @@
 	cs = appctx->owner;
 	s = __cs_strm(cs);
 
-	if (!sockaddr_alloc(&cs_opposite(cs)->si->dst, addr, sizeof(*addr))) {
+	if (!sockaddr_alloc(&cs_opposite(cs)->dst, addr, sizeof(*addr))) {
 		xref_unlock(&socket->xref, peer);
 		WILL_LJMP(luaL_error(L, "connect: internal error"));
 	}
diff --git a/src/http_ana.c b/src/http_ana.c
index 2c93edb..f17e2e2 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -20,6 +20,8 @@
 #include <haproxy/channel.h>
 #include <haproxy/check.h>
 #include <haproxy/connection.h>
+#include <haproxy/conn_stream.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/errors.h>
 #include <haproxy/filters.h>
 #include <haproxy/http.h>
@@ -653,7 +655,7 @@
 	 * asks for it.
 	 */
 	if ((sess->fe->options | s->be->options) & PR_O_FWDFOR) {
-		const struct sockaddr_storage *src = si_src(cs_si(s->csf));
+		const struct sockaddr_storage *src = cs_src(s->csf);
 		struct http_hdr_ctx ctx = { .blk = NULL };
 		struct ist hdr = isttest(s->be->fwdfor_hdr_name) ? s->be->fwdfor_hdr_name : sess->fe->fwdfor_hdr_name;
 
@@ -710,7 +712,7 @@
 	 * asks for it.
 	 */
 	if ((sess->fe->options | s->be->options) & PR_O_ORGTO) {
-		const struct sockaddr_storage *dst = si_dst(cs_si(s->csf));
+		const struct sockaddr_storage *dst = cs_dst(s->csf);
 		struct ist hdr = isttest(s->be->orgto_hdr_name) ? s->be->orgto_hdr_name : sess->fe->orgto_hdr_name;
 
 		if (dst && dst->ss_family == AF_INET) {
diff --git a/src/http_client.c b/src/http_client.c
index 965dc9d..83faffe 100644
--- a/src/http_client.c
+++ b/src/http_client.c
@@ -525,7 +525,7 @@
 			break;
 	}
 
-	cs_si(s->csb)->dst = addr;
+	s->csb->dst = addr;
 	cs_si(s->csb)->flags |= SI_FL_NOLINGER;
 	s->flags |= SF_ASSIGNED|SF_ADDR_SET;
 	s->res.flags |= CF_READ_DONTWAIT;
diff --git a/src/http_fetch.c b/src/http_fetch.c
index 2ee507b..5b83c19 100644
--- a/src/http_fetch.c
+++ b/src/http_fetch.c
@@ -23,6 +23,7 @@
 #include <haproxy/channel.h>
 #include <haproxy/chunk.h>
 #include <haproxy/connection.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/global.h>
 #include <haproxy/h1.h>
 #include <haproxy/h1_htx.h>
@@ -1186,7 +1187,7 @@
  */
 static int smp_fetch_base32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	const struct sockaddr_storage *src = (smp->strm ? si_src(smp->strm->csf->si) : NULL);
+	const struct sockaddr_storage *src = (smp->strm ? cs_src(smp->strm->csf) : NULL);
 	struct buffer *temp;
 
 	if (!src)
@@ -2053,7 +2054,7 @@
  */
 static int smp_fetch_url32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-	const struct sockaddr_storage *src = (smp->strm ? si_src(smp->strm->csf->si) : NULL);
+	const struct sockaddr_storage *src = (smp->strm ? cs_src(smp->strm->csf) : NULL);
 	struct buffer *temp;
 
 	if (!src)
diff --git a/src/log.c b/src/log.c
index edffcbd..c0c3e29 100644
--- a/src/log.c
+++ b/src/log.c
@@ -2116,7 +2116,7 @@
 				break;
 
 			case LOG_FMT_CLIENTIP:  // %ci
-				addr = (s ? si_src(cs_si(s->csf)) : sess_src(sess));
+				addr = (s ? cs_src(s->csf) : sess_src(sess));
 				if (addr)
 					ret = lf_ip(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
 				else
@@ -2129,7 +2129,7 @@
 				break;
 
 			case LOG_FMT_CLIENTPORT:  // %cp
-				addr = (s ? si_src(cs_si(s->csf)) : sess_src(sess));
+				addr = (s ? cs_src(s->csf) : sess_src(sess));
 				if (addr) {
 					/* sess->listener is always defined when the session's owner is an inbound connections */
 					if (addr->ss_family == AF_UNIX)
@@ -2147,7 +2147,7 @@
 				break;
 
 			case LOG_FMT_FRONTENDIP: // %fi
-				addr = (s ? si_dst(cs_si(s->csf)) : sess_dst(sess));
+				addr = (s ? cs_dst(s->csf) : sess_dst(sess));
 				if (addr)
 					ret = lf_ip(tmplog, (struct sockaddr *)addr, dst + maxsize - tmplog, tmp);
 				else
@@ -2160,7 +2160,7 @@
 				break;
 
 			case  LOG_FMT_FRONTENDPORT: // %fp
-				addr = (s ? si_dst(cs_si(s->csf)) : sess_dst(sess));
+				addr = (s ? cs_dst(s->csf) : sess_dst(sess));
 				if (addr) {
 					/* sess->listener is always defined when the session's owner is an inbound connections */
 					if (addr->ss_family == AF_UNIX)
diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c
index 50f271f..6e99393 100644
--- a/src/mux_fcgi.c
+++ b/src/mux_fcgi.c
@@ -1235,8 +1235,8 @@
 				  struct fcgi_strm_params *params)
 {
 	struct connection *cli_conn = objt_conn(fstrm->sess->origin);
-	const struct sockaddr_storage *src = (cs_check(fstrm->cs) ? conn_src(fconn->conn) : si_src(cs_opposite(fstrm->cs)->si));
-	const struct sockaddr_storage *dst = (cs_check(fstrm->cs) ? conn_dst(fconn->conn) : si_dst(cs_opposite(fstrm->cs)->si));
+	const struct sockaddr_storage *src = (cs_check(fstrm->cs) ? conn_src(fconn->conn) : cs_src(cs_opposite(fstrm->cs)));
+	const struct sockaddr_storage *dst = (cs_check(fstrm->cs) ? conn_dst(fconn->conn) : cs_dst(cs_opposite(fstrm->cs)));
 	struct ist p;
 
 	if (!sl)
diff --git a/src/peers.c b/src/peers.c
index 9846612..4d86126 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -3209,7 +3209,7 @@
 	appctx_wakeup(appctx);
 
 	/* initiate an outgoing connection */
-	cs_si(s->csb)->dst = addr;
+	s->csb->dst = addr;
 	cs_si(s->csb)->flags |= SI_FL_NOLINGER;
 	s->flags = SF_ASSIGNED|SF_ADDR_SET;
 	s->target = peer_session_target(peer, s);
diff --git a/src/queue.c b/src/queue.c
index 002b94b..97862f0 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -601,7 +601,7 @@
 
 	/* the entry might have been redistributed to another server */
 	if (!(strm->flags & SF_ADDR_SET))
-		sockaddr_free(&cs_si(strm->csb)->dst);
+		sockaddr_free(&strm->csb->dst);
 
 	if (p->target) {
 		/* a server picked this pendconn, it must skip LB */
diff --git a/src/sink.c b/src/sink.c
index 91ee67f..e7ad4bd 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -656,7 +656,7 @@
 	}
 	s = DISGUISE(cs_strm(cs));
 
-	cs_si(s->csb)->dst = addr;
+	s->csb->dst = addr;
 	cs_si(s->csb)->flags |= SI_FL_NOLINGER;
 
 	s->target = &sft->srv->obj_type;
diff --git a/src/stream_interface.c b/src/stream_interface.c
index 1e28a8f..b4d7cab 100644
--- a/src/stream_interface.c
+++ b/src/stream_interface.c
@@ -125,8 +125,6 @@
 		return;
 
 	tasklet_free(si->wait_event.tasklet);
-	sockaddr_free(&si->src);
-	sockaddr_free(&si->dst);
 	pool_free(pool_head_streaminterface, si);
 }
 
diff --git a/src/tcp_act.c b/src/tcp_act.c
index 04400d2..0050515 100644
--- a/src/tcp_act.c
+++ b/src/tcp_act.c
@@ -30,6 +30,7 @@
 #include <haproxy/arg.h>
 #include <haproxy/channel.h>
 #include <haproxy/connection.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/global.h>
 #include <haproxy/http_rules.h>
 #include <haproxy/proto_tcp.h>
@@ -68,9 +69,9 @@
 
 	case ACT_F_TCP_REQ_CNT:
 	case ACT_F_HTTP_REQ:
-		if (!si_get_src(cs_si(s->csf)))
+		if (!cs_get_src(s->csf))
 			goto end;
-		src = cs_si(s->csf)->src;
+		src = s->csf->src;
 		break;
 
 	default:
@@ -124,9 +125,9 @@
 
 	case ACT_F_TCP_REQ_CNT:
 	case ACT_F_HTTP_REQ:
-		if (!si_get_dst(cs_si(s->csf)))
+		if (!cs_get_dst(s->csf))
 			goto end;
-		dst = cs_si(s->csf)->dst;
+		dst = s->csf->dst;
 		break;
 
 	default:
@@ -181,9 +182,9 @@
 
 	case ACT_F_TCP_REQ_CNT:
 	case ACT_F_HTTP_REQ:
-		if (!si_get_src(cs_si(s->csf)))
+		if (!cs_get_src(s->csf))
 			goto end;
-		src = cs_si(s->csf)->src;
+		src = s->csf->src;
 		break;
 
 	default:
@@ -236,9 +237,9 @@
 
 	case ACT_F_TCP_REQ_CNT:
 	case ACT_F_HTTP_REQ:
-		if (!si_get_dst(cs_si(s->csf)))
+		if (!cs_get_dst(s->csf))
 			goto end;
-		dst = cs_si(s->csf)->dst;
+		dst = s->csf->dst;
 		break;
 
 	default:
diff --git a/src/tcp_sample.c b/src/tcp_sample.c
index 53e3d1e..fe10fc2 100644
--- a/src/tcp_sample.c
+++ b/src/tcp_sample.c
@@ -33,6 +33,7 @@
 #include <haproxy/api.h>
 #include <haproxy/arg.h>
 #include <haproxy/connection.h>
+#include <haproxy/cs_utils.h>
 #include <haproxy/errors.h>
 #include <haproxy/global.h>
 #include <haproxy/listener-t.h>
@@ -65,7 +66,7 @@
 			src = conn_src(conn);
 	}
         else /* src */
-		src = (smp->strm ? si_src(smp->strm->csf->si) : sess_src(smp->sess));
+		src = (smp->strm ? cs_src(smp->strm->csf) : sess_src(smp->sess));
 
 	if (!src)
 		return 0;
@@ -109,7 +110,7 @@
 			src = conn_src(conn);
 	}
         else /* src_port */
-		src = (smp->strm ? si_src(smp->strm->csf->si) : sess_src(smp->sess));
+		src = (smp->strm ? cs_src(smp->strm->csf) : sess_src(smp->sess));
 
 	if (!src)
 		return 0;
@@ -144,7 +145,7 @@
 			dst = conn_dst(conn);
 	}
         else /* dst */
-		dst = (smp->strm ? si_dst(smp->strm->csf->si) : sess_dst(smp->sess));
+		dst = (smp->strm ? cs_dst(smp->strm->csf) : sess_dst(smp->sess));
 
 	if (!dst)
 		return 0;
@@ -181,7 +182,7 @@
 			dst = conn_dst(conn);
 	}
 	else /* dst_is_local */
-		dst = (smp->strm ? si_dst(smp->strm->csf->si) : sess_dst(smp->sess));
+		dst = (smp->strm ? cs_dst(smp->strm->csf) : sess_dst(smp->sess));
 
 	if (!dst)
 		return 0;
@@ -207,7 +208,7 @@
 			src = conn_src(conn);
 	}
 	else /* src_is_local */
-		src = (smp->strm ? si_src(smp->strm->csf->si) : sess_src(smp->sess));
+		src = (smp->strm ? cs_src(smp->strm->csf) : sess_src(smp->sess));
 
 	if (!src)
 		return 0;
@@ -240,7 +241,7 @@
 			dst = conn_dst(conn);
 	}
         else /* dst_port */
-		dst = (smp->strm ? si_dst(smp->strm->csf->si) : sess_dst(smp->sess));
+		dst = (smp->strm ? cs_dst(smp->strm->csf) : sess_dst(smp->sess));
 
 	if (!dst)
 		return 0;