MEDIUM: connection: add a destroy callback

This callback will be used to release upper layers when a mux is in
use. Given that the mux can be asynchronously deleted, we need a way
to release the extra information such as the session.

This callback will be called directly by the mux upon releasing
everything and before the connection itself is released, so that
the callee can find its information inside the connection if needed.

The way it currently works is not perfect, and most likely this should
instead become a mux release callback, but for now we have no easy way
to add mux-specific stuff, and since there's one mux per connection,
it works fine this way.
diff --git a/include/proto/connection.h b/include/proto/connection.h
index 4c952e0..05a63fe 100644
--- a/include/proto/connection.h
+++ b/include/proto/connection.h
@@ -615,14 +615,16 @@
 	conn->err_code = CO_ER_NONE;
 	conn->target = NULL;
 	conn->xprt_done_cb = NULL;
+	conn->destroy_cb = NULL;
 	conn->proxy_netns = NULL;
 	LIST_INIT(&conn->list);
 }
 
 /* sets <owner> as the connection's owner */
-static inline void conn_set_owner(struct connection *conn, void *owner)
+static inline void conn_set_owner(struct connection *conn, void *owner, void (*cb)(struct connection *))
 {
 	conn->owner = owner;
+	conn->destroy_cb = cb;
 }
 
 /* registers <cb> as a callback to notify for transport's readiness or failure */
diff --git a/include/types/connection.h b/include/types/connection.h
index ff9868e..beb0b71 100644
--- a/include/types/connection.h
+++ b/include/types/connection.h
@@ -377,6 +377,7 @@
 	enum obj_type *target;        /* the target to connect to (server, proxy, applet, ...) */
 	struct list list;             /* attach point to various connection lists (idle, ...) */
 	int (*xprt_done_cb)(struct connection *conn);  /* callback to notify of end of handshake */
+	void (*destroy_cb)(struct connection *conn);  /* callback to notify of imminent death of the connection */
 	const struct netns_entry *proxy_netns;
 	struct {
 		struct sockaddr_storage from;	/* client address, or address to spoof when connecting to the server */
diff --git a/src/mux_pt.c b/src/mux_pt.c
index 8a8aec0..54244c3 100644
--- a/src/mux_pt.c
+++ b/src/mux_pt.c
@@ -122,6 +122,8 @@
 	LIST_DEL(&conn->list);
 	conn_stop_tracking(conn);
 	conn_full_close(conn);
+	if (conn->destroy_cb)
+		conn->destroy_cb(conn);
 	conn_free(conn);
 }
 
diff --git a/src/session.c b/src/session.c
index c68cec5..6c7399d 100644
--- a/src/session.c
+++ b/src/session.c
@@ -154,7 +154,7 @@
 	if (!sess)
 		goto out_free_conn;
 
-	conn_set_owner(cli_conn, sess);
+	conn_set_owner(cli_conn, sess, NULL);
 
 	/* now evaluate the tcp-request layer4 rules. We only need a session
 	 * and no stream for these rules.