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 <wdau...@gmail.com>
---
 doc/configuration.txt      | 10 +++++-----
 include/haproxy/check.h    |  1 +
 include/haproxy/server-t.h |  1 +
 src/check.c                | 12 +++++++++++-
 4 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/doc/configuration.txt b/doc/configuration.txt
index 2abd684fa..eb685785d 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -14061,11 +14061,11 @@ pool-purge-delay <delay>
 
 port <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 <name>
   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 ed8124470..ffeef4e22 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 45f41959c..32697a9c4 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 31f108bff..194f3b4a6 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))
+               set_srv_agent_port(srv, srv->check.port);
 
   out:
        return err_code;
-- 
2.30.0


Reply via email to