blob: e4cf4ce664a4a3dc7dbb3ea8e30b8813452949dd [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 Tarreaua8cff1d2007-04-09 16:10:57 +02005 Copyright (C) 2000-2007 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 Tarreau2dd0d472006-06-29 17:53:05 +020032#include <common/mini-clist.h>
33#include <common/regex.h>
Willy Tarreau51041c72007-09-09 21:56:53 +020034#include <common/sessionhash.h>
Willy Tarreaua8cff1d2007-04-09 16:10:57 +020035#include <common/tools.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020036
Willy Tarreaueb0c6142007-05-07 00:53:22 +020037#include <types/acl.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020038#include <types/buffers.h>
Willy Tarreau0f772532006-12-23 20:51:41 +010039#include <types/httperr.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020040#include <types/session.h>
41#include <types/server.h>
42
43/* values for proxy->state */
44#define PR_STNEW 0
45#define PR_STIDLE 1
46#define PR_STRUN 2
47#define PR_STSTOPPED 3
48#define PR_STPAUSED 4
49#define PR_STERROR 5
50
51/* values for proxy->mode */
52#define PR_MODE_TCP 0
53#define PR_MODE_HTTP 1
54#define PR_MODE_HEALTH 2
55
Willy Tarreau5af3a692007-07-24 23:32:33 +020056/* values for proxy->map_state */
57#define PR_MAP_RECALC (1 << 0)
58
Willy Tarreau977b8e42006-12-29 14:19:17 +010059/* flag values for proxy->cap. This is a bitmask of capabilities supported by the proxy */
60#define PR_CAP_NONE 0x0000
61#define PR_CAP_FE 0x0001
62#define PR_CAP_BE 0x0002
63#define PR_CAP_RS 0x0004
64#define PR_CAP_LISTEN (PR_CAP_FE|PR_CAP_BE|PR_CAP_RS)
65
Willy Tarreaubaaee002006-06-26 02:48:02 +020066/* return codes for start_proxies */
67#define ERR_NONE 0 /* no error */
68#define ERR_RETRYABLE 1 /* retryable error, may be cumulated */
69#define ERR_FATAL 2 /* fatal error, may be cumulated */
70
71
72struct listener {
73 int fd; /* the listen socket */
74 struct sockaddr_storage addr; /* the address we listen to */
75 struct listener *next; /* next address or NULL */
76};
77
78struct proxy {
79 struct listener *listen; /* the listen addresses and sockets */
80 struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */
81 int state; /* proxy state */
Willy Tarreau35d66b02007-01-02 00:28:21 +010082 int options; /* PR_O_REDISP, PR_O_TRANSP, ... */
83 int mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */
Willy Tarreaubaaee002006-06-26 02:48:02 +020084 struct sockaddr_in dispatch_addr; /* the default address to connect to */
Willy Tarreau5fdfb912007-01-01 23:11:07 +010085 union {
86 struct proxy *be; /* default backend, or NULL if none set */
87 char *name; /* default backend name during config parse */
88 } defbe;
Willy Tarreaueb0c6142007-05-07 00:53:22 +020089 struct list acl; /* ACL declared on this proxy */
Willy Tarreau5c8e3e02007-05-07 00:58:25 +020090 struct list block_cond; /* early blocking conditions (chained) */
Willy Tarreau55ea7572007-06-17 19:56:27 +020091 struct list switching_rules; /* content switching rules (chained) */
Willy Tarreau5af3a692007-07-24 23:32:33 +020092 int map_state; /* PR_MAP_RECALC */
Willy Tarreaubaaee002006-06-26 02:48:02 +020093 struct server *srv; /* known servers */
Willy Tarreau1c47f852006-07-09 08:22:27 +020094 int srv_act, srv_bck; /* # of running servers */
95 int tot_wact, tot_wbck; /* total weights of active and backup servers */
Willy Tarreaubaaee002006-06-26 02:48:02 +020096 struct server **srv_map; /* the server map used to apply weights */
Willy Tarreau1c47f852006-07-09 08:22:27 +020097 int srv_map_sz; /* the size of the effective server map */
98 int srv_rr_idx; /* next server to be elected in round robin mode */
Willy Tarreaubaaee002006-06-26 02:48:02 +020099 char *cookie_name; /* name of the cookie to look for */
100 int cookie_len; /* strlen(cookie_name), computed only once */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200101 char *appsession_name; /* name of the cookie to look for */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200102 int appsession_name_len; /* strlen(appsession_name), computed only once */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200103 int appsession_len; /* length of the appsession cookie value to be used */
Willy Tarreau51041c72007-09-09 21:56:53 +0200104 struct appsession_hash htbl_proxy; /* Per Proxy hashtable */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105 char *capture_name; /* beginning of the name of the cookie to capture */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200106 int capture_namelen; /* length of the cookie name to match */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200107 int capture_len; /* length of the string to be captured */
108 struct uri_auth *uri_auth; /* if non-NULL, the (list of) per-URI authentications */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200109 char *monitor_uri; /* a special URI to which we respond with HTTP/200 OK */
110 int monitor_uri_len; /* length of the string above. 0 if unused */
Willy Tarreaud825eef2007-05-12 22:35:00 +0200111 struct timeval clitimeout; /* client I/O timeout (in milliseconds) */
112 struct timeval srvtimeout; /* server I/O timeout (in milliseconds) */
113 struct timeval contimeout; /* connect timeout (in milliseconds) */
114 struct timeval appsession_timeout;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200115 char *id; /* proxy id */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200116 struct list pendconns; /* pending connections with no server assigned yet */
117 int nbpend, nbpend_max; /* number of pending connections with no server assigned yet */
118 int totpend; /* total number of pending connections on this instance (for stats) */
Willy Tarreauf1221aa2006-12-17 22:14:12 +0100119 unsigned int feconn, feconn_max; /* # of active frontend sessions */
120 unsigned int beconn, beconn_max; /* # of active backend sessions */
121 unsigned int cum_feconn, cum_beconn; /* cumulated number of processed sessions */
Willy Tarreau86034312006-12-29 00:10:33 +0100122 unsigned int maxconn; /* max # of active sessions on the frontend */
123 unsigned int fullconn; /* #conns on backend above which servers are used at full load */
Willy Tarreau7ac51f62007-03-25 16:00:04 +0200124 struct in_addr except_net, except_mask; /* don't x-forward-for for this address. FIXME: should support IPv6 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200125 unsigned failed_conns, failed_resp; /* failed connect() and responses */
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100126 unsigned denied_req, denied_resp; /* blocked requests/responses because of security concerns */
127 unsigned failed_req; /* failed requests (eg: invalid or timeout) */
Willy Tarreau35d66b02007-01-02 00:28:21 +0100128 long long bytes_in; /* number of bytes transferred from the client to the server */
129 long long bytes_out; /* number of bytes transferred from the server to the client */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200130 int conn_retries; /* maximum number of connect retries */
Willy Tarreau977b8e42006-12-29 14:19:17 +0100131 int cap; /* supported capabilities (PR_CAP_*) */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200132 struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */
Willy Tarreau77074d52006-11-12 23:57:19 +0100133#ifdef CONFIG_HAP_CTTPROXY
134 struct sockaddr_in tproxy_addr; /* non-local address we want to bind to for connect() */
135#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +0200136 struct proxy *next;
Willy Tarreau1c47f852006-07-09 08:22:27 +0200137 struct sockaddr_in logsrv1, logsrv2; /* 2 syslog servers */
138 signed char logfac1, logfac2; /* log facility for both servers. -1 = disabled */
139 int loglev1, loglev2; /* log level for each server, 7 by default */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200140 int to_log; /* things to be logged (LW_*) */
141 struct timeval stop_time; /* date to stop listening, when stopping != 0 */
142 int nb_reqadd, nb_rspadd;
143 struct hdr_exp *req_exp; /* regular expressions for request headers */
144 struct hdr_exp *rsp_exp; /* regular expressions for response headers */
145 int nb_req_cap, nb_rsp_cap; /* # of headers to be captured */
146 struct cap_hdr *req_cap; /* chained list of request headers to be captured */
147 struct cap_hdr *rsp_cap; /* chained list of response headers to be captured */
Willy Tarreaucf7f3202007-05-13 22:46:04 +0200148 struct pool_head *req_cap_pool, /* pools of pre-allocated char ** used to build the sessions */
149 *rsp_cap_pool;
Willy Tarreau1d4154a2007-05-13 22:57:02 +0200150 struct pool_head *hdr_idx_pool; /* pools of pre-allocated int* used for headers indexing */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200151 char *req_add[MAX_NEWHDR], *rsp_add[MAX_NEWHDR]; /* headers to be added */
152 int grace; /* grace time after stop request */
Willy Tarreauf3c69202006-07-09 16:42:34 +0200153 char *check_req; /* HTTP or SSL request to use for PR_O_HTTP_CHK|PR_O_SSL3_CHK */
154 int check_len; /* Length of the HTTP or SSL3 request */
Willy Tarreau0f772532006-12-23 20:51:41 +0100155 struct chunk errmsg[HTTP_ERR_SIZE]; /* default or customized error messages for known errors */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200156};
157
Willy Tarreau55ea7572007-06-17 19:56:27 +0200158struct switching_rule {
159 struct list list; /* list linked to from the proxy */
160 struct acl_cond *cond; /* acl condition to meet */
161 union {
162 struct proxy *backend; /* target backend */
163 char *name; /* target backend name during config parsing */
164 } be;
165};
166
Willy Tarreaubaaee002006-06-26 02:48:02 +0200167extern struct proxy *proxy;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200168
169#endif /* _TYPES_PROXY_H */
170
171/*
172 * Local variables:
173 * c-indent-level: 8
174 * c-basic-offset: 8
175 * End:
176 */