blob: 42b7b07c17c2549f4daae753286982af1942c3ff [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) */
Willy Tarreau8e85ad52013-12-11 16:45:07 +010044
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020045/* check status */
46enum {
47 HCHK_STATUS_UNKNOWN = 0, /* Unknown */
48 HCHK_STATUS_INI, /* Initializing */
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020049 HCHK_STATUS_START, /* Check started - SPECIAL STATUS */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020050
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020051 /* Below we have finished checks */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020052 HCHK_STATUS_CHECKED, /* DUMMY STATUS */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010053
Simon Hormanb7cd8f92012-03-19 07:25:28 +090054 HCHK_STATUS_HANA, /* Health analyze detected enough consecutive errors */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010055
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020056 HCHK_STATUS_SOCKERR, /* Socket error */
57
58 HCHK_STATUS_L4OK, /* L4 check passed, for example tcp connect */
59 HCHK_STATUS_L4TOUT, /* L4 timeout */
60 HCHK_STATUS_L4CON, /* L4 connection problem, for example: */
61 /* "Connection refused" (tcp rst) or "No route to host" (icmp) */
62
63 HCHK_STATUS_L6OK, /* L6 check passed */
64 HCHK_STATUS_L6TOUT, /* L6 (SSL) timeout */
65 HCHK_STATUS_L6RSP, /* L6 invalid response - protocol error */
66
67 HCHK_STATUS_L7TOUT, /* L7 (HTTP/SMTP) timeout */
68 HCHK_STATUS_L7RSP, /* L7 invalid response - protocol error */
69
Simon Hormanb7cd8f92012-03-19 07:25:28 +090070 /* Below we have layer 5-7 data available */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020071 HCHK_STATUS_L57DATA, /* DUMMY STATUS */
72 HCHK_STATUS_L7OKD, /* L7 check passed */
73 HCHK_STATUS_L7OKCD, /* L7 check conditionally passed */
74 HCHK_STATUS_L7STS, /* L7 response error, for example HTTP 5xx */
75
76 HCHK_STATUS_SIZE
77};
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020078
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010079
80/* health status for response tracking */
81enum {
82 HANA_STATUS_UNKNOWN = 0,
83
84 HANA_STATUS_L4_OK, /* L4 successful connection */
85 HANA_STATUS_L4_ERR, /* L4 unsuccessful connection */
86
87 HANA_STATUS_HTTP_OK, /* Correct http response */
88 HANA_STATUS_HTTP_STS, /* Wrong http response, for example HTTP 5xx */
89 HANA_STATUS_HTTP_HDRRSP, /* Invalid http response (headers) */
90 HANA_STATUS_HTTP_RSP, /* Invalid http response */
91
92 HANA_STATUS_HTTP_READ_ERROR, /* Read error */
93 HANA_STATUS_HTTP_READ_TIMEOUT, /* Read timeout */
94 HANA_STATUS_HTTP_BROKEN_PIPE, /* Unexpected close from server */
95
96 HANA_STATUS_SIZE
97};
98
99enum {
100 HANA_ONERR_UNKNOWN = 0,
101
102 HANA_ONERR_FASTINTER, /* Force fastinter*/
103 HANA_ONERR_FAILCHK, /* Simulate a failed check */
104 HANA_ONERR_SUDDTH, /* Enters sudden death - one more failed check will mark this server down */
105 HANA_ONERR_MARKDWN, /* Mark this server down, now! */
106};
107
108enum {
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900109 HANA_ONMARKEDDOWN_NONE = 0,
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900110 HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS, /* Shutdown peer sessions */
111};
112
113enum {
Justin Karnegeseb2c24a2012-05-24 15:28:52 -0700114 HANA_ONMARKEDUP_NONE = 0,
115 HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS, /* Shutdown peer sessions */
116};
117
118enum {
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100119 HANA_OBS_NONE = 0,
120
121 HANA_OBS_LAYER4, /* Observe L4 - for example tcp */
122 HANA_OBS_LAYER7, /* Observe L7 - for example http */
123
124 HANA_OBS_SIZE
125};
126
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100127struct check {
Cyril Bonté1f96a872014-11-15 22:41:27 +0100128 struct xprt_ops *xprt; /* transport layer operations for health checks */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100129 struct connection *conn; /* connection state for health checks */
130 unsigned short port; /* the port to use for the health checks */
131 struct buffer *bi, *bo; /* input and output buffers to send/recv check */
132 struct task *task; /* the task associated to the health check processing, NULL if disabled */
133 struct timeval start; /* last health check start time */
134 long duration; /* time in ms took to finish last health check */
135 short status, code; /* check result, check code */
Cyril Bonté1f96a872014-11-15 22:41:27 +0100136 char desc[HCHK_DESC_LEN]; /* health check description */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100137 int use_ssl; /* use SSL for health checks */
138 int send_proxy; /* send a PROXY protocol header with checks */
139 struct tcpcheck_rule *current_step; /* current step when using tcpcheck */
Baptiste Assmann69e273f2013-12-11 00:52:19 +0100140 struct tcpcheck_rule *last_started_step;/* pointer to latest tcpcheck rule started */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100141 int inter, fastinter, downinter; /* checks: time in milliseconds */
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100142 enum chk_result result; /* health-check result : CHK_RES_* */
Willy Tarreau2c115e52013-12-11 19:41:16 +0100143 int state; /* state of the check : CHK_ST_* */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100144 int health; /* 0 to rise-1 = bad;
145 * rise to rise+fall-1 = good */
146 int rise, fall; /* time in iterations */
147 int type; /* Check type, one of PR_O2_*_CHK */
148 struct server *server; /* back-pointer to server */
149};
150
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200151struct check_status {
152 short result; /* one of SRV_CHK_* */
153 char *info; /* human readable short info */
154 char *desc; /* long description */
155};
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100156
157struct analyze_status {
158 char *desc; /* description */
159 unsigned char lr[HANA_OBS_SIZE]; /* result for l4/l7: 0 = ignore, 1 - error, 2 - OK */
160};
Thierry FOURNIER7eeb4352013-06-14 15:28:25 +0200161
Willy Tarreau98aec9f2013-12-06 16:16:41 +0100162/* possible actions for tcpcheck_rule->action */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200163enum {
Willy Tarreau98aec9f2013-12-06 16:16:41 +0100164 TCPCHK_ACT_SEND = 0, /* send action, regular string format */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200165 TCPCHK_ACT_EXPECT, /* expect action, either regular or binary string */
Baptiste Assmann69e273f2013-12-11 00:52:19 +0100166 TCPCHK_ACT_CONNECT, /* connect action, to probe a new port */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200167};
168
Baptiste Assmann69e273f2013-12-11 00:52:19 +0100169/* flags used by tcpcheck_rule->conn_opts */
170#define TCPCHK_OPT_NONE 0x0000 /* no options specified, default */
171#define TCPCHK_OPT_SEND_PROXY 0x0001 /* send proxy-protocol string */
172#define TCPCHK_OPT_SSL 0x0002 /* SSL connection */
173
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200174struct tcpcheck_rule {
175 struct list list; /* list linked to from the proxy */
176 int action; /* action: send or expect */
177 /* match type uses NON-NULL pointer from either string or expect_regex below */
178 /* sent string is string */
179 char *string; /* sent or expected string */
180 int string_len; /* string lenght */
Thierry FOURNIER09af0d62014-06-18 11:35:54 +0200181 struct my_regex *expect_regex; /* expected */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200182 int inverse; /* 0 = regular match, 1 = inverse match */
Baptiste Assmann69e273f2013-12-11 00:52:19 +0100183 unsigned short port; /* port to connect to */
184 unsigned short conn_opts; /* options when setting up a new connection */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200185};
186
Thierry FOURNIER7eeb4352013-06-14 15:28:25 +0200187#endif /* _TYPES_CHECKS_H */