Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 2 | * include/types/server.h |
| 3 | * This file defines everything related to servers. |
| 4 | * |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 5 | * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
| 22 | #ifndef _TYPES_SERVER_H |
| 23 | #define _TYPES_SERVER_H |
| 24 | |
| 25 | #include <netinet/in.h> |
| 26 | #include <arpa/inet.h> |
| 27 | |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 28 | #include <common/config.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 29 | #include <common/mini-clist.h> |
Willy Tarreau | 45cb4fb | 2009-10-26 21:10:04 +0100 | [diff] [blame] | 30 | #include <eb32tree.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 32 | #include <types/connection.h> |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 33 | #include <types/counters.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 34 | #include <types/freq_ctr.h> |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 35 | #include <types/port_range.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 36 | #include <types/proxy.h> |
| 37 | #include <types/queue.h> |
| 38 | #include <types/task.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 39 | #include <types/checks.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | |
| 41 | |
| 42 | /* server flags */ |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 43 | #define SRV_RUNNING 0x0001 /* the server is UP */ |
| 44 | #define SRV_BACKUP 0x0002 /* this server is a backup server */ |
| 45 | #define SRV_MAPPORTS 0x0004 /* this server uses mapped ports */ |
| 46 | #define SRV_BIND_SRC 0x0008 /* this server uses a specific source address */ |
| 47 | #define SRV_CHECKED 0x0010 /* this server needs to be checked */ |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 48 | #define SRV_GOINGDOWN 0x0020 /* this server says that it's going down (404) */ |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 49 | #define SRV_WARMINGUP 0x0040 /* this server is warming up after a failure */ |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 50 | #define SRV_MAINTAIN 0x0080 /* this server is in maintenance mode */ |
Willy Tarreau | c297b52 | 2008-01-13 18:12:24 +0100 | [diff] [blame] | 51 | #define SRV_TPROXY_ADDR 0x0100 /* bind to this non-local address to reach this server */ |
| 52 | #define SRV_TPROXY_CIP 0x0200 /* bind to the client's IP address to reach this server */ |
| 53 | #define SRV_TPROXY_CLI 0x0300 /* bind to the client's IP+port to reach this server */ |
Willy Tarreau | 090466c | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 54 | #define SRV_TPROXY_DYN 0x0400 /* bind to a dynamically computed non-local address */ |
| 55 | #define SRV_TPROXY_MASK 0x0700 /* bind to a non-local address to reach this server */ |
Willy Tarreau | 5ab04ec | 2011-03-20 10:32:26 +0100 | [diff] [blame] | 56 | #define SRV_SEND_PROXY 0x0800 /* this server talks the PROXY protocol */ |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 57 | #define SRV_NON_STICK 0x1000 /* never add connections allocated to this server to a stick table */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 58 | |
| 59 | /* function which act on servers need to return various errors */ |
| 60 | #define SRV_STATUS_OK 0 /* everything is OK. */ |
| 61 | #define SRV_STATUS_INTERNAL 1 /* other unrecoverable errors. */ |
| 62 | #define SRV_STATUS_NOSRV 2 /* no server is available */ |
| 63 | #define SRV_STATUS_FULL 3 /* the/all server(s) are saturated */ |
| 64 | #define SRV_STATUS_QUEUED 4 /* the/all server(s) are saturated but the connection was queued */ |
| 65 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 66 | /* bits for s->result used for health-checks */ |
| 67 | #define SRV_CHK_UNKNOWN 0x0000 /* initialized to this by default */ |
| 68 | #define SRV_CHK_ERROR 0x0001 /* error encountered during the check; has precedence */ |
| 69 | #define SRV_CHK_RUNNING 0x0002 /* server seen as running */ |
| 70 | #define SRV_CHK_DISABLE 0x0004 /* server returned a "disable" code */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 71 | |
Willy Tarreau | b698f0f | 2007-12-02 11:01:23 +0100 | [diff] [blame] | 72 | /* various constants */ |
| 73 | #define SRV_UWGHT_RANGE 256 |
| 74 | #define SRV_UWGHT_MAX (SRV_UWGHT_RANGE - 1) |
| 75 | #define SRV_EWGHT_RANGE (SRV_UWGHT_RANGE * BE_WEIGHT_SCALE) |
| 76 | #define SRV_EWGHT_MAX (SRV_UWGHT_MAX * BE_WEIGHT_SCALE) |
| 77 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 78 | /* A tree occurrence is a descriptor of a place in a tree, with a pointer back |
| 79 | * to the server itself. |
| 80 | */ |
| 81 | struct server; |
| 82 | struct tree_occ { |
| 83 | struct server *server; |
| 84 | struct eb32_node node; |
| 85 | }; |
| 86 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 87 | struct server { |
| 88 | struct server *next; |
| 89 | int state; /* server state (SRV_*) */ |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 90 | int prev_state; /* server state before last change (SRV_*) */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 91 | int cklen; /* the len of the cookie, to speed up checks */ |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 92 | int rdr_len; /* the length of the redirection prefix */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 93 | char *cookie; /* the id set in the cookie */ |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 94 | char *rdr_pfx; /* the redirection prefix */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 95 | |
| 96 | struct proxy *proxy; /* the proxy this server belongs to */ |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 97 | int served; /* # of active sessions currently being served (ie not pending) */ |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 98 | int cur_sess; /* number of currently active sessions (including syn_sent) */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 99 | unsigned maxconn, minconn; /* max # of active sessions (0 = unlimited), min# for dynamic limit. */ |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 100 | int nbpend; /* number of pending connections */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 101 | int maxqueue; /* maximum number of pending connections allowed */ |
Willy Tarreau | 7b81563 | 2011-10-21 18:51:57 +0200 | [diff] [blame] | 102 | struct freq_ctr sess_per_sec; /* sessions per second on this server */ |
Willy Tarreau | ac68c5d | 2009-10-04 23:12:44 +0200 | [diff] [blame] | 103 | struct srvcounters counters; /* statistics counters */ |
| 104 | |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 105 | struct list pendconns; /* pending connections */ |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 106 | struct list actconns; /* active connections */ |
Krzysztof Piotr Oledzki | a643baf | 2008-05-29 23:53:44 +0200 | [diff] [blame] | 107 | struct task *check; /* the task associated to the health check processing */ |
Willy Tarreau | 2e99390 | 2011-10-31 11:53:20 +0100 | [diff] [blame] | 108 | struct task *warmup; /* the task dedicated to the warmup when slowstart is set */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 109 | |
Willy Tarreau | c76721d | 2009-02-04 20:20:58 +0100 | [diff] [blame] | 110 | int iface_len; /* bind interface name length */ |
| 111 | char *iface_name; /* bind interface name or NULL */ |
Willy Tarreau | c6f4ce8 | 2009-06-10 11:09:37 +0200 | [diff] [blame] | 112 | struct port_range *sport_range; /* optional per-server TCP source ports */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 113 | |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 114 | struct server *tracknext, *track; /* next server in a tracking list, tracked server */ |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 115 | char *trackit; /* temporary variable to make assignment deferrable */ |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 116 | struct sockaddr_storage check_addr; /* the address to check, if different from <addr> */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 117 | short check_port; /* the port to use for the health checks */ |
| 118 | int health; /* 0->rise-1 = bad; rise->rise+fall-1 = good */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 119 | int consecutive_errors; /* current number of consecutive errors */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 120 | int rise, fall; /* time in iterations */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 121 | int consecutive_errors_limit; /* number of consecutive errors that triggers an event */ |
| 122 | short observe, onerror; /* observing mode: one of HANA_OBS_*; what to do on error: on of ANA_ONERR_* */ |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 123 | short onmarkeddown; /* what to do when marked down: one of HANA_ONMARKEDDOWN_* */ |
| 124 | short onmarkedup; /* what to do when marked up: one of HANA_ONMARKEDUP_* */ |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 125 | int inter, fastinter, downinter; /* checks: time in milliseconds */ |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 126 | int slowstart; /* slowstart time in seconds (ms in the conf) */ |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 127 | int result; /* health-check result : SRV_CHK_* */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 128 | int curfd; /* file desc used for current test, or -1 if not in test */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 129 | |
| 130 | char *id; /* just for identification */ |
Willy Tarreau | 975c50b | 2009-10-10 19:34:06 +0200 | [diff] [blame] | 131 | unsigned iweight,uweight, eweight; /* initial weight, user-specified weight, and effective weight */ |
Willy Tarreau | 417fae0 | 2007-03-25 21:16:40 +0200 | [diff] [blame] | 132 | unsigned wscore; /* weight score, used during srv map computation */ |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 133 | unsigned prev_eweight; /* eweight before last change */ |
| 134 | unsigned rweight; /* remainer of weight in the current LB tree */ |
| 135 | unsigned npos, lpos; /* next and last positions in the LB tree */ |
| 136 | struct eb32_node lb_node; /* node used for tree-based load balancing */ |
| 137 | struct eb_root *lb_tree; /* we want to know in what tree the server is */ |
| 138 | struct server *next_full; /* next server in the temporary full list */ |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 139 | unsigned lb_nodes_tot; /* number of allocated lb_nodes (C-HASH) */ |
| 140 | unsigned lb_nodes_now; /* number of lb_nodes placed in the tree (C-HASH) */ |
| 141 | struct tree_occ *lb_nodes; /* lb_nodes_tot * struct tree_occ */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 142 | |
Willy Tarreau | 7b81563 | 2011-10-21 18:51:57 +0200 | [diff] [blame] | 143 | /* warning, these structs are huge, keep them at the bottom */ |
| 144 | struct sockaddr_storage addr; /* the address to connect to */ |
| 145 | struct sockaddr_storage source_addr; /* the address to which we want to bind for connect() */ |
| 146 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
| 147 | struct sockaddr_storage tproxy_addr; /* non-local address we want to bind to for connect() */ |
| 148 | char *bind_hdr_name; /* bind to this header name if defined */ |
| 149 | int bind_hdr_len; /* length of the name of the header above */ |
| 150 | int bind_hdr_occ; /* occurrence number of header above: >0 = from first, <0 = from end, 0=disabled */ |
| 151 | #endif |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 152 | struct protocol *proto; /* server address protocol */ |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 153 | struct data_ops *data; /* data-layer operations */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 154 | unsigned down_time; /* total time the server was down */ |
| 155 | time_t last_change; /* last time, when the state was changed */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 156 | struct timeval check_start; /* last health check start time */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 157 | long check_duration; /* time in ms took to finish last health check */ |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 158 | short check_status, check_code; /* check result, check code */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 159 | char check_desc[HCHK_DESC_LEN]; /* health check descritpion */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 160 | |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 161 | int puid; /* proxy-unique server ID, used for SNMP, and "first" LB algo */ |
Krzysztof Piotr Oledzki | 052d4fd | 2009-10-04 14:52:57 +0200 | [diff] [blame] | 162 | |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 163 | char *check_data; /* storage of partial check results */ |
Willy Tarreau | da92e2f | 2012-07-06 09:40:59 +0200 | [diff] [blame] | 164 | struct connection *check_conn; /* connection state for health checks */ |
Nick Chalk | 57b1bf7 | 2010-03-16 15:50:46 +0000 | [diff] [blame] | 165 | int check_data_len; /* length of partial check results stored in check_data */ |
| 166 | |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 167 | struct { |
| 168 | const char *file; /* file where the section appears */ |
| 169 | int line; /* line where the section appears */ |
Willy Tarreau | 53fb4ae | 2009-10-04 23:04:08 +0200 | [diff] [blame] | 170 | struct eb32_node id; /* place in the tree of used IDs */ |
Willy Tarreau | 90a570f | 2009-10-04 20:54:54 +0200 | [diff] [blame] | 171 | } conf; /* config information */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | |
| 175 | #endif /* _TYPES_SERVER_H */ |
| 176 | |
| 177 | /* |
| 178 | * Local variables: |
| 179 | * c-indent-level: 8 |
| 180 | * c-basic-offset: 8 |
| 181 | * End: |
| 182 | */ |