]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: session: remove redundant target argument from session_add_conn()
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 24 Jul 2025 09:53:13 +0000 (11:53 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 30 Jul 2025 09:39:57 +0000 (11:39 +0200)
session_add_conn() uses three argument : connection and session
instances, plus a void pointer labelled as target. Typically, it
represents the server, but can also be a backend instance (for example
on dispatch).

In fact, this argument is redundant as <target> is already a member of
the connection. This commit simplifies session_add_conn() by removing
it. A BUG_ON() on target is extended to ensure it is never NULL.

include/haproxy/session.h
src/backend.c
src/connection.c
src/http_ana.c
src/mux_fcgi.c
src/mux_h1.c
src/mux_h2.c
src/mux_quic.c
src/mux_spop.c

index cb0b6e7b5ee313d140ea8e714f786a0fe245ab91..aa36fa9daa1ea7f3e578bf3f6c22292e942ac3f8 100644 (file)
@@ -171,17 +171,21 @@ static inline void session_unown_conn(struct session *sess, struct connection *c
        }
 }
 
-/* Add the connection <conn> to the private conns list of session <sess>. This
- * function is called only if the connection is private. Nothing is performed
- * if the connection is already in the session list.
+/* Add the connection <conn> to the private conns list of session <sess>. Each
+ * connection is indexed by their respective target in the session. Nothing is
+ * performed if the connection is already in the session list.
+ *
+ * Returns true if conn is inserted or already present else false if a failure
+ * occurs during insertion.
  */
-static inline int session_add_conn(struct session *sess, struct connection *conn, void *target)
+static inline int session_add_conn(struct session *sess, struct connection *conn)
 {
        struct sess_priv_conns *pconns = NULL;
        struct server *srv = objt_server(conn->target);
        int found = 0;
 
-       BUG_ON(objt_listener(conn->target));
+       /* Connection target is used to index it in the session. Only BE conns are expected in session list. */
+       BUG_ON(!conn->target || objt_listener(conn->target));
 
        /* A connection cannot be attached already to another session. */
        BUG_ON(conn->owner && conn->owner != sess);
@@ -191,7 +195,7 @@ static inline int session_add_conn(struct session *sess, struct connection *conn
                return 1;
 
        list_for_each_entry(pconns, &sess->priv_conns, sess_el) {
-               if (pconns->target == target) {
+               if (pconns->target == conn->target) {
                        found = 1;
                        break;
                }
@@ -201,7 +205,7 @@ static inline int session_add_conn(struct session *sess, struct connection *conn
                pconns = pool_alloc(pool_head_sess_priv_conns);
                if (!pconns)
                        return 0;
-               pconns->target = target;
+               pconns->target = conn->target;
                LIST_INIT(&pconns->conn_list);
                LIST_APPEND(&sess->priv_conns, &pconns->sess_el);
 
index de16e680c0952c9c65b8fff21d028746d41a9ff8..3f0411ca72e0de3853f5c6f6bef64b8ac5890047 100644 (file)
@@ -1425,7 +1425,7 @@ check_tgid:
                if (reuse_mode == PR_O_REUSE_SAFE && conn->mux->flags & MX_FL_HOL_RISK) {
                        /* attach the connection to the session private list */
                        conn->owner = sess;
-                       session_add_conn(sess, conn, conn->target);
+                       session_add_conn(sess, conn);
                }
                else {
                        srv_add_to_avail_list(srv, conn);
@@ -2159,7 +2159,7 @@ int connect_server(struct stream *s)
                                 (reuse_mode == PR_O_REUSE_SAFE &&
                                  srv_conn->mux->flags & MX_FL_HOL_RISK)) {
                                /* If it fail now, the same will be done in mux->detach() callback */
-                               session_add_conn(s->sess, srv_conn, srv_conn->target);
+                               session_add_conn(s->sess, srv_conn);
                        }
                }
        }
index e8509fc2d3dd188c7328544d320442f2afdf7f92..458e6b0da83c07bceaaa85bdc97cc84ef9425da6 100644 (file)
@@ -117,7 +117,7 @@ int conn_create_mux(struct connection *conn, int *closed_connection)
                }
                else if (conn->flags & CO_FL_PRIVATE) {
                        /* If it fail now, the same will be done in mux->detach() callback */
-                       session_add_conn(sess, conn, conn->target);
+                       session_add_conn(sess, conn);
                }
                return 0;
 fail:
index bda8fe2409d0dbfd6449fb9bb75d96b4488272e6..568739050bb83a7aca850f7a97462c7625537749 100644 (file)
@@ -1641,7 +1641,7 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                                conn_set_owner(srv_conn, sess, NULL);
                                conn_set_private(srv_conn);
                                /* If it fail now, the same will be done in mux->detach() callback */
-                               session_add_conn(srv_conn->owner, srv_conn, srv_conn->target);
+                               session_add_conn(srv_conn->owner, srv_conn);
                                break;
                        }
                }
