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/dev/flags/flags.c b/dev/flags/flags.c
index 02064b3..266df9d 100644
--- a/dev/flags/flags.c
+++ b/dev/flags/flags.c
@@ -219,6 +219,8 @@
 		printf("0\n");
 		return;
 	}
+	SHOW_FLAG(f, CS_FL_ADDR_FROM_SET);
+	SHOW_FLAG(f, CS_FL_ADDR_TO_SET);
 	SHOW_FLAG(f, CS_FL_ISBACK);
 
 	if (f) {
@@ -279,8 +281,6 @@
 	SHOW_FLAG(f, SI_FL_RXBLK_SHUT);
 	SHOW_FLAG(f, SI_FL_RXBLK_CONN);
 	SHOW_FLAG(f, SI_FL_RX_WAIT_EP);
-	SHOW_FLAG(f, SI_FL_ADDR_FROM_SET);
-	SHOW_FLAG(f, SI_FL_ADDR_TO_SET);
 
 	if (f) {
 		printf("EXTRA(0x%08x)", f);
diff --git a/include/haproxy/conn_stream-t.h b/include/haproxy/conn_stream-t.h
index 226d451..fdaa6c3 100644
--- a/include/haproxy/conn_stream-t.h
+++ b/include/haproxy/conn_stream-t.h
@@ -79,6 +79,9 @@
 enum {
 	CS_FL_NONE          = 0x00000000,  /* Just for initialization purposes */
 	CS_FL_ISBACK        = 0x00000001,  /* Set for CS on back-side */
+
+	CS_FL_ADDR_FROM_SET = 0x00000002, /* source address is set */
+	CS_FL_ADDR_TO_SET   = 0x00000004, /* destination address is set */
 };
 
 /* cs_shutr() modes */
@@ -125,6 +128,8 @@
 	enum obj_type *app;                  /* points to the applicative point (stream or check) */
 	struct stream_interface *si;
 	const struct data_cb *data_cb;       /* data layer callbacks. Must be set before xprt->init() */
+	struct sockaddr_storage *src;        /* source address (pool), when known, otherwise NULL */
+	struct sockaddr_storage *dst;        /* destination address (pool), when known, otherwise NULL */
 };
 
 
diff --git a/include/haproxy/cs_utils.h b/include/haproxy/cs_utils.h
index 58334b8..7381499 100644
--- a/include/haproxy/cs_utils.h
+++ b/include/haproxy/cs_utils.h
@@ -27,7 +27,10 @@
 #include <haproxy/channel-t.h>
 #include <haproxy/stream-t.h>
 #include <haproxy/task-t.h>
+#include <haproxy/connection.h>
 #include <haproxy/conn_stream.h>
+#include <haproxy/session.h>
+#include <haproxy/stream.h>
 
 /* returns the channel which receives data from this conn-stream (input channel) */
 static inline struct channel *cs_ic(struct conn_stream *cs)
@@ -73,4 +76,105 @@
 }
 
 
