Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 1 | /* |
| 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 FOURNIER | 7eeb435 | 2013-06-14 15:28:25 +0200 | [diff] [blame] | 13 | #ifndef _TYPES_CHECKS_H |
| 14 | #define _TYPES_CHECKS_H |
| 15 | |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 16 | #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 Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 27 | /* enum used by check->result. Must remain in this order, as some code uses |
| 28 | * result >= CHK_RES_PASSED to declare success. |
| 29 | */ |
| 30 | enum chk_result { |
| 31 | CHK_RES_UNKNOWN = 0, /* initialized to this by default */ |
| 32 | CHK_RES_FAILED, /* check failed */ |
| 33 | CHK_RES_PASSED, /* check succeeded and server is fully up again */ |
| 34 | CHK_RES_CONDPASS, /* check reports the server doesn't want new sessions */ |
| 35 | }; |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 36 | |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 37 | /* flags used by check->state */ |
| 38 | #define CHK_ST_INPROGRESS 0x0001 /* a check is currently running */ |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 39 | #define CHK_ST_CONFIGURED 0x0002 /* this check is configured and may be enabled */ |
| 40 | #define CHK_ST_ENABLED 0x0004 /* this check is currently administratively enabled */ |
Willy Tarreau | 33a08db | 2013-12-11 21:03:31 +0100 | [diff] [blame] | 41 | #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] | 42 | #define CHK_ST_AGENT 0x0010 /* check is an agent check (otherwise it's a health check) */ |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 43 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 44 | /* check status */ |
| 45 | enum { |
| 46 | HCHK_STATUS_UNKNOWN = 0, /* Unknown */ |
| 47 | HCHK_STATUS_INI, /* Initializing */ |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 48 | HCHK_STATUS_START, /* Check started - SPECIAL STATUS */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 49 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 50 | /* Below we have finished checks */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 51 | HCHK_STATUS_CHECKED, /* DUMMY STATUS */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 52 | |
Simon Horman | b7cd8f9 | 2012-03-19 07:25:28 +0900 | [diff] [blame] | 53 | HCHK_STATUS_HANA, /* Health analyze detected enough consecutive errors */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 54 | |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 55 | HCHK_STATUS_SOCKERR, /* Socket error */ |
| 56 | |
| 57 | HCHK_STATUS_L4OK, /* L4 check passed, for example tcp connect */ |
| 58 | HCHK_STATUS_L4TOUT, /* L4 timeout */ |
| 59 | HCHK_STATUS_L4CON, /* L4 connection problem, for example: */ |
| 60 | /* "Connection refused" (tcp rst) or "No route to host" (icmp) */ |
| 61 | |
| 62 | HCHK_STATUS_L6OK, /* L6 check passed */ |
| 63 | HCHK_STATUS_L6TOUT, /* L6 (SSL) timeout */ |
| 64 | HCHK_STATUS_L6RSP, /* L6 invalid response - protocol error */ |
| 65 | |
| 66 | HCHK_STATUS_L7TOUT, /* L7 (HTTP/SMTP) timeout */ |
| 67 | HCHK_STATUS_L7RSP, /* L7 invalid response - protocol error */ |
| 68 | |
Simon Horman | b7cd8f9 | 2012-03-19 07:25:28 +0900 | [diff] [blame] | 69 | /* Below we have layer 5-7 data available */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 70 | HCHK_STATUS_L57DATA, /* DUMMY STATUS */ |
| 71 | HCHK_STATUS_L7OKD, /* L7 check passed */ |
| 72 | HCHK_STATUS_L7OKCD, /* L7 check conditionally passed */ |
| 73 | HCHK_STATUS_L7STS, /* L7 response error, for example HTTP 5xx */ |
| 74 | |
| 75 | HCHK_STATUS_SIZE |
| 76 | }; |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 77 | |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 78 | |
| 79 | /* health status for response tracking */ |
| 80 | enum { |
| 81 | HANA_STATUS_UNKNOWN = 0, |
| 82 | |
| 83 | HANA_STATUS_L4_OK, /* L4 successful connection */ |
| 84 | HANA_STATUS_L4_ERR, /* L4 unsuccessful connection */ |
| 85 | |
| 86 | HANA_STATUS_HTTP_OK, /* Correct http response */ |
| 87 | HANA_STATUS_HTTP_STS, /* Wrong http response, for example HTTP 5xx */ |
| 88 | HANA_STATUS_HTTP_HDRRSP, /* Invalid http response (headers) */ |
| 89 | HANA_STATUS_HTTP_RSP, /* Invalid http response */ |
| 90 | |
| 91 | HANA_STATUS_HTTP_READ_ERROR, /* Read error */ |
| 92 | HANA_STATUS_HTTP_READ_TIMEOUT, /* Read timeout */ |
| 93 | HANA_STATUS_HTTP_BROKEN_PIPE, /* Unexpected close from server */ |
| 94 | |
| 95 | HANA_STATUS_SIZE |
| 96 | }; |
| 97 | |
| 98 | enum { |
| 99 | HANA_ONERR_UNKNOWN = 0, |
| 100 | |
| 101 | HANA_ONERR_FASTINTER, /* Force fastinter*/ |
| 102 | HANA_ONERR_FAILCHK, /* Simulate a failed check */ |
| 103 | HANA_ONERR_SUDDTH, /* Enters sudden death - one more failed check will mark this server down */ |
| 104 | HANA_ONERR_MARKDWN, /* Mark this server down, now! */ |
| 105 | }; |
| 106 | |
| 107 | enum { |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 108 | HANA_ONMARKEDDOWN_NONE = 0, |
Simon Horman | e0d1bfb | 2011-06-21 14:34:58 +0900 | [diff] [blame] | 109 | HANA_ONMARKEDDOWN_SHUTDOWNSESSIONS, /* Shutdown peer sessions */ |
| 110 | }; |
| 111 | |
| 112 | enum { |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 113 | HANA_ONMARKEDUP_NONE = 0, |
| 114 | HANA_ONMARKEDUP_SHUTDOWNBACKUPSESSIONS, /* Shutdown peer sessions */ |
| 115 | }; |
| 116 | |
| 117 | enum { |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 118 | HANA_OBS_NONE = 0, |
| 119 | |
| 120 | HANA_OBS_LAYER4, /* Observe L4 - for example tcp */ |
| 121 | HANA_OBS_LAYER7, /* Observe L7 - for example http */ |
| 122 | |
| 123 | HANA_OBS_SIZE |
| 124 | }; |
| 125 | |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 126 | struct check { |
| 127 | struct connection *conn; /* connection state for health checks */ |
| 128 | unsigned short port; /* the port to use for the health checks */ |
| 129 | struct buffer *bi, *bo; /* input and output buffers to send/recv check */ |
| 130 | struct task *task; /* the task associated to the health check processing, NULL if disabled */ |
| 131 | struct timeval start; /* last health check start time */ |
| 132 | long duration; /* time in ms took to finish last health check */ |
| 133 | short status, code; /* check result, check code */ |
| 134 | char desc[HCHK_DESC_LEN]; /* health check descritpion */ |
| 135 | int use_ssl; /* use SSL for health checks */ |
| 136 | int send_proxy; /* send a PROXY protocol header with checks */ |
| 137 | struct tcpcheck_rule *current_step; /* current step when using tcpcheck */ |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 138 | struct tcpcheck_rule *last_started_step;/* pointer to latest tcpcheck rule started */ |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 139 | int inter, fastinter, downinter; /* checks: time in milliseconds */ |
Willy Tarreau | 6aaa1b8 | 2013-12-11 17:09:34 +0100 | [diff] [blame] | 140 | enum chk_result result; /* health-check result : CHK_RES_* */ |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 141 | int state; /* state of the check : CHK_ST_* */ |
Willy Tarreau | 8e85ad5 | 2013-12-11 16:45:07 +0100 | [diff] [blame] | 142 | int health; /* 0 to rise-1 = bad; |
| 143 | * rise to rise+fall-1 = good */ |
| 144 | int rise, fall; /* time in iterations */ |
| 145 | int type; /* Check type, one of PR_O2_*_CHK */ |
| 146 | struct server *server; /* back-pointer to server */ |
| 147 | }; |
| 148 | |
Krzysztof Piotr Oledzki | 213014e | 2009-09-27 15:50:02 +0200 | [diff] [blame] | 149 | struct check_status { |
| 150 | short result; /* one of SRV_CHK_* */ |
| 151 | char *info; /* human readable short info */ |
| 152 | char *desc; /* long description */ |
| 153 | }; |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 154 | |
| 155 | struct analyze_status { |
| 156 | char *desc; /* description */ |
| 157 | unsigned char lr[HANA_OBS_SIZE]; /* result for l4/l7: 0 = ignore, 1 - error, 2 - OK */ |
| 158 | }; |
Thierry FOURNIER | 7eeb435 | 2013-06-14 15:28:25 +0200 | [diff] [blame] | 159 | |
Willy Tarreau | 98aec9f | 2013-12-06 16:16:41 +0100 | [diff] [blame] | 160 | /* possible actions for tcpcheck_rule->action */ |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 161 | enum { |
Willy Tarreau | 98aec9f | 2013-12-06 16:16:41 +0100 | [diff] [blame] | 162 | TCPCHK_ACT_SEND = 0, /* send action, regular string format */ |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 163 | TCPCHK_ACT_EXPECT, /* expect action, either regular or binary string */ |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 164 | TCPCHK_ACT_CONNECT, /* connect action, to probe a new port */ |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 165 | }; |
| 166 | |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 167 | /* flags used by tcpcheck_rule->conn_opts */ |
| 168 | #define TCPCHK_OPT_NONE 0x0000 /* no options specified, default */ |
| 169 | #define TCPCHK_OPT_SEND_PROXY 0x0001 /* send proxy-protocol string */ |
| 170 | #define TCPCHK_OPT_SSL 0x0002 /* SSL connection */ |
| 171 | |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 172 | struct tcpcheck_rule { |
| 173 | struct list list; /* list linked to from the proxy */ |
| 174 | int action; /* action: send or expect */ |
| 175 | /* match type uses NON-NULL pointer from either string or expect_regex below */ |
| 176 | /* sent string is string */ |
| 177 | char *string; /* sent or expected string */ |
| 178 | int string_len; /* string lenght */ |
| 179 | regex_t *expect_regex; /* expected */ |
| 180 | int inverse; /* 0 = regular match, 1 = inverse match */ |
Baptiste Assmann | 69e273f | 2013-12-11 00:52:19 +0100 | [diff] [blame] | 181 | unsigned short port; /* port to connect to */ |
| 182 | unsigned short conn_opts; /* options when setting up a new connection */ |
Baptiste Assmann | 5ecb77f | 2013-10-06 23:24:13 +0200 | [diff] [blame] | 183 | }; |
| 184 | |
Thierry FOURNIER | 7eeb435 | 2013-06-14 15:28:25 +0200 | [diff] [blame] | 185 | #endif /* _TYPES_CHECKS_H */ |