From: William Dauchy Date: Wed, 3 Feb 2021 21:30:09 +0000 (+0100) Subject: MEDIUM: check: align agentaddr and agentport behaviour X-Git-Tag: v2.4-dev7~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4858fb2e18e84b2784d975b02d03a1df2819eb35;p=thirdparty%2Fhaproxy.git MEDIUM: check: align agentaddr and agentport behaviour in the same manner of agentaddr, we now: - permit to set agentport through `port` keyword, like it is the case for agentaddr through `addr` - set the priority on `agent-port` keyword when used - add a flag to be able to test when the value is set like for agentaddr it makes the behaviour between `addr` and `port` more consistent. Signed-off-by: William Dauchy --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 2abd684fa5..eb685785d1 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -14061,11 +14061,11 @@ pool-purge-delay port Using the "port" parameter, it becomes possible to use a different port to - send health-checks. On some servers, it may be desirable to dedicate a port - to a specific component able to perform complex tests which are more suitable - to health-checks than the application. It is common to run a simple script in - inetd for instance. This parameter is ignored if the "check" parameter is not - set. See also the "addr" parameter. + send health-checks or to probe the agent-check. On some servers, it may be + desirable to dedicate a port to a specific component able to perform complex + tests which are more suitable to health-checks than the application. It is + common to run a simple script in inetd for instance. This parameter is + ignored if the "check" parameter is not set. See also the "addr" parameter. proto Forces the multiplexer's protocol to use for the outgoing connections to this diff --git a/include/haproxy/check.h b/include/haproxy/check.h index ed8124470e..ffeef4e220 100644 --- a/include/haproxy/check.h +++ b/include/haproxy/check.h @@ -53,6 +53,7 @@ int spoe_handle_healthcheck_response(char *frame, size_t size, char *err, int er int set_srv_agent_send(struct server *srv, const char *send); void set_srv_agent_addr(struct server *srv, struct sockaddr_storage *sk); +void set_srv_agent_port(struct server *srv, int port); /* Use this one only. This inline version only ensures that we don't * call the function when the observe mode is disabled. diff --git a/include/haproxy/server-t.h b/include/haproxy/server-t.h index 45f41959c2..32697a9c42 100644 --- a/include/haproxy/server-t.h +++ b/include/haproxy/server-t.h @@ -138,6 +138,7 @@ enum srv_initaddr { #define SRV_F_NON_STICK 0x0004 /* never add connections allocated to this server to a stick table */ #define SRV_F_USE_NS_FROM_PP 0x0008 /* use namespace associated with connection if present */ #define SRV_F_FORCED_ID 0x0010 /* server's ID was forced in the configuration */ +#define SRV_F_AGENTPORT 0x0040 /* this server has a agent port configured */ #define SRV_F_AGENTADDR 0x0080 /* this server has a agent addr configured */ #define SRV_F_COOKIESET 0x0100 /* this server has a cookie configured, so don't generate dynamic cookies */ #define SRV_F_FASTOPEN 0x0200 /* Use TCP Fast Open to connect to server */ diff --git a/src/check.c b/src/check.c index 688812717a..edb2ac29f8 100644 --- a/src/check.c +++ b/src/check.c @@ -1697,7 +1697,7 @@ static int srv_parse_agent_port(char **args, int *cur_arg, struct proxy *curpx, } global.maxsock++; - srv->agent.port = atol(args[*cur_arg+1]); + set_srv_agent_port(srv, atol(args[*cur_arg + 1])); out: return err_code; @@ -1741,6 +1741,13 @@ inline void set_srv_agent_addr(struct server *srv, struct sockaddr_storage *sk) srv->flags |= SRV_F_AGENTADDR; } +/* set agent port and apprropriate flag */ +inline void set_srv_agent_port(struct server *srv, int port) +{ + srv->agent.port = port; + srv->flags |= SRV_F_AGENTPORT; +} + /* Parse the "agent-send" server keyword */ static int srv_parse_agent_send(char **args, int *cur_arg, struct proxy *curpx, struct server *srv, char **errmsg) @@ -2060,6 +2067,9 @@ static int srv_parse_check_port(char **args, int *cur_arg, struct proxy *curpx, global.maxsock++; srv->check.port = atol(args[*cur_arg+1]); + /* if agentport was never set, we can use port */ + if (!(srv->flags & SRV_F_AGENTPORT)) + srv->agent.port = srv->check.port; out: return err_code;