This is in preparation for associating a agent check
with a server which runs as well as the server's existing check.

The split has been made by:
* Moving elements of struct server's check element that will
  be shared by both checks into a new check_common element
  of struct server.
* Moving the remaining elements to a new struct check and
  making struct server's check element a struct check.
* Adding a server element to struct check, a back-pointer
  to the server element it is a member of.
  - At this time the server could be obtained using
    container_of, however, this will not be so easy
    once a second struct check element is added to struct server
    to accommodate an agent health check.

Signed-off-by: Simon Horman <ho...@verge.net.au>
---
 include/types/server.h |   31 +++++++++++++++++++------------
 src/cfgparse.c         |   15 ++++++++-------
 src/checks.c           |   10 +++++-----
 3 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/include/types/server.h b/include/types/server.h
index b58a062..c8b2766 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -103,6 +103,21 @@ struct tree_occ {
        struct eb32_node node;
 };
 
+struct check {
+       struct connection *conn;                /* connection state for health 
checks */
+
+       short port;                             /* the port to use for the 
health checks */
+       struct buffer *bi, *bo;                 /* input and output buffers to 
send/recv check */
+       struct task *task;                      /* the task associated to the 
health check processing, NULL if disabled */
+       struct timeval start;                   /* last health check start time 
*/
+       long duration;                          /* time in ms took to finish 
last health check */
+       short status, code;                     /* check result, check code */
+       char desc[HCHK_DESC_LEN];               /* health check descritpion */
+       int use_ssl;                            /* use SSL for health checks */
+       int send_proxy;                         /* send a PROXY protocol header 
with checks */
+       struct server *server;                  /* back-pointer to server */
+};
+
 struct server {
        enum obj_type obj_type;                 /* object type == 
OBJ_TYPE_SERVER */
        struct server *next;
@@ -163,21 +178,13 @@ struct server {
 
        int puid;                               /* proxy-unique server ID, used 
for SNMP, and "first" LB algo */
 
-       struct {                                /* health-check specific 
configuration */
-               struct connection *conn;        /* connection state for health 
checks */
+       struct {                                /* configuration  used by 
halth-check and agent-check */
                struct protocol *proto;         /* server address protocol for 
health checks */
                struct xprt_ops *xprt;          /* transport layer operations 
for health checks */
                struct sockaddr_storage addr;   /* the address to check, if 
different from <addr> */
-               short port;                     /* the port to use for the 
health checks */
-               struct buffer *bi, *bo;         /* input and output buffers to 
send/recv check */
-               struct task *task;              /* the task associated to the 
health check processing, NULL if disabled */
-               struct timeval start;           /* last health check start time 
*/
-               long duration;                  /* time in ms took to finish 
last health check */
-               short status, code;             /* check result, check code */
-               char desc[HCHK_DESC_LEN];       /* health check descritpion */
-               int use_ssl;                    /* use SSL for health checks */
-               int send_proxy;                 /* send a PROXY protocol header 
with checks */
-       } check;
+       } check_common;
+
+       struct check check;                     /* health-check specific 
configuration */
 
 #ifdef USE_OPENSSL
        int use_ssl;                            /* ssl enabled */
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 1a2fc8a..f7af294 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -4112,8 +4112,8 @@ stats_error_parsing:
                        }
 
                        newsrv->addr = *sk;
-                       newsrv->proto = newsrv->check.proto = 
protocol_by_family(newsrv->addr.ss_family);
-                       newsrv->xprt  = newsrv->check.xprt  = &raw_sock;
+                       newsrv->proto = newsrv->check_common.proto = 
protocol_by_family(newsrv->addr.ss_family);
+                       newsrv->xprt  = newsrv->check_common.xprt  = &raw_sock;
 
                        if (!newsrv->proto) {
                                Alert("parsing [%s:%d] : Unknown protocol 
family %d '%s'\n",
@@ -4122,7 +4122,7 @@ stats_error_parsing:
                                goto out;
                        }
 
-                       newsrv->check.use_ssl   = 
curproxy->defsrv.check.use_ssl;
+                       newsrv->check.use_ssl = curproxy->defsrv.check.use_ssl;
                        newsrv->check.port      = curproxy->defsrv.check.port;
                        newsrv->inter           = curproxy->defsrv.inter;
                        newsrv->fastinter       = curproxy->defsrv.fastinter;
@@ -4269,7 +4269,7 @@ stats_error_parsing:
                                        goto out;
                                }
 
-                               newsrv->check.addr = *sk;
+                               newsrv->check_common.addr = *sk;
                                cur_arg += 2;
                        }
                        else if (!strcmp(args[cur_arg], "port")) {
@@ -4684,15 +4684,15 @@ stats_error_parsing:
                         * 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.addr)) {
+                       if (!newsrv->check.port && 
!is_addr(&newsrv->check_common.addr)) {
 #ifdef USE_OPENSSL
                                newsrv->check.use_ssl |= newsrv->use_ssl;
 #endif
                                newsrv->check.send_proxy |= (newsrv->state & 
SRV_SEND_PROXY);
                        }
-                       /* try to get the port from check.addr if check.port 
not set */
+                       /* 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.addr);
+                               newsrv->check.port = 
get_host_port(&newsrv->check_common.addr);
 
                        if (!newsrv->check.port)
                                newsrv->check.port = realport; /* by default */
@@ -4742,6 +4742,7 @@ stats_error_parsing:
 
                        newsrv->check.conn->t.sock.fd = -1; /* no check in 
progress yet */
                        newsrv->check.status = HCHK_STATUS_INI;
+                       newsrv->check.server = newsrv;
                        newsrv->state |= SRV_CHECKED;
                }
 
diff --git a/src/checks.c b/src/checks.c
index 2ab509d..f35abaf 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -1352,14 +1352,14 @@ static struct task *process_chk(struct task *t)
                conn->flags = CO_FL_NONE;
                conn->err_code = CO_ER_NONE;
                conn->target = &s->obj_type;
-               conn_prepare(conn, &check_conn_cb, s->check.proto, 
s->check.xprt, s);
+               conn_prepare(conn, &check_conn_cb, s->check_common.proto, 
s->check_common.xprt, s);
 
                /* no client address */
                clear_addr(&conn->addr.from);
 
-               if (is_addr(&s->check.addr))
+               if (is_addr(&s->check_common.addr))
                        /* we'll connect to the check addr specified on the 
server */
-                       conn->addr.to = s->check.addr;
+                       conn->addr.to = s->check_common.addr;
                else
                        /* we'll connect to the addr on the server */
                        conn->addr.to = s->addr;
@@ -1377,8 +1377,8 @@ static struct task *process_chk(struct task *t)
                 * Note that we try to prevent the network stack from sending 
the ACK during the
                 * connect() when a pure TCP check is used (without PROXY 
protocol).
                 */
-               ret = s->check.proto->connect(conn, s->proxy->options2 & 
PR_O2_CHK_ANY,
-                                             s->check.send_proxy ? 1 : 
(s->proxy->options2 & PR_O2_CHK_ANY) ? 0 : 2);
+               ret = s->check_common.proto->connect(conn, s->proxy->options2 & 
PR_O2_CHK_ANY,
+                                                    s->check.send_proxy ? 1 : 
(s->proxy->options2 & PR_O2_CHK_ANY) ? 0 : 2);
                conn->flags |= CO_FL_WAKE_DATA;
                if (s->check.send_proxy)
                        conn->flags |= CO_FL_LOCAL_SPROXY;
-- 
1.7.10.4


Reply via email to