MEDIUM: stream_sock: add a get_src and get_dst callback and remove SN_FRT_ADDR_SET

These callbacks are used to retrieve the source and destination address
of a socket. The address flags are not hold on the stream interface and
not on the session anymore. The addresses are collected when needed.

This still needs to be improved to store the IP and port separately so
that it is not needed to perform a getsockname() when only the IP address
is desired for outgoing traffic.
diff --git a/include/proto/frontend.h b/include/proto/frontend.h
index 6a68622..a80f9bd 100644
--- a/include/proto/frontend.h
+++ b/include/proto/frontend.h
@@ -25,7 +25,6 @@
 #include <common/config.h>
 #include <types/session.h>
 
-void get_frt_addr(struct session *s);
 int frontend_accept(struct session *s);
 int frontend_decode_proxy_request(struct session *s, struct buffer *req, int an_bit);
 int make_proxy_line(char *buf, int buf_len, struct sockaddr_storage *src, struct sockaddr_storage *dst);
diff --git a/include/proto/stream_sock.h b/include/proto/stream_sock.h
index e5d4f51..9e1bc3f 100644
--- a/include/proto/stream_sock.h
+++ b/include/proto/stream_sock.h
@@ -58,6 +58,50 @@
 }
 
 
+/*
+ * Retrieves the original destination address for the stream interface. On the
+ * client side, if the original destination address was translated, the original
+ * address is retrieved.
+ */
+static inline void stream_sock_get_to_addr(struct stream_interface *si)
+{
+	socklen_t namelen;
+
+	if (si->flags & SI_FL_TO_SET)
+		return;
+
+	namelen = sizeof(si->addr.to);
+
+#if defined(TPROXY) && defined(SO_ORIGINAL_DST)
+	if (getsockopt(si->fd, SOL_IP, SO_ORIGINAL_DST, (struct sockaddr *)&si->addr.to, &namelen) != -1) {
+		si->flags |= SI_FL_TO_SET;
+		return;
+	}
+#endif
+	if (si->get_dst &&
+	    si->get_dst(si->fd, (struct sockaddr *)&si->addr.to, &namelen) != -1)
+		si->flags |= SI_FL_TO_SET;
+	return;
+}
+
+/*
+ * Retrieves the source address for the stream interface.
+ */
+static inline void stream_sock_get_from_addr(struct stream_interface *si)
+{
+	socklen_t namelen;
+
+	if (si->flags & SI_FL_FROM_SET)
+		return;
+
+	namelen = sizeof(si->addr.to);
+	if (si->get_src &&
+	    si->get_src(si->fd, (struct sockaddr *)&si->addr.from, &namelen) != -1)
+		si->flags |= SI_FL_FROM_SET;
+	return;
+}
+
+
 #endif /* _PROTO_STREAM_SOCK_H */
 
 /*