MAJOR: connection: move the addr field from the stream_interface
We need to have the source and destination addresses in the connection.
They were lying in the stream interface so let's move them. The flags
SI_FL_FROM_SET and SI_FL_TO_SET have been moved as well.
It's worth noting that tcp_connect_server() almost does not use the
stream interface anymore except for a few flags.
It has been identified that once we detach the connection from the SI,
it will probably be needed to keep a copy of the server-side addresses
in the SI just for logging purposes. This has not been implemented right
now though.
diff --git a/include/proto/connection.h b/include/proto/connection.h
index abc7e22..7c8e2cb 100644
--- a/include/proto/connection.h
+++ b/include/proto/connection.h
@@ -371,6 +371,39 @@
return t->ptr.l;
}
+/* Retrieves the connection's source address */
+static inline void conn_get_from_addr(struct connection *conn)
+{
+ if (conn->flags & CO_FL_ADDR_FROM_SET)
+ return;
+
+ if (!conn->ctrl || !conn->ctrl->get_src)
+ return;
+
+ if (conn->ctrl->get_src(conn->t.sock.fd, (struct sockaddr *)&conn->addr.from,
+ sizeof(conn->addr.from),
+ conn->target.type != TARG_TYPE_CLIENT) == -1)
+ return;
+ conn->flags |= CO_FL_ADDR_FROM_SET;
+}
+
+/* Retrieves the connection's original destination address */
+static inline void conn_get_to_addr(struct connection *conn)
+{
+ if (conn->flags & CO_FL_ADDR_TO_SET)
+ return;
+
+ if (!conn->ctrl || !conn->ctrl->get_dst)
+ return;
+
+ if (conn->ctrl->get_dst(conn->t.sock.fd, (struct sockaddr *)&conn->addr.to,
+ sizeof(conn->addr.to),
+ conn->target.type != TARG_TYPE_CLIENT) == -1)
+ return;
+ conn->flags |= CO_FL_ADDR_TO_SET;
+}
+
+
#endif /* _PROTO_CONNECTION_H */
/*
diff --git a/include/proto/proto_tcp.h b/include/proto/proto_tcp.h
index 6aadb5a..cdc1d37 100644
--- a/include/proto/proto_tcp.h
+++ b/include/proto/proto_tcp.h
@@ -46,12 +46,12 @@
*/
static inline struct stktable_key *tcp_src_to_stktable_key(struct session *s)
{
- switch (s->si[0].addr.from.ss_family) {
+ switch (s->si[0].conn.addr.from.ss_family) {
case AF_INET:
- static_table_key.key = (void *)&((struct sockaddr_in *)&s->si[0].addr.from)->sin_addr;
+ static_table_key.key = (void *)&((struct sockaddr_in *)&s->si[0].conn.addr.from)->sin_addr;
break;
case AF_INET6:
- static_table_key.key = (void *)&((struct sockaddr_in6 *)&s->si[0].addr.from)->sin6_addr;
+ static_table_key.key = (void *)&((struct sockaddr_in6 *)&s->si[0].conn.addr.from)->sin6_addr;
break;
default:
return NULL;
diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h
index 7536e95..8cd4a31 100644
--- a/include/proto/stream_interface.h
+++ b/include/proto/stream_interface.h
@@ -93,38 +93,6 @@
si->conn.data_ctx = NULL;
}
-/* Retrieves the source address for the stream interface. */
-static inline void si_get_from_addr(struct stream_interface *si)
-{
- if (si->flags & SI_FL_FROM_SET)
- return;
-
- if (!si_ctrl(si) || !si_ctrl(si)->get_src)
- return;
-
- if (si_ctrl(si)->get_src(si_fd(si), (struct sockaddr *)&si->addr.from,
- sizeof(si->addr.from),
- si->conn.target.type != TARG_TYPE_CLIENT) == -1)
- return;
- si->flags |= SI_FL_FROM_SET;
-}
-
-/* Retrieves the original destination address for the stream interface. */
-static inline void si_get_to_addr(struct stream_interface *si)
-{
- if (si->flags & SI_FL_TO_SET)
- return;
-
- if (!si_ctrl(si) || !si_ctrl(si)->get_dst)
- return;
-
- if (si_ctrl(si)->get_dst(si_fd(si), (struct sockaddr *)&si->addr.to,
- sizeof(si->addr.to),
- si->conn.target.type != TARG_TYPE_CLIENT) == -1)
- return;
- si->flags |= SI_FL_TO_SET;
-}
-
/* Sends a shutr to the connection using the data layer */
static inline void si_shutr(struct stream_interface *si)
{