Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 2 | * include/haproxy/check-t.h |
| 3 | * Health-checks definitions, enums, macros and bitfields. |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright 2008-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 6 | * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 7 | * |
| 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 Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 15 | #ifndef _HAPROXY_CHECKS_T_H |
| 16 | #define _HAPROXY_CHECKS_T_H |
Thierry FOURNIER | 7eeb435 | 2013-06-14 15:28:25 +0200 | [diff] [blame] | 17 | |
Willy Tarreau | 8d2b777 | 2020-05-27 10:58:19 +0200 | [diff] [blame] | 18 | #include <import/ebpttree.h> |
Willy Tarreau | eb6f701 | 2020-05-27 16:21:26 +0200 | [diff] [blame] | 19 | #include <import/ist.h> |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 20 | #include <haproxy/buf-t.h> |
Willy Tarreau | 7ea393d | 2020-06-04 18:02:10 +0200 | [diff] [blame] | 21 | #include <haproxy/connection-t.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 22 | #include <haproxy/list-t.h> |
Willy Tarreau | 8efbdfb | 2020-06-04 11:29:21 +0200 | [diff] [blame] | 23 | #include <haproxy/obj_type-t.h> |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 24 | #include <haproxy/api-t.h> |
| 25 | #include <haproxy/vars-t.h> |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 26 | |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 27 | /* 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 Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 34 | |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 35 | /* enum used by check->result. Must remain in this order, as some code uses |
| 36 | * result >= CHK_RES_PASSED to declare success. |
| 37 | */ |
| 38 | enum chk_result { |
| 39 | CHK_RES_UNKNOWN = 0, /* initialized to this by default */ |
Willy Tarreau | 2396418 | 2014-05-20 20:56:30 +0200 | [diff] [blame] | 40 | CHK_RES_NEUTRAL, /* valid check but no status information */ |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 41 | 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 Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 45 | |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 46 | /* flags used by check->state */ |
| 47 | #define CHK_ST_INPROGRESS 0x0001 /* a check is currently running */ |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 48 | #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 Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 50 | #define CHK_ST_PAUSED 0x0008 /* checks are paused because of maintenance (health only) */ |
Willy Tarreau | 3343432 | 2013-12-11 21:15:19 +0100 | [diff] [blame] | 51 | #define CHK_ST_AGENT 0x0010 /* check is an agent check (otherwise it's a health check) */ |
Baptiste Assmann | 95db2bc | 2016-06-13 14:15:41 +0200 | [diff] [blame] | 52 | #define CHK_ST_PORT_MISS 0x0020 /* check can't be send because no port is configured to run it */ |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 53 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 54 | /* check status */ |
Christopher Faulet | 1032059 | 2020-04-01 10:37:29 +0200 | [diff] [blame] | 55 | enum healthcheck_status { |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 56 | HCHK_STATUS_UNKNOWN = 0, /* Unknown */ |
| 57 | HCHK_STATUS_INI, /* Initializing */ |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 58 | HCHK_STATUS_START, /* Check started - SPECIAL STATUS */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 59 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 60 | /* Below we have finished checks */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 61 | HCHK_STATUS_CHECKED, /* DUMMY STATUS */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 62 | |
Simon Horman | b7cd8f9 | 2012-03-19 07:25:28 +0900 | [diff] [blame] | 63 | HCHK_STATUS_HANA, /* Health analyze detected enough consecutive errors */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 64 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 65 | 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 Horman | b7cd8f9 | 2012-03-19 07:25:28 +0900 | [diff] [blame] | 79 | /* Below we have layer 5-7 data available */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 80 | 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 Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 85 | 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 Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 89 | HCHK_STATUS_SIZE |
| 90 | }; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 91 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 92 | /* health status for response tracking */ |
| 93 | enum { |
| 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 | |
| 111 | enum { |
| 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 | |
| 120 | enum { |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 121 | HANA_ONMARKEDDOWN_NONE = 0, |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 122 | HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS, /* Shutdown peer sessions */ |
| 123 | }; |
| 124 | |
| 125 | enum { |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 126 | HANA_ONMARKEDUP_NONE = 0, |
| 127 | HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS, /* Shutdown peer sessions */ |
| 128 | }; |
| 129 | |
| 130 | enum { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 131 | 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 Tarreau | 51cd595 | 2020-06-05 12:25:38 +0200 | [diff] [blame^] | 139 | struct tcpcheck_rule; |
| 140 | struct tcpcheck_rules; |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 141 | |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 142 | struct check { |
Christopher Faulet | 3829046 | 2020-04-21 11:46:40 +0200 | [diff] [blame] | 143 | enum obj_type obj_type; /* object type == OBJ_TYPE_CHECK */ |
Gaetan Rivet | 05d692d | 2020-02-14 17:42:54 +0100 | [diff] [blame] | 144 | struct session *sess; /* Health check session. */ |
Gaetan Rivet | 13a5043 | 2020-02-21 18:13:44 +0100 | [diff] [blame] | 145 | struct vars vars; /* Health check dynamic variables. */ |
Cyril Bonté | 9ce1311 | 2014-11-15 22:41:27 +0100 | [diff] [blame] | 146 | struct xprt_ops *xprt; /* transport layer operations for health checks */ |
Olivier Houchard | 9aaf778 | 2017-09-13 18:30:23 +0200 | [diff] [blame] | 147 | struct conn_stream *cs; /* conn_stream state for health checks */ |
Willy Tarreau | c9fa048 | 2018-07-10 17:43:27 +0200 | [diff] [blame] | 148 | struct buffer bi, bo; /* input and output buffers to send/recv check */ |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 149 | 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 Tarreau | 08eaa78 | 2017-11-26 08:44:34 +0100 | [diff] [blame] | 153 | unsigned short port; /* the port to use for the health checks */ |
Cyril Bonté | 9ce1311 | 2014-11-15 22:41:27 +0100 | [diff] [blame] | 154 | char desc[HCHK_DESC_LEN]; /* health check description */ |
Christopher Faulet | 4a8c026 | 2020-04-27 12:13:06 +0200 | [diff] [blame] | 155 | signed char use_ssl; /* use SSL for health checks (1: on, 0: server mode, -1: off) */ |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 156 | int send_proxy; /* send a PROXY protocol header with checks */ |
Christopher Faulet | 5d503fc | 2020-03-30 20:34:34 +0200 | [diff] [blame] | 157 | struct tcpcheck_rules *tcpcheck_rules; /* tcp-check send / expect rules */ |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 158 | struct tcpcheck_rule *current_step; /* current step when using tcpcheck */ |
| 159 | int inter, fastinter, downinter; /* checks: time in milliseconds */ |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 160 | enum chk_result result; /* health-check result : CHK_RES_* */ |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 161 | int state; /* state of the check : CHK_ST_* */ |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 162 | 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 Houchard | c98aa1f | 2019-01-11 18:17:17 +0100 | [diff] [blame] | 167 | struct proxy *proxy; /* proxy to be used */ |
Simon Horman | 98637e5 | 2014-06-20 12:30:16 +0900 | [diff] [blame] | 168 | 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 Horman | 0ba0e4a | 2015-01-30 11:23:00 +0900 | [diff] [blame] | 171 | struct sockaddr_storage addr; /* the address to check */ |
Olivier Houchard | fa8aa86 | 2018-10-10 18:25:41 +0200 | [diff] [blame] | 172 | struct wait_event wait_list; /* Waiting for I/O events */ |
Olivier Houchard | 9130a96 | 2017-10-17 17:33:43 +0200 | [diff] [blame] | 173 | char *sni; /* Server name */ |
Olivier Houchard | 9215014 | 2018-12-21 19:47:01 +0100 | [diff] [blame] | 174 | char *alpn_str; /* ALPN to use for checks */ |
| 175 | int alpn_len; /* ALPN string length */ |
Christopher Faulet | b356714 | 2020-04-21 11:59:32 +0200 | [diff] [blame] | 176 | const struct mux_proto_list *mux_proto; /* the mux to use for all outgoing connections (specified by the "proto" keyword) */ |
Alexander Liu | 2a54bb7 | 2019-05-22 19:44:48 +0800 | [diff] [blame] | 177 | int via_socks4; /* check the connection via socks4 proxy */ |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 178 | }; |
| 179 | |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 180 | #endif /* _HAPROXY_CHECKS_T_H */ |