CLEANUP: stream-int: add si_opposite() to find the other stream interface

At a few places we need to find one stream interface from the other one.
Instead of passing via the channel, we simply use the session as an
intermediary, which simply results in applying an offset to the pointer.
diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h
index 889a855..70b2ac8 100644
--- a/include/proto/stream_interface.h
+++ b/include/proto/stream_interface.h
@@ -94,6 +94,15 @@
 		return LIST_ELEM(si, struct session *, si[0])->task;
 }
 
+/* returns the stream interface on the other side. Used during forwarding. */
+static inline struct stream_interface *si_opposite(struct stream_interface *si)
+{
+	if (si->flags & SI_FL_ISBACK)
+		return &LIST_ELEM(si, struct session *, si[1])->si[0];
+	else
+		return &LIST_ELEM(si, struct session *, si[0])->si[1];
+}
+
 /* Initializes all required fields for a new appctx. Note that it does the
  * minimum acceptable initialization for an appctx. This means only the
  * 3 integer states st0, st1, st2 are zeroed.
diff --git a/src/hlua.c b/src/hlua.c
index b003750..0aa92e9 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -1095,7 +1095,7 @@
 static void hlua_socket_handler(struct stream_interface *si)
 {
 	struct appctx *appctx = objt_appctx(si->end);
-	struct connection *c = objt_conn(si_ic(si)->cons->end);
+	struct connection *c = objt_conn(si_opposite(si)->end);
 
 	/* Wakeup the main session if the client connection is closed. */
 	if (!c || channel_output_closed(si_ic(si)) || channel_input_closed(si_oc(si))) {
diff --git a/src/stream_interface.c b/src/stream_interface.c
index f45678f..87df334 100644
--- a/src/stream_interface.c
+++ b/src/stream_interface.c
@@ -176,13 +176,13 @@
 	old_flags = si->flags;
 	if (likely((si_oc(si)->flags & (CF_SHUTW|CF_WRITE_PARTIAL|CF_DONT_READ)) == CF_WRITE_PARTIAL &&
 		   channel_may_recv(si_oc(si)) &&
-		   (si_oc(si)->prod->flags & SI_FL_WAIT_ROOM)))
-		si_chk_rcv(si_oc(si)->prod);
+		   (si_opposite(si)->flags & SI_FL_WAIT_ROOM)))
+		si_chk_rcv(si_opposite(si));
 
 	if (((si_ic(si)->flags & CF_READ_PARTIAL) && !channel_is_empty(si_ic(si))) &&
 	    (si_ic(si)->pipe /* always try to send spliced data */ ||
-	     (si_ib(si)->i == 0 && (si_ic(si)->cons->flags & SI_FL_WAIT_DATA)))) {
-		si_chk_snd(si_ic(si)->cons);
+	     (si_ib(si)->i == 0 && (si_opposite(si)->flags & SI_FL_WAIT_DATA)))) {
+		si_chk_snd(si_opposite(si));
 		/* check if the consumer has freed some space */
 		if (channel_may_recv(si_ic(si)) && !si_ic(si)->pipe)
 			si->flags &= ~SI_FL_WAIT_ROOM;
@@ -203,14 +203,14 @@
 	    si->state != SI_ST_EST ||
 	    (si->flags & SI_FL_ERR) ||
 	    ((si_ic(si)->flags & CF_READ_PARTIAL) &&
-	     (!si_ic(si)->to_forward || si_ic(si)->cons->state != SI_ST_EST)) ||
+	     (!si_ic(si)->to_forward || si_opposite(si)->state != SI_ST_EST)) ||
 
 	    /* changes on the consumption side */
 	    (si_oc(si)->flags & (CF_WRITE_NULL|CF_WRITE_ERROR)) ||
 	    ((si_oc(si)->flags & CF_WRITE_ACTIVITY) &&
 	     ((si_oc(si)->flags & CF_SHUTW) ||
 	      ((si_oc(si)->flags & CF_WAKE_WRITE) &&
-	       (si_oc(si)->prod->state != SI_ST_EST ||
+	       (si_opposite(si)->state != SI_ST_EST ||
 	        (channel_is_empty(si_oc(si)) && !si_oc(si)->to_forward)))))) {
 		if (!(si->flags & SI_FL_DONT_WAKE))
 			task_wakeup(si_task(si), TASK_WOKEN_IO);
@@ -424,7 +424,7 @@
 		 */
 		if (conn->data == &si_conn_cb) {
 			struct stream_interface *si = conn->owner;
-			struct connection *remote = objt_conn(si_oc(si)->prod->end);
+			struct connection *remote = objt_conn(si_opposite(si)->end);
 			ret = make_proxy_line(trash.str, trash.size, objt_server(conn->target), remote);
 		}
 		else {
@@ -586,8 +586,8 @@
 
 		if (likely((si_oc(si)->flags & (CF_SHUTW|CF_WRITE_PARTIAL|CF_DONT_READ)) == CF_WRITE_PARTIAL &&
 			   channel_may_recv(si_oc(si)) &&
-			   (si_oc(si)->prod->flags & SI_FL_WAIT_ROOM)))
-			si_chk_rcv(si_oc(si)->prod);
+			   (si_opposite(si)->flags & SI_FL_WAIT_ROOM)))
+			si_chk_rcv(si_opposite(si));
 	}
 
 	/* process producer side.
@@ -599,10 +599,10 @@
 	 */
 	if (((si_ic(si)->flags & CF_READ_PARTIAL) && !channel_is_empty(si_ic(si))) &&
 	    (si_ic(si)->pipe /* always try to send spliced data */ ||
-	     (si_ib(si)->i == 0 && (si_ic(si)->cons->flags & SI_FL_WAIT_DATA)))) {
+	     (si_ib(si)->i == 0 && (si_opposite(si)->flags & SI_FL_WAIT_DATA)))) {
 		int last_len = si_ic(si)->pipe ? si_ic(si)->pipe->data : 0;
 
-		si_chk_snd(si_ic(si)->cons);
+		si_chk_snd(si_opposite(si));
 
 		/* check if the consumer has freed some space either in the
 		 * buffer or in the pipe.
@@ -630,14 +630,14 @@
 	    si->state != SI_ST_EST ||
 	    (si->flags & SI_FL_ERR) ||
 	    ((si_ic(si)->flags & CF_READ_PARTIAL) &&
-	     (!si_ic(si)->to_forward || si_ic(si)->cons->state != SI_ST_EST)) ||
+	     (!si_ic(si)->to_forward || si_opposite(si)->state != SI_ST_EST)) ||
 
 	    /* changes on the consumption side */
 	    (si_oc(si)->flags & (CF_WRITE_NULL|CF_WRITE_ERROR)) ||
 	    ((si_oc(si)->flags & CF_WRITE_ACTIVITY) &&
 	     ((si_oc(si)->flags & CF_SHUTW) ||
 	      ((si_oc(si)->flags & CF_WAKE_WRITE) &&
-	       (si_oc(si)->prod->state != SI_ST_EST ||
+	       (si_opposite(si)->state != SI_ST_EST ||
 	        (channel_is_empty(si_oc(si)) && !si_oc(si)->to_forward)))))) {
 		task_wakeup(si_task(si), TASK_WOKEN_IO);
 	}