]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: check: implement check-pool-conn-name srv keyword
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 3 Apr 2025 13:58:49 +0000 (15:58 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 3 Apr 2025 15:19:07 +0000 (17:19 +0200)
This commit is a direct follow-up of the previous one. It defines a new
server keyword check-pool-conn-name. It is used as the default value for
the name parameter of idle connection hash generation.

Its behavior is similar to server keyword pool-conn-name, but reserved
for checks reuse. If check-pool-conn-name is set, it is used in priority
to match a connection for reuse. If unset, a fallback is performed on
check-sni.

doc/configuration.txt
include/haproxy/check-t.h
src/check.c
src/server.c
src/tcpcheck.c

index 57c04f5d53a0bea4b24a89b38671efbe764ada19..f139f809c039fd4615b5fbf7282a5235903917fa 100644 (file)
@@ -18218,6 +18218,8 @@ check-reuse-pool
   This option is automatically enabled for servers acting as passive reverse
   HTTP gateway, as for those servers connect is only supported through reuse.
 
+  See also: "check-pool-conn-name"
+
 check-send-proxy
   May be used in the following contexts: tcp, http
 
@@ -18236,6 +18238,16 @@ check-alpn <protocols>
   a comma-delimited list of protocol names, for instance: "http/1.1,http/1.0"
   (without quotes). If it is not set, the server ALPN is used.
 
+check-pool-conn-name <name>
+  May be used in the following contexts: tcp, http
+
+  When connection reuse is performed for checks, uses <name> if set as a
+  connection identifier to match a corresponding connection in the pool. This
+  serves as the equivalent to the "pool-conn-name" server keyword. "check-sni"
+  will also be used as a fallback if the current option is not used.
+
+  See also: "check-reuse-pool"
+
 check-proto <name>
   May be used in the following contexts: tcp, http
 
index 24cee86e930d189a1bef2423b2905f47b12dd8ae..df75d4acadcaec673cf77345da9f9c1556d56c28 100644 (file)
@@ -188,6 +188,7 @@ struct check {
        char **envp;                            /* the environment to use if running a process-based check */
        struct pid_list *curpid;                /* entry in pid_list used for current process-based test, or -1 if not in test */
        struct sockaddr_storage addr;           /* the address to check */
+       char *pool_conn_name;                   /* conn name used on reuse */
        char *sni;                              /* Server name */
        char *alpn_str;                         /* ALPN to use for checks */
        int alpn_len;                           /* ALPN string length */
index 52a55921f196e6fb8585cb3a20978fb3544494e0..9e615ea9d6fdd7b8089b672ac9ea8c029c173d3f 100644 (file)
@@ -1572,6 +1572,8 @@ void free_check(struct check *check)
                ha_free(&check->tcpcheck_rules);
        }
 
+       ha_free(&check->pool_conn_name);
+
        task_destroy(check->task);
 
        check_release_buf(check, &check->bi);
@@ -2362,6 +2364,34 @@ static int srv_parse_no_check_send_proxy(char **args, int *cur_arg, struct proxy
        return 0;
 }
 
+/* parse the "check-pool-conn-name" server keyword */
+static int srv_parse_check_pool_conn_name(char **args, int *cur_arg,
+                                          struct proxy *px,
+                                          struct server *newsrv, char **err)
+{
+       int err_code = 0;
+
+       if (!*args[*cur_arg + 1]) {
+               memprintf(err, "'%s' : missing value", args[*cur_arg]);
+               goto error;
+       }
+
+       ha_free(&newsrv->check.pool_conn_name);
+       newsrv->check.pool_conn_name = strdup(args[*cur_arg + 1]);
+       if (!newsrv->check.pool_conn_name) {
+               memprintf(err, "'%s' : out of memory", args[*cur_arg]);
+               return ERR_ALERT | ERR_FATAL;
+       }
+
+  out:
+       return err_code;
+
+  error:
+       err_code |= ERR_ALERT | ERR_FATAL;
+       goto out;
+}
+
+
 /* parse the "check-proto" server keyword */
 static int srv_parse_check_proto(char **args, int *cur_arg,
                                 struct proxy *px, struct server *newsrv, char **err)
@@ -2662,6 +2692,7 @@ static struct srv_kw_list srv_kws = { "CHK", { }, {
        { "agent-port",          srv_parse_agent_port,          1,  1,  1 }, /* Set the TCP port used for agent checks. */
        { "agent-send",          srv_parse_agent_send,          1,  1,  1 }, /* Set string to send to agent. */
        { "check",               srv_parse_check,               0,  1,  1 }, /* Enable health checks */
+       { "check-pool-conn-name", srv_parse_check_pool_conn_name, 1, 1, 1 }, /* */
        { "check-proto",         srv_parse_check_proto,         1,  1,  1 }, /* Set the mux protocol for health checks  */
        { "check-reuse-pool",    srv_parse_check_reuse_pool,    0,  1,  1 }, /* Allows to reuse idle connections for checks */
        { "check-send-proxy",    srv_parse_check_send_proxy,    0,  1,  1 }, /* Enable PROXY protocol for health checks */
index 4af5ce2d2492dc00ac171d46a9c2f68dbf3270cd..a94fef190d3a46295bff7564a8e5592cce316abd 100644 (file)
@@ -2854,6 +2854,8 @@ void srv_settings_cpy(struct server *srv, const struct server *src, int srv_tmpl
        srv->check.alpn_len           = src->check.alpn_len;
        if (!(srv->flags & SRV_F_RHTTP))
                srv->check.reuse_pool = src->check.reuse_pool;
+       if (src->check.pool_conn_name)
+               srv->check.pool_conn_name = strdup(src->check.pool_conn_name);
        /* Note: 'flags' field has potentially been already initialized. */
        srv->flags                   |= src->flags;
        srv->do_check                 = src->do_check;
index 5329233a3992dec60633a23d31296b3394f5d9dc..9342f30d2a5c3f64754a38db643bb0a163898cc6 100644 (file)
@@ -1272,7 +1272,9 @@ enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct tcpchec
 
                TRACE_DEVEL("trying connection reuse for check", CHK_EV_TCPCHK_CONN, check);
 
-               if (connect->sni)
+               if (check->pool_conn_name)
+                       pool_conn_name = ist(check->pool_conn_name);
+               else if (connect->sni)
                        pool_conn_name = ist(connect->sni);
                else if ((connect->options & TCPCHK_OPT_DEFAULT_CONNECT) && check->sni)
                        pool_conn_name = ist(check->sni);