From ec1ab8d1715e0dbb2eab6e19424b06790a6784ff Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Thu, 24 Jul 2025 11:53:13 +0200 Subject: [PATCH] MINOR: session: remove redundant target argument from session_add_conn() 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 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 | 18 +++++++++++------- src/backend.c | 4 ++-- src/connection.c | 2 +- src/http_ana.c | 2 +- src/mux_fcgi.c | 2 +- src/mux_h1.c | 2 +- src/mux_h2.c | 2 +- src/mux_quic.c | 2 +- src/mux_spop.c | 2 +- 9 files changed, 20 insertions(+), 16 deletions(-) diff --git a/include/haproxy/session.h b/include/haproxy/session.h index cb0b6e7b5..aa36fa9da 100644 --- a/include/haproxy/session.h +++ b/include/haproxy/session.h @@ -171,17 +171,21 @@ static inline void session_unown_conn(struct session *sess, struct connection *c } } -/* Add the connection to the private conns list of session . 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 to the private conns list of session . 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); diff --git a/src/backend.c b/src/backend.c index de16e680c..3f0411ca7 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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); } } } diff --git a/src/connection.c b/src/connection.c index e8509fc2d..458e6b0da 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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: diff --git a/src/http_ana.c b/src/http_ana.c index bda8fe240..568739050 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -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; } } diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 53d8f6b8c..ce607422b 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -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 */ diff --git a/src/mux_h1.c b/src/mux_h1.c index 6f1e95273..1e9c2b0de 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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; diff --git a/src/mux_h2.c b/src/mux_h2.c index 46c2d756c..b893f5db2 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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); diff --git a/src/mux_quic.c b/src/mux_quic.c index cd014db23..2faa3cc1c 100644 --- a/src/mux_quic.c +++ b/src/mux_quic.c @@ -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) diff --git a/src/mux_spop.c b/src/mux_spop.c index 6baf2a2dc..622515b37 100644 --- a/src/mux_spop.c +++ b/src/mux_spop.c @@ -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); -- 2.47.2