The motivation for this is to make checks more independent of each
other to allow further reuse of their infrastructure.

For nowserver->check and server->agent still always use the same values
for the addr and proto fields so this patch should not introduce any
behavioural changes.

Signed-off-by: Simon Horman <ho...@verge.net.au>
---
 include/types/checks.h |  2 ++
 include/types/server.h |  5 -----
 src/checks.c           | 14 +++++++-------
 src/server.c           | 14 +++++++-------
 4 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/include/types/checks.h b/include/types/checks.h
index 831166e..04d79c4 100644
--- a/include/types/checks.h
+++ b/include/types/checks.h
@@ -179,6 +179,8 @@ struct check {
        char **argv;                            /* the arguments to use if 
running a process-based 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 protocol *proto;                 /* server address protocol for 
health checks */
+       struct sockaddr_storage addr;           /* the address to check, if 
different from <addr> */
 };
 
 struct check_status {
diff --git a/include/types/server.h b/include/types/server.h
index 1cabb83..4f97e17 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -202,11 +202,6 @@ struct server {
 
        int puid;                               /* proxy-unique server ID, used 
for SNMP, and "first" LB algo */
 
-       struct {                                /* configuration  used by 
health-check and agent-check */
-               struct protocol *proto;         /* server address protocol for 
health checks */
-               struct sockaddr_storage addr;   /* the address to check, if 
different from <addr> */
-       } check_common;
-
        struct check check;                     /* health-check specific 
configuration */
        struct check agent;                     /* agent specific configuration 
*/
 
diff --git a/src/checks.c b/src/checks.c
index b2f89a5..6624714 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -1437,18 +1437,18 @@ static int connect_conn_chk(struct task *t)
 
        /* prepare a new connection */
        conn_init(conn);
-       conn_prepare(conn, s->check_common.proto, check->xprt);
+       conn_prepare(conn, check->proto, check->xprt);
        conn_attach(conn, check, &check_conn_cb);
        conn->target = &s->obj_type;
 
        /* no client address */
        clear_addr(&conn->addr.from);
 
-       if (is_addr(&s->check_common.addr)) {
+       if (is_addr(&check->addr)) {
 
                /* we'll connect to the check addr specified on the server */
-               conn->addr.to = s->check_common.addr;
-               proto = s->check_common.proto;
+               conn->addr.to = check->addr;
+               proto = check->proto;
        }
        else {
                /* we'll connect to the addr on the server */
@@ -2498,10 +2498,10 @@ static void tcpcheck_main(struct connection *conn)
                        /* no client address */
                        clear_addr(&conn->addr.from);
 
-                       if (is_addr(&s->check_common.addr)) {
+                       if (is_addr(&check->addr)) {
                                /* we'll connect to the check addr specified on 
the server */
-                               conn->addr.to = s->check_common.addr;
-                               proto = s->check_common.proto;
+                               conn->addr.to = check->addr;
+                               proto = check->proto;
                        }
                        else {
                                /* we'll connect to the addr on the server */
diff --git a/src/server.c b/src/server.c
index 8554e75..31f319b 100644
--- a/src/server.c
+++ b/src/server.c
@@ -901,7 +901,7 @@ int parse_server(const char *file, int linenum, char 
**args, struct proxy *curpr
                        }
 
                        newsrv->addr = *sk;
-                       newsrv->proto = newsrv->check_common.proto = 
protocol_by_family(newsrv->addr.ss_family);
+                       newsrv->proto = newsrv->check.proto = 
newsrv->agent.proto = protocol_by_family(newsrv->addr.ss_family);
                        newsrv->xprt  = newsrv->check.xprt = newsrv->agent.xprt 
= &raw_sock;
 
                        if (!newsrv->proto) {
@@ -1109,8 +1109,8 @@ int parse_server(const char *file, int linenum, char 
**args, struct proxy *curpr
                                        goto out;
                                }
 
-                               newsrv->check_common.addr = *sk;
-                               newsrv->check_common.proto = 
protocol_by_family(sk->ss_family);
+                               newsrv->check.addr = newsrv->agent.addr = *sk;
+                               newsrv->check.proto = newsrv->agent.proto = 
protocol_by_family(sk->ss_family);
                                cur_arg += 2;
                        }
                        else if (!strcmp(args[cur_arg], "port")) {
@@ -1578,7 +1578,7 @@ int parse_server(const char *file, int linenum, char 
**args, struct proxy *curpr
                         * same as for the production traffic. Otherwise we use 
raw_sock by
                         * default, unless one is specified.
                         */
-                       if (!newsrv->check.port && 
!is_addr(&newsrv->check_common.addr)) {
+                       if (!newsrv->check.port && 
!is_addr(&newsrv->check.addr)) {
 #ifdef USE_OPENSSL
                                newsrv->check.use_ssl |= (newsrv->use_ssl || 
(newsrv->proxy->options & PR_O_TCPCHK_SSL));
 #endif
@@ -1586,7 +1586,7 @@ int parse_server(const char *file, int linenum, char 
**args, struct proxy *curpr
                        }
                        /* try to get the port from check_core.addr if 
check.port not set */
                        if (!newsrv->check.port)
-                               newsrv->check.port = 
get_host_port(&newsrv->check_common.addr);
+                               newsrv->check.port = 
get_host_port(&newsrv->check.addr);
 
                        if (!newsrv->check.port)
                                newsrv->check.port = realport; /* by default */
@@ -1609,8 +1609,8 @@ int parse_server(const char *file, int linenum, char 
**args, struct proxy *curpr
                         * be a 'connect' one when checking an IPv4/IPv6 server.
                         */
                        if (!newsrv->check.port &&
-                           (is_inet_addr(&newsrv->check_common.addr) ||
-                            (!is_addr(&newsrv->check_common.addr) && 
is_inet_addr(&newsrv->addr)))) {
+                           (is_inet_addr(&newsrv->check.addr) ||
+                            (!is_addr(&newsrv->check.addr) && 
is_inet_addr(&newsrv->addr)))) {
                                struct tcpcheck_rule *n = NULL, *r = NULL;
                                struct list *l;
 
-- 
2.1.4


Reply via email to