]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: Add a wrapper to mark a connection as private
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 1 Jul 2020 13:26:14 +0000 (15:26 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 15 Jul 2020 12:08:14 +0000 (14:08 +0200)
To set a connection as private, the conn_set_private() function must now be
called. It sets the CO_FL_PRIVATE flags, but it also remove the connection from
the available connection list, if necessary. For now, it never happens because
only HTTP/1 connections may be set as private after their creation. And these
connections are never inserted in the available connection list.

include/haproxy/connection.h
src/backend.c
src/http_ana.c
src/mux_fcgi.c
src/mux_h2.c
src/proto_tcp.c
src/tcpcheck.c

index f8f235c1a7a032491429d38b476288b1aec08bf3..b0974886029ce233ecf02f7afdde635dd7510696 100644 (file)
@@ -342,6 +342,17 @@ static inline void conn_set_owner(struct connection *conn, void *owner, void (*c
        conn->destroy_cb = cb;
 }
 
+
+/* Mark the connection <conn> 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 <sap> is NULL, the address is always allocated and returned.
  * if <sap> is non-null, an address will only be allocated if it points to a
index e94fc1faf488ccb6780be4417fe3ad058e894f6c..c83371e0d874a41d7d3dc14925ebc35450847d72 100644 (file)
@@ -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 */
index f394f987432c7e18e1027117f538c3d205c728ae..71e723c384e60aa210e4f07b0d9290b5d124708c 100644 (file)
@@ -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;
                        }
                }
index 7cd56121957ebb80ba2509391cbbd250eebdd23e..64b91fdb46f32c27126d82844feda62a424fc93f 100644 (file)
@@ -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)) {
index 22c67b02a711273cc0e03173c661687524e06840..bb554258ba396fa15dc9ba024e55e14043d60e75 100644 (file)
@@ -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)) {
index b772c88d9fce8dd84bf2ee415fe1c9fea36cab3f..f2bc3de224f28235b3236bf1709dd2ec8c40959e 100644 (file)
@@ -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;
                        }
index 4b8806c6595e7c99cb58c44c83ea0a7f0fc5c96e..4e714fa352116ff17ff60a4ba1c25abec39a77f6 100644 (file)
@@ -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