Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/types/server.h |
| 3 | This file defines everything related to servers. |
| 4 | |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 5 | Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [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 | */ |
| 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 | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 29 | #include <common/eb32tree.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 30 | #include <common/mini-clist.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 31 | |
| 32 | #include <types/buffers.h> |
| 33 | #include <types/proxy.h> |
| 34 | #include <types/queue.h> |
| 35 | #include <types/task.h> |
| 36 | |
| 37 | |
| 38 | /* server flags */ |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 39 | #define SRV_RUNNING 0x0001 /* the server is UP */ |
| 40 | #define SRV_BACKUP 0x0002 /* this server is a backup server */ |
| 41 | #define SRV_MAPPORTS 0x0004 /* this server uses mapped ports */ |
| 42 | #define SRV_BIND_SRC 0x0008 /* this server uses a specific source address */ |
| 43 | #define SRV_CHECKED 0x0010 /* this server needs to be checked */ |
Willy Tarreau | 48494c0 | 2007-11-30 10:41:39 +0100 | [diff] [blame] | 44 | #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] | 45 | #define SRV_WARMINGUP 0x0040 /* this server is warming up after a failure */ |
Willy Tarreau | c297b52 | 2008-01-13 18:12:24 +0100 | [diff] [blame] | 46 | /* unused: 0x0080 */ |
| 47 | #define SRV_TPROXY_ADDR 0x0100 /* bind to this non-local address to reach this server */ |
| 48 | #define SRV_TPROXY_CIP 0x0200 /* bind to the client's IP address to reach this server */ |
| 49 | #define SRV_TPROXY_CLI 0x0300 /* bind to the client's IP+port to reach this server */ |
| 50 | #define SRV_TPROXY_MASK 0x0300 /* bind to a non-local address to reach this server */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 51 | |
| 52 | /* function which act on servers need to return various errors */ |
| 53 | #define SRV_STATUS_OK 0 /* everything is OK. */ |
| 54 | #define SRV_STATUS_INTERNAL 1 /* other unrecoverable errors. */ |
| 55 | #define SRV_STATUS_NOSRV 2 /* no server is available */ |
| 56 | #define SRV_STATUS_FULL 3 /* the/all server(s) are saturated */ |
| 57 | #define SRV_STATUS_QUEUED 4 /* the/all server(s) are saturated but the connection was queued */ |
| 58 | |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 59 | /* bits for s->result used for health-checks */ |
| 60 | #define SRV_CHK_UNKNOWN 0x0000 /* initialized to this by default */ |
| 61 | #define SRV_CHK_ERROR 0x0001 /* error encountered during the check; has precedence */ |
| 62 | #define SRV_CHK_RUNNING 0x0002 /* server seen as running */ |
| 63 | #define SRV_CHK_DISABLE 0x0004 /* server returned a "disable" code */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 64 | |
Willy Tarreau | b698f0f | 2007-12-02 11:01:23 +0100 | [diff] [blame] | 65 | /* various constants */ |
| 66 | #define SRV_UWGHT_RANGE 256 |
| 67 | #define SRV_UWGHT_MAX (SRV_UWGHT_RANGE - 1) |
| 68 | #define SRV_EWGHT_RANGE (SRV_UWGHT_RANGE * BE_WEIGHT_SCALE) |
| 69 | #define SRV_EWGHT_MAX (SRV_UWGHT_MAX * BE_WEIGHT_SCALE) |
| 70 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 71 | struct server { |
| 72 | struct server *next; |
| 73 | int state; /* server state (SRV_*) */ |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 74 | int prev_state; /* server state before last change (SRV_*) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 75 | int cklen; /* the len of the cookie, to speed up checks */ |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 76 | int rdr_len; /* the length of the redirection prefix */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 77 | char *cookie; /* the id set in the cookie */ |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 78 | char *rdr_pfx; /* the redirection prefix */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 79 | |
| 80 | struct proxy *proxy; /* the proxy this server belongs to */ |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 81 | int served; /* # of active sessions currently being served (ie not pending) */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 82 | int cur_sess, cur_sess_max; /* number of currently active sessions (including syn_sent) */ |
| 83 | unsigned maxconn, minconn; /* max # of active sessions (0 = unlimited), min# for dynamic limit. */ |
| 84 | int nbpend, nbpend_max; /* number of pending connections */ |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 85 | int maxqueue; /* maximum number of pending connections allowed */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 86 | struct list pendconns; /* pending connections */ |
Krzysztof Piotr Oledzki | a643baf | 2008-05-29 23:53:44 +0200 | [diff] [blame] | 87 | struct task *check; /* the task associated to the health check processing */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 88 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 89 | struct sockaddr_in addr; /* the address to connect to */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 90 | struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */ |
Willy Tarreau | 4864c35 | 2008-01-14 16:36:15 +0100 | [diff] [blame] | 91 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 92 | struct sockaddr_in tproxy_addr; /* non-local address we want to bind to for connect() */ |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 93 | #endif |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 94 | |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 95 | struct server *tracknext, *tracked; /* next server in a tracking list, tracked server */ |
| 96 | char *trackit; /* temporary variable to make assignment deferrable */ |
Willy Tarreau | 0f03c6f | 2007-03-25 20:46:19 +0200 | [diff] [blame] | 97 | struct sockaddr_in check_addr; /* the address to check, if different from <addr> */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 98 | short check_port; /* the port to use for the health checks */ |
| 99 | int health; /* 0->rise-1 = bad; rise->rise+fall-1 = good */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 100 | int rise, fall; /* time in iterations */ |
Krzysztof Piotr Oledzki | 5259dfe | 2008-01-21 01:54:06 +0100 | [diff] [blame] | 101 | int inter, fastinter, downinter; /* checks: time in milliseconds */ |
Willy Tarreau | 9909fc1 | 2007-11-30 17:42:05 +0100 | [diff] [blame] | 102 | int slowstart; /* slowstart time in seconds (ms in the conf) */ |
Willy Tarreau | c7dd71a | 2007-11-30 08:33:21 +0100 | [diff] [blame] | 103 | int result; /* health-check result : SRV_CHK_* */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 104 | 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] | 105 | |
| 106 | char *id; /* just for identification */ |
Willy Tarreau | 417fae0 | 2007-03-25 21:16:40 +0200 | [diff] [blame] | 107 | unsigned uweight, eweight; /* user-specified weight, and effective weight */ |
| 108 | unsigned wscore; /* weight score, used during srv map computation */ |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 109 | unsigned prev_eweight; /* eweight before last change */ |
| 110 | unsigned rweight; /* remainer of weight in the current LB tree */ |
| 111 | unsigned npos, lpos; /* next and last positions in the LB tree */ |
| 112 | struct eb32_node lb_node; /* node used for tree-based load balancing */ |
| 113 | struct eb_root *lb_tree; /* we want to know in what tree the server is */ |
| 114 | struct server *next_full; /* next server in the temporary full list */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 115 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 116 | unsigned failed_checks, down_trans; /* failed checks and up-down transitions */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 117 | unsigned down_time; /* total time the server was down */ |
| 118 | time_t last_change; /* last time, when the state was changed */ |
| 119 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 120 | unsigned failed_conns, failed_resp; /* failed connect() and responses */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 121 | unsigned retries, redispatches; /* retried and redispatched connections */ |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 122 | unsigned failed_secu; /* blocked responses because of security concerns */ |
| 123 | unsigned cum_sess; /* cumulated number of sessions really sent to this server */ |
Willy Tarreau | ddbb82f | 2007-12-05 10:34:49 +0100 | [diff] [blame] | 124 | unsigned cum_lbconn; /* cumulated number of sessions directed by load balancing */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 125 | |
Willy Tarreau | 91b6f32 | 2007-03-25 21:03:01 +0200 | [diff] [blame] | 126 | long long bytes_in; /* number of bytes transferred from the client to the server */ |
| 127 | long long bytes_out; /* number of bytes transferred from the server to the client */ |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 128 | int puid; /* proxy-unique server ID, used for SNMP */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | |
| 132 | #endif /* _TYPES_SERVER_H */ |
| 133 | |
| 134 | /* |
| 135 | * Local variables: |
| 136 | * c-indent-level: 8 |
| 137 | * c-basic-offset: 8 |
| 138 | * End: |
| 139 | */ |