blob: 3ea4a06384ecdcdced5d2c98035f44bc5be53bfb [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 Tarreau4c7e4b72020-05-27 12:58:42 +020016#include <haproxy/api-t.h>
Willy Tarreau8d2b7772020-05-27 10:58:19 +020017#include <import/ebpttree.h>
Willy Tarreau8e85ad52013-12-11 16:45:07 +010018
Christopher Fauletdc75d572020-04-29 13:32:21 +020019#include <common/standard.h>
Willy Tarreaueb6f7012020-05-27 16:21:26 +020020#include <import/ist.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020021#include <haproxy/list-t.h>
Willy Tarreau8e85ad52013-12-11 16:45:07 +010022#include <common/regex.h>
Willy Tarreau8dabda72020-05-27 17:22:10 +020023#include <haproxy/buf-t.h>
Willy Tarreau8e85ad52013-12-11 16:45:07 +010024
25#include <types/connection.h>
26#include <types/obj_type.h>
Christopher Fauletdc75d572020-04-29 13:32:21 +020027#include <types/proxy.h>
28#include <types/sample.h>
29#include <types/server.h>
30#include <types/session.h>
Willy Tarreau8e85ad52013-12-11 16:45:07 +010031#include <types/task.h>
Willy Tarreau8e85ad52013-12-11 16:45:07 +010032
Willy Tarreau6aaa1b82013-12-11 17:09:34 +010033/* enum used by check->result. Must remain in this order, as some code uses
34 * result >= CHK_RES_PASSED to declare success.
35 */
36enum chk_result {
37 CHK_RES_UNKNOWN = 0, /* initialized to this by default */
Willy Tarreau23964182014-05-20 20:56:30 +020038 CHK_RES_NEUTRAL, /* valid check but no status information */
Willy Tarreau6aaa1b82013-12-11 17:09:34 +010039 CHK_RES_FAILED, /* check failed */
40 CHK_RES_PASSED, /* check succeeded and server is fully up again */
41 CHK_RES_CONDPASS, /* check reports the server doesn't want new sessions */
42};
Willy Tarreau8e85ad52013-12-11 16:45:07 +010043
Willy Tarreau2c115e52013-12-11 19:41:16 +010044/* flags used by check->state */
45#define CHK_ST_INPROGRESS 0x0001 /* a check is currently running */
Willy Tarreau2e10f5a2013-12-11 20:11:55 +010046#define CHK_ST_CONFIGURED 0x0002 /* this check is configured and may be enabled */
47#define CHK_ST_ENABLED 0x0004 /* this check is currently administratively enabled */
Willy Tarreau33a08db2013-12-11 21:03:31 +010048#define CHK_ST_PAUSED 0x0008 /* checks are paused because of maintenance (health only) */
Willy Tarreau33434322013-12-11 21:15:19 +010049#define CHK_ST_AGENT 0x0010 /* check is an agent check (otherwise it's a health check) */
Baptiste Assmann95db2bc2016-06-13 14:15:41 +020050#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 +010051
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020052/* check status */
Christopher Faulet10320592020-04-01 10:37:29 +020053enum healthcheck_status {
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020054 HCHK_STATUS_UNKNOWN = 0, /* Unknown */
55 HCHK_STATUS_INI, /* Initializing */
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020056 HCHK_STATUS_START, /* Check started - SPECIAL STATUS */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020057
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020058 /* Below we have finished checks */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020059 HCHK_STATUS_CHECKED, /* DUMMY STATUS */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010060
Simon Hormanb7cd8f92012-03-19 07:25:28 +090061 HCHK_STATUS_HANA, /* Health analyze detected enough consecutive errors */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010062
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020063 HCHK_STATUS_SOCKERR, /* Socket error */
64
65 HCHK_STATUS_L4OK, /* L4 check passed, for example tcp connect */
66 HCHK_STATUS_L4TOUT, /* L4 timeout */
67 HCHK_STATUS_L4CON, /* L4 connection problem, for example: */
68 /* "Connection refused" (tcp rst) or "No route to host" (icmp) */
69
70 HCHK_STATUS_L6OK, /* L6 check passed */
71 HCHK_STATUS_L6TOUT, /* L6 (SSL) timeout */
72 HCHK_STATUS_L6RSP, /* L6 invalid response - protocol error */
73
74 HCHK_STATUS_L7TOUT, /* L7 (HTTP/SMTP) timeout */
75 HCHK_STATUS_L7RSP, /* L7 invalid response - protocol error */
76
Simon Hormanb7cd8f92012-03-19 07:25:28 +090077 /* Below we have layer 5-7 data available */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020078 HCHK_STATUS_L57DATA, /* DUMMY STATUS */
79 HCHK_STATUS_L7OKD, /* L7 check passed */
80 HCHK_STATUS_L7OKCD, /* L7 check conditionally passed */
81 HCHK_STATUS_L7STS, /* L7 response error, for example HTTP 5xx */
82
Simon Horman98637e52014-06-20 12:30:16 +090083 HCHK_STATUS_PROCERR, /* External process check failure */
84 HCHK_STATUS_PROCTOUT, /* External process check timeout */
85 HCHK_STATUS_PROCOK, /* External process check passed */
86
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020087 HCHK_STATUS_SIZE
88};
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020089
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010090/* health status for response tracking */
91enum {
92 HANA_STATUS_UNKNOWN = 0,
93
94 HANA_STATUS_L4_OK, /* L4 successful connection */
95 HANA_STATUS_L4_ERR, /* L4 unsuccessful connection */
96
97 HANA_STATUS_HTTP_OK, /* Correct http response */
98 HANA_STATUS_HTTP_STS, /* Wrong http response, for example HTTP 5xx */
99 HANA_STATUS_HTTP_HDRRSP, /* Invalid http response (headers) */
100 HANA_STATUS_HTTP_RSP, /* Invalid http response */
101
102 HANA_STATUS_HTTP_READ_ERROR, /* Read error */
103 HANA_STATUS_HTTP_READ_TIMEOUT, /* Read timeout */
104 HANA_STATUS_HTTP_BROKEN_PIPE, /* Unexpected close from server */
105
106 HANA_STATUS_SIZE
107};
108
109enum {
110 HANA_ONERR_UNKNOWN = 0,
111
112 HANA_ONERR_FASTINTER, /* Force fastinter*/
113 HANA_ONERR_FAILCHK, /* Simulate a failed check */
114 HANA_ONERR_SUDDTH, /* Enters sudden death - one more failed check will mark this server down */
115 HANA_ONERR_MARKDWN, /* Mark this server down, now! */
116};
117
118enum {
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900119 HANA_ONMARKEDDOWN_NONE = 0,
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900120 HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS, /* Shutdown peer sessions */
121};
122
123enum {
Justin Karnegeseb2c24a2012-05-24 15:28:52 -0700124 HANA_ONMARKEDUP_NONE = 0,
125 HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS, /* Shutdown peer sessions */
126};
127
128enum {
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100129 HANA_OBS_NONE = 0,
130
131 HANA_OBS_LAYER4, /* Observe L4 - for example tcp */
132 HANA_OBS_LAYER7, /* Observe L7 - for example http */
133
134 HANA_OBS_SIZE
135};
136
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100137struct check {
Christopher Faulet38290462020-04-21 11:46:40 +0200138 enum obj_type obj_type; /* object type == OBJ_TYPE_CHECK */
Gaetan Rivet05d692d2020-02-14 17:42:54 +0100139 struct session *sess; /* Health check session. */
Gaetan Rivet13a50432020-02-21 18:13:44 +0100140 struct vars vars; /* Health check dynamic variables. */
Cyril Bonté9ce13112014-11-15 22:41:27 +0100141 struct xprt_ops *xprt; /* transport layer operations for health checks */
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200142 struct conn_stream *cs; /* conn_stream state for health checks */
Willy Tarreauc9fa0482018-07-10 17:43:27 +0200143 struct buffer bi, bo; /* input and output buffers to send/recv check */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100144 struct task *task; /* the task associated to the health check processing, NULL if disabled */
145 struct timeval start; /* last health check start time */
146 long duration; /* time in ms took to finish last health check */
147 short status, code; /* check result, check code */
Willy Tarreau08eaa782017-11-26 08:44:34 +0100148 unsigned short port; /* the port to use for the health checks */
Cyril Bonté9ce13112014-11-15 22:41:27 +0100149 char desc[HCHK_DESC_LEN]; /* health check description */
Christopher Faulet4a8c0262020-04-27 12:13:06 +0200150 signed char use_ssl; /* use SSL for health checks (1: on, 0: server mode, -1: off) */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100151 int send_proxy; /* send a PROXY protocol header with checks */
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200152 struct tcpcheck_rules *tcpcheck_rules; /* tcp-check send / expect rules */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100153 struct tcpcheck_rule *current_step; /* current step when using tcpcheck */
154 int inter, fastinter, downinter; /* checks: time in milliseconds */
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100155 enum chk_result result; /* health-check result : CHK_RES_* */
Willy Tarreau2c115e52013-12-11 19:41:16 +0100156 int state; /* state of the check : CHK_ST_* */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100157 int health; /* 0 to rise-1 = bad;
158 * rise to rise+fall-1 = good */
159 int rise, fall; /* time in iterations */
160 int type; /* Check type, one of PR_O2_*_CHK */
161 struct server *server; /* back-pointer to server */
Olivier Houchardc98aa1f2019-01-11 18:17:17 +0100162 struct proxy *proxy; /* proxy to be used */
Simon Horman98637e52014-06-20 12:30:16 +0900163 char **argv; /* the arguments to use if running a process-based check */
164 char **envp; /* the environment to use if running a process-based check */
165 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 +0900166 struct sockaddr_storage addr; /* the address to check */
Olivier Houchardfa8aa862018-10-10 18:25:41 +0200167 struct wait_event wait_list; /* Waiting for I/O events */
Olivier Houchard9130a962017-10-17 17:33:43 +0200168 char *sni; /* Server name */
Olivier Houchard92150142018-12-21 19:47:01 +0100169 char *alpn_str; /* ALPN to use for checks */
170 int alpn_len; /* ALPN string length */
Christopher Fauletb3567142020-04-21 11:59:32 +0200171 const struct mux_proto_list *mux_proto; /* the mux to use for all outgoing connections (specified by the "proto" keyword) */
Alexander Liu2a54bb72019-05-22 19:44:48 +0800172 int via_socks4; /* check the connection via socks4 proxy */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100173};
174
Christopher Fauleta202d1d2020-03-26 17:38:49 +0100175#define TCPCHK_OPT_NONE 0x0000 /* no options specified, default */
176#define TCPCHK_OPT_SEND_PROXY 0x0001 /* send proxy-protocol string */
177#define TCPCHK_OPT_SSL 0x0002 /* SSL connection */
178#define TCPCHK_OPT_LINGER 0x0004 /* Do not RST connection, let it linger */
179#define TCPCHK_OPT_DEFAULT_CONNECT 0x0008 /* Do a connect using server params */
Christopher Fauletbb591a12020-04-01 16:52:17 +0200180#define TCPCHK_OPT_IMPLICIT 0x0010 /* Implicit connect */
181#define TCPCHK_OPT_SOCKS4 0x0020 /* check the connection via socks4 proxy */
Gaetan Rivet06d963a2020-02-21 18:49:05 +0100182
183struct tcpcheck_connect {
Christopher Faulet5c288742020-03-31 08:15:58 +0200184 char *sni; /* server name to use for SSL connections */
185 char *alpn; /* ALPN to use for the SSL connection */
186 int alpn_len; /* ALPN string length */
Christopher Fauletb3567142020-04-21 11:59:32 +0200187 const struct mux_proto_list *mux_proto; /* the mux to use for all outgoing connections (specified by the "proto" keyword) */
Christopher Faulet5c288742020-03-31 08:15:58 +0200188 uint16_t options; /* options when setting up a new connection */
189 uint16_t port; /* port to connect to */
Christopher Fauletb7d30092020-03-30 15:19:03 +0200190 struct sample_expr *port_expr; /* sample expr to determine the port, may be NULL */
Christopher Faulet5c288742020-03-31 08:15:58 +0200191 struct sockaddr_storage addr; /* the address to the connect */
Gaetan Rivet06d963a2020-02-21 18:49:05 +0100192};
193
Gaetan Rivet48219dc2020-02-21 18:41:28 +0100194enum tcpcheck_send_type {
Christopher Fauletf50f4e92020-03-30 19:52:29 +0200195 TCPCHK_SEND_UNDEF = 0, /* Send is not parsed. */
196 TCPCHK_SEND_STRING, /* Send an ASCII string. */
197 TCPCHK_SEND_BINARY, /* Send a binary sequence. */
Christopher Faulete5870d82020-04-15 11:32:03 +0200198 TCPCHK_SEND_STRING_LF, /* Send an ASCII log-format string. */
199 TCPCHK_SEND_BINARY_LF, /* Send a binary log-format sequence. */
200 TCPCHK_SEND_HTTP, /* Send an HTTP request */
Gaetan Rivet48219dc2020-02-21 18:41:28 +0100201};
202
Christopher Faulete5870d82020-04-15 11:32:03 +0200203struct tcpcheck_http_hdr {
204 struct ist name; /* the header name */
205 struct list value; /* the log-format string value */
206 struct list list; /* header chained list */
207};
208
Christopher Faulet8021a5f2020-04-24 13:53:12 +0200209struct tcpcheck_codes {
210 unsigned int (*codes)[2]; /* an array of roange of codes: [0]=min [1]=max */
211 size_t num; /* number of entry in the array */
212};
213
Christopher Faulete5870d82020-04-15 11:32:03 +0200214#define TCPCHK_SND_HTTP_FL_URI_FMT 0x0001 /* Use a log-format string for the uri */
215#define TCPCHK_SND_HTTP_FL_BODY_FMT 0x0002 /* Use a log-format string for the body */
216#define TCPCHK_SND_HTTP_FROM_OPT 0x0004 /* Send rule coming from "option httpck" directive */
217
Gaetan Rivet48219dc2020-02-21 18:41:28 +0100218struct tcpcheck_send {
219 enum tcpcheck_send_type type;
Christopher Fauletf50f4e92020-03-30 19:52:29 +0200220 union {
221 struct ist data; /* an ASCII string or a binary sequence */
222 struct list fmt; /* an ASCII or hexa log-format string */
Christopher Faulete5870d82020-04-15 11:32:03 +0200223 struct {
224 unsigned int flags; /* TCPCHK_SND_HTTP_FL_* */
225 struct http_meth meth; /* the HTTP request method */
226 union {
227 struct ist uri; /* the HTTP request uri is a string */
228 struct list uri_fmt; /* or a log-format string */
229 };
230 struct ist vsn; /* the HTTP request version string */
231 struct list hdrs; /* the HTTP request header list */
232 union {
233 struct ist body; /* the HTTP request payload is a string */
234 struct list body_fmt; /* or a log-format string */
235 };
236 } http; /* Info about the HTTP request to send */
Christopher Fauletf50f4e92020-03-30 19:52:29 +0200237 };
Gaetan Rivet48219dc2020-02-21 18:41:28 +0100238};
239
Christopher Faulet6f87adc2020-04-03 11:16:13 +0200240enum tcpcheck_eval_ret {
241 TCPCHK_EVAL_WAIT = 0,
242 TCPCHK_EVAL_STOP,
243 TCPCHK_EVAL_CONTINUE,
244};
245
Gaetan Rivetb616add2020-02-07 15:37:17 +0100246enum tcpcheck_expect_type {
Christopher Faulete5870d82020-04-15 11:32:03 +0200247 TCPCHK_EXPECT_UNDEF = 0, /* Match is not used. */
248 TCPCHK_EXPECT_STRING, /* Matches a string. */
Christopher Faulet67a23452020-05-05 18:10:01 +0200249 TCPCHK_EXPECT_STRING_REGEX, /* Matches a regular pattern. */
Christopher Fauletaaab0832020-05-05 15:54:22 +0200250 TCPCHK_EXPECT_STRING_LF, /* Matches a log-format string. */
Christopher Faulet39708192020-05-05 10:47:36 +0200251 TCPCHK_EXPECT_BINARY, /* Matches a binary sequence on a hex-encoded text. */
Christopher Faulet67a23452020-05-05 18:10:01 +0200252 TCPCHK_EXPECT_BINARY_REGEX, /* Matches a regular pattern on a hex-encoded text. */
Christopher Fauletaaab0832020-05-05 15:54:22 +0200253 TCPCHK_EXPECT_BINARY_LF, /* Matches a log-format binary sequence on a hex-encoded text. */
Christopher Faulete5870d82020-04-15 11:32:03 +0200254 TCPCHK_EXPECT_CUSTOM, /* Execute a custom function. */
Christopher Faulet39708192020-05-05 10:47:36 +0200255 TCPCHK_EXPECT_HTTP_STATUS, /* Matches a list of codes on the HTTP status */
Christopher Faulet67a23452020-05-05 18:10:01 +0200256 TCPCHK_EXPECT_HTTP_STATUS_REGEX, /* Matches a regular pattern on the HTTP status */
Christopher Faulet39708192020-05-05 10:47:36 +0200257 TCPCHK_EXPECT_HTTP_HEADER, /* Matches on HTTP headers */
258 TCPCHK_EXPECT_HTTP_BODY, /* Matches a string oa the HTTP payload */
Christopher Faulet67a23452020-05-05 18:10:01 +0200259 TCPCHK_EXPECT_HTTP_BODY_REGEX, /* Matches a regular pattern on a HTTP payload */
Christopher Fauletaaab0832020-05-05 15:54:22 +0200260 TCPCHK_EXPECT_HTTP_BODY_LF, /* Matches a log-format string on the HTTP payload */
Gaetan Rivetb616add2020-02-07 15:37:17 +0100261};
262
Christopher Faulet12d57402020-04-10 09:58:42 +0200263/* tcp-check expect flags */
Christopher Faulet39708192020-05-05 10:47:36 +0200264#define TCPCHK_EXPT_FL_INV 0x0001 /* Matching is inversed */
265#define TCPCHK_EXPT_FL_HTTP_HNAME_STR 0x0002 /* Exact match on the HTTP header name */
266#define TCPCHK_EXPT_FL_HTTP_HNAME_BEG 0x0004 /* Prefix match on the HTTP header name */
267#define TCPCHK_EXPT_FL_HTTP_HNAME_END 0x0008 /* Suffix match on the HTTP header name */
268#define TCPCHK_EXPT_FL_HTTP_HNAME_SUB 0x0010 /* Substring match on the HTTP header name */
269#define TCPCHK_EXPT_FL_HTTP_HNAME_REG 0x0020 /* Regex match on the HTTP header name */
270#define TCPCHK_EXPT_FL_HTTP_HNAME_FMT 0x0040 /* The HTTP header name is a log-format string */
271#define TCPCHK_EXPT_FL_HTTP_HVAL_NONE 0x0080 /* No match on the HTTP header value */
272#define TCPCHK_EXPT_FL_HTTP_HVAL_STR 0x0100 /* Exact match on the HTTP header value */
273#define TCPCHK_EXPT_FL_HTTP_HVAL_BEG 0x0200 /* Prefix match on the HTTP header value */
274#define TCPCHK_EXPT_FL_HTTP_HVAL_END 0x0400 /* Suffix match on the HTTP header value */
275#define TCPCHK_EXPT_FL_HTTP_HVAL_SUB 0x0800 /* Substring match on the HTTP header value */
276#define TCPCHK_EXPT_FL_HTTP_HVAL_REG 0x1000 /* Regex match on the HTTP header value*/
277#define TCPCHK_EXPT_FL_HTTP_HVAL_FMT 0x2000 /* The HTTP header value is a log-format string */
278#define TCPCHK_EXPT_FL_HTTP_HVAL_FULL 0x4000 /* Match the full header value ( no stop on commas ) */
Christopher Faulet12d57402020-04-10 09:58:42 +0200279
Christopher Faulet39708192020-05-05 10:47:36 +0200280#define TCPCHK_EXPT_FL_HTTP_HNAME_TYPE 0x003E /* Mask to get matching method on header name */
281#define TCPCHK_EXPT_FL_HTTP_HVAL_TYPE 0x1F00 /* Mask to get matching method on header value */
Christopher Fauletaaab0832020-05-05 15:54:22 +0200282
Gaetan Rivetb616add2020-02-07 15:37:17 +0100283struct tcpcheck_expect {
Christopher Faulet12d57402020-04-10 09:58:42 +0200284 enum tcpcheck_expect_type type; /* Type of pattern used for matching. */
285 unsigned int flags; /* TCPCHK_EXPT_FL_* */
Gaetan Rivetb616add2020-02-07 15:37:17 +0100286 union {
Christopher Faulet8021a5f2020-04-24 13:53:12 +0200287 struct ist data; /* Matching a literal string / binary anywhere in the response. */
288 struct my_regex *regex; /* Matching a regex pattern. */
289 struct tcpcheck_codes codes; /* Matching a list of codes */
Christopher Fauletaaab0832020-05-05 15:54:22 +0200290 struct list fmt; /* Matching a log-format string / binary */
Christopher Faulet39708192020-05-05 10:47:36 +0200291 struct {
292 union {
293 struct ist name;
294 struct list name_fmt;
295 struct my_regex *name_re;
296 };
297 union {
298 struct ist value;
299 struct list value_fmt;
300 struct my_regex *value_re;
301 };
302 } hdr; /* Matching a header pattern */
303
Christopher Faulet9e6ed152020-04-03 15:24:06 +0200304
305 /* custom function to eval epxect rule */
306 enum tcpcheck_eval_ret (*custom)(struct check *, struct tcpcheck_rule *, int);
Gaetan Rivetb616add2020-02-07 15:37:17 +0100307 };
308 struct tcpcheck_rule *head; /* first expect of a chain. */
Gaetan Rivetb616add2020-02-07 15:37:17 +0100309 int min_recv; /* Minimum amount of data before an expect can be applied. (default: -1, ignored) */
Christopher Fauletec07e382020-04-07 14:56:26 +0200310 enum healthcheck_status ok_status; /* The healthcheck status to use on success (default: L7OKD) */
Christopher Fauletcf80f2f2020-04-01 11:04:52 +0200311 enum healthcheck_status err_status; /* The healthcheck status to use on error (default: L7RSP) */
312 enum healthcheck_status tout_status; /* The healthcheck status to use on timeout (default: L7TOUT) */
Christopher Faulete5870d82020-04-15 11:32:03 +0200313 struct list onerror_fmt; /* log-format string to use as comment on error */
314 struct list onsuccess_fmt; /* log-format string to use as comment on success (if last rule) */
Christopher Faulet98cc57c2020-04-01 20:52:31 +0200315 struct sample_expr *status_expr; /* sample expr to determine the check status code */
Gaetan Rivetb616add2020-02-07 15:37:17 +0100316};
317
Gaetan Rivet707b52f2020-02-21 18:14:59 +0100318struct tcpcheck_action_kw {
319 struct act_rule *rule;
320};
321
Willy Tarreau98aec9f2013-12-06 16:16:41 +0100322/* possible actions for tcpcheck_rule->action */
Gaetan Rivetdd667322020-02-14 11:25:09 +0100323enum tcpcheck_rule_type {
324 TCPCHK_ACT_SEND = 0, /* send action, regular string format */
325 TCPCHK_ACT_EXPECT, /* expect action, either regular or binary string */
326 TCPCHK_ACT_CONNECT, /* connect action, to probe a new port */
327 TCPCHK_ACT_COMMENT, /* no action, simply a comment used for logs */
Gaetan Rivet707b52f2020-02-21 18:14:59 +0100328 TCPCHK_ACT_ACTION_KW, /* custom registered action_kw rule. */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200329};
330
331struct tcpcheck_rule {
332 struct list list; /* list linked to from the proxy */
Gaetan Rivetdd667322020-02-14 11:25:09 +0100333 enum tcpcheck_rule_type action; /* type of the rule. */
Gaetan Rivet5301b012020-02-25 17:19:17 +0100334 int index; /* Index within the list. Starts at 0. */
Baptiste Assmannaa12b472015-04-25 16:16:48 +0200335 char *comment; /* comment to be used in the logs and on the stats socket */
Gaetan Rivet48219dc2020-02-21 18:41:28 +0100336 union {
Gaetan Rivet06d963a2020-02-21 18:49:05 +0100337 struct tcpcheck_connect connect; /* Connect rule. */
Gaetan Rivet48219dc2020-02-21 18:41:28 +0100338 struct tcpcheck_send send; /* Send rule. */
339 struct tcpcheck_expect expect; /* Expected pattern. */
Gaetan Rivet707b52f2020-02-21 18:14:59 +0100340 struct tcpcheck_action_kw action_kw; /* Custom action. */
Gaetan Rivet48219dc2020-02-21 18:41:28 +0100341 };
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200342};
343
Christopher Faulet404f9192020-04-09 23:13:54 +0200344#define TCPCHK_RULES_NONE 0x00000000
345#define TCPCHK_RULES_UNUSED_TCP_RS 0x00000001 /* An unused tcp-check ruleset exists */
Christopher Faulete5870d82020-04-15 11:32:03 +0200346#define TCPCHK_RULES_UNUSED_HTTP_RS 0x00000002 /* An unused http-check ruleset exists */
347#define TCPCHK_RULES_UNUSED_RS 0x00000003 /* Mask for unused ruleset */
Christopher Faulet33f05df2020-04-01 11:08:50 +0200348
Christopher Fauletce355072020-04-02 11:44:39 +0200349#define TCPCHK_RULES_PGSQL_CHK 0x00000010
Christopher Faulet33f05df2020-04-01 11:08:50 +0200350#define TCPCHK_RULES_REDIS_CHK 0x00000020
Christopher Fauletfbcc77c2020-04-01 20:54:05 +0200351#define TCPCHK_RULES_SMTP_CHK 0x00000030
Christopher Faulete5870d82020-04-15 11:32:03 +0200352#define TCPCHK_RULES_HTTP_CHK 0x00000040
Christopher Fauletf2b3be52020-04-02 18:07:37 +0200353#define TCPCHK_RULES_MYSQL_CHK 0x00000050
Christopher Faulet1997eca2020-04-03 23:13:50 +0200354#define TCPCHK_RULES_LDAP_CHK 0x00000060
Christopher Faulet811f78c2020-04-01 11:10:27 +0200355#define TCPCHK_RULES_SSL3_CHK 0x00000070
Christopher Faulet0ae3d1d2020-04-06 17:54:24 +0200356#define TCPCHK_RULES_AGENT_CHK 0x00000080
Christopher Faulet267b01b2020-04-04 10:27:09 +0200357#define TCPCHK_RULES_SPOP_CHK 0x00000090
Christopher Fauletd7e63962020-04-17 20:15:59 +0200358/* Unused 0x000000A0..0x00000FF0 (reserverd for futur proto) */
359#define TCPCHK_RULES_TCP_CHK 0x00000FF0
Christopher Faulet799f3a42020-04-07 12:06:14 +0200360#define TCPCHK_RULES_PROTO_CHK 0x00000FF0 /* Mask to cover protocol check */
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200361
Christopher Faulet7a1e2e12020-04-02 18:05:11 +0200362/* A list of tcp-check vars, to be registered before executing a ruleset */
363struct tcpcheck_var {
364 struct ist name; /* the variable name with the scope */
365 struct sample_data data; /* the data associated to the variable */
366 struct list list; /* element to chain tcp-check vars */
367};
368
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200369/* a list of tcp-check rules */
370struct tcpcheck_rules {
Christopher Faulet7a1e2e12020-04-02 18:05:11 +0200371 unsigned int flags; /* flags applied to the rules */
372 struct list *list; /* the list of tcpcheck_rules */
373 struct list preset_vars; /* The list of variable to preset before executing the ruleset */
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200374};
375
376/* A list of tcp-check rules with a name */
377struct tcpcheck_ruleset {
Christopher Fauletd7cee712020-04-21 13:45:00 +0200378 struct list rules; /* the list of tcpcheck_rule */
379 struct ebpt_node node; /* node in the shared tree */
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200380};
381
382
Thierry FOURNIER7eeb4352013-06-14 15:28:25 +0200383#endif /* _TYPES_CHECKS_H */