+/* Returns the source address of the conn-stream and, if not set, fallbacks on
+ * the session for frontend CS and the server connection for the backend CS. It
+ * returns a const address on success or NULL on failure.
+ */
+static inline const struct sockaddr_storage *cs_src(struct conn_stream *cs)
+{
+	if (cs->flags & CS_FL_ADDR_FROM_SET)
+		return cs->src;
+	if (!(cs->flags & CS_FL_ISBACK))
+		return sess_src(strm_sess(__cs_strm(cs)));
+	else {
+		struct connection *conn = cs_conn(cs);
+
+		if (conn)
+			return conn_src(conn);
+	}
+	return NULL;
+}
+
+
+/* Returns the destination address of the conn-stream and, if not set, fallbacks
+ * on the session for frontend CS and the server connection for the backend
+ * CS. It returns a const address on success or NULL on failure.
+ */
+static inline const struct sockaddr_storage *cs_dst(struct conn_stream *cs)
+{
+	if (cs->flags & CS_FL_ADDR_TO_SET)
+		return cs->dst;
+	if (!(cs->flags & CS_FL_ISBACK))
+		return sess_dst(strm_sess(__cs_strm(cs)));
+	else {
+		struct connection *conn = cs_conn(cs);
+
+		if (conn)
+			return conn_dst(conn);
+	}
+	return NULL;
+}
+
+/* Retrieves the source address of the conn-stream. Returns non-zero on success
+ * or zero on failure. The operation is only performed once and the address is
+ * stored in the conn-stream for future use. On the first call, the conn-stream
+ * source address is copied from the session one for frontend CS and the server
+ * connection for the backend CS.
+ */
+static inline int cs_get_src(struct conn_stream *cs)
+{
+	const struct sockaddr_storage *src = NULL;
+
+	if (cs->flags & CS_FL_ADDR_FROM_SET)
+		return 1;
+
+	if (!(cs->flags & CS_FL_ISBACK))
+		src = sess_src(strm_sess(__cs_strm(cs)));
+	else {
+		struct connection *conn = cs_conn(cs);
+
+		if (conn)
+			src = conn_src(conn);
+	}
+	if (!src)
+		return 0;
+
+	if (!sockaddr_alloc(&cs->src, src, sizeof(*src)))
+		return 0;
+
+	cs->flags |= CS_FL_ADDR_FROM_SET;
+	return 1;
+}
+
+/* Retrieves the destination address of the conn-stream. Returns non-zero on
+ * success or zero on failure. The operation is only performed once and the
+ * address is stored in the conn-stream for future use. On the first call, the
+ * conn-stream destination address is copied from the session one for frontend
+ * CS and the server connection for the backend CS.
+ */
+static inline int cs_get_dst(struct conn_stream *cs)
+{
+	const struct sockaddr_storage *dst = NULL;
+
+	if (cs->flags & CS_FL_ADDR_TO_SET)
+		return 1;
+
+	if (!(cs->flags & CS_FL_ISBACK))
+		dst = sess_dst(strm_sess(__cs_strm(cs)));
+	else {
+		struct connection *conn = cs_conn(cs);
+
+		if (conn)
+			dst = conn_dst(conn);
+	}
+	if (!dst)
+		return 0;
+
+	if (!sockaddr_alloc(&cs->dst, dst, sizeof(*dst)))
+		return 0;
+
+	cs->flags |= CS_FL_ADDR_TO_SET;
+	return 1;
+}
+
 #endif /* _HAPROXY_CS_UTILS_H */
diff --git a/include/haproxy/stream.h b/include/haproxy/stream.h
index 1983230..db1a2d6 100644
--- a/include/haproxy/stream.h
+++ b/include/haproxy/stream.h
@@ -340,7 +340,7 @@
 		if (may_dequeue_tasks(objt_server(s->target), s->be))
 			process_srv_queue(objt_server(s->target));
 
-		sockaddr_free(&cs_si(s->csb)->dst);
+		sockaddr_free(&s->csb->dst);
 		s->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
 		si->state = SI_ST_REQ;
 	} else {
diff --git a/include/haproxy/stream_interface-t.h b/include/haproxy/stream_interface-t.h
index 8ed3d4e..d9f1242 100644
--- a/include/haproxy/stream_interface-t.h
+++ b/include/haproxy/stream_interface-t.h
@@ -104,10 +104,6 @@
 	SI_FL_RXBLK_CONN = 0x00100000,  /* other side is not connected */
 	SI_FL_RXBLK_ANY  = 0x001F0000,  /* any of the RXBLK flags above */
 	SI_FL_RX_WAIT_EP = 0x00200000,  /* stream-int waits for more data from the end point */
-	/* unused: 0x01000000, 0x02000000 */
-
-	SI_FL_ADDR_FROM_SET = 0x04000000, /* source address is set */
-	SI_FL_ADDR_TO_SET   = 0x08000000  /* destination address is set */
 };
 
 /* A stream interface has 3 parts :
@@ -129,8 +125,6 @@
 	unsigned int flags;     /* SI_FL_* */
 	struct conn_stream *cs; /* points to the conn-streams that owns the endpoint (connection or applet) */
 	struct si_ops *ops;     /* general operations at the stream interface layer */
-	struct sockaddr_storage *src; /* source address (pool), when known, otherwise NULL */
-	struct sockaddr_storage *dst; /* destination address (pool), when known, otherwise NULL */
 	unsigned int exp;       /* wake up time for connect, queue, turn-around, ... */
 
 	/* struct members below are the "remote" part, as seen from the buffer side */
