blob: b58a06207b5c90c2e9b11a9a623dafcf1238e411 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau5ab04ec2011-03-20 10:32:26 +01002 * include/types/server.h
3 * This file defines everything related to servers.
4 *
Willy Tarreauf09c6602012-02-13 17:12:08 +01005 * Copyright (C) 2000-2012 Willy Tarreau - w@1wt.eu
Willy Tarreau5ab04ec2011-03-20 10:32:26 +01006 *
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 Tarreaubaaee002006-06-26 02:48:02 +020021
22#ifndef _TYPES_SERVER_H
23#define _TYPES_SERVER_H
24
25#include <netinet/in.h>
26#include <arpa/inet.h>
27
Emeric Brunc6545ac2012-05-18 15:46:21 +020028#ifdef USE_OPENSSL
29#include <openssl/ssl.h>
30#endif
31
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020032#include <common/config.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020033#include <common/mini-clist.h>
Willy Tarreau45cb4fb2009-10-26 21:10:04 +010034#include <eb32tree.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020035
Willy Tarreauda92e2f2012-07-06 09:40:59 +020036#include <types/connection.h>
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +020037#include <types/counters.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010038#include <types/freq_ctr.h>
Willy Tarreau3fdb3662012-11-12 00:42:33 +010039#include <types/obj_type.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020040#include <types/proxy.h>
41#include <types/queue.h>
42#include <types/task.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020043#include <types/checks.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020044
45
46/* server flags */
Willy Tarreau77074d52006-11-12 23:57:19 +010047#define SRV_RUNNING 0x0001 /* the server is UP */
48#define SRV_BACKUP 0x0002 /* this server is a backup server */
49#define SRV_MAPPORTS 0x0004 /* this server uses mapped ports */
Willy Tarreauef9a3602012-12-08 22:29:20 +010050/* unused: 0x0008 */
Willy Tarreau77074d52006-11-12 23:57:19 +010051#define SRV_CHECKED 0x0010 /* this server needs to be checked */
Willy Tarreau48494c02007-11-30 10:41:39 +010052#define SRV_GOINGDOWN 0x0020 /* this server says that it's going down (404) */
Willy Tarreau9909fc12007-11-30 17:42:05 +010053#define SRV_WARMINGUP 0x0040 /* this server is warming up after a failure */
Cyril Bontécd19e512010-01-31 22:34:03 +010054#define SRV_MAINTAIN 0x0080 /* this server is in maintenance mode */
Willy Tarreauef9a3602012-12-08 22:29:20 +010055/* unused: 0x0100, 0x0200, 0x0400 */
Willy Tarreau5ab04ec2011-03-20 10:32:26 +010056#define SRV_SEND_PROXY 0x0800 /* this server talks the PROXY protocol */
Simon Hormanfa461682011-06-25 09:39:49 +090057#define SRV_NON_STICK 0x1000 /* never add connections allocated to this server to a stick table */
Willy Tarreau5a78f362012-11-23 12:47:05 +010058#define SRV_CHK_RUNNING 0x2000 /* a check is currently running on this server */
Willy Tarreaubaaee002006-06-26 02:48:02 +020059
60/* function which act on servers need to return various errors */
61#define SRV_STATUS_OK 0 /* everything is OK. */
62#define SRV_STATUS_INTERNAL 1 /* other unrecoverable errors. */
63#define SRV_STATUS_NOSRV 2 /* no server is available */
64#define SRV_STATUS_FULL 3 /* the/all server(s) are saturated */
65#define SRV_STATUS_QUEUED 4 /* the/all server(s) are saturated but the connection was queued */
66
Willy Tarreauc7dd71a2007-11-30 08:33:21 +010067/* bits for s->result used for health-checks */
68#define SRV_CHK_UNKNOWN 0x0000 /* initialized to this by default */
Willy Tarreaud3aac702012-11-23 11:32:12 +010069#define SRV_CHK_FAILED 0x0001 /* server check failed, flag has precedence over SRV_CHK_PASSED */
70#define SRV_CHK_PASSED 0x0002 /* server check succeeded unless FAILED is also set */
Willy Tarreauc7dd71a2007-11-30 08:33:21 +010071#define SRV_CHK_DISABLE 0x0004 /* server returned a "disable" code */
Willy Tarreaubaaee002006-06-26 02:48:02 +020072
Willy Tarreaub698f0f2007-12-02 11:01:23 +010073/* various constants */
74#define SRV_UWGHT_RANGE 256
75#define SRV_UWGHT_MAX (SRV_UWGHT_RANGE - 1)
76#define SRV_EWGHT_RANGE (SRV_UWGHT_RANGE * BE_WEIGHT_SCALE)
77#define SRV_EWGHT_MAX (SRV_UWGHT_MAX * BE_WEIGHT_SCALE)
78
Emeric Brun89675492012-10-05 13:48:26 +020079#ifdef USE_OPENSSL
80/* server ssl options */
81#define SRV_SSL_O_NONE 0x0000
Emeric Brun992adc92012-10-11 18:36:21 +020082#define SRV_SSL_O_NO_VMASK 0x000F /* force version mask */
Emeric Brun89675492012-10-05 13:48:26 +020083#define SRV_SSL_O_NO_SSLV3 0x0001 /* disable SSLv3 */
84#define SRV_SSL_O_NO_TLSV10 0x0002 /* disable TLSv1.0 */
85#define SRV_SSL_O_NO_TLSV11 0x0004 /* disable TLSv1.1 */
86#define SRV_SSL_O_NO_TLSV12 0x0008 /* disable TLSv1.2 */
87/* 0x000F reserved for 'no' protocol version options */
Emeric Brun992adc92012-10-11 18:36:21 +020088#define SRV_SSL_O_USE_VMASK 0x00F0 /* force version mask */
89#define SRV_SSL_O_USE_SSLV3 0x0010 /* force SSLv3 */
90#define SRV_SSL_O_USE_TLSV10 0x0020 /* force TLSv1.0 */
91#define SRV_SSL_O_USE_TLSV11 0x0040 /* force TLSv1.1 */
92#define SRV_SSL_O_USE_TLSV12 0x0080 /* force TLSv1.2 */
Emeric Brun8694b9a2012-10-05 14:39:07 +020093/* 0x00F0 reserved for 'force' protocol version options */
Emeric Brunf9c5c472012-10-11 15:28:34 +020094#define SRV_SSL_O_NO_TLS_TICKETS 0x0100 /* disable session resumption tickets */
Emeric Brun89675492012-10-05 13:48:26 +020095#endif
96
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020097/* A tree occurrence is a descriptor of a place in a tree, with a pointer back
98 * to the server itself.
99 */
100struct server;
101struct tree_occ {
102 struct server *server;
103 struct eb32_node node;
104};
105
Willy Tarreaubaaee002006-06-26 02:48:02 +0200106struct server {
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100107 enum obj_type obj_type; /* object type == OBJ_TYPE_SERVER */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200108 struct server *next;
109 int state; /* server state (SRV_*) */
Willy Tarreaub625a082007-11-26 01:15:43 +0100110 int prev_state; /* server state before last change (SRV_*) */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200111 int cklen; /* the len of the cookie, to speed up checks */
Willy Tarreau21d2af32008-02-14 20:25:24 +0100112 int rdr_len; /* the length of the redirection prefix */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200113 char *cookie; /* the id set in the cookie */
Willy Tarreau21d2af32008-02-14 20:25:24 +0100114 char *rdr_pfx; /* the redirection prefix */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200115
116 struct proxy *proxy; /* the proxy this server belongs to */
Willy Tarreau7c669d72008-06-20 15:04:11 +0200117 int served; /* # of active sessions currently being served (ie not pending) */
Willy Tarreauac68c5d2009-10-04 23:12:44 +0200118 int cur_sess; /* number of currently active sessions (including syn_sent) */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200119 unsigned maxconn, minconn; /* max # of active sessions (0 = unlimited), min# for dynamic limit. */
Willy Tarreauac68c5d2009-10-04 23:12:44 +0200120 int nbpend; /* number of pending connections */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +0200121 int maxqueue; /* maximum number of pending connections allowed */
Willy Tarreau7b815632011-10-21 18:51:57 +0200122 struct freq_ctr sess_per_sec; /* sessions per second on this server */
Willy Tarreauac68c5d2009-10-04 23:12:44 +0200123 struct srvcounters counters; /* statistics counters */
124
Willy Tarreau91b6f322007-03-25 21:03:01 +0200125 struct list pendconns; /* pending connections */
Simon Hormanaf514952011-06-21 14:34:57 +0900126 struct list actconns; /* active connections */
Willy Tarreau2e993902011-10-31 11:53:20 +0100127 struct task *warmup; /* the task dedicated to the warmup when slowstart is set */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200128
Willy Tarreauef9a3602012-12-08 22:29:20 +0100129 struct conn_src conn_src; /* connection source settings */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200130
Willy Tarreau44267702011-10-28 15:35:33 +0200131 struct server *tracknext, *track; /* next server in a tracking list, tracked server */
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100132 char *trackit; /* temporary variable to make assignment deferrable */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200133 int health; /* 0->rise-1 = bad; rise->rise+fall-1 = good */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100134 int consecutive_errors; /* current number of consecutive errors */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200135 int rise, fall; /* time in iterations */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100136 int consecutive_errors_limit; /* number of consecutive errors that triggers an event */
137 short observe, onerror; /* observing mode: one of HANA_OBS_*; what to do on error: on of ANA_ONERR_* */
Justin Karnegeseb2c24a2012-05-24 15:28:52 -0700138 short onmarkeddown; /* what to do when marked down: one of HANA_ONMARKEDDOWN_* */
139 short onmarkedup; /* what to do when marked up: one of HANA_ONMARKEDUP_* */
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +0100140 int inter, fastinter, downinter; /* checks: time in milliseconds */
Willy Tarreau9909fc12007-11-30 17:42:05 +0100141 int slowstart; /* slowstart time in seconds (ms in the conf) */
Willy Tarreauc7dd71a2007-11-30 08:33:21 +0100142 int result; /* health-check result : SRV_CHK_* */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200143
144 char *id; /* just for identification */
Willy Tarreau975c50b2009-10-10 19:34:06 +0200145 unsigned iweight,uweight, eweight; /* initial weight, user-specified weight, and effective weight */
Willy Tarreau417fae02007-03-25 21:16:40 +0200146 unsigned wscore; /* weight score, used during srv map computation */
Willy Tarreaub625a082007-11-26 01:15:43 +0100147 unsigned prev_eweight; /* eweight before last change */
148 unsigned rweight; /* remainer of weight in the current LB tree */
149 unsigned npos, lpos; /* next and last positions in the LB tree */
150 struct eb32_node lb_node; /* node used for tree-based load balancing */
151 struct eb_root *lb_tree; /* we want to know in what tree the server is */
152 struct server *next_full; /* next server in the temporary full list */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200153 unsigned lb_nodes_tot; /* number of allocated lb_nodes (C-HASH) */
154 unsigned lb_nodes_now; /* number of lb_nodes placed in the tree (C-HASH) */
155 struct tree_occ *lb_nodes; /* lb_nodes_tot * struct tree_occ */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200156
Willy Tarreau7b815632011-10-21 18:51:57 +0200157 /* warning, these structs are huge, keep them at the bottom */
158 struct sockaddr_storage addr; /* the address to connect to */
Willy Tarreau26d8c592012-05-07 18:12:14 +0200159 struct protocol *proto; /* server address protocol */
Willy Tarreauf7bc57c2012-10-03 00:19:48 +0200160 struct xprt_ops *xprt; /* transport-layer operations */
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200161 unsigned down_time; /* total time the server was down */
162 time_t last_change; /* last time, when the state was changed */
163
Willy Tarreauf09c6602012-02-13 17:12:08 +0100164 int puid; /* proxy-unique server ID, used for SNMP, and "first" LB algo */
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200165
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200166 struct { /* health-check specific configuration */
167 struct connection *conn; /* connection state for health checks */
Willy Tarreauf4288ee2012-09-28 18:13:10 +0200168 struct protocol *proto; /* server address protocol for health checks */
169 struct xprt_ops *xprt; /* transport layer operations for health checks */
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200170 struct sockaddr_storage addr; /* the address to check, if different from <addr> */
171 short port; /* the port to use for the health checks */
Willy Tarreau1ae1b7b2012-09-28 15:28:30 +0200172 struct buffer *bi, *bo; /* input and output buffers to send/recv check */
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200173 struct task *task; /* the task associated to the health check processing, NULL if disabled */
174 struct timeval start; /* last health check start time */
175 long duration; /* time in ms took to finish last health check */
176 short status, code; /* check result, check code */
177 char desc[HCHK_DESC_LEN]; /* health check descritpion */
Willy Tarreauf4288ee2012-09-28 18:13:10 +0200178 int use_ssl; /* use SSL for health checks */
Willy Tarreau6c16adc2012-10-05 00:04:16 +0200179 int send_proxy; /* send a PROXY protocol header with checks */
Willy Tarreau5b3a2022012-09-28 15:01:02 +0200180 } check;
Nick Chalk57b1bf72010-03-16 15:50:46 +0000181
Emeric Brunc6545ac2012-05-18 15:46:21 +0200182#ifdef USE_OPENSSL
Emeric Brun01f8e2f2012-05-18 16:02:00 +0200183 int use_ssl; /* ssl enabled */
Emeric Brunc6545ac2012-05-18 15:46:21 +0200184 struct {
185 SSL_CTX *ctx;
186 SSL_SESSION *reused_sess;
Willy Tarreaud7aacbf2012-09-03 23:34:19 +0200187 char *ciphers; /* cipher suite to use if non-null */
Emeric Brun89675492012-10-05 13:48:26 +0200188 int options; /* ssl options */
Emeric Brunef42d922012-10-11 16:11:36 +0200189 int verify; /* verify method (set of SSL_VERIFY_* flags) */
190 char *ca_file; /* CAfile to use on verify */
191 char *crl_file; /* CRLfile to use on verify */
Emeric Bruna7aa3092012-10-26 12:58:00 +0200192 char *client_crt; /* client certificate to send */
Emeric Brunc6545ac2012-05-18 15:46:21 +0200193 } ssl_ctx;
194#endif
Willy Tarreau90a570f2009-10-04 20:54:54 +0200195 struct {
196 const char *file; /* file where the section appears */
197 int line; /* line where the section appears */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +0200198 struct eb32_node id; /* place in the tree of used IDs */
Willy Tarreau90a570f2009-10-04 20:54:54 +0200199 } conf; /* config information */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200200};
201
Willy Tarreau21faa912012-10-10 08:27:36 +0200202/* Descriptor for a "server" keyword. The ->parse() function returns 0 in case of
203 * success, or a combination of ERR_* flags if an error is encountered. The
204 * function pointer can be NULL if not implemented. The function also has an
205 * access to the current "server" config line. The ->skip value tells the parser
206 * how many words have to be skipped after the keyword. If the function needs to
207 * parse more keywords, it needs to update cur_arg.
208 */
209struct srv_kw {
210 const char *kw;
211 int (*parse)(char **args, int *cur_arg, struct proxy *px, struct server *srv, char **err);
212 int skip; /* nb min of args to skip, for use when kw is not handled */
213 int default_ok; /* non-zero if kw is supported in default-server section */
214};
215
216/*
217 * A keyword list. It is a NULL-terminated array of keywords. It embeds a
218 * struct list in order to be linked to other lists, allowing it to easily
219 * be declared where it is needed, and linked without duplicating data nor
220 * allocating memory. It is also possible to indicate a scope for the keywords.
221 */
222struct srv_kw_list {
223 const char *scope;
224 struct list list;
225 struct srv_kw kw[VAR_ARRAY];
226};
Willy Tarreaubaaee002006-06-26 02:48:02 +0200227
228#endif /* _TYPES_SERVER_H */
229
230/*
231 * Local variables:
232 * c-indent-level: 8
233 * c-basic-offset: 8
234 * End:
235 */