blob: bf3d6b01e926b899fdb9f985b7ce53a7fd84f6f3 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/types/server.h
3 This file defines everything related to servers.
4
Willy Tarreau7f062c42009-03-05 18:43:00 +01005 Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
Willy Tarreaubaaee002006-06-26 02:48:02 +02006
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*/
21
22#ifndef _TYPES_SERVER_H
23#define _TYPES_SERVER_H
24
25#include <netinet/in.h>
26#include <arpa/inet.h>
27
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020028#include <common/config.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020029#include <common/mini-clist.h>
Willy Tarreau45cb4fb2009-10-26 21:10:04 +010030#include <eb32tree.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020031
32#include <types/buffers.h>
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +020033#include <types/counters.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010034#include <types/freq_ctr.h>
Willy Tarreauc6f4ce82009-06-10 11:09:37 +020035#include <types/port_range.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020036#include <types/proxy.h>
37#include <types/queue.h>
38#include <types/task.h>
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020039#include <types/checks.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020040
41
42/* server flags */
Willy Tarreau77074d52006-11-12 23:57:19 +010043#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 Tarreau48494c02007-11-30 10:41:39 +010048#define SRV_GOINGDOWN 0x0020 /* this server says that it's going down (404) */
Willy Tarreau9909fc12007-11-30 17:42:05 +010049#define SRV_WARMINGUP 0x0040 /* this server is warming up after a failure */
Cyril Bontécd19e512010-01-31 22:34:03 +010050#define SRV_MAINTAIN 0x0080 /* this server is in maintenance mode */
Willy Tarreauc297b522008-01-13 18:12:24 +010051#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 Tarreau090466c2009-09-07 11:51:47 +020054#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 Tarreaubaaee002006-06-26 02:48:02 +020056
57/* function which act on servers need to return various errors */
58#define SRV_STATUS_OK 0 /* everything is OK. */
59#define SRV_STATUS_INTERNAL 1 /* other unrecoverable errors. */
60#define SRV_STATUS_NOSRV 2 /* no server is available */
61#define SRV_STATUS_FULL 3 /* the/all server(s) are saturated */
62#define SRV_STATUS_QUEUED 4 /* the/all server(s) are saturated but the connection was queued */
63
Willy Tarreauc7dd71a2007-11-30 08:33:21 +010064/* bits for s->result used for health-checks */
65#define SRV_CHK_UNKNOWN 0x0000 /* initialized to this by default */
66#define SRV_CHK_ERROR 0x0001 /* error encountered during the check; has precedence */
67#define SRV_CHK_RUNNING 0x0002 /* server seen as running */
68#define SRV_CHK_DISABLE 0x0004 /* server returned a "disable" code */
Willy Tarreaubaaee002006-06-26 02:48:02 +020069
Willy Tarreaub698f0f2007-12-02 11:01:23 +010070/* various constants */
71#define SRV_UWGHT_RANGE 256
72#define SRV_UWGHT_MAX (SRV_UWGHT_RANGE - 1)
73#define SRV_EWGHT_RANGE (SRV_UWGHT_RANGE * BE_WEIGHT_SCALE)
74#define SRV_EWGHT_MAX (SRV_UWGHT_MAX * BE_WEIGHT_SCALE)
75
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020076/* A tree occurrence is a descriptor of a place in a tree, with a pointer back
77 * to the server itself.
78 */
79struct server;
80struct tree_occ {
81 struct server *server;
82 struct eb32_node node;
83};
84
Willy Tarreaubaaee002006-06-26 02:48:02 +020085struct server {
86 struct server *next;
87 int state; /* server state (SRV_*) */
Willy Tarreaub625a082007-11-26 01:15:43 +010088 int prev_state; /* server state before last change (SRV_*) */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +020089 int cklen; /* the len of the cookie, to speed up checks */
Willy Tarreau21d2af32008-02-14 20:25:24 +010090 int rdr_len; /* the length of the redirection prefix */
Willy Tarreau91b6f322007-03-25 21:03:01 +020091 char *cookie; /* the id set in the cookie */
Willy Tarreau21d2af32008-02-14 20:25:24 +010092 char *rdr_pfx; /* the redirection prefix */
Willy Tarreau91b6f322007-03-25 21:03:01 +020093
94 struct proxy *proxy; /* the proxy this server belongs to */
Willy Tarreau7c669d72008-06-20 15:04:11 +020095 int served; /* # of active sessions currently being served (ie not pending) */
Willy Tarreauac68c5d2009-10-04 23:12:44 +020096 int cur_sess; /* number of currently active sessions (including syn_sent) */
Willy Tarreau91b6f322007-03-25 21:03:01 +020097 unsigned maxconn, minconn; /* max # of active sessions (0 = unlimited), min# for dynamic limit. */
Willy Tarreauac68c5d2009-10-04 23:12:44 +020098 int nbpend; /* number of pending connections */
Elijah Epifanovacafc5f2007-10-25 20:15:38 +020099 int maxqueue; /* maximum number of pending connections allowed */
Willy Tarreauac68c5d2009-10-04 23:12:44 +0200100 struct srvcounters counters; /* statistics counters */
101
Willy Tarreau91b6f322007-03-25 21:03:01 +0200102 struct list pendconns; /* pending connections */
Krzysztof Piotr Oledzkia643baf2008-05-29 23:53:44 +0200103 struct task *check; /* the task associated to the health check processing */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200104
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105 struct sockaddr_in addr; /* the address to connect to */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200106 struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */
Willy Tarreau4864c352008-01-14 16:36:15 +0100107#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY)
Willy Tarreau91b6f322007-03-25 21:03:01 +0200108 struct sockaddr_in tproxy_addr; /* non-local address we want to bind to for connect() */
Willy Tarreau77074d52006-11-12 23:57:19 +0100109#endif
Willy Tarreauc76721d2009-02-04 20:20:58 +0100110 int iface_len; /* bind interface name length */
111 char *iface_name; /* bind interface name or NULL */
Willy Tarreauc6f4ce82009-06-10 11:09:37 +0200112 struct port_range *sport_range; /* optional per-server TCP source ports */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200113
Krzysztof Piotr Oledzkic8b16fc2008-02-18 01:26:35 +0100114 struct server *tracknext, *tracked; /* next server in a tracking list, tracked server */
115 char *trackit; /* temporary variable to make assignment deferrable */
Willy Tarreau0f03c6f2007-03-25 20:46:19 +0200116 struct sockaddr_in check_addr; /* the address to check, if different from <addr> */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200117 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 Oledzki97f07b82009-12-15 22:31:24 +0100119 int consecutive_errors; /* current number of consecutive errors */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200120 int rise, fall; /* time in iterations */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100121 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_* */
Krzysztof Piotr Oledzki5259dfe2008-01-21 01:54:06 +0100123 int inter, fastinter, downinter; /* checks: time in milliseconds */
Willy Tarreau9909fc12007-11-30 17:42:05 +0100124 int slowstart; /* slowstart time in seconds (ms in the conf) */
Willy Tarreauc7dd71a2007-11-30 08:33:21 +0100125 int result; /* health-check result : SRV_CHK_* */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200126 int curfd; /* file desc used for current test, or -1 if not in test */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200127
128 char *id; /* just for identification */
Willy Tarreau975c50b2009-10-10 19:34:06 +0200129 unsigned iweight,uweight, eweight; /* initial weight, user-specified weight, and effective weight */
Willy Tarreau417fae02007-03-25 21:16:40 +0200130 unsigned wscore; /* weight score, used during srv map computation */
Willy Tarreaub625a082007-11-26 01:15:43 +0100131 unsigned prev_eweight; /* eweight before last change */
132 unsigned rweight; /* remainer of weight in the current LB tree */
133 unsigned npos, lpos; /* next and last positions in the LB tree */
134 struct eb32_node lb_node; /* node used for tree-based load balancing */
135 struct eb_root *lb_tree; /* we want to know in what tree the server is */
136 struct server *next_full; /* next server in the temporary full list */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200137 unsigned lb_nodes_tot; /* number of allocated lb_nodes (C-HASH) */
138 unsigned lb_nodes_now; /* number of lb_nodes placed in the tree (C-HASH) */
139 struct tree_occ *lb_nodes; /* lb_nodes_tot * struct tree_occ */
Willy Tarreau91b6f322007-03-25 21:03:01 +0200140
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200141 unsigned down_time; /* total time the server was down */
142 time_t last_change; /* last time, when the state was changed */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200143 struct timeval check_start; /* last health check start time */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100144 long check_duration; /* time in ms took to finish last health check */
Krzysztof Piotr Oledzki09605412009-09-23 22:09:24 +0200145 short check_status, check_code; /* check result, check code */
Krzysztof Piotr Oledzki97f07b82009-12-15 22:31:24 +0100146 char check_desc[HCHK_DESC_LEN]; /* health check descritpion */
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200147
Willy Tarreau7f062c42009-03-05 18:43:00 +0100148 struct freq_ctr sess_per_sec; /* sessions per second on this server */
Willy Tarreaudcd47712007-11-04 23:35:08 +0100149 int puid; /* proxy-unique server ID, used for SNMP */
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200150
Nick Chalk57b1bf72010-03-16 15:50:46 +0000151 char *check_data; /* storage of partial check results */
152 int check_data_len; /* length of partial check results stored in check_data */
153
Willy Tarreau90a570f2009-10-04 20:54:54 +0200154 struct {
155 const char *file; /* file where the section appears */
156 int line; /* line where the section appears */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +0200157 struct eb32_node id; /* place in the tree of used IDs */
Willy Tarreau90a570f2009-10-04 20:54:54 +0200158 } conf; /* config information */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200159};
160
161
162#endif /* _TYPES_SERVER_H */
163
164/*
165 * Local variables:
166 * c-indent-level: 8
167 * c-basic-offset: 8
168 * End:
169 */