From: Amaury Denoyelle Date: Thu, 3 Apr 2025 13:58:49 +0000 (+0200) Subject: MINOR: check: implement check-pool-conn-name srv keyword X-Git-Tag: v3.2-dev10~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0f1816f1a462abfb8984233f7454c61dc04fc0b;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 57c04f5d5..f139f809c 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -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 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 + May be used in the following contexts: tcp, http + + When connection reuse is performed for checks, uses 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 May be used in the following contexts: tcp, http diff --git a/include/haproxy/check-t.h b/include/haproxy/check-t.h index 24cee86e9..df75d4aca 100644 --- a/include/haproxy/check-t.h +++ b/include/haproxy/check-t.h @@ -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 */ diff --git a/src/check.c b/src/check.c index 52a55921f..9e615ea9d 100644 --- a/src/check.c +++ b/src/check.c @@ -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 */ diff --git a/src/server.c b/src/server.c index 4af5ce2d2..a94fef190 100644 --- a/src/server.c +++ b/src/server.c @@ -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; diff --git a/src/tcpcheck.c b/src/tcpcheck.c index 5329233a3..9342f30d2 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -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);