diff --git a/include/haproxy/connection.h b/include/haproxy/connection.h index f8f235c1a..b09748860 100644 --- a/include/haproxy/connection.h +++ b/include/haproxy/connection.h @@ -342,6 +342,17 @@ static inline void conn_set_owner(struct connection *conn, void *owner, void (*c conn->destroy_cb = cb; } + +/* Mark the connection as private and remove it from the available connection list */ +static inline void conn_set_private(struct connection *conn) +{ + conn->flags |= CO_FL_PRIVATE; + + /* Be sure to remove the connection from the available_conns list */ + if (!MT_LIST_ISEMPTY(&conn->list)) + MT_LIST_DEL(&conn->list); +} + /* Allocates a struct sockaddr from the pool if needed, assigns it to *sap and * returns it. If is NULL, the address is always allocated and returned. * if is non-null, an address will only be allocated if it points to a diff --git a/src/backend.c b/src/backend.c index e94fc1faf..c83371e0d 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1403,7 +1403,7 @@ int connect_server(struct stream *s) srv_cs = NULL; if ((s->be->options & PR_O_REUSE_MASK) == PR_O_REUSE_NEVR) - conn->flags |= CO_FL_PRIVATE; + conn_set_private(srv_conn); } if (srv_conn && srv && was_unused) { @@ -1474,7 +1474,7 @@ int connect_server(struct stream *s) srv_conn->send_proxy_ofs = 0; if (srv && srv->pp_opts) { - srv_conn->flags |= CO_FL_PRIVATE; + conn_set_private(srv_conn); srv_conn->flags |= CO_FL_SEND_PROXY; srv_conn->send_proxy_ofs = 1; /* must compute size */ if (cli_conn) @@ -1530,7 +1530,7 @@ int connect_server(struct stream *s) srv->ssl_ctx.sni, SMP_T_STR); if (smp_make_safe(smp)) { ssl_sock_set_servername(srv_conn, smp->data.u.str.area); - srv_conn->flags |= CO_FL_PRIVATE; + conn_set_private(srv_conn); } } #endif /* USE_OPENSSL */ diff --git a/src/http_ana.c b/src/http_ana.c index f394f9874..71e723c38 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -1838,7 +1838,7 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit) if ((ctx.value.len >= 4 && strncasecmp(ctx.value.ptr, "Nego", 4) == 0) || (ctx.value.len >= 4 && strncasecmp(ctx.value.ptr, "NTLM", 4) == 0)) { sess->flags |= SESS_FL_PREFER_LAST; - srv_conn->flags |= CO_FL_PRIVATE; + conn_set_private(srv_conn); break; } } diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 7cd561219..64b91fdb4 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -3560,10 +3560,6 @@ static void fcgi_detach(struct conn_stream *cs) return; } } - - /* Be sure to remove the connection from the available_conns list */ - if (!MT_LIST_ISEMPTY(&fconn->conn->list)) - MT_LIST_DEL(&fconn->conn->list); } else { if (eb_is_empty(&fconn->streams_by_id)) { diff --git a/src/mux_h2.c b/src/mux_h2.c index 22c67b02a..bb554258b 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -3961,10 +3961,6 @@ static void h2_detach(struct conn_stream *cs) return; } } - - /* Be sure to remove the connection from the available_conns list */ - if (!MT_LIST_ISEMPTY(&h2c->conn->list)) - MT_LIST_DEL(&h2c->conn->list); } else { if (eb_is_empty(&h2c->streams_by_id)) { diff --git a/src/proto_tcp.c b/src/proto_tcp.c index b772c88d9..f2bc3de22 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -415,14 +415,14 @@ int tcp_connect_server(struct connection *conn, int flags) if (conn->src && is_inet_addr(conn->src)) { switch (src->opts & CO_SRC_TPROXY_MASK) { case CO_SRC_TPROXY_CLI: - conn->flags |= CO_FL_PRIVATE; + conn_set_private(conn); /* fall through */ case CO_SRC_TPROXY_ADDR: flags = 3; break; case CO_SRC_TPROXY_CIP: case CO_SRC_TPROXY_DYN: - conn->flags |= CO_FL_PRIVATE; + conn_set_private(conn); flags = 1; break; } diff --git a/src/tcpcheck.c b/src/tcpcheck.c index 4b8806c65..4e714fa35 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -1093,7 +1093,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct tcpchec if (status != SF_ERR_NONE) goto fail_check; - conn->flags |= CO_FL_PRIVATE; + conn_set_private(conn); conn->ctx = cs; /* The mux may be initialized now if there isn't server attached to the