diff --git a/include/haproxy/stream_interface.h b/include/haproxy/stream_interface.h
index 33d5e19..56f772b 100644
--- a/include/haproxy/stream_interface.h
+++ b/include/haproxy/stream_interface.h
@@ -107,8 +107,6 @@
  */
 static inline int si_init(struct stream_interface *si)
 {
-	si->src            = NULL;
-	si->dst            = NULL;
 	si->err_type       = SI_ET_NONE;
 	si->exp            = TICK_ETERNITY;
 	si->flags         &= SI_FL_ISBACK;
@@ -429,108 +427,6 @@
 	}
 }
 
-
-/* Returns the source address of the stream-int and, if not set, fallbacks on
- * the session for frontend SI and the server connection for the backend SI. It
- * returns a const address on success or NULL on failure.
- */
-static inline const struct sockaddr_storage *si_src(struct stream_interface *si)
-{
-	if (si->flags & SI_FL_ADDR_FROM_SET)
-		return si->src;
-	if (!(si->flags & SI_FL_ISBACK))
-		return sess_src(strm_sess(si_strm(si)));
-	else {
-		struct connection *conn = cs_conn(si->cs);
-
-		if (conn)
-			return conn_src(conn);
-	}
-	return NULL;
-}
-
-
-/* Returns the destination address of the stream-int and, if not set, fallbacks
- * on the session for frontend SI and the server connection for the backend
- * SI. It returns a const address on success or NULL on failure.
- */
-static inline const struct sockaddr_storage *si_dst(struct stream_interface *si)
-{
-	if (si->flags & SI_FL_ADDR_TO_SET)
-		return si->dst;
-	if (!(si->flags & SI_FL_ISBACK))
-		return sess_dst(strm_sess(si_strm(si)));
-	else {
-		struct connection *conn = cs_conn(si->cs);
-
-		if (conn)
-			return conn_dst(conn);
-	}
-	return NULL;
-}
-
-/* Retrieves the source address of the stream-int. Returns non-zero on success
- * or zero on failure. The operation is only performed once and the address is
- * stored in the stream-int for future use. On the first call, the stream-int
- * source address is copied from the session one for frontend SI and the server
- * connection for the backend SI.
- */
-static inline int si_get_src(struct stream_interface *si)
-{
-	const struct sockaddr_storage *src = NULL;
-
-	if (si->flags & SI_FL_ADDR_FROM_SET)
-		return 1;
-
-	if (!(si->flags & SI_FL_ISBACK))
-		src = sess_src(strm_sess(si_strm(si)));
-	else {
-		struct connection *conn = cs_conn(si->cs);
-
-		if (conn)
-			src = conn_src(conn);
-	}
-	if (!src)
-		return 0;
-
-	if (!sockaddr_alloc(&si->src, src, sizeof(*src)))
-		return 0;
-
-	si->flags |= SI_FL_ADDR_FROM_SET;
-	return 1;
-}
-
-/* Retrieves the destination address of the stream-int. Returns non-zero on
- * success or zero on failure. The operation is only performed once and the
- * address is stored in the stream-int for future use. On the first call, the
- * stream-int destination address is copied from the session one for frontend SI
- * and the server connection for the backend SI.
- */
-static inline int si_get_dst(struct stream_interface *si)
-{
-	const struct sockaddr_storage *dst = NULL;
-
-	if (si->flags & SI_FL_ADDR_TO_SET)
-		return 1;
-
-	if (!(si->flags & SI_FL_ISBACK))
-		dst = sess_dst(strm_sess(si_strm(si)));
-	else {
-		struct connection *conn = cs_conn(si->cs);
-
-		if (conn)
-			dst = conn_dst(conn);
-	}
-	if (!dst)
-		return 0;
-
-	if (!sockaddr_alloc(&si->dst, dst, sizeof(*dst)))
-		return 0;
-
-	si->flags |= SI_FL_ADDR_TO_SET;
-	return 1;
-}
-
 #endif /* _HAPROXY_STREAM_INTERFACE_H */
 
 /*
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;