index 53d8f6b8c02815fe0db13cdaaee670ea40b9f97b..ce607422bcc998db3e7c2205f45530b4f0a26ff4 100644 (file)
@@ -3723,7 +3723,7 @@ static void fcgi_detach(struct sedesc *sd)
            (fconn->flags & FCGI_CF_KEEP_CONN)) {
                if (fconn->conn->flags & CO_FL_PRIVATE) {
                        /* Add the connection in the session serverlist, if not already done */
-                       if (!session_add_conn(sess, fconn->conn, fconn->conn->target)) {
+                       if (!session_add_conn(sess, fconn->conn)) {
                                fconn->conn->owner = NULL;
                                if (eb_is_empty(&fconn->streams_by_id)) {
                                        /* let's kill the connection right away */
index 6f1e95273c2a9ad7ccc634ab30684a3d47b26610..1e9c2b0decc93a25478c2b8809d2efdd09d04021 100644 (file)
@@ -1138,7 +1138,7 @@ static int h1s_finish_detach(struct h1s *h1s)
 
                if (h1c->conn->flags & CO_FL_PRIVATE) {
                        /* Add the connection in the session server list, if not already done */
-                       if (!session_add_conn(sess, h1c->conn, h1c->conn->target)) {
+                       if (!session_add_conn(sess, h1c->conn)) {
                                h1c->conn->owner = NULL;
                                h1c->conn->mux->destroy(h1c);
                                goto released;
index 46c2d756cf1976438ef53739f04641b4b461d948..b893f5db2c5b4076ce9a7dfcc08eab8ee867b3ee 100644 (file)
@@ -5533,7 +5533,7 @@ static void h2_detach(struct sedesc *sd)
 
                        if (h2c->conn->flags & CO_FL_PRIVATE) {
                                /* Add the connection in the session server list, if not already done */
-                               if (!session_add_conn(sess, h2c->conn, h2c->conn->target)) {
+                               if (!session_add_conn(sess, h2c->conn)) {
                                        h2c->conn->owner = NULL;
                                        if (eb_is_empty(&h2c->streams_by_id)) {
                                                h2c->conn->mux->destroy(h2c);
index cd014db233851af2465a53b3cf56ac38dbdd887e..2faa3cc1c4b6de053be842a1fc410a2c4b76205f 100644 (file)
@@ -3788,7 +3788,7 @@ static void qmux_strm_detach(struct sedesc *sd)
                         * conn will be closed if idle, or insert will be
                         * retried on next detach.
                         */
-                       if (!session_add_conn(sess, conn, conn->target)) {
+                       if (!session_add_conn(sess, conn)) {
                                TRACE_ERROR("error during connection insert into session list", QMUX_EV_STRM_END, conn);
                                conn->owner = NULL;
                                if (!qcc->nb_sc)
index 6baf2a2dca183169b384673a7eb22d52fb59e231..622515b37864a2e72bd444a6c193f1f760d1494a 100644 (file)
@@ -2977,7 +2977,7 @@ static void spop_detach(struct sedesc *sd)
        if (!(spop_conn->flags & (SPOP_CF_RCVD_SHUT|SPOP_CF_ERR_PENDING|SPOP_CF_ERROR))) {
                if (spop_conn->conn->flags & CO_FL_PRIVATE) {
                        /* Add the connection in the session server list, if not already done */
-                       if (!session_add_conn(sess, spop_conn->conn, spop_conn->conn->target)) {
+                       if (!session_add_conn(sess, spop_conn->conn)) {
                                spop_conn->conn->owner = NULL;
                                if (eb_is_empty(&spop_conn->streams_by_id)) {
                                        spop_conn->conn->mux->destroy(spop_conn);