blob: ac3e7b644138fb4a9e89d13e89465bc442ba58b1 [file] [log] [blame]
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001/*
2 * Health-checks.
3 *
4 * Copyright 2008-2009 Krzysztof Piotr Oledzki <ole@ans.pl>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Thierry FOURNIER7eeb4352013-06-14 15:28:25 +020013#ifndef _TYPES_CHECKS_H
14#define _TYPES_CHECKS_H
15
Willy Tarreau8e85ad52013-12-11 16:45:07 +010016#include <sys/time.h>
17
18#include <common/config.h>
19#include <common/mini-clist.h>
20#include <common/regex.h>
21
22#include <types/connection.h>
23#include <types/obj_type.h>
24#include <types/task.h>
25#include <types/server.h>
26
Willy Tarreau6aaa1b82013-12-11 17:09:34 +010027/* enum used by check->result. Must remain in this order, as some code uses
28 * result >= CHK_RES_PASSED to declare success.
29 */
30enum chk_result {
31 CHK_RES_UNKNOWN = 0, /* initialized to this by default */
Willy Tarreau23964182014-05-20 20:56:30 +020032 CHK_RES_NEUTRAL, /* valid check but no status information */
Willy Tarreau6aaa1b82013-12-11 17:09:34 +010033 CHK_RES_FAILED, /* check failed */
34 CHK_RES_PASSED, /* check succeeded and server is fully up again */
35 CHK_RES_CONDPASS, /* check reports the server doesn't want new sessions */
36};
Willy Tarreau8e85ad52013-12-11 16:45:07 +010037
Willy Tarreau2c115e52013-12-11 19:41:16 +010038/* flags used by check->state */
39#define CHK_ST_INPROGRESS 0x0001 /* a check is currently running */
Willy Tarreau2e10f5a2013-12-11 20:11:55 +010040#define CHK_ST_CONFIGURED 0x0002 /* this check is configured and may be enabled */
41#define CHK_ST_ENABLED 0x0004 /* this check is currently administratively enabled */
Willy Tarreau33a08db2013-12-11 21:03:31 +010042#define CHK_ST_PAUSED 0x0008 /* checks are paused because of maintenance (health only) */
Willy Tarreau33434322013-12-11 21:15:19 +010043#define CHK_ST_AGENT 0x0010 /* check is an agent check (otherwise it's a health check) */
Baptiste Assmann95db2bc2016-06-13 14:15:41 +020044#define CHK_ST_PORT_MISS 0x0020 /* check can't be send because no port is configured to run it */
Willy Tarreau8e85ad52013-12-11 16:45:07 +010045
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020046/* check status */
47enum {
48 HCHK_STATUS_UNKNOWN = 0, /* Unknown */
49 HCHK_STATUS_INI, /* Initializing */
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020050 HCHK_STATUS_START, /* Check started - SPECIAL STATUS */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020051
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020052 /* Below we have finished checks */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020053 HCHK_STATUS_CHECKED, /* DUMMY STATUS */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010054
Simon Hormanb7cd8f92012-03-19 07:25:28 +090055 HCHK_STATUS_HANA, /* Health analyze detected enough consecutive errors */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010056
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020057 HCHK_STATUS_SOCKERR, /* Socket error */
58
59 HCHK_STATUS_L4OK, /* L4 check passed, for example tcp connect */
60 HCHK_STATUS_L4TOUT, /* L4 timeout */
61 HCHK_STATUS_L4CON, /* L4 connection problem, for example: */
62 /* "Connection refused" (tcp rst) or "No route to host" (icmp) */
63
64 HCHK_STATUS_L6OK, /* L6 check passed */
65 HCHK_STATUS_L6TOUT, /* L6 (SSL) timeout */
66 HCHK_STATUS_L6RSP, /* L6 invalid response - protocol error */
67
68 HCHK_STATUS_L7TOUT, /* L7 (HTTP/SMTP) timeout */
69 HCHK_STATUS_L7RSP, /* L7 invalid response - protocol error */
70
Simon Hormanb7cd8f92012-03-19 07:25:28 +090071 /* Below we have layer 5-7 data available */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020072 HCHK_STATUS_L57DATA, /* DUMMY STATUS */
73 HCHK_STATUS_L7OKD, /* L7 check passed */
74 HCHK_STATUS_L7OKCD, /* L7 check conditionally passed */
75 HCHK_STATUS_L7STS, /* L7 response error, for example HTTP 5xx */
76
Simon Horman98637e52014-06-20 12:30:16 +090077 HCHK_STATUS_PROCERR, /* External process check failure */
78 HCHK_STATUS_PROCTOUT, /* External process check timeout */
79 HCHK_STATUS_PROCOK, /* External process check passed */
80
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020081 HCHK_STATUS_SIZE
82};
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020083
Cyril Bontéac92a062014-12-27 22:28:38 +010084/* environment variables memory requirement for different types of data */
85#define EXTCHK_SIZE_EVAL_INIT 0 /* size determined during the init phase,
86 * such environment variables are not updatable. */
87#define EXTCHK_SIZE_ULONG 20 /* max string length for an unsigned long value */
88
89/* external checks environment variables */
90enum {
91 EXTCHK_PATH = 0,
92
93 /* Proxy specific environment variables */
94 EXTCHK_HAPROXY_PROXY_NAME, /* the backend name */
95 EXTCHK_HAPROXY_PROXY_ID, /* the backend id */
96 EXTCHK_HAPROXY_PROXY_ADDR, /* the first bind address if available (or empty) */
97 EXTCHK_HAPROXY_PROXY_PORT, /* the first bind port if available (or empty) */
98
99 /* Server specific environment variables */
100 EXTCHK_HAPROXY_SERVER_NAME, /* the server name */
101 EXTCHK_HAPROXY_SERVER_ID, /* the server id */
102 EXTCHK_HAPROXY_SERVER_ADDR, /* the server address */
103 EXTCHK_HAPROXY_SERVER_PORT, /* the server port if available (or empty) */
104 EXTCHK_HAPROXY_SERVER_MAXCONN, /* the server max connections */
105 EXTCHK_HAPROXY_SERVER_CURCONN, /* the current number of connections on the server */
106
107 EXTCHK_SIZE
108};
109
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100110
111/* health status for response tracking */
112enum {
113 HANA_STATUS_UNKNOWN = 0,
114
115 HANA_STATUS_L4_OK, /* L4 successful connection */
116 HANA_STATUS_L4_ERR, /* L4 unsuccessful connection */
117
118 HANA_STATUS_HTTP_OK, /* Correct http response */
119 HANA_STATUS_HTTP_STS, /* Wrong http response, for example HTTP 5xx */
120 HANA_STATUS_HTTP_HDRRSP, /* Invalid http response (headers) */
121 HANA_STATUS_HTTP_RSP, /* Invalid http response */
122
123 HANA_STATUS_HTTP_READ_ERROR, /* Read error */
124 HANA_STATUS_HTTP_READ_TIMEOUT, /* Read timeout */
125 HANA_STATUS_HTTP_BROKEN_PIPE, /* Unexpected close from server */
126
127 HANA_STATUS_SIZE
128};
129
130enum {
131 HANA_ONERR_UNKNOWN = 0,
132
133 HANA_ONERR_FASTINTER, /* Force fastinter*/
134 HANA_ONERR_FAILCHK, /* Simulate a failed check */
135 HANA_ONERR_SUDDTH, /* Enters sudden death - one more failed check will mark this server down */
136 HANA_ONERR_MARKDWN, /* Mark this server down, now! */
137};
138
139enum {
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900140 HANA_ONMARKEDDOWN_NONE = 0,
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900141 HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS, /* Shutdown peer sessions */
142};
143
144enum {
Justin Karnegeseb2c24a2012-05-24 15:28:52 -0700145 HANA_ONMARKEDUP_NONE = 0,
146 HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS, /* Shutdown peer sessions */
147};
148
149enum {
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100150 HANA_OBS_NONE = 0,
151
152 HANA_OBS_LAYER4, /* Observe L4 - for example tcp */
153 HANA_OBS_LAYER7, /* Observe L7 - for example http */
154
155 HANA_OBS_SIZE
156};
157
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100158struct check {
Cyril Bonté9ce13112014-11-15 22:41:27 +0100159 struct xprt_ops *xprt; /* transport layer operations for health checks */
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200160 struct conn_stream *cs; /* conn_stream state for health checks */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100161 unsigned short port; /* the port to use for the health checks */
162 struct buffer *bi, *bo; /* input and output buffers to send/recv check */
163 struct task *task; /* the task associated to the health check processing, NULL if disabled */
164 struct timeval start; /* last health check start time */
165 long duration; /* time in ms took to finish last health check */
166 short status, code; /* check result, check code */
Cyril Bonté9ce13112014-11-15 22:41:27 +0100167 char desc[HCHK_DESC_LEN]; /* health check description */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100168 int use_ssl; /* use SSL for health checks */
169 int send_proxy; /* send a PROXY protocol header with checks */
Simon Hormane16c1b32015-01-30 11:22:57 +0900170 struct list *tcpcheck_rules; /* tcp-check send / expect rules */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100171 struct tcpcheck_rule *current_step; /* current step when using tcpcheck */
Baptiste Assmann69e273f2013-12-11 00:52:19 +0100172 struct tcpcheck_rule *last_started_step;/* pointer to latest tcpcheck rule started */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100173 int inter, fastinter, downinter; /* checks: time in milliseconds */
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100174 enum chk_result result; /* health-check result : CHK_RES_* */
Willy Tarreau2c115e52013-12-11 19:41:16 +0100175 int state; /* state of the check : CHK_ST_* */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100176 int health; /* 0 to rise-1 = bad;
177 * rise to rise+fall-1 = good */
178 int rise, fall; /* time in iterations */
179 int type; /* Check type, one of PR_O2_*_CHK */
James Brown55f9ff12015-10-21 18:19:05 -0700180 char *send_string; /* optionally send a string when connecting to the agent */
181 int send_string_len; /* length of agent command string */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100182 struct server *server; /* back-pointer to server */
Simon Horman98637e52014-06-20 12:30:16 +0900183 char **argv; /* the arguments to use if running a process-based check */
184 char **envp; /* the environment to use if running a process-based check */
185 struct pid_list *curpid; /* entry in pid_list used for current process-based test, or -1 if not in test */
Simon Horman0ba0e4a2015-01-30 11:23:00 +0900186 struct sockaddr_storage addr; /* the address to check */
Olivier Houchard9130a962017-10-17 17:33:43 +0200187 char *sni; /* Server name */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100188};
189
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200190struct check_status {
191 short result; /* one of SRV_CHK_* */
192 char *info; /* human readable short info */
193 char *desc; /* long description */
194};
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100195
Cyril Bontéac92a062014-12-27 22:28:38 +0100196struct extcheck_env {
197 char *name; /* environment variable name */
198 int vmaxlen; /* value maximum length, used to determine the required memory allocation */
199};
200
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100201struct analyze_status {
202 char *desc; /* description */
203 unsigned char lr[HANA_OBS_SIZE]; /* result for l4/l7: 0 = ignore, 1 - error, 2 - OK */
204};
Thierry FOURNIER7eeb4352013-06-14 15:28:25 +0200205
Willy Tarreau98aec9f2013-12-06 16:16:41 +0100206/* possible actions for tcpcheck_rule->action */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200207enum {
Willy Tarreau98aec9f2013-12-06 16:16:41 +0100208 TCPCHK_ACT_SEND = 0, /* send action, regular string format */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200209 TCPCHK_ACT_EXPECT, /* expect action, either regular or binary string */
Baptiste Assmann69e273f2013-12-11 00:52:19 +0100210 TCPCHK_ACT_CONNECT, /* connect action, to probe a new port */
Baptiste Assmann22b09d22015-05-01 08:03:04 +0200211 TCPCHK_ACT_COMMENT, /* no action, simply a comment used for logs */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200212};
213
Baptiste Assmann69e273f2013-12-11 00:52:19 +0100214/* flags used by tcpcheck_rule->conn_opts */
215#define TCPCHK_OPT_NONE 0x0000 /* no options specified, default */
216#define TCPCHK_OPT_SEND_PROXY 0x0001 /* send proxy-protocol string */
217#define TCPCHK_OPT_SSL 0x0002 /* SSL connection */
218
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200219struct tcpcheck_rule {
220 struct list list; /* list linked to from the proxy */
221 int action; /* action: send or expect */
Baptiste Assmannaa12b472015-04-25 16:16:48 +0200222 char *comment; /* comment to be used in the logs and on the stats socket */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200223 /* match type uses NON-NULL pointer from either string or expect_regex below */
224 /* sent string is string */
225 char *string; /* sent or expected string */
226 int string_len; /* string lenght */
Thierry FOURNIER09af0d62014-06-18 11:35:54 +0200227 struct my_regex *expect_regex; /* expected */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200228 int inverse; /* 0 = regular match, 1 = inverse match */
Baptiste Assmann69e273f2013-12-11 00:52:19 +0100229 unsigned short port; /* port to connect to */
230 unsigned short conn_opts; /* options when setting up a new connection */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200231};
232
Thierry FOURNIER7eeb4352013-06-14 15:28:25 +0200233#endif /* _TYPES_CHECKS_H */