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> |
| 31 | #include <common/chtbl.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 32 | #include <common/config.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 | a8cff1d | 2007-04-09 16:10:57 +0200 | [diff] [blame] | 35 | #include <common/tools.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 36 | |
| 37 | #include <types/buffers.h> |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 38 | #include <types/httperr.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 39 | #include <types/session.h> |
| 40 | #include <types/server.h> |
| 41 | |
| 42 | /* values for proxy->state */ |
| 43 | #define PR_STNEW 0 |
| 44 | #define PR_STIDLE 1 |
| 45 | #define PR_STRUN 2 |
| 46 | #define PR_STSTOPPED 3 |
| 47 | #define PR_STPAUSED 4 |
| 48 | #define PR_STERROR 5 |
| 49 | |
| 50 | /* values for proxy->mode */ |
| 51 | #define PR_MODE_TCP 0 |
| 52 | #define PR_MODE_HTTP 1 |
| 53 | #define PR_MODE_HEALTH 2 |
| 54 | |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 55 | /* flag values for proxy->cap. This is a bitmask of capabilities supported by the proxy */ |
| 56 | #define PR_CAP_NONE 0x0000 |
| 57 | #define PR_CAP_FE 0x0001 |
| 58 | #define PR_CAP_BE 0x0002 |
| 59 | #define PR_CAP_RS 0x0004 |
| 60 | #define PR_CAP_LISTEN (PR_CAP_FE|PR_CAP_BE|PR_CAP_RS) |
| 61 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 62 | /* return codes for start_proxies */ |
| 63 | #define ERR_NONE 0 /* no error */ |
| 64 | #define ERR_RETRYABLE 1 /* retryable error, may be cumulated */ |
| 65 | #define ERR_FATAL 2 /* fatal error, may be cumulated */ |
| 66 | |
| 67 | |
| 68 | struct listener { |
| 69 | int fd; /* the listen socket */ |
| 70 | struct sockaddr_storage addr; /* the address we listen to */ |
| 71 | struct listener *next; /* next address or NULL */ |
| 72 | }; |
| 73 | |
| 74 | struct proxy { |
| 75 | struct listener *listen; /* the listen addresses and sockets */ |
| 76 | struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */ |
| 77 | int state; /* proxy state */ |
Willy Tarreau | 35d66b0 | 2007-01-02 00:28:21 +0100 | [diff] [blame] | 78 | int options; /* PR_O_REDISP, PR_O_TRANSP, ... */ |
| 79 | 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] | 80 | struct sockaddr_in dispatch_addr; /* the default address to connect to */ |
Willy Tarreau | 5fdfb91 | 2007-01-01 23:11:07 +0100 | [diff] [blame] | 81 | union { |
| 82 | struct proxy *be; /* default backend, or NULL if none set */ |
| 83 | char *name; /* default backend name during config parse */ |
| 84 | } defbe; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 85 | struct server *srv; /* known servers */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 86 | int srv_act, srv_bck; /* # of running servers */ |
| 87 | int tot_wact, tot_wbck; /* total weights of active and backup servers */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 88 | struct server **srv_map; /* the server map used to apply weights */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 89 | int srv_map_sz; /* the size of the effective server map */ |
| 90 | int srv_rr_idx; /* next server to be elected in round robin mode */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 91 | char *cookie_name; /* name of the cookie to look for */ |
| 92 | int cookie_len; /* strlen(cookie_name), computed only once */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 93 | char *appsession_name; /* name of the cookie to look for */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 94 | int appsession_name_len; /* strlen(appsession_name), computed only once */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 95 | int appsession_len; /* length of the appsession cookie value to be used */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 96 | int appsession_timeout; |
| 97 | CHTbl htbl_proxy; /* Per Proxy hashtable */ |
| 98 | char *capture_name; /* beginning of the name of the cookie to capture */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 99 | int capture_namelen; /* length of the cookie name to match */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 100 | int capture_len; /* length of the string to be captured */ |
| 101 | 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] | 102 | char *monitor_uri; /* a special URI to which we respond with HTTP/200 OK */ |
| 103 | int monitor_uri_len; /* length of the string above. 0 if unused */ |
| 104 | int clitimeout; /* client I/O timeout (in milliseconds) */ |
| 105 | int srvtimeout; /* server I/O timeout (in milliseconds) */ |
| 106 | int contimeout; /* connect timeout (in milliseconds) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 107 | char *id; /* proxy id */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 108 | struct list pendconns; /* pending connections with no server assigned yet */ |
| 109 | int nbpend, nbpend_max; /* number of pending connections with no server assigned yet */ |
| 110 | int totpend; /* total number of pending connections on this instance (for stats) */ |
Willy Tarreau | f1221aa | 2006-12-17 22:14:12 +0100 | [diff] [blame] | 111 | unsigned int feconn, feconn_max; /* # of active frontend sessions */ |
| 112 | unsigned int beconn, beconn_max; /* # of active backend sessions */ |
| 113 | unsigned int cum_feconn, cum_beconn; /* cumulated number of processed sessions */ |
Willy Tarreau | 8603431 | 2006-12-29 00:10:33 +0100 | [diff] [blame] | 114 | unsigned int maxconn; /* max # of active sessions on the frontend */ |
| 115 | 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] | 116 | struct in_addr except_net, except_mask; /* don't x-forward-for for this address. FIXME: should support IPv6 */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 117 | unsigned failed_conns, failed_resp; /* failed connect() and responses */ |
Willy Tarreau | c0dde7a | 2007-01-01 21:38:07 +0100 | [diff] [blame] | 118 | unsigned denied_req, denied_resp; /* blocked requests/responses because of security concerns */ |
| 119 | unsigned failed_req; /* failed requests (eg: invalid or timeout) */ |
Willy Tarreau | 35d66b0 | 2007-01-02 00:28:21 +0100 | [diff] [blame] | 120 | long long bytes_in; /* number of bytes transferred from the client to the server */ |
| 121 | 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] | 122 | int conn_retries; /* maximum number of connect retries */ |
Willy Tarreau | 977b8e4 | 2006-12-29 14:19:17 +0100 | [diff] [blame] | 123 | int cap; /* supported capabilities (PR_CAP_*) */ |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 124 | 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] | 125 | #ifdef CONFIG_HAP_CTTPROXY |
| 126 | struct sockaddr_in tproxy_addr; /* non-local address we want to bind to for connect() */ |
| 127 | #endif |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 128 | struct proxy *next; |
Willy Tarreau | 1c47f85 | 2006-07-09 08:22:27 +0200 | [diff] [blame] | 129 | struct sockaddr_in logsrv1, logsrv2; /* 2 syslog servers */ |
| 130 | signed char logfac1, logfac2; /* log facility for both servers. -1 = disabled */ |
| 131 | int loglev1, loglev2; /* log level for each server, 7 by default */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 132 | int to_log; /* things to be logged (LW_*) */ |
| 133 | struct timeval stop_time; /* date to stop listening, when stopping != 0 */ |
| 134 | int nb_reqadd, nb_rspadd; |
| 135 | struct hdr_exp *req_exp; /* regular expressions for request headers */ |
| 136 | struct hdr_exp *rsp_exp; /* regular expressions for response headers */ |
| 137 | int nb_req_cap, nb_rsp_cap; /* # of headers to be captured */ |
| 138 | struct cap_hdr *req_cap; /* chained list of request headers to be captured */ |
| 139 | struct cap_hdr *rsp_cap; /* chained list of response headers to be captured */ |
| 140 | void *req_cap_pool, *rsp_cap_pool; /* pools of pre-allocated char ** used to build the sessions */ |
Willy Tarreau | e5f20dc | 2006-12-03 15:21:35 +0100 | [diff] [blame] | 141 | void *hdr_idx_pool; /* pools of pre-allocated int* used for headers indexing */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 142 | char *req_add[MAX_NEWHDR], *rsp_add[MAX_NEWHDR]; /* headers to be added */ |
| 143 | int grace; /* grace time after stop request */ |
Willy Tarreau | f3c6920 | 2006-07-09 16:42:34 +0200 | [diff] [blame] | 144 | char *check_req; /* HTTP or SSL request to use for PR_O_HTTP_CHK|PR_O_SSL3_CHK */ |
| 145 | int check_len; /* Length of the HTTP or SSL3 request */ |
Willy Tarreau | 0f77253 | 2006-12-23 20:51:41 +0100 | [diff] [blame] | 146 | struct chunk errmsg[HTTP_ERR_SIZE]; /* default or customized error messages for known errors */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | extern struct proxy *proxy; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 150 | |
| 151 | #endif /* _TYPES_PROXY_H */ |
| 152 | |
| 153 | /* |
| 154 | * Local variables: |
| 155 | * c-indent-level: 8 |
| 156 | * c-basic-offset: 8 |
| 157 | * End: |
| 158 | */ |