diff --git a/include/proto/connection.h b/include/proto/connection.h index 4c952e034..05a63fe6a 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -615,14 +615,16 @@ static inline void conn_init(struct connection *conn) 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 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 as a callback to notify for transport's readiness or failure */ diff --git a/include/types/connection.h b/include/types/connection.h index ff9868e47..beb0b71b8 100644 --- a/include/types/connection.h +++ b/include/types/connection.h @@ -377,6 +377,7 @@ struct connection { 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 8a8aec088..54244c34e 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -122,6 +122,8 @@ static void mux_pt_detach(struct conn_stream *cs) 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 c68cec545..6c7399dd4 100644 --- a/src/session.c +++ b/src/session.c @@ -154,7 +154,7 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr 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.