blob: 03cb5f638e105c42cbfd582f260e9e3b067cf2be [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 include/types/proxy.h
3 This file defines everything related to proxies.
4
Willy Tarreau3a70f942008-02-15 11:15:34 +01005 Copyright (C) 2000-2008 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_PROXY_H
23#define _TYPES_PROXY_H
24
Willy Tarreau7d677682006-10-15 23:18:47 +020025#include <sys/types.h>
26#include <sys/socket.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020027#include <netinet/in.h>
28#include <arpa/inet.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020029
Willy Tarreau2dd0d472006-06-29 17:53:05 +020030#include <common/appsession.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020031#include <common/config.h>
Willy Tarreaub625a082007-11-26 01:15:43 +010032#include <common/ebtree.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020033#include <common/mini-clist.h>
34#include <common/regex.h>
Willy Tarreau51041c72007-09-09 21:56:53 +020035#include <common/sessionhash.h>
Willy Tarreaua8cff1d2007-04-09 16:10:57 +020036#include <common/tools.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020037
Willy Tarreaueb0c6142007-05-07 00:53:22 +020038#include <types/acl.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020039#include <types/buffers.h>
Willy Tarreau0f772532006-12-23 20:51:41 +010040#include <types/httperr.h>
Robert Tsai81ae1952007-12-05 10:47:29 +010041#include <types/log.h>
Willy Tarreaudd815982007-10-16 12:25:14 +020042#include <types/protocols.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020043#include <types/session.h>
44#include <types/server.h>
45
46/* values for proxy->state */
47#define PR_STNEW 0
48#define PR_STIDLE 1
49#define PR_STRUN 2
50#define PR_STSTOPPED 3
51#define PR_STPAUSED 4
52#define PR_STERROR 5
53
54/* values for proxy->mode */
55#define PR_MODE_TCP 0
56#define PR_MODE_HTTP 1
57#define PR_MODE_HEALTH 2
58
Willy Tarreau20697042007-11-15 23:26:18 +010059/* values for proxy->lbprm.map.state */
Willy Tarreau5af3a692007-07-24 23:32:33 +020060#define PR_MAP_RECALC (1 << 0)
61
Willy Tarreau977b8e42006-12-29 14:19:17 +010062/* flag values for proxy->cap. This is a bitmask of capabilities supported by the proxy */
63#define PR_CAP_NONE 0x0000
64#define PR_CAP_FE 0x0001
65#define PR_CAP_BE 0x0002
66#define PR_CAP_RS 0x0004
67#define PR_CAP_LISTEN (PR_CAP_FE|PR_CAP_BE|PR_CAP_RS)
68
Willy Tarreau31682232007-11-29 15:38:04 +010069/* bits for proxy->options */
70#define PR_O_REDISP 0x00000001 /* allow reconnection to dispatch in case of errors */
71#define PR_O_TRANSP 0x00000002 /* transparent mode : use original DEST as dispatch */
72#define PR_O_COOK_RW 0x00000004 /* rewrite all direct cookies with the right serverid */
73#define PR_O_COOK_IND 0x00000008 /* keep only indirect cookies */
74#define PR_O_COOK_INS 0x00000010 /* insert cookies when not accessing a server directly */
75#define PR_O_COOK_PFX 0x00000020 /* rewrite all cookies by prefixing the right serverid */
76#define PR_O_COOK_ANY (PR_O_COOK_RW | PR_O_COOK_IND | PR_O_COOK_INS | PR_O_COOK_PFX)
77#define PR_O_SMTP_CHK 0x00000040 /* use SMTP EHLO check for server health - pvandijk@vision6.com.au */
78#define PR_O_KEEPALIVE 0x00000080 /* follow keep-alive sessions */
79#define PR_O_FWDFOR 0x00000100 /* insert x-forwarded-for with client address */
80#define PR_O_BIND_SRC 0x00000200 /* bind to a specific source address when connect()ing */
81#define PR_O_NULLNOLOG 0x00000400 /* a connect without request will not be logged */
82#define PR_O_COOK_NOC 0x00000800 /* add a 'Cache-control' header with the cookie */
83#define PR_O_COOK_POST 0x00001000 /* don't insert cookies for requests other than a POST */
84#define PR_O_HTTP_CHK 0x00002000 /* use HTTP 'OPTIONS' method to check server health */
85#define PR_O_PERSIST 0x00004000 /* server persistence stays effective even when server is down */
86#define PR_O_LOGASAP 0x00008000 /* log as soon as possible, without waiting for the session to complete */
87#define PR_O_HTTP_CLOSE 0x00010000 /* force 'connection: close' in both directions */
88#define PR_O_CHK_CACHE 0x00020000 /* require examination of cacheability of the 'set-cookie' field */
89#define PR_O_TCP_CLI_KA 0x00040000 /* enable TCP keep-alive on client-side sessions */
90#define PR_O_TCP_SRV_KA 0x00080000 /* enable TCP keep-alive on server-side sessions */
91#define PR_O_USE_ALL_BK 0x00100000 /* load-balance between backup servers */
92#define PR_O_FORCE_CLO 0x00200000 /* enforce the connection close immediately after server response */
93#define PR_O_TCP_NOLING 0x00400000 /* disable lingering on client and server connections */
94#define PR_O_ABRT_CLOSE 0x00800000 /* immediately abort request when client closes */
95#define PR_O_SSL3_CHK 0x01000000 /* use SSLv3 CLIENT_HELLO packets for server health */
96
97/* TPXY: exclusive values */
98#define PR_O_TPXY_ADDR 0x02000000 /* bind to this non-local address when connect()ing */
99#define PR_O_TPXY_CIP 0x04000000 /* bind to the client's IP address when connect()ing */
100#define PR_O_TPXY_CLI 0x06000000 /* bind to the client's IP+port when connect()ing */
101#define PR_O_TPXY_MASK 0x06000000 /* bind to a non-local address when connect()ing */
102
103#define PR_O_TCPSPLICE 0x08000000 /* delegate data transfer to linux kernel's tcp_splice */
104#define PR_O_CONTSTATS 0x10000000 /* continous counters */
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100105#define PR_O_HTTP_PROXY 0x20000000 /* Enable session to use HTTP proxy operations */
Willy Tarreau48494c02007-11-30 10:41:39 +0100106#define PR_O_DISABLE404 0x40000000 /* Disable a server on a 404 response to a health-check */
Willy Tarreau31682232007-11-29 15:38:04 +0100107
Willy Tarreaub625a082007-11-26 01:15:43 +0100108/* This structure is used to apply fast weighted round robin on a server group */
109struct fwrr_group {
110 struct eb_root curr; /* tree for servers in "current" time range */
111 struct eb_root t0, t1; /* "init" and "next" servers */
112 struct eb_root *init; /* servers waiting to be placed */
113 struct eb_root *next; /* servers to be placed at next run */
114 int curr_pos; /* current position in the tree */
115 int curr_weight; /* total weight of the current time range */
116 int next_weight; /* total weight of the next time range */
117};
118
Willy Tarreaubaaee002006-06-26 02:48:02 +0200119struct proxy {
120 struct listener *listen; /* the listen addresses and sockets */
121 struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */
122 int state; /* proxy state */
Willy Tarreau35d66b02007-01-02 00:28:21 +0100123 int options; /* PR_O_REDISP, PR_O_TRANSP, ... */
124 int mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200125 struct sockaddr_in dispatch_addr; /* the default address to connect to */
Willy Tarreau5fdfb912007-01-01 23:11:07 +0100126 union {
127 struct proxy *be; /* default backend, or NULL if none set */
128 char *name; /* default backend name during config parse */
129 } defbe;
Willy Tarreaueb0c6142007-05-07 00:53:22 +0200130 struct list acl; /* ACL declared on this proxy */
Willy Tarreau5c8e3e02007-05-07 00:58:25 +0200131 struct list block_cond; /* early blocking conditions (chained) */
Willy Tarreaub463dfb2008-06-07 23:08:56 +0200132 struct list redirect_rules; /* content redirecting rules (chained) */
Willy Tarreau55ea7572007-06-17 19:56:27 +0200133 struct list switching_rules; /* content switching rules (chained) */
Willy Tarreaub6866442008-07-14 23:54:42 +0200134 struct { /* TCP request processing */
135 int inspect_delay; /* inspection delay */
136 struct list inspect_rules; /* inspection rules */
137 } tcp_req;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200138 struct server *srv; /* known servers */
Willy Tarreaub625a082007-11-26 01:15:43 +0100139 int srv_act, srv_bck; /* # of servers eligible for LB (UP|!checked) AND (enabled+weight!=0) */
Willy Tarreau20697042007-11-15 23:26:18 +0100140
141 struct {
Willy Tarreau31682232007-11-29 15:38:04 +0100142 int algo; /* load balancing algorithm and variants: BE_LB_ALGO* */
Willy Tarreau20697042007-11-15 23:26:18 +0100143 int tot_wact, tot_wbck; /* total effective weights of active and backup servers */
144 int tot_weight; /* total effective weight of servers participating to LB */
145 int tot_used; /* total number of servers used for LB */
146 int wmult; /* ratio between user weight and effective weight */
Willy Tarreau5dc2fa62007-11-19 19:10:18 +0100147 int wdiv; /* ratio between effective weight and user weight */
Willy Tarreaub625a082007-11-26 01:15:43 +0100148 struct server *fbck; /* first backup server when !PR_O_USE_ALL_BK, or NULL */
Willy Tarreau20697042007-11-15 23:26:18 +0100149 struct {
150 struct server **srv; /* the server map used to apply weights */
151 int rr_idx; /* next server to be elected in round robin mode */
152 int state; /* PR_MAP_RECALC */
153 } map; /* LB parameters for map-based algorithms */
Willy Tarreaub625a082007-11-26 01:15:43 +0100154 struct {
155 struct fwrr_group act; /* weighted round robin on the active servers */
156 struct fwrr_group bck; /* weighted round robin on the backup servers */
157 } fwrr;
Willy Tarreau51406232008-03-10 22:04:20 +0100158 struct {
159 struct eb_root act; /* weighted least conns on the active servers */
160 struct eb_root bck; /* weighted least conns on the backup servers */
161 } fwlc;
Willy Tarreaub625a082007-11-26 01:15:43 +0100162 void (*update_server_eweight)(struct server *);/* if non-NULL, to be called after eweight change */
163 void (*set_server_status_up)(struct server *);/* to be called after status changes to UP */
164 void (*set_server_status_down)(struct server *);/* to be called after status changes to DOWN */
Willy Tarreau51406232008-03-10 22:04:20 +0100165 void (*server_take_conn)(struct server *);/* to be called when connection is assigned */
166 void (*server_drop_conn)(struct server *);/* to be called when connection is dropped */
Willy Tarreau20697042007-11-15 23:26:18 +0100167 } lbprm; /* LB parameters for all algorithms */
168
Krzysztof Piotr Oledzki1acf2172008-05-29 23:03:34 +0200169 char *cookie_domain; /* domain used to insert the cookie */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200170 char *cookie_name; /* name of the cookie to look for */
171 int cookie_len; /* strlen(cookie_name), computed only once */
Willy Tarreau01732802007-11-01 22:48:15 +0100172 char *url_param_name; /* name of the URL parameter used for hashing */
173 int url_param_len; /* strlen(url_param_name), computed only once */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200174 unsigned url_param_post_limit; /* if checking POST body for URI parameter, max body to wait for */
Marek Majkowski9c30fc12008-04-27 23:25:55 +0200175 int uri_len_limit; /* character limit for uri balancing algorithm */
176 int uri_dirs_depth1; /* directories+1 (slashes) limit for uri balancing algorithm */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200177 char *appsession_name; /* name of the cookie to look for */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200178 int appsession_name_len; /* strlen(appsession_name), computed only once */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200179 int appsession_len; /* length of the appsession cookie value to be used */
Willy Tarreau51041c72007-09-09 21:56:53 +0200180 struct appsession_hash htbl_proxy; /* Per Proxy hashtable */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200181 char *capture_name; /* beginning of the name of the cookie to capture */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200182 int capture_namelen; /* length of the cookie name to match */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200183 int capture_len; /* length of the string to be captured */
184 struct uri_auth *uri_auth; /* if non-NULL, the (list of) per-URI authentications */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200185 char *monitor_uri; /* a special URI to which we respond with HTTP/200 OK */
186 int monitor_uri_len; /* length of the string above. 0 if unused */
Willy Tarreaub80c2302007-11-30 20:51:32 +0100187 struct list mon_fail_cond; /* list of conditions to fail monitoring requests (chained) */
Willy Tarreau3a70f942008-02-15 11:15:34 +0100188 struct { /* WARNING! check proxy_reset_timeouts() in proxy.h !!! */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200189 int client; /* client I/O timeout (in ticks) */
190 int tarpit; /* tarpit timeout, defaults to connect if unspecified */
191 int queue; /* queue timeout, defaults to connect if unspecified */
192 int connect; /* connect timeout (in ticks) */
193 int server; /* server I/O timeout (in ticks) */
194 int appsession; /* appsession cookie expiration */
195 int httpreq; /* maximum time for complete HTTP request */
196 int check; /* maximum time for complete check */
Willy Tarreau1fa31262007-12-03 00:36:16 +0100197 } timeout;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200198 char *id; /* proxy id */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200199 struct list pendconns; /* pending connections with no server assigned yet */
200 int nbpend, nbpend_max; /* number of pending connections with no server assigned yet */
201 int totpend; /* total number of pending connections on this instance (for stats) */
Willy Tarreauf1221aa2006-12-17 22:14:12 +0100202 unsigned int feconn, feconn_max; /* # of active frontend sessions */
203 unsigned int beconn, beconn_max; /* # of active backend sessions */
204 unsigned int cum_feconn, cum_beconn; /* cumulated number of processed sessions */
Willy Tarreauddbb82f2007-12-05 10:34:49 +0100205 unsigned int cum_lbconn; /* cumulated number of sessions processed by load balancing */
Willy Tarreau86034312006-12-29 00:10:33 +0100206 unsigned int maxconn; /* max # of active sessions on the frontend */
207 unsigned int fullconn; /* #conns on backend above which servers are used at full load */
Willy Tarreau7ac51f62007-03-25 16:00:04 +0200208 struct in_addr except_net, except_mask; /* don't x-forward-for for this address. FIXME: should support IPv6 */
Ross Westaf72a1d2008-08-03 10:51:45 +0200209 char *fwdfor_hdr_name; /* header to use - default: "x-forwarded-for" */
210 int fwdfor_hdr_len; /* length of "x-forwarded-for" header */
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200211
212 unsigned down_trans; /* up-down transitions */
213 unsigned down_time; /* total time the proxy was down */
214 time_t last_change; /* last time, when the state was changed */
215
Willy Tarreaubaaee002006-06-26 02:48:02 +0200216 unsigned failed_conns, failed_resp; /* failed connect() and responses */
Krzysztof Oledzki1cf36ba2007-10-18 19:12:30 +0200217 unsigned retries, redispatches; /* retried and redispatched connections */
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100218 unsigned denied_req, denied_resp; /* blocked requests/responses because of security concerns */
219 unsigned failed_req; /* failed requests (eg: invalid or timeout) */
Willy Tarreau35d66b02007-01-02 00:28:21 +0100220 long long bytes_in; /* number of bytes transferred from the client to the server */
221 long long bytes_out; /* number of bytes transferred from the server to the client */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200222 int conn_retries; /* maximum number of connect retries */
Willy Tarreau977b8e42006-12-29 14:19:17 +0100223 int cap; /* supported capabilities (PR_CAP_*) */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200224 struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */
Willy Tarreau4864c352008-01-14 16:36:15 +0100225#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY)
Willy Tarreau77074d52006-11-12 23:57:19 +0100226 struct sockaddr_in tproxy_addr; /* non-local address we want to bind to for connect() */
227#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +0200228 struct proxy *next;
Robert Tsai81ae1952007-12-05 10:47:29 +0100229 struct logsrv logsrv1, logsrv2; /* 2 syslog servers */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200230 signed char logfac1, logfac2; /* log facility for both servers. -1 = disabled */
231 int loglev1, loglev2; /* log level for each server, 7 by default */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200232 int to_log; /* things to be logged (LW_*) */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200233 int stop_time; /* date to stop listening, when stopping != 0 (int ticks) */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200234 int nb_reqadd, nb_rspadd;
235 struct hdr_exp *req_exp; /* regular expressions for request headers */
236 struct hdr_exp *rsp_exp; /* regular expressions for response headers */
237 int nb_req_cap, nb_rsp_cap; /* # of headers to be captured */
238 struct cap_hdr *req_cap; /* chained list of request headers to be captured */
239 struct cap_hdr *rsp_cap; /* chained list of response headers to be captured */
Willy Tarreaucf7f3202007-05-13 22:46:04 +0200240 struct pool_head *req_cap_pool, /* pools of pre-allocated char ** used to build the sessions */
241 *rsp_cap_pool;
Willy Tarreau1d4154a2007-05-13 22:57:02 +0200242 struct pool_head *hdr_idx_pool; /* pools of pre-allocated int* used for headers indexing */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200243 char *req_add[MAX_NEWHDR], *rsp_add[MAX_NEWHDR]; /* headers to be added */
244 int grace; /* grace time after stop request */
Willy Tarreauf3c69202006-07-09 16:42:34 +0200245 char *check_req; /* HTTP or SSL request to use for PR_O_HTTP_CHK|PR_O_SSL3_CHK */
246 int check_len; /* Length of the HTTP or SSL3 request */
Willy Tarreau0f772532006-12-23 20:51:41 +0100247 struct chunk errmsg[HTTP_ERR_SIZE]; /* default or customized error messages for known errors */
Willy Tarreaudcd47712007-11-04 23:35:08 +0100248 int uuid; /* universally unique proxy ID, used for SNMP */
249 int next_svid; /* next server-id, used for SNMP */
Willy Tarreauc73ce2b2008-01-06 10:55:10 +0100250 unsigned int backlog; /* force the frontend's listen backlog */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200251};
252
Willy Tarreau55ea7572007-06-17 19:56:27 +0200253struct switching_rule {
254 struct list list; /* list linked to from the proxy */
255 struct acl_cond *cond; /* acl condition to meet */
256 union {
257 struct proxy *backend; /* target backend */
258 char *name; /* target backend name during config parsing */
259 } be;
260};
261
Willy Tarreaub463dfb2008-06-07 23:08:56 +0200262struct redirect_rule {
263 struct list list; /* list linked to from the proxy */
264 struct acl_cond *cond; /* acl condition to meet */
265 int type;
266 int rdr_len;
267 char *rdr_str;
268 int code;
269};
270
Willy Tarreaubaaee002006-06-26 02:48:02 +0200271extern struct proxy *proxy;
Willy Tarreaudcd47712007-11-04 23:35:08 +0100272extern int next_pxid;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200273
274#endif /* _TYPES_PROXY_H */
275
276/*
277 * Local variables:
278 * c-indent-level: 8
279 * c-basic-offset: 8
280 * End:
281 */