blob: b78a9f9f5d338f4e437e93e1e7adabe604ac4c1b [file] [log] [blame]
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02001/*
Willy Tarreau4aa573d2020-06-04 18:21:56 +02002 * include/haproxy/check-t.h
3 * Health-checks definitions, enums, macros and bitfields.
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02004 *
5 * Copyright 2008-2009 Krzysztof Piotr Oledzki <ole@ans.pl>
Willy Tarreau4aa573d2020-06-04 18:21:56 +02006 * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +02007 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 *
13 */
14
Willy Tarreau4aa573d2020-06-04 18:21:56 +020015#ifndef _HAPROXY_CHECKS_T_H
16#define _HAPROXY_CHECKS_T_H
Thierry FOURNIER7eeb4352013-06-14 15:28:25 +020017
Willy Tarreau8d2b7772020-05-27 10:58:19 +020018#include <import/ebpttree.h>
Willy Tarreaueb6f7012020-05-27 16:21:26 +020019#include <import/ist.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020020#include <haproxy/api-t.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020021#include <haproxy/buf-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020022#include <haproxy/connection-t.h>
Christopher Fauletb381a502020-11-25 13:47:00 +010023#include <haproxy/dynbuf-t.h>
Willy Tarreau8efbdfb2020-06-04 11:29:21 +020024#include <haproxy/obj_type-t.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020025#include <haproxy/vars-t.h>
Willy Tarreau8e85ad52013-12-11 16:45:07 +010026
Willy Tarreau4aa573d2020-06-04 18:21:56 +020027/* Please note: this file tends to commonly be part of circular dependencies,
28 * so it is important to keep its includes list to the minimum possible (i.e.
29 * only types whose size needs to be known). Since there are no function
30 * prototypes nor pointers here, forward declarations are not really necessary.
31 * This file oughtt to be split into multiple parts, at least regular checks vs
32 * tcp-checks.
33 */
Willy Tarreau8e85ad52013-12-11 16:45:07 +010034
Willy Tarreau6aaa1b82013-12-11 17:09:34 +010035/* enum used by check->result. Must remain in this order, as some code uses
36 * result >= CHK_RES_PASSED to declare success.
37 */
38enum chk_result {
39 CHK_RES_UNKNOWN = 0, /* initialized to this by default */
Willy Tarreau23964182014-05-20 20:56:30 +020040 CHK_RES_NEUTRAL, /* valid check but no status information */
Willy Tarreau6aaa1b82013-12-11 17:09:34 +010041 CHK_RES_FAILED, /* check failed */
42 CHK_RES_PASSED, /* check succeeded and server is fully up again */
43 CHK_RES_CONDPASS, /* check reports the server doesn't want new sessions */
44};
Willy Tarreau8e85ad52013-12-11 16:45:07 +010045
Willy Tarreau2c115e52013-12-11 19:41:16 +010046/* flags used by check->state */
47#define CHK_ST_INPROGRESS 0x0001 /* a check is currently running */
Willy Tarreau2e10f5a2013-12-11 20:11:55 +010048#define CHK_ST_CONFIGURED 0x0002 /* this check is configured and may be enabled */
49#define CHK_ST_ENABLED 0x0004 /* this check is currently administratively enabled */
Willy Tarreau33a08db2013-12-11 21:03:31 +010050#define CHK_ST_PAUSED 0x0008 /* checks are paused because of maintenance (health only) */
Willy Tarreau33434322013-12-11 21:15:19 +010051#define CHK_ST_AGENT 0x0010 /* check is an agent check (otherwise it's a health check) */
Baptiste Assmann95db2bc2016-06-13 14:15:41 +020052#define CHK_ST_PORT_MISS 0x0020 /* check can't be send because no port is configured to run it */
Christopher Fauletb381a502020-11-25 13:47:00 +010053#define CHK_ST_IN_ALLOC 0x0040 /* check blocked waiting for input buffer allocation */
54#define CHK_ST_OUT_ALLOC 0x0080 /* check blocked waiting for output buffer allocation */
Christopher Faulet8f100422021-01-18 15:47:03 +010055#define CHK_ST_CLOSE_CONN 0x0100 /* check is waiting that the connection gets closed */
Willy Tarreau8e85ad52013-12-11 16:45:07 +010056
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020057/* check status */
Christopher Faulet10320592020-04-01 10:37:29 +020058enum healthcheck_status {
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020059 HCHK_STATUS_UNKNOWN = 0, /* Unknown */
60 HCHK_STATUS_INI, /* Initializing */
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020061 HCHK_STATUS_START, /* Check started - SPECIAL STATUS */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020062
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020063 /* Below we have finished checks */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020064 HCHK_STATUS_CHECKED, /* DUMMY STATUS */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010065
Simon Hormanb7cd8f92012-03-19 07:25:28 +090066 HCHK_STATUS_HANA, /* Health analyze detected enough consecutive errors */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010067
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020068 HCHK_STATUS_SOCKERR, /* Socket error */
69
70 HCHK_STATUS_L4OK, /* L4 check passed, for example tcp connect */
71 HCHK_STATUS_L4TOUT, /* L4 timeout */
72 HCHK_STATUS_L4CON, /* L4 connection problem, for example: */
73 /* "Connection refused" (tcp rst) or "No route to host" (icmp) */
74
75 HCHK_STATUS_L6OK, /* L6 check passed */
76 HCHK_STATUS_L6TOUT, /* L6 (SSL) timeout */
77 HCHK_STATUS_L6RSP, /* L6 invalid response - protocol error */
78
79 HCHK_STATUS_L7TOUT, /* L7 (HTTP/SMTP) timeout */
80 HCHK_STATUS_L7RSP, /* L7 invalid response - protocol error */
81
Simon Hormanb7cd8f92012-03-19 07:25:28 +090082 /* Below we have layer 5-7 data available */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020083 HCHK_STATUS_L57DATA, /* DUMMY STATUS */
84 HCHK_STATUS_L7OKD, /* L7 check passed */
85 HCHK_STATUS_L7OKCD, /* L7 check conditionally passed */
86 HCHK_STATUS_L7STS, /* L7 response error, for example HTTP 5xx */
87
Simon Horman98637e52014-06-20 12:30:16 +090088 HCHK_STATUS_PROCERR, /* External process check failure */
89 HCHK_STATUS_PROCTOUT, /* External process check timeout */
90 HCHK_STATUS_PROCOK, /* External process check passed */
91
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020092 HCHK_STATUS_SIZE
93};
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020094
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010095/* health status for response tracking */
96enum {
97 HANA_STATUS_UNKNOWN = 0,
98
99 HANA_STATUS_L4_OK, /* L4 successful connection */
100 HANA_STATUS_L4_ERR, /* L4 unsuccessful connection */
101
102 HANA_STATUS_HTTP_OK, /* Correct http response */
103 HANA_STATUS_HTTP_STS, /* Wrong http response, for example HTTP 5xx */
104 HANA_STATUS_HTTP_HDRRSP, /* Invalid http response (headers) */
105 HANA_STATUS_HTTP_RSP, /* Invalid http response */
106
107 HANA_STATUS_HTTP_READ_ERROR, /* Read error */
108 HANA_STATUS_HTTP_READ_TIMEOUT, /* Read timeout */
109 HANA_STATUS_HTTP_BROKEN_PIPE, /* Unexpected close from server */
110
111 HANA_STATUS_SIZE
112};
113
114enum {
115 HANA_ONERR_UNKNOWN = 0,
116
117 HANA_ONERR_FASTINTER, /* Force fastinter*/
118 HANA_ONERR_FAILCHK, /* Simulate a failed check */
119 HANA_ONERR_SUDDTH, /* Enters sudden death - one more failed check will mark this server down */
120 HANA_ONERR_MARKDWN, /* Mark this server down, now! */
121};
122
123enum {
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900124 HANA_ONMARKEDDOWN_NONE = 0,
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900125 HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS, /* Shutdown peer sessions */
126};
127
128enum {
Justin Karnegeseb2c24a2012-05-24 15:28:52 -0700129 HANA_ONMARKEDUP_NONE = 0,
130 HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS, /* Shutdown peer sessions */
131};
132
133enum {
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100134 HANA_OBS_NONE = 0,
135
136 HANA_OBS_LAYER4, /* Observe L4 - for example tcp */
137 HANA_OBS_LAYER7, /* Observe L7 - for example http */
138
139 HANA_OBS_SIZE
140};
141
Willy Tarreau51cd5952020-06-05 12:25:38 +0200142struct tcpcheck_rule;
143struct tcpcheck_rules;
Willy Tarreau4aa573d2020-06-04 18:21:56 +0200144
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100145struct check {
Christopher Faulet38290462020-04-21 11:46:40 +0200146 enum obj_type obj_type; /* object type == OBJ_TYPE_CHECK */
Gaetan Rivet05d692d2020-02-14 17:42:54 +0100147 struct session *sess; /* Health check session. */
Gaetan Rivet13a50432020-02-21 18:13:44 +0100148 struct vars vars; /* Health check dynamic variables. */
Cyril Bonté9ce13112014-11-15 22:41:27 +0100149 struct xprt_ops *xprt; /* transport layer operations for health checks */
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200150 struct conn_stream *cs; /* conn_stream state for health checks */
Willy Tarreauc9fa0482018-07-10 17:43:27 +0200151 struct buffer bi, bo; /* input and output buffers to send/recv check */
Christopher Fauletb381a502020-11-25 13:47:00 +0100152 struct buffer_wait buf_wait; /* Wait list for buffer allocation */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100153 struct task *task; /* the task associated to the health check processing, NULL if disabled */
154 struct timeval start; /* last health check start time */
155 long duration; /* time in ms took to finish last health check */
156 short status, code; /* check result, check code */
Willy Tarreau08eaa782017-11-26 08:44:34 +0100157 unsigned short port; /* the port to use for the health checks */
Cyril Bonté9ce13112014-11-15 22:41:27 +0100158 char desc[HCHK_DESC_LEN]; /* health check description */
Christopher Faulet4a8c0262020-04-27 12:13:06 +0200159 signed char use_ssl; /* use SSL for health checks (1: on, 0: server mode, -1: off) */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100160 int send_proxy; /* send a PROXY protocol header with checks */
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200161 struct tcpcheck_rules *tcpcheck_rules; /* tcp-check send / expect rules */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100162 struct tcpcheck_rule *current_step; /* current step when using tcpcheck */
163 int inter, fastinter, downinter; /* checks: time in milliseconds */
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100164 enum chk_result result; /* health-check result : CHK_RES_* */
Willy Tarreau2c115e52013-12-11 19:41:16 +0100165 int state; /* state of the check : CHK_ST_* */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100166 int health; /* 0 to rise-1 = bad;
167 * rise to rise+fall-1 = good */
168 int rise, fall; /* time in iterations */
169 int type; /* Check type, one of PR_O2_*_CHK */
170 struct server *server; /* back-pointer to server */
Olivier Houchardc98aa1f2019-01-11 18:17:17 +0100171 struct proxy *proxy; /* proxy to be used */
Simon Horman98637e52014-06-20 12:30:16 +0900172 char **argv; /* the arguments to use if running a process-based check */
173 char **envp; /* the environment to use if running a process-based check */
174 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 +0900175 struct sockaddr_storage addr; /* the address to check */
Olivier Houchardfa8aa862018-10-10 18:25:41 +0200176 struct wait_event wait_list; /* Waiting for I/O events */
Olivier Houchard9130a962017-10-17 17:33:43 +0200177 char *sni; /* Server name */
Olivier Houchard92150142018-12-21 19:47:01 +0100178 char *alpn_str; /* ALPN to use for checks */
179 int alpn_len; /* ALPN string length */
Christopher Fauletb3567142020-04-21 11:59:32 +0200180 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 +0800181 int via_socks4; /* check the connection via socks4 proxy */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100182};
183
Willy Tarreau4aa573d2020-06-04 18:21:56 +0200184#endif /* _HAPROXY_CHECKS_T_H */