Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/types/proxy.h |
| 3 | This file defines everything related to proxies. |
| 4 | |
Willy Tarreau | a8cff1d | 2007-04-09 16:10:57 +0200 | [diff] [blame] | 5 | Copyright (C) 2000-2007 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_PROXY_H |
| 23 | #define _TYPES_PROXY_H |
| 24 | |
Willy Tarreau | 7d67768 | 2006-10-15 23:18:47 +0200 | [diff] [blame] | 25 | #include <sys/types.h> |
| 26 | #include <sys/socket.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 27 | #include <netinet/in.h> |
| 28 | #include <arpa/inet.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 29 | |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 30 | #include <common/appsession.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 31 | #include <common/config.h> |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 32 | #include <common/ebtree.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 33 | #include <common/mini-clist.h> |
| 34 | #include <common/regex.h> |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 35 | #include <common/sessionhash.h> |
Willy Tarreau | a8cff1d | 2007-04-09 16:10:57 +0200 | [diff] [blame] | 36 | #include <common/tools.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 37 | |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 38 | #include <types/acl.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | #include <types/buffers.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 40 | #include <types/httperr.h> |
Willy Tarreau | dd81598 | 2007-10-16 12:25:14 +0200 | [diff] [blame] | 41 | #include <types/protocols.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | #include <types/session.h> |
| 43 | #include <types/server.h> |
| 44 | |
| 45 | /* values for proxy->state */ |
| 46 | #define PR_STNEW 0 |
| 47 | #define PR_STIDLE 1 |
| 48 | #define PR_STRUN 2 |
| 49 | #define PR_STSTOPPED 3 |
| 50 | #define PR_STPAUSED 4 |
| 51 | #define PR_STERROR 5 |
| 52 | |
| 53 | /* values for proxy->mode */ |
| 54 | #define PR_MODE_TCP 0 |
| 55 | #define PR_MODE_HTTP 1 |
| 56 | #define PR_MODE_HEALTH 2 |
| 57 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 58 | /* values for proxy->lbprm.map.state */ |
Willy Tarreau | 5af3a69 | 2007-07-24 23:32:33 +0200 | [diff] [blame] | 59 | #define PR_MAP_RECALC (1 << 0) |
| 60 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 61 | /* flag values for proxy->cap. This is a bitmask of capabilities supported by the proxy */ |
| 62 | #define PR_CAP_NONE 0x0000 |
| 63 | #define PR_CAP_FE 0x0001 |
| 64 | #define PR_CAP_BE 0x0002 |
| 65 | #define PR_CAP_RS 0x0004 |
| 66 | #define PR_CAP_LISTEN (PR_CAP_FE|PR_CAP_BE|PR_CAP_RS) |
| 67 | |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 68 | /* This structure is used to apply fast weighted round robin on a server group */ |
| 69 | struct fwrr_group { |
| 70 | struct eb_root curr; /* tree for servers in "current" time range */ |
| 71 | struct eb_root t0, t1; /* "init" and "next" servers */ |
| 72 | struct eb_root *init; /* servers waiting to be placed */ |
| 73 | struct eb_root *next; /* servers to be placed at next run */ |
| 74 | int curr_pos; /* current position in the tree */ |
| 75 | int curr_weight; /* total weight of the current time range */ |
| 76 | int next_weight; /* total weight of the next time range */ |
| 77 | }; |
| 78 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 79 | struct proxy { |
| 80 | struct listener *listen; /* the listen addresses and sockets */ |
| 81 | struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */ |
| 82 | int state; /* proxy state */ |
Willy Tarreau | 35d66b0 | 2007-01-02 00:28:21 +0100 | [diff] [blame] | 83 | int options; /* PR_O_REDISP, PR_O_TRANSP, ... */ |
| 84 | int mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | struct sockaddr_in dispatch_addr; /* the default address to connect to */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 86 | union { |
| 87 | struct proxy *be; /* default backend, or NULL if none set */ |
| 88 | char *name; /* default backend name during config parse */ |
| 89 | } defbe; |
Willy Tarreau | eb0c614 | 2007-05-07 00:53:22 +0200 | [diff] [blame] | 90 | struct list acl; /* ACL declared on this proxy */ |
Willy Tarreau | 5c8e3e0 | 2007-05-07 00:58:25 +0200 | [diff] [blame] | 91 | struct list block_cond; /* early blocking conditions (chained) */ |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 92 | struct list switching_rules; /* content switching rules (chained) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 93 | struct server *srv; /* known servers */ |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 94 | int srv_act, srv_bck; /* # of servers eligible for LB (UP|!checked) AND (enabled+weight!=0) */ |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 95 | |
| 96 | struct { |
| 97 | int tot_wact, tot_wbck; /* total effective weights of active and backup servers */ |
| 98 | int tot_weight; /* total effective weight of servers participating to LB */ |
| 99 | int tot_used; /* total number of servers used for LB */ |
| 100 | int wmult; /* ratio between user weight and effective weight */ |
Willy Tarreau | 5dc2fa6 | 2007-11-19 19:10:18 +0100 | [diff] [blame] | 101 | int wdiv; /* ratio between effective weight and user weight */ |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 102 | struct server *fbck; /* first backup server when !PR_O_USE_ALL_BK, or NULL */ |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 103 | struct { |
| 104 | struct server **srv; /* the server map used to apply weights */ |
| 105 | int rr_idx; /* next server to be elected in round robin mode */ |
| 106 | int state; /* PR_MAP_RECALC */ |
| 107 | } map; /* LB parameters for map-based algorithms */ |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 108 | struct { |
| 109 | struct fwrr_group act; /* weighted round robin on the active servers */ |
| 110 | struct fwrr_group bck; /* weighted round robin on the backup servers */ |
| 111 | } fwrr; |
| 112 | void (*update_server_eweight)(struct server *);/* if non-NULL, to be called after eweight change */ |
| 113 | void (*set_server_status_up)(struct server *);/* to be called after status changes to UP */ |
| 114 | void (*set_server_status_down)(struct server *);/* to be called after status changes to DOWN */ |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 115 | } lbprm; /* LB parameters for all algorithms */ |
| 116 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 117 | char *cookie_name; /* name of the cookie to look for */ |
| 118 | int cookie_len; /* strlen(cookie_name), computed only once */ |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 119 | char *url_param_name; /* name of the URL parameter used for hashing */ |
| 120 | int url_param_len; /* strlen(url_param_name), computed only once */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 121 | char *appsession_name; /* name of the cookie to look for */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 122 | int appsession_name_len; /* strlen(appsession_name), computed only once */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 123 | int appsession_len; /* length of the appsession cookie value to be used */ |
Willy Tarreau | 51041c7 | 2007-09-09 21:56:53 +0200 | [diff] [blame] | 124 | struct appsession_hash htbl_proxy; /* Per Proxy hashtable */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 125 | char *capture_name; /* beginning of the name of the cookie to capture */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 126 | int capture_namelen; /* length of the cookie name to match */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 127 | int capture_len; /* length of the string to be captured */ |
| 128 | struct uri_auth *uri_auth; /* if non-NULL, the (list of) per-URI authentications */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 129 | char *monitor_uri; /* a special URI to which we respond with HTTP/200 OK */ |
| 130 | int monitor_uri_len; /* length of the string above. 0 if unused */ |
Willy Tarreau | d825eef | 2007-05-12 22:35:00 +0200 | [diff] [blame] | 131 | struct timeval clitimeout; /* client I/O timeout (in milliseconds) */ |
| 132 | struct timeval srvtimeout; /* server I/O timeout (in milliseconds) */ |
| 133 | struct timeval contimeout; /* connect timeout (in milliseconds) */ |
| 134 | struct timeval appsession_timeout; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 135 | char *id; /* proxy id */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 136 | struct list pendconns; /* pending connections with no server assigned yet */ |
| 137 | int nbpend, nbpend_max; /* number of pending connections with no server assigned yet */ |
| 138 | int totpend; /* total number of pending connections on this instance (for stats) */ |
Willy Tarreau | f1221aa | 2006-12-17 22:14:12 +0100 | [diff] [blame] | 139 | unsigned int feconn, feconn_max; /* # of active frontend sessions */ |
| 140 | unsigned int beconn, beconn_max; /* # of active backend sessions */ |
| 141 | unsigned int cum_feconn, cum_beconn; /* cumulated number of processed sessions */ |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 142 | unsigned int maxconn; /* max # of active sessions on the frontend */ |
| 143 | unsigned int fullconn; /* #conns on backend above which servers are used at full load */ |
Willy Tarreau | 7ac51f6 | 2007-03-25 16:00:04 +0200 | [diff] [blame] | 144 | struct in_addr except_net, except_mask; /* don't x-forward-for for this address. FIXME: should support IPv6 */ |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 145 | |
| 146 | unsigned down_trans; /* up-down transitions */ |
| 147 | unsigned down_time; /* total time the proxy was down */ |
| 148 | time_t last_change; /* last time, when the state was changed */ |
| 149 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 150 | unsigned failed_conns, failed_resp; /* failed connect() and responses */ |
Krzysztof Oledzki | 1cf36ba | 2007-10-18 19:12:30 +0200 | [diff] [blame] | 151 | unsigned retries, redispatches; /* retried and redispatched connections */ |
Willy Tarreau | c0dde7a | 2007-01-01 21:38:07 +0100 | [diff] [blame] | 152 | unsigned denied_req, denied_resp; /* blocked requests/responses because of security concerns */ |
| 153 | unsigned failed_req; /* failed requests (eg: invalid or timeout) */ |
Willy Tarreau | 35d66b0 | 2007-01-02 00:28:21 +0100 | [diff] [blame] | 154 | long long bytes_in; /* number of bytes transferred from the client to the server */ |
| 155 | long long bytes_out; /* number of bytes transferred from the server to the client */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 156 | int conn_retries; /* maximum number of connect retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 157 | int cap; /* supported capabilities (PR_CAP_*) */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 158 | struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */ |
Willy Tarreau | 77074d5 | 2006-11-12 23:57:19 +0100 | [diff] [blame] | 159 | #ifdef CONFIG_HAP_CTTPROXY |
| 160 | struct sockaddr_in tproxy_addr; /* non-local address we want to bind to for connect() */ |
| 161 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 162 | struct proxy *next; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 163 | struct sockaddr_in logsrv1, logsrv2; /* 2 syslog servers */ |
| 164 | signed char logfac1, logfac2; /* log facility for both servers. -1 = disabled */ |
| 165 | int loglev1, loglev2; /* log level for each server, 7 by default */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 166 | int to_log; /* things to be logged (LW_*) */ |
| 167 | struct timeval stop_time; /* date to stop listening, when stopping != 0 */ |
| 168 | int nb_reqadd, nb_rspadd; |
| 169 | struct hdr_exp *req_exp; /* regular expressions for request headers */ |
| 170 | struct hdr_exp *rsp_exp; /* regular expressions for response headers */ |
| 171 | int nb_req_cap, nb_rsp_cap; /* # of headers to be captured */ |
| 172 | struct cap_hdr *req_cap; /* chained list of request headers to be captured */ |
| 173 | struct cap_hdr *rsp_cap; /* chained list of response headers to be captured */ |
Willy Tarreau | cf7f320 | 2007-05-13 22:46:04 +0200 | [diff] [blame] | 174 | struct pool_head *req_cap_pool, /* pools of pre-allocated char ** used to build the sessions */ |
| 175 | *rsp_cap_pool; |
Willy Tarreau | 1d4154a | 2007-05-13 22:57:02 +0200 | [diff] [blame] | 176 | struct pool_head *hdr_idx_pool; /* pools of pre-allocated int* used for headers indexing */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 177 | char *req_add[MAX_NEWHDR], *rsp_add[MAX_NEWHDR]; /* headers to be added */ |
| 178 | int grace; /* grace time after stop request */ |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 179 | char *check_req; /* HTTP or SSL request to use for PR_O_HTTP_CHK|PR_O_SSL3_CHK */ |
| 180 | int check_len; /* Length of the HTTP or SSL3 request */ |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 181 | struct chunk errmsg[HTTP_ERR_SIZE]; /* default or customized error messages for known errors */ |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 182 | int uuid; /* universally unique proxy ID, used for SNMP */ |
| 183 | int next_svid; /* next server-id, used for SNMP */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 184 | }; |
| 185 | |
Willy Tarreau | 55ea757 | 2007-06-17 19:56:27 +0200 | [diff] [blame] | 186 | struct switching_rule { |
| 187 | struct list list; /* list linked to from the proxy */ |
| 188 | struct acl_cond *cond; /* acl condition to meet */ |
| 189 | union { |
| 190 | struct proxy *backend; /* target backend */ |
| 191 | char *name; /* target backend name during config parsing */ |
| 192 | } be; |
| 193 | }; |
| 194 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 195 | extern struct proxy *proxy; |
Willy Tarreau | dcd4771 | 2007-11-04 23:35:08 +0100 | [diff] [blame] | 196 | extern int next_pxid; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 197 | |
| 198 | #endif /* _TYPES_PROXY_H */ |
| 199 | |
| 200 | /* |
| 201 | * Local variables: |
| 202 | * c-indent-level: 8 |
| 203 | * c-basic-offset: 8 |
| 204 | * End: |
| 205 | */ |