MINOR: check: implement check-pool-conn-name srv keyword

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.
This commit is contained in:
Amaury Denoyelle 2025-04-03 15:58:49 +02:00
parent 43367f94f1
commit f0f1816f1a
5 changed files with 49 additions and 1 deletions

View 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

View 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 */

View 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 */

View 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;

View 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);