]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: check: consitent way to set agentaddr
authorWilliam Dauchy <wdauchy@gmail.com>
Wed, 3 Feb 2021 21:30:08 +0000 (22:30 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 4 Feb 2021 12:55:04 +0000 (13:55 +0100)
small consistency problem with `addr` and `agent-addr` options:
for the both options, the last one parsed is always used to set the
agent-check addr.  Thus these two lines don't have the same behavior:

  server ... addr <addr1> agent-addr <addr2>
  server ... agent-addr <addr2> addr <addr1>

After this patch `agent-addr` will always be the priority option over
`addr`. It means we test the flag before setting agentaddr.
We also fix all the places where we did not set the flag to be coherent
everywhere.

I was not really able to determine where this issue is coming from. So
it is probable we may backport it to all stable version where the agent
is supported.

Signed-off-by: William Dauchy <wdauchy@gmail.com>
include/haproxy/check.h
src/check.c
src/server.c

index 8d70040a3e9b21bed4d73b8e366c304debc90a86..ed8124470e3cedf983c0aa720b1c4fb6e7f6d7e3 100644 (file)
@@ -52,6 +52,7 @@ int spoe_prepare_healthcheck_request(char **req, int *len);
 int spoe_handle_healthcheck_response(char *frame, size_t size, char *err, int errlen);
 
 int set_srv_agent_send(struct server *srv, const char *send);
+void set_srv_agent_addr(struct server *srv, struct sockaddr_storage *sk);
 
 /* Use this one only. This inline version only ensures that we don't
  * call the function when the observe mode is disabled.
index e24050ff24b5b844914f4919a24e6dfbb190807b..688812717a338c89d5df607691cc6d12a028a5be 100644 (file)
@@ -1526,8 +1526,10 @@ static int srv_parse_addr(char **args, int *cur_arg, struct proxy *curpx, struct
                goto error;
        }
 
-       srv->check.addr = srv->agent.addr = *sk;
-       srv->flags |= SRV_F_AGENTADDR;
+       srv->check.addr = *sk;
+       /* if agentaddr was never set, we can use addr */
+       if (!(srv->flags & SRV_F_AGENTADDR))
+               srv->agent.addr = *sk;
 
   out:
        return err_code;
@@ -1537,21 +1539,23 @@ static int srv_parse_addr(char **args, int *cur_arg, struct proxy *curpx, struct
        goto out;
 }
 
-
 /* Parse the "agent-addr" server keyword */
 static int srv_parse_agent_addr(char **args, int *cur_arg, struct proxy *curpx, struct server *srv,
                                char **errmsg)
 {
+       struct sockaddr_storage sk;
        int err_code = 0;
 
        if (!*(args[*cur_arg+1])) {
                memprintf(errmsg, "'%s' expects an address as argument.", args[*cur_arg]);
                goto error;
        }
-       if(str2ip(args[*cur_arg+1], &srv->agent.addr) == NULL) {
+       memset(&sk, 0, sizeof(sk));
+       if (str2ip(args[*cur_arg + 1], &sk) == NULL) {
                memprintf(errmsg, "parsing agent-addr failed. Check if '%s' is correct address.", args[*cur_arg+1]);
                goto error;
        }
+       set_srv_agent_addr(srv, &sk);
 
   out:
        return err_code;
@@ -1730,6 +1734,13 @@ int set_srv_agent_send(struct server *srv, const char *send)
        return 0;
 }
 
+/* set agent addr and apprropriate flag */
+inline void set_srv_agent_addr(struct server *srv, struct sockaddr_storage *sk)
+{
+       srv->agent.addr = *sk;
+       srv->flags |= SRV_F_AGENTADDR;
+}
+
 /* 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)
index 8019dd18ac029888253abe08b3bb5ac0724db91d..ba85bb8782e6e3576ca2ef727454af19036cfbc5 100644 (file)
@@ -4383,9 +4383,14 @@ static int cli_parse_set_server(char **args, char *payload, struct appctx *appct
                        cli_err(appctx, "'set server <srv> agent' expects 'up' or 'down'.\n");
        }
        else if (strcmp(args[3], "agent-addr") == 0) {
+               struct sockaddr_storage sk;
+
+               memset(&sk, 0, sizeof(sk));
                if (!(sv->agent.state & CHK_ST_ENABLED))
                        cli_err(appctx, "agent checks are not enabled on this server.\n");
-               else if (str2ip(args[4], &sv->agent.addr) == NULL)
+               else if (str2ip(args[4], &sk))
+                       set_srv_agent_addr(sv, &sk);
+               else
                        cli_err(appctx, "incorrect addr address given for agent.\n");
        }
        else if (strcmp(args[3], "agent-send") == 0) {