blob: 71f0f5c2acdebae20fa26949ed76dfab917fbe69 [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
5 Copyright (C) 2000-2006 Willy Tarreau - w@1wt.eu
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 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>
31#include <common/chtbl.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020032#include <common/config.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020033#include <common/mini-clist.h>
34#include <common/regex.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020035
36#include <types/buffers.h>
Willy Tarreau0f772532006-12-23 20:51:41 +010037#include <types/httperr.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020038#include <types/session.h>
39#include <types/server.h>
40
41/* values for proxy->state */
42#define PR_STNEW 0
43#define PR_STIDLE 1
44#define PR_STRUN 2
45#define PR_STSTOPPED 3
46#define PR_STPAUSED 4
47#define PR_STERROR 5
48
49/* values for proxy->mode */
50#define PR_MODE_TCP 0
51#define PR_MODE_HTTP 1
52#define PR_MODE_HEALTH 2
53
Willy Tarreau977b8e42006-12-29 14:19:17 +010054/* flag values for proxy->cap. This is a bitmask of capabilities supported by the proxy */
55#define PR_CAP_NONE 0x0000
56#define PR_CAP_FE 0x0001
57#define PR_CAP_BE 0x0002
58#define PR_CAP_RS 0x0004
59#define PR_CAP_LISTEN (PR_CAP_FE|PR_CAP_BE|PR_CAP_RS)
60
Willy Tarreaubaaee002006-06-26 02:48:02 +020061/* return codes for start_proxies */
62#define ERR_NONE 0 /* no error */
63#define ERR_RETRYABLE 1 /* retryable error, may be cumulated */
64#define ERR_FATAL 2 /* fatal error, may be cumulated */
65
66
67struct listener {
68 int fd; /* the listen socket */
69 struct sockaddr_storage addr; /* the address we listen to */
70 struct listener *next; /* next address or NULL */
71};
72
73struct proxy {
74 struct listener *listen; /* the listen addresses and sockets */
75 struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */
76 int state; /* proxy state */
77 struct sockaddr_in dispatch_addr; /* the default address to connect to */
Willy Tarreau97a738f2006-12-17 18:02:30 +010078 struct proxy *fiprm, *beprm; /* proxy we find filter and backend params from (default: self) */
Willy Tarreau5fdfb912007-01-01 23:11:07 +010079 union {
80 struct proxy *be; /* default backend, or NULL if none set */
81 char *name; /* default backend name during config parse */
82 } defbe;
Willy Tarreaubaaee002006-06-26 02:48:02 +020083 struct server *srv; /* known servers */
Willy Tarreau1c47f852006-07-09 08:22:27 +020084 int srv_act, srv_bck; /* # of running servers */
85 int tot_wact, tot_wbck; /* total weights of active and backup servers */
Willy Tarreaubaaee002006-06-26 02:48:02 +020086 struct server **srv_map; /* the server map used to apply weights */
Willy Tarreau1c47f852006-07-09 08:22:27 +020087 int srv_map_sz; /* the size of the effective server map */
88 int srv_rr_idx; /* next server to be elected in round robin mode */
Willy Tarreaubaaee002006-06-26 02:48:02 +020089 char *cookie_name; /* name of the cookie to look for */
90 int cookie_len; /* strlen(cookie_name), computed only once */
Willy Tarreau1c47f852006-07-09 08:22:27 +020091 char *appsession_name; /* name of the cookie to look for */
Willy Tarreaubaaee002006-06-26 02:48:02 +020092 int appsession_name_len; /* strlen(appsession_name), computed only once */
Willy Tarreau1c47f852006-07-09 08:22:27 +020093 int appsession_len; /* length of the appsession cookie value to be used */
Willy Tarreaubaaee002006-06-26 02:48:02 +020094 int appsession_timeout;
95 CHTbl htbl_proxy; /* Per Proxy hashtable */
96 char *capture_name; /* beginning of the name of the cookie to capture */
Willy Tarreau1c47f852006-07-09 08:22:27 +020097 int capture_namelen; /* length of the cookie name to match */
Willy Tarreaubaaee002006-06-26 02:48:02 +020098 int capture_len; /* length of the string to be captured */
99 struct uri_auth *uri_auth; /* if non-NULL, the (list of) per-URI authentications */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200100 char *monitor_uri; /* a special URI to which we respond with HTTP/200 OK */
101 int monitor_uri_len; /* length of the string above. 0 if unused */
102 int clitimeout; /* client I/O timeout (in milliseconds) */
103 int srvtimeout; /* server I/O timeout (in milliseconds) */
104 int contimeout; /* connect timeout (in milliseconds) */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105 char *id; /* proxy id */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200106 struct list pendconns; /* pending connections with no server assigned yet */
107 int nbpend, nbpend_max; /* number of pending connections with no server assigned yet */
108 int totpend; /* total number of pending connections on this instance (for stats) */
Willy Tarreauf1221aa2006-12-17 22:14:12 +0100109 unsigned int feconn, feconn_max; /* # of active frontend sessions */
110 unsigned int beconn, beconn_max; /* # of active backend sessions */
111 unsigned int cum_feconn, cum_beconn; /* cumulated number of processed sessions */
Willy Tarreau86034312006-12-29 00:10:33 +0100112 unsigned int maxconn; /* max # of active sessions on the frontend */
113 unsigned int fullconn; /* #conns on backend above which servers are used at full load */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200114 unsigned failed_conns, failed_resp; /* failed connect() and responses */
Willy Tarreauc0dde7a2007-01-01 21:38:07 +0100115 unsigned denied_req, denied_resp; /* blocked requests/responses because of security concerns */
116 unsigned failed_req; /* failed requests (eg: invalid or timeout) */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200117 int conn_retries; /* maximum number of connect retries */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200118 int options; /* PR_O_REDISP, PR_O_TRANSP, ... */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200119 int mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */
Willy Tarreau977b8e42006-12-29 14:19:17 +0100120 int cap; /* supported capabilities (PR_CAP_*) */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200121 struct sockaddr_in source_addr; /* the address to which we want to bind for connect() */
Willy Tarreau77074d52006-11-12 23:57:19 +0100122#ifdef CONFIG_HAP_CTTPROXY
123 struct sockaddr_in tproxy_addr; /* non-local address we want to bind to for connect() */
124#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +0200125 struct proxy *next;
Willy Tarreau1c47f852006-07-09 08:22:27 +0200126 struct sockaddr_in logsrv1, logsrv2; /* 2 syslog servers */
127 signed char logfac1, logfac2; /* log facility for both servers. -1 = disabled */
128 int loglev1, loglev2; /* log level for each server, 7 by default */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200129 int to_log; /* things to be logged (LW_*) */
130 struct timeval stop_time; /* date to stop listening, when stopping != 0 */
131 int nb_reqadd, nb_rspadd;
132 struct hdr_exp *req_exp; /* regular expressions for request headers */
133 struct hdr_exp *rsp_exp; /* regular expressions for response headers */
134 int nb_req_cap, nb_rsp_cap; /* # of headers to be captured */
135 struct cap_hdr *req_cap; /* chained list of request headers to be captured */
136 struct cap_hdr *rsp_cap; /* chained list of response headers to be captured */
137 void *req_cap_pool, *rsp_cap_pool; /* pools of pre-allocated char ** used to build the sessions */
Willy Tarreaue5f20dc2006-12-03 15:21:35 +0100138 void *hdr_idx_pool; /* pools of pre-allocated int* used for headers indexing */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200139 char *req_add[MAX_NEWHDR], *rsp_add[MAX_NEWHDR]; /* headers to be added */
140 int grace; /* grace time after stop request */
Willy Tarreauf3c69202006-07-09 16:42:34 +0200141 char *check_req; /* HTTP or SSL request to use for PR_O_HTTP_CHK|PR_O_SSL3_CHK */
142 int check_len; /* Length of the HTTP or SSL3 request */
Willy Tarreau0f772532006-12-23 20:51:41 +0100143 struct chunk errmsg[HTTP_ERR_SIZE]; /* default or customized error messages for known errors */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200144};
145
146extern struct proxy *proxy;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200147
148#endif /* _TYPES_PROXY_H */
149
150/*
151 * Local variables:
152 * c-indent-level: 8
153 * c-basic-offset: 8
154 * End:
155 */