]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: connection: add a destroy callback
authorWilly Tarreau <w@1wt.eu>
Sun, 8 Oct 2017 09:16:46 +0000 (11:16 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 17:03:24 +0000 (18:03 +0100)
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.

include/proto/connection.h
include/types/connection.h
src/mux_pt.c
src/session.c

index 4c952e0346dfa48805891c45e9d87845698c851a..05a63fe6adf1b1aa62bf85717a91af7af458d946 100644 (file)
@@ -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 <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 */
index ff9868e4759a31205a1e7f60f0c937085ef50514..beb0b71b88ee7ed3141ebbd1dfcbbbce9b8ad338 100644 (file)
@@ -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 */
index 8a8aec0889e3827e4a6df7efed23138e67188796..54244c34efcd2caa3202da1dae72817879223d45 100644 (file)
@@ -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);
 }
 
index c68cec545f5461979f6711b081c3e2a9917d302f..6c7399dd4ba22ef176060d2e90bab5d47f1403e0 100644 (file)
@@ -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.