blob: fb2f0a1f2be920aa63f2777817c99f0ca80918d5 [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 Tarreau4aa573d2020-06-04 18:21:56 +020020#include <haproxy/buf-t.h>
Willy Tarreau7ea393d2020-06-04 18:02:10 +020021#include <haproxy/connection-t.h>
Willy Tarreau853b2972020-05-27 18:01:47 +020022#include <haproxy/list-t.h>
Willy Tarreau8efbdfb2020-06-04 11:29:21 +020023#include <haproxy/obj_type-t.h>
Willy Tarreau4aa573d2020-06-04 18:21:56 +020024#include <haproxy/api-t.h>
25#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 */
Willy Tarreau8e85ad52013-12-11 16:45:07 +010053
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020054/* check status */
Christopher Faulet10320592020-04-01 10:37:29 +020055enum healthcheck_status {
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020056 HCHK_STATUS_UNKNOWN = 0, /* Unknown */
57 HCHK_STATUS_INI, /* Initializing */
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020058 HCHK_STATUS_START, /* Check started - SPECIAL STATUS */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020059
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020060 /* Below we have finished checks */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020061 HCHK_STATUS_CHECKED, /* DUMMY STATUS */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010062
Simon Hormanb7cd8f92012-03-19 07:25:28 +090063 HCHK_STATUS_HANA, /* Health analyze detected enough consecutive errors */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010064
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020065 HCHK_STATUS_SOCKERR, /* Socket error */
66
67 HCHK_STATUS_L4OK, /* L4 check passed, for example tcp connect */
68 HCHK_STATUS_L4TOUT, /* L4 timeout */
69 HCHK_STATUS_L4CON, /* L4 connection problem, for example: */
70 /* "Connection refused" (tcp rst) or "No route to host" (icmp) */
71
72 HCHK_STATUS_L6OK, /* L6 check passed */
73 HCHK_STATUS_L6TOUT, /* L6 (SSL) timeout */
74 HCHK_STATUS_L6RSP, /* L6 invalid response - protocol error */
75
76 HCHK_STATUS_L7TOUT, /* L7 (HTTP/SMTP) timeout */
77 HCHK_STATUS_L7RSP, /* L7 invalid response - protocol error */
78
Simon Hormanb7cd8f92012-03-19 07:25:28 +090079 /* Below we have layer 5-7 data available */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020080 HCHK_STATUS_L57DATA, /* DUMMY STATUS */
81 HCHK_STATUS_L7OKD, /* L7 check passed */
82 HCHK_STATUS_L7OKCD, /* L7 check conditionally passed */
83 HCHK_STATUS_L7STS, /* L7 response error, for example HTTP 5xx */
84
Simon Horman98637e52014-06-20 12:30:16 +090085 HCHK_STATUS_PROCERR, /* External process check failure */
86 HCHK_STATUS_PROCTOUT, /* External process check timeout */
87 HCHK_STATUS_PROCOK, /* External process check passed */
88
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020089 HCHK_STATUS_SIZE
90};
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +020091
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +010092/* health status for response tracking */
93enum {
94 HANA_STATUS_UNKNOWN = 0,
95
96 HANA_STATUS_L4_OK, /* L4 successful connection */
97 HANA_STATUS_L4_ERR, /* L4 unsuccessful connection */
98
99 HANA_STATUS_HTTP_OK, /* Correct http response */
100 HANA_STATUS_HTTP_STS, /* Wrong http response, for example HTTP 5xx */
101 HANA_STATUS_HTTP_HDRRSP, /* Invalid http response (headers) */
102 HANA_STATUS_HTTP_RSP, /* Invalid http response */
103
104 HANA_STATUS_HTTP_READ_ERROR, /* Read error */
105 HANA_STATUS_HTTP_READ_TIMEOUT, /* Read timeout */
106 HANA_STATUS_HTTP_BROKEN_PIPE, /* Unexpected close from server */
107
108 HANA_STATUS_SIZE
109};
110
111enum {
112 HANA_ONERR_UNKNOWN = 0,
113
114 HANA_ONERR_FASTINTER, /* Force fastinter*/
115 HANA_ONERR_FAILCHK, /* Simulate a failed check */
116 HANA_ONERR_SUDDTH, /* Enters sudden death - one more failed check will mark this server down */
117 HANA_ONERR_MARKDWN, /* Mark this server down, now! */
118};
119
120enum {
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900121 HANA_ONMARKEDDOWN_NONE = 0,
Simon Hormane0d1bfb2011-06-21 14:34:58 +0900122 HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS, /* Shutdown peer sessions */
123};
124
125enum {
Justin Karnegeseb2c24a2012-05-24 15:28:52 -0700126 HANA_ONMARKEDUP_NONE = 0,
127 HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS, /* Shutdown peer sessions */
128};
129
130enum {
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100131 HANA_OBS_NONE = 0,
132
133 HANA_OBS_LAYER4, /* Observe L4 - for example tcp */
134 HANA_OBS_LAYER7, /* Observe L7 - for example http */
135
136 HANA_OBS_SIZE
137};
138
Willy Tarreau51cd5952020-06-05 12:25:38 +0200139struct tcpcheck_rule;
140struct tcpcheck_rules;
Willy Tarreau4aa573d2020-06-04 18:21:56 +0200141
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100142struct check {
Christopher Faulet38290462020-04-21 11:46:40 +0200143 enum obj_type obj_type; /* object type == OBJ_TYPE_CHECK */
Gaetan Rivet05d692d2020-02-14 17:42:54 +0100144 struct session *sess; /* Health check session. */
Gaetan Rivet13a50432020-02-21 18:13:44 +0100145 struct vars vars; /* Health check dynamic variables. */
Cyril Bonté9ce13112014-11-15 22:41:27 +0100146 struct xprt_ops *xprt; /* transport layer operations for health checks */
Olivier Houchard9aaf7782017-09-13 18:30:23 +0200147 struct conn_stream *cs; /* conn_stream state for health checks */
Willy Tarreauc9fa0482018-07-10 17:43:27 +0200148 struct buffer bi, bo; /* input and output buffers to send/recv check */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100149 struct task *task; /* the task associated to the health check processing, NULL if disabled */
150 struct timeval start; /* last health check start time */
151 long duration; /* time in ms took to finish last health check */
152 short status, code; /* check result, check code */
Willy Tarreau08eaa782017-11-26 08:44:34 +0100153 unsigned short port; /* the port to use for the health checks */
Cyril Bonté9ce13112014-11-15 22:41:27 +0100154 char desc[HCHK_DESC_LEN]; /* health check description */
Christopher Faulet4a8c0262020-04-27 12:13:06 +0200155 signed char use_ssl; /* use SSL for health checks (1: on, 0: server mode, -1: off) */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100156 int send_proxy; /* send a PROXY protocol header with checks */
Christopher Faulet5d503fc2020-03-30 20:34:34 +0200157 struct tcpcheck_rules *tcpcheck_rules; /* tcp-check send / expect rules */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100158 struct tcpcheck_rule *current_step; /* current step when using tcpcheck */
159 int inter, fastinter, downinter; /* checks: time in milliseconds */
Willy Tarreau6aaa1b82013-12-11 17:09:34 +0100160 enum chk_result result; /* health-check result : CHK_RES_* */
Willy Tarreau2c115e52013-12-11 19:41:16 +0100161 int state; /* state of the check : CHK_ST_* */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100162 int health; /* 0 to rise-1 = bad;
163 * rise to rise+fall-1 = good */
164 int rise, fall; /* time in iterations */
165 int type; /* Check type, one of PR_O2_*_CHK */
166 struct server *server; /* back-pointer to server */
Olivier Houchardc98aa1f2019-01-11 18:17:17 +0100167 struct proxy *proxy; /* proxy to be used */
Simon Horman98637e52014-06-20 12:30:16 +0900168 char **argv; /* the arguments to use if running a process-based check */
169 char **envp; /* the environment to use if running a process-based check */
170 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 +0900171 struct sockaddr_storage addr; /* the address to check */
Olivier Houchardfa8aa862018-10-10 18:25:41 +0200172 struct wait_event wait_list; /* Waiting for I/O events */
Olivier Houchard9130a962017-10-17 17:33:43 +0200173 char *sni; /* Server name */
Olivier Houchard92150142018-12-21 19:47:01 +0100174 char *alpn_str; /* ALPN to use for checks */
175 int alpn_len; /* ALPN string length */
Christopher Fauletb3567142020-04-21 11:59:32 +0200176 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 +0800177 int via_socks4; /* check the connection via socks4 proxy */
Willy Tarreau8e85ad52013-12-11 16:45:07 +0100178};
179
Willy Tarreau4aa573d2020-06-04 18:21:56 +0200180#endif /* _HAPROXY_CHECKS_T_H */