blob: b7c9038d6e3d37877e937496602b5e87c1b1a6d6 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau5b4c2b52009-10-03 11:21:53 +02002 * include/types/proxy.h
3 * This file defines everything related to proxies.
4 *
Willy Tarreauff011f22011-01-06 17:51:27 +01005 * Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu
Willy Tarreau5b4c2b52009-10-03 11:21:53 +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 */
Willy Tarreaubaaee002006-06-26 02:48:02 +020021
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 Tarreauc7e42382012-08-24 19:22:53 +020030#include <common/chunk.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020031#include <common/config.h>
Willy Tarreau35b51c62018-09-10 15:38:55 +020032#include <common/http.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020033#include <common/mini-clist.h>
34#include <common/regex.h>
Willy Tarreaua8cff1d2007-04-09 16:10:57 +020035#include <common/tools.h>
Christopher Fauletff8abcd2017-06-02 15:33:24 +020036#include <common/hathreads.h>
37
Willy Tarreau45cb4fb2009-10-26 21:10:04 +010038#include <eb32tree.h>
Willy Tarreauf79d9502014-03-15 07:22:35 +010039#include <ebistree.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020040
Willy Tarreaueb0c6142007-05-07 00:53:22 +020041#include <types/acl.h>
Willy Tarreau5b4c2b52009-10-03 11:21:53 +020042#include <types/backend.h>
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +020043#include <types/counters.h>
Christopher Fauletd7c91962015-04-30 11:48:27 +020044#include <types/filters.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010045#include <types/freq_ctr.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020046#include <types/listener.h>
Robert Tsai81ae1952007-12-05 10:47:29 +010047#include <types/log.h>
Willy Tarreau3fdb3662012-11-12 00:42:33 +010048#include <types/obj_type.h>
Willy Tarreaucd3b0942012-04-27 21:52:18 +020049#include <types/sample.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020050#include <types/server.h>
Emeric Brunb982a3d2010-01-04 15:45:53 +010051#include <types/stick_table.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020052
53/* values for proxy->state */
Willy Tarreau8379c172013-12-06 21:29:13 +010054enum pr_state {
Willy Tarreau562515c2011-07-25 08:11:52 +020055 PR_STNEW = 0, /* proxy has not been initialized yet */
56 PR_STREADY, /* proxy has been initialized and is ready */
57 PR_STFULL, /* frontend is full (maxconn reached) */
58 PR_STPAUSED, /* frontend is paused (during hot restart) */
59 PR_STSTOPPED, /* proxy is stopped (end of a restart) */
60 PR_STERROR, /* proxy experienced an unrecoverable error */
Willy Tarreau8379c172013-12-06 21:29:13 +010061} __attribute__((packed));
Willy Tarreaubaaee002006-06-26 02:48:02 +020062
63/* values for proxy->mode */
Willy Tarreau8379c172013-12-06 21:29:13 +010064enum pr_mode {
65 PR_MODE_TCP = 0,
66 PR_MODE_HTTP,
67 PR_MODE_HEALTH,
William Lallemandcf62f7e2018-10-26 14:47:40 +020068 PR_MODE_CLI,
Willy Tarreau8379c172013-12-06 21:29:13 +010069} __attribute__((packed));
Willy Tarreaubaaee002006-06-26 02:48:02 +020070
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +020071enum PR_SRV_STATE_FILE {
72 PR_SRV_STATE_FILE_UNSPEC = 0,
73 PR_SRV_STATE_FILE_NONE,
74 PR_SRV_STATE_FILE_GLOBAL,
75 PR_SRV_STATE_FILE_LOCAL,
76};
77
78
Willy Tarreau977b8e42006-12-29 14:19:17 +010079/* flag values for proxy->cap. This is a bitmask of capabilities supported by the proxy */
80#define PR_CAP_NONE 0x0000
81#define PR_CAP_FE 0x0001
82#define PR_CAP_BE 0x0002
Christopher Faulet898566e2016-10-26 11:06:28 +020083#define PR_CAP_LISTEN (PR_CAP_FE|PR_CAP_BE)
Willy Tarreau977b8e42006-12-29 14:19:17 +010084
Willy Tarreau31682232007-11-29 15:38:04 +010085/* bits for proxy->options */
86#define PR_O_REDISP 0x00000001 /* allow reconnection to dispatch in case of errors */
87#define PR_O_TRANSP 0x00000002 /* transparent mode : use original DEST as dispatch */
Willy Tarreaud8fecee2015-08-05 14:12:31 +020088
89/* HTTP server-side reuse */
90#define PR_O_REUSE_NEVR 0x00000000 /* never reuse a shared connection */
91#define PR_O_REUSE_SAFE 0x00000004 /* only reuse a shared connection when it's safe to do so */
92#define PR_O_REUSE_AGGR 0x00000008 /* aggressively reuse a shared connection */
93#define PR_O_REUSE_ALWS 0x0000000C /* always reuse a shared connection */
94#define PR_O_REUSE_MASK 0x0000000C /* mask to retrieve shared connection preferences */
95
96/* unused: 0x10 */
Willy Tarreau9420b122013-12-15 18:58:25 +010097#define PR_O_PREF_LAST 0x00000020 /* prefer last server */
Willy Tarreau1620ec32011-08-06 17:05:02 +020098#define PR_O_DISPATCH 0x00000040 /* use dispatch mode */
Willy Tarreau0d1fdf72015-05-27 16:44:02 +020099#define PR_O_FORCED_ID 0x00000080 /* proxy's ID was forced in the configuration */
Willy Tarreau87cf5142011-08-19 22:57:24 +0200100#define PR_O_FWDFOR 0x00000100 /* conditionally insert x-forwarded-for with client address */
Willy Tarreau0f228a02015-05-01 15:37:53 +0200101#define PR_O_IGNORE_PRB 0x00000200 /* ignore empty requests (aborts and timeouts) */
Willy Tarreau31682232007-11-29 15:38:04 +0100102#define PR_O_NULLNOLOG 0x00000400 /* a connect without request will not be logged */
Willy Tarreau9fbe18e2015-05-01 22:42:08 +0200103#define PR_O_WREQ_BODY 0x00000800 /* always wait for the HTTP request body */
104/* unused: 0x1000 */
Willy Tarreau87cf5142011-08-19 22:57:24 +0200105#define PR_O_FF_ALWAYS 0x00002000 /* always set x-forwarded-for */
Willy Tarreau31682232007-11-29 15:38:04 +0100106#define PR_O_PERSIST 0x00004000 /* server persistence stays effective even when server is down */
Willy Tarreau87b09662015-04-03 00:22:06 +0200107#define PR_O_LOGASAP 0x00008000 /* log as soon as possible, without waiting for the stream to complete */
Willy Tarreau02bce8b2014-01-30 00:15:28 +0100108/* unused: 0x00010000 */
Willy Tarreau31682232007-11-29 15:38:04 +0100109#define PR_O_CHK_CACHE 0x00020000 /* require examination of cacheability of the 'set-cookie' field */
Willy Tarreau87b09662015-04-03 00:22:06 +0200110#define PR_O_TCP_CLI_KA 0x00040000 /* enable TCP keep-alive on client-side streams */
111#define PR_O_TCP_SRV_KA 0x00080000 /* enable TCP keep-alive on server-side streams */
Willy Tarreau31682232007-11-29 15:38:04 +0100112#define PR_O_USE_ALL_BK 0x00100000 /* load-balance between backup servers */
Willy Tarreau02bce8b2014-01-30 00:15:28 +0100113/* unused: 0x00020000 */
Willy Tarreau31682232007-11-29 15:38:04 +0100114#define PR_O_TCP_NOLING 0x00400000 /* disable lingering on client and server connections */
115#define PR_O_ABRT_CLOSE 0x00800000 /* immediately abort request when client closes */
Willy Tarreau31682232007-11-29 15:38:04 +0100116
Willy Tarreau70dffda2014-01-30 03:07:23 +0100117#define PR_O_HTTP_KAL 0x00000000 /* HTTP keep-alive mode (http-keep-alive) */
Christopher Faulet315b39c2018-09-21 16:26:19 +0200118#define PR_O_HTTP_CLO 0x01000000 /* HTTP close mode (httpclose) */
119#define PR_O_HTTP_SCL 0x02000000 /* HTTP server close mode (http-server-close) */
Willy Tarreau70dffda2014-01-30 03:07:23 +0100120#define PR_O_HTTP_TUN 0x04000000 /* HTTP tunnel mode : no analysis past first request/response */
Willy Tarreau02bce8b2014-01-30 00:15:28 +0100121#define PR_O_HTTP_MODE 0x07000000 /* MASK to retrieve the HTTP mode */
Christopher Faulet315b39c2018-09-21 16:26:19 +0200122
Baptiste Assmann69e273f2013-12-11 00:52:19 +0100123#define PR_O_TCPCHK_SSL 0x08000000 /* at least one TCPCHECK connect rule requires SSL */
Willy Tarreau31682232007-11-29 15:38:04 +0100124#define PR_O_CONTSTATS 0x10000000 /* continous counters */
Willy Tarreau87b09662015-04-03 00:22:06 +0200125#define PR_O_HTTP_PROXY 0x20000000 /* Enable stream to use HTTP proxy operations */
Willy Tarreau48494c02007-11-30 10:41:39 +0100126#define PR_O_DISABLE404 0x40000000 /* Disable a server on a 404 response to a health-check */
Maik Broemme2850cb42009-04-17 18:53:21 +0200127#define PR_O_ORGTO 0x80000000 /* insert x-original-to with destination address */
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100128
129/* bits for proxy->options2 */
130#define PR_O2_SPLIC_REQ 0x00000001 /* transfer requests using linux kernel's splice() */
131#define PR_O2_SPLIC_RTR 0x00000002 /* transfer responses using linux kernel's splice() */
132#define PR_O2_SPLIC_AUT 0x00000004 /* automatically use linux kernel's splice() */
133#define PR_O2_SPLIC_ANY (PR_O2_SPLIC_REQ|PR_O2_SPLIC_RTR|PR_O2_SPLIC_AUT)
Willy Tarreau32a4ec02009-04-02 11:35:18 +0200134#define PR_O2_REQBUG_OK 0x00000008 /* let buggy requests pass through */
135#define PR_O2_RSPBUG_OK 0x00000010 /* let buggy responses pass through */
Willy Tarreauc9bd0cc2009-05-10 11:57:02 +0200136#define PR_O2_NOLOGNORM 0x00000020 /* don't log normal traffic, only errors and retries */
137#define PR_O2_LOGERRORS 0x00000040 /* log errors and retries at level LOG_ERR */
Willy Tarreau9ea05a72009-06-14 12:07:01 +0200138#define PR_O2_SMARTACC 0x00000080 /* don't immediately ACK request after accept */
Willy Tarreaud88edf22009-06-14 15:48:17 +0200139#define PR_O2_SMARTCON 0x00000100 /* don't immediately send empty ACK after connect */
Emeric Brun647caf12009-06-30 17:57:00 +0200140#define PR_O2_RDPC_PRST 0x00000200 /* Actvate rdp cookie analyser */
Emeric Brun3a058f32009-06-30 18:26:00 +0200141#define PR_O2_CLFLOG 0x00000400 /* log into clf format */
Krzysztof Piotr Oledzki213014e2009-09-27 15:50:02 +0200142#define PR_O2_LOGHCHKS 0x00000800 /* log health checks */
Jamie Gloudon801a0a32012-08-25 00:18:33 -0400143#define PR_O2_INDEPSTR 0x00001000 /* independent streams, don't update rex on write */
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200144#define PR_O2_SOCKSTAT 0x00002000 /* collect & provide separate statistics for sockets */
Cyril Bontéb21570a2009-11-29 20:04:48 +0100145
Willy Tarreau3580b032015-08-10 19:15:14 +0200146/* unused: 0x00004000 0x00008000 0x00010000 */
Cyril Bontéb21570a2009-11-29 20:04:48 +0100147
Willy Tarreau1620ec32011-08-06 17:05:02 +0200148#define PR_O2_NODELAY 0x00020000 /* fully interactive mode, never delay outgoing data */
Willy Tarreau88d349d2010-01-25 12:15:43 +0100149#define PR_O2_USE_PXHDR 0x00040000 /* use Proxy-Connection for proxy requests */
Willy Tarreauef781042010-01-27 11:53:01 +0100150#define PR_O2_CHK_SNDST 0x00080000 /* send the state of each server along with HTTP health checks */
William Lallemandb7ff6a32012-03-02 14:35:21 +0100151
152#define PR_O2_SRC_ADDR 0x00100000 /* get the source ip and port for logs */
153
Willy Tarreau8a8e1d92010-04-05 16:15:16 +0200154#define PR_O2_FAKE_KA 0x00200000 /* pretend we do keep-alive with server eventhough we close */
Willy Tarreau68ad3a42018-10-22 11:49:15 +0200155#define PR_O2_USE_HTX 0x00400000 /* use the HTX representation for the HTTP protocol */
Willy Tarreaubd741542010-03-16 18:46:54 +0100156#define PR_O2_EXP_NONE 0x00000000 /* http-check : no expect rule */
157#define PR_O2_EXP_STS 0x00800000 /* http-check expect status */
158#define PR_O2_EXP_RSTS 0x01000000 /* http-check expect rstatus */
159#define PR_O2_EXP_STR 0x01800000 /* http-check expect string */
160#define PR_O2_EXP_RSTR 0x02000000 /* http-check expect rstring */
161#define PR_O2_EXP_TYPE 0x03800000 /* mask for http-check expect type */
162#define PR_O2_EXP_INV 0x04000000 /* http-check expect !<rule> */
Willy Tarreau67402132012-05-31 20:40:20 +0200163/* unused: 0x08000000 */
Rauf Kuliyev38b41562011-01-04 15:14:13 +0100164
Willy Tarreau1620ec32011-08-06 17:05:02 +0200165/* server health checks */
166#define PR_O2_CHK_NONE 0x00000000 /* no L7 health checks configured (TCP by default) */
Rauf Kuliyev38b41562011-01-04 15:14:13 +0100167#define PR_O2_PGSQL_CHK 0x10000000 /* use PGSQL check for server health */
Willy Tarreau1620ec32011-08-06 17:05:02 +0200168#define PR_O2_REDIS_CHK 0x20000000 /* use LDAP check for server health */
169#define PR_O2_SMTP_CHK 0x30000000 /* use SMTP EHLO check for server health - pvandijk@vision6.com.au */
170#define PR_O2_HTTP_CHK 0x40000000 /* use HTTP 'OPTIONS' method to check server health */
171#define PR_O2_MYSQL_CHK 0x50000000 /* use MYSQL check for server health */
172#define PR_O2_LDAP_CHK 0x60000000 /* use LDAP check for server health */
173#define PR_O2_SSL3_CHK 0x70000000 /* use SSLv3 CLIENT_HELLO packets for server health */
Simon Hormana2b9dad2013-02-12 10:45:54 +0900174#define PR_O2_LB_AGENT_CHK 0x80000000 /* use a TCP connection to obtain a metric of server health */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200175#define PR_O2_TCPCHK_CHK 0x90000000 /* use TCPCHK check for server health */
Simon Horman98637e52014-06-20 12:30:16 +0900176#define PR_O2_EXT_CHK 0xA0000000 /* use external command for server health */
Christopher Fauletba7bc162016-11-07 21:07:38 +0100177#define PR_O2_SPOP_CHK 0xB0000000 /* use SPOP for server health */
178/* unused: 0xC0000000 to 0xF000000, reserved for health checks */
Willy Tarreau1620ec32011-08-06 17:05:02 +0200179#define PR_O2_CHK_ANY 0xF0000000 /* Mask to cover any check */
Emeric Brunb982a3d2010-01-04 15:45:53 +0100180/* end of proxy->options2 */
181
Willy Tarreau67402132012-05-31 20:40:20 +0200182/* Cookie settings for pr->ck_opts */
Willy Tarreaub5ba17e2012-05-31 20:43:11 +0200183#define PR_CK_RW 0x00000001 /* rewrite all direct cookies with the right serverid */
184#define PR_CK_IND 0x00000002 /* keep only indirect cookies */
185#define PR_CK_INS 0x00000004 /* insert cookies when not accessing a server directly */
186#define PR_CK_PFX 0x00000008 /* rewrite all cookies by prefixing the right serverid */
187#define PR_CK_ANY (PR_CK_RW | PR_CK_IND | PR_CK_INS | PR_CK_PFX)
188#define PR_CK_NOC 0x00000010 /* add a 'Cache-control' header with the cookie */
189#define PR_CK_POST 0x00000020 /* don't insert cookies for requests other than a POST */
190#define PR_CK_PSV 0x00000040 /* cookie ... preserve */
Willy Tarreau4992dd22012-05-31 21:02:17 +0200191#define PR_CK_HTTPONLY 0x00000080 /* emit the "HttpOnly" attribute */
192#define PR_CK_SECURE 0x00000100 /* emit the "Secure" attribute */
Olivier Houchard4e694042017-03-14 20:01:29 +0100193#define PR_CK_DYNAMIC 0x00000200 /* create dynamic cookies for each server */
Willy Tarreau67402132012-05-31 20:40:20 +0200194
Emeric Brunb982a3d2010-01-04 15:45:53 +0100195/* bits for sticking rules */
196#define STK_IS_MATCH 0x00000001 /* match on request fetch */
197#define STK_IS_STORE 0x00000002 /* store on request fetch */
198#define STK_ON_RSP 0x00000004 /* store on response fetch */
Hervé COMMOWICK698ae002010-01-12 09:25:13 +0100199
Baptiste Assmann8a027cc2015-07-03 11:03:33 +0200200/* diff bits for proxy_find_best_match */
201#define PR_FBM_MISMATCH_ID 0x01
202#define PR_FBM_MISMATCH_NAME 0x02
203#define PR_FBM_MISMATCH_PROXYTYPE 0x04
204
Willy Tarreau87b09662015-04-03 00:22:06 +0200205struct stream;
Thierry FOURNIERac836ba2014-12-16 15:41:18 +0100206
Willy Tarreau7480f322018-09-06 19:41:22 +0200207struct http_snapshot {
Willy Tarreau87b09662015-04-03 00:22:06 +0200208 unsigned int sid; /* ID of the faulty stream */
Willy Tarreau078272e2010-12-12 12:46:33 +0100209 unsigned int state; /* message state before the error (when saved) */
Willy Tarreaud04b1bc2012-05-08 11:03:10 +0200210 unsigned int b_flags; /* buffer flags */
Willy Tarreau87b09662015-04-03 00:22:06 +0200211 unsigned int s_flags; /* stream flags */
Willy Tarreau7480f322018-09-06 19:41:22 +0200212
Willy Tarreaud04b1bc2012-05-08 11:03:10 +0200213 unsigned int t_flags; /* transaction flags */
214 unsigned int m_flags; /* message flags */
Willy Tarreaud04b1bc2012-05-08 11:03:10 +0200215 unsigned long long m_clen; /* chunk len for this message */
216 unsigned long long m_blen; /* body len for this message */
Willy Tarreau7480f322018-09-06 19:41:22 +0200217};
218
219union error_snapshot_ctx {
220 struct http_snapshot http;
221};
222
223struct error_snapshot {
224 /**** common part ****/
225 struct timeval when; /* date of this event, (tv_sec == 0) means "never" */
226 /* @16 */
Willy Tarreau4bc7d902018-09-07 20:07:17 +0200227 void (*show)(struct buffer *, const struct error_snapshot *); /* dump function */
Willy Tarreau7480f322018-09-06 19:41:22 +0200228 unsigned long long buf_ofs; /* relative position of the buffer's input inside its container */
229 /* @32 */
230 unsigned int buf_out; /* pending output bytes _before_ the buffer's input (0..buf->data-1) */
231 unsigned int buf_len; /* original length of the last invalid request/response (0..buf->data-1-buf_out) */
232 unsigned int buf_err; /* buffer-relative position where the error was detected (0..len-1) */
233 unsigned int buf_wrap; /* buffer-relative position where the buffer is expected to wrap (1..buf_size) */
234 /* @48 */
235 struct proxy *oe; /* other end = frontend or backend involved */
236 struct server *srv; /* server associated with the error (or NULL) */
237 /* @64 */
238 unsigned int ev_id; /* event number (counter incremented for each capture) */
239 /* @68: 4 bytes hole here */
240 struct sockaddr_storage src; /* client's address */
241
242 /**** protocol-specific part ****/
243 union error_snapshot_ctx ctx;
Willy Tarreau4bc7d902018-09-07 20:07:17 +0200244 char buf[0]; /* copy of the beginning of the message for bufsize bytes */
Willy Tarreauf073a832009-03-01 23:21:47 +0100245};
246
Simon Horman0ba0e4a2015-01-30 11:23:00 +0900247struct email_alert {
248 struct list list;
249 struct list tcpcheck_rules;
Christopher Faulet0108bb32017-10-20 21:34:32 +0200250 struct server *srv;
Simon Horman0ba0e4a2015-01-30 11:23:00 +0900251};
252
253struct email_alertq {
254 struct list email_alerts;
255 struct check check; /* Email alerts are implemented using existing check
256 * code even though they are not checks. This structure
257 * is as a parameter to the check code.
258 * Each check corresponds to a mailer */
Christopher Faulet9dcf9b62017-11-13 10:34:01 +0100259 __decl_hathreads(HA_SPINLOCK_T lock);
Simon Horman0ba0e4a2015-01-30 11:23:00 +0900260};
261
Willy Tarreaubaaee002006-06-26 02:48:02 +0200262struct proxy {
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100263 enum obj_type obj_type; /* object type == OBJ_TYPE_PROXY */
Willy Tarreau8379c172013-12-06 21:29:13 +0100264 enum pr_state state; /* proxy state, one of PR_* */
265 enum pr_mode mode; /* mode = PR_MODE_TCP, PR_MODE_HTTP or PR_MODE_HEALTH */
266 char cap; /* supported capabilities (PR_CAP_*) */
Willy Tarreau87b09662015-04-03 00:22:06 +0200267 unsigned int maxconn; /* max # of active streams on the frontend */
Willy Tarreau8379c172013-12-06 21:29:13 +0100268
Willy Tarreau35d66b02007-01-02 00:28:21 +0100269 int options; /* PR_O_REDISP, PR_O_TRANSP, ... */
Willy Tarreau66aa61f2009-01-18 21:44:07 +0100270 int options2; /* PR_O2_* */
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100271 struct in_addr mon_net, mon_mask; /* don't forward connections from this net (network order) FIXME: should support IPv6 */
Willy Tarreau67402132012-05-31 20:40:20 +0200272 unsigned int ck_opts; /* PR_CK_* (cookie options) */
Willy Tarreauc1a21672009-08-16 22:37:44 +0200273 unsigned int fe_req_ana, be_req_ana; /* bitmap of common request protocol analysers for the frontend and backend */
Willy Tarreau4e5b8282009-08-16 22:57:50 +0200274 unsigned int fe_rsp_ana, be_rsp_ana; /* bitmap of common response protocol analysers for the frontend and backend */
Willy Tarreau25320b22013-03-24 07:22:08 +0100275 unsigned int http_needed; /* non-null if HTTP analyser may be used */
Willy Tarreau5fdfb912007-01-01 23:11:07 +0100276 union {
277 struct proxy *be; /* default backend, or NULL if none set */
278 char *name; /* default backend name during config parse */
279 } defbe;
Willy Tarreaueb0c6142007-05-07 00:53:22 +0200280 struct list acl; /* ACL declared on this proxy */
Willy Tarreaue365c0b2013-06-11 16:06:12 +0200281 struct list http_req_rules; /* HTTP request rules: allow/deny/... */
282 struct list http_res_rules; /* HTTP response rules: allow/deny/... */
Willy Tarreau353bc9f2014-04-28 22:05:31 +0200283 struct list block_rules; /* http-request block rules to be inserted before other ones */
Willy Tarreaub463dfb2008-06-07 23:08:56 +0200284 struct list redirect_rules; /* content redirecting rules (chained) */
Willy Tarreau55ea7572007-06-17 19:56:27 +0200285 struct list switching_rules; /* content switching rules (chained) */
Cyril Bonté47fdd8e2010-04-25 00:00:51 +0200286 struct list persist_rules; /* 'force-persist' and 'ignore-persist' rules (chained) */
Emeric Brunb982a3d2010-01-04 15:45:53 +0100287 struct list sticking_rules; /* content sticking rules (chained) */
288 struct list storersp_rules; /* content store response rules (chained) */
Willy Tarreau4a5cade2012-04-05 21:09:48 +0200289 struct list server_rules; /* server switching rules (chained) */
Willy Tarreaub6866442008-07-14 23:54:42 +0200290 struct { /* TCP request processing */
Willy Tarreauc7e961e2008-08-17 17:13:47 +0200291 unsigned int inspect_delay; /* inspection delay */
Willy Tarreaub6866442008-07-14 23:54:42 +0200292 struct list inspect_rules; /* inspection rules */
Willy Tarreauab786192010-05-23 22:39:25 +0200293 struct list l4_rules; /* layer4 rules */
Willy Tarreau620408f2016-10-21 16:37:51 +0200294 struct list l5_rules; /* layer5 rules */
Willy Tarreaub6866442008-07-14 23:54:42 +0200295 } tcp_req;
Emeric Brun97679e72010-09-23 17:56:44 +0200296 struct { /* TCP request processing */
297 unsigned int inspect_delay; /* inspection delay */
298 struct list inspect_rules; /* inspection rules */
299 } tcp_rep;
Krzysztof Piotr Oledzkic6df0662010-01-05 16:38:49 +0100300 struct server *srv, defsrv; /* known servers; default server configuration */
Willy Tarreaua5110842017-11-26 08:41:31 +0100301 struct lbprm lbprm; /* load-balancing parameters */
Willy Tarreaub625a082007-11-26 01:15:43 +0100302 int srv_act, srv_bck; /* # of servers eligible for LB (UP|!checked) AND (enabled+weight!=0) */
Andrew Rodlande168feb2016-10-25 12:48:17 -0400303 int served; /* # of active sessions currently being served */
Willy Tarreaua5110842017-11-26 08:41:31 +0100304 int cookie_len; /* strlen(cookie_name), computed only once */
Krzysztof Piotr Oledzki1acf2172008-05-29 23:03:34 +0200305 char *cookie_domain; /* domain used to insert the cookie */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200306 char *cookie_name; /* name of the cookie to look for */
Olivier Houchard4e694042017-03-14 20:01:29 +0100307 char *dyncookie_key; /* Secret key used to generate dynamic persistent cookies */
Willy Tarreau31936852010-10-06 16:59:56 +0200308 unsigned int cookie_maxidle; /* max idle time for this cookie */
309 unsigned int cookie_maxlife; /* max life time for this cookie */
Willy Tarreau4edd6832014-08-28 14:36:36 +0200310 char *rdp_cookie_name; /* name of the RDP cookie to look for */
Willy Tarreaua5110842017-11-26 08:41:31 +0100311 int rdp_cookie_len; /* strlen(rdp_cookie_name), computed only once */
Willy Tarreau01732802007-11-01 22:48:15 +0100312 char *url_param_name; /* name of the URL parameter used for hashing */
313 int url_param_len; /* strlen(url_param_name), computed only once */
Marek Majkowski9c30fc12008-04-27 23:25:55 +0200314 int uri_len_limit; /* character limit for uri balancing algorithm */
315 int uri_dirs_depth1; /* directories+1 (slashes) limit for uri balancing algorithm */
Oskar Stolc8dc41842012-05-19 10:19:54 +0100316 int uri_whole; /* if != 0, calculates the hash from the whole uri. Still honors the len_limit and dirs_depth1 */
Benoitaffb4812009-03-25 13:02:10 +0100317 char *hh_name; /* name of the header parameter used for hashing */
318 int hh_len; /* strlen(hh_name), computed only once */
319 int hh_match_domain; /* toggle use of special match function */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200320 char *capture_name; /* beginning of the name of the cookie to capture */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200321 int capture_namelen; /* length of the cookie name to match */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200322 int capture_len; /* length of the string to be captured */
323 struct uri_auth *uri_auth; /* if non-NULL, the (list of) per-URI authentications */
Willy Tarreau4edd6832014-08-28 14:36:36 +0200324 int max_ka_queue; /* 1+maximum requests in queue accepted for reusing a K-A conn (0=none) */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200325 int monitor_uri_len; /* length of the string above. 0 if unused */
Willy Tarreau4edd6832014-08-28 14:36:36 +0200326 char *monitor_uri; /* a special URI to which we respond with HTTP/200 OK */
Willy Tarreaub80c2302007-11-30 20:51:32 +0100327 struct list mon_fail_cond; /* list of conditions to fail monitoring requests (chained) */
Willy Tarreau3a70f942008-02-15 11:15:34 +0100328 struct { /* WARNING! check proxy_reset_timeouts() in proxy.h !!! */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200329 int client; /* client I/O timeout (in ticks) */
330 int tarpit; /* tarpit timeout, defaults to connect if unspecified */
331 int queue; /* queue timeout, defaults to connect if unspecified */
332 int connect; /* connect timeout (in ticks) */
333 int server; /* server I/O timeout (in ticks) */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200334 int httpreq; /* maximum time for complete HTTP request */
Willy Tarreaub16a5742010-01-10 14:46:16 +0100335 int httpka; /* maximum time for a new HTTP request when using keep-alive */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200336 int check; /* maximum time for complete check */
Willy Tarreauce887fd2012-05-12 12:50:00 +0200337 int tunnel; /* I/O timeout to use in tunnel mode (in ticks) */
Willy Tarreau05cdd962014-05-10 14:30:07 +0200338 int clientfin; /* timeout to apply to client half-closed connections */
339 int serverfin; /* timeout to apply to server half-closed connections */
Willy Tarreau1fa31262007-12-03 00:36:16 +0100340 } timeout;
Krzysztof Piotr Oledzki48cb2ae2009-10-02 22:51:14 +0200341 char *id, *desc; /* proxy id (name) and description */
Patrick Hemmer0355dab2018-05-11 12:52:31 -0400342 struct eb_root pendconns; /* pending connections with no server assigned yet */
Willy Tarreauac68c5d2009-10-04 23:12:44 +0200343 int nbpend; /* number of pending connections with no server assigned yet */
Willy Tarreau1c47f852006-07-09 08:22:27 +0200344 int totpend; /* total number of pending connections on this instance (for stats) */
Patrick Hemmerda282f42018-05-11 12:52:31 -0400345 unsigned int queue_idx; /* number of pending connections which have been de-queued */
Willy Tarreau87b09662015-04-03 00:22:06 +0200346 unsigned int feconn, beconn; /* # of active frontend and backends streams */
Willy Tarreaud9b587f2010-02-26 10:05:55 +0100347 struct freq_ctr fe_req_per_sec; /* HTTP requests per second on the frontend */
Willy Tarreaub36b4242010-06-04 20:59:39 +0200348 struct freq_ctr fe_conn_per_sec; /* received connections per second on the frontend */
349 struct freq_ctr fe_sess_per_sec; /* accepted sessions per second on the frontend (after tcp rules) */
Willy Tarreau7f062c42009-03-05 18:43:00 +0100350 struct freq_ctr be_sess_per_sec; /* sessions per second on the backend */
Willy Tarreau13a34bd2009-05-10 18:52:49 +0200351 unsigned int fe_sps_lim; /* limit on new sessions per second on the frontend */
Willy Tarreau86034312006-12-29 00:10:33 +0100352 unsigned int fullconn; /* #conns on backend above which servers are used at full load */
Emeric Brun3f783572017-01-12 11:21:28 +0100353 unsigned int tot_fe_maxconn; /* #maxconn of frontends linked to that backend, it is used to compute fullconn */
Willy Tarreau7ac51f62007-03-25 16:00:04 +0200354 struct in_addr except_net, except_mask; /* don't x-forward-for for this address. FIXME: should support IPv6 */
Maik Broemme2850cb42009-04-17 18:53:21 +0200355 struct in_addr except_to; /* don't x-original-to for this address. */
356 struct in_addr except_mask_to; /* the netmask for except_to. */
Ross Westaf72a1d2008-08-03 10:51:45 +0200357 char *fwdfor_hdr_name; /* header to use - default: "x-forwarded-for" */
Maik Broemme2850cb42009-04-17 18:53:21 +0200358 char *orgto_hdr_name; /* header to use - default: "x-original-to" */
Willy Tarreau4edd6832014-08-28 14:36:36 +0200359 int fwdfor_hdr_len; /* length of "x-forwarded-for" header */
Maik Broemme2850cb42009-04-17 18:53:21 +0200360 int orgto_hdr_len; /* length of "x-original-to" header */
Mark Lamourinec2247f02012-01-04 13:02:01 -0500361 char *server_id_hdr_name; /* the header to use to send the server id (name) */
362 int server_id_hdr_len; /* the length of the id (name) header... name */
Willy Tarreau4edd6832014-08-28 14:36:36 +0200363 int conn_retries; /* maximum number of connect retries */
Joseph Lynch726ab712015-05-11 23:25:34 -0700364 int redispatch_after; /* number of retries before redispatch */
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200365 unsigned down_trans; /* up-down transitions */
366 unsigned down_time; /* total time the proxy was down */
Willy Tarreaua5110842017-11-26 08:41:31 +0100367 unsigned int log_count; /* number of logs produced by the frontend */
Krzysztof Oledzki85130942007-10-22 16:21:10 +0200368 time_t last_change; /* last time, when the state was changed */
Willy Tarreau87b09662015-04-03 00:22:06 +0200369 int (*accept)(struct stream *s); /* application layer's accept() */
Willy Tarreauef9a3602012-12-08 22:29:20 +0100370 struct conn_src conn_src; /* connection source settings */
Willy Tarreau87b09662015-04-03 00:22:06 +0200371 enum obj_type *default_target; /* default target to use for accepted streams or NULL */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200372 struct proxy *next;
Willy Tarreau7346acb2014-08-28 15:03:15 +0200373
William Lallemand0f99e342011-10-12 17:50:54 +0200374 struct list logsrvs;
William Lallemand723b73a2012-02-08 16:37:49 +0100375 struct list logformat; /* log_format linked list */
Dragan Dosen0b85ece2015-09-25 19:17:44 +0200376 struct list logformat_sd; /* log_format linked list for the RFC5424 structured-data part */
Willy Tarreau83061a82018-07-13 11:56:34 +0200377 struct buffer log_tag; /* override default syslog tag */
William Lallemanda73203e2012-03-12 12:48:57 +0100378 char *header_unique_id; /* unique-id header */
379 struct list format_unique_id; /* unique-id format */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200380 int to_log; /* things to be logged (LW_*) */
Willy Tarreau0c303ee2008-07-07 00:09:58 +0200381 int stop_time; /* date to stop listening, when stopping != 0 (int ticks) */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200382 struct hdr_exp *req_exp; /* regular expressions for request headers */
383 struct hdr_exp *rsp_exp; /* regular expressions for response headers */
384 int nb_req_cap, nb_rsp_cap; /* # of headers to be captured */
385 struct cap_hdr *req_cap; /* chained list of request headers to be captured */
386 struct cap_hdr *rsp_cap; /* chained list of response headers to be captured */
Willy Tarreau87b09662015-04-03 00:22:06 +0200387 struct pool_head *req_cap_pool, /* pools of pre-allocated char ** used to build the streams */
Willy Tarreaucf7f3202007-05-13 22:46:04 +0200388 *rsp_cap_pool;
Willy Tarreaudeb9ed82010-01-03 21:03:22 +0100389 struct list req_add, rsp_add; /* headers to be added */
Willy Tarreauae9bea02016-11-25 14:44:52 +0100390 struct be_counters be_counters; /* backend statistics counters */
391 struct fe_counters fe_counters; /* frontend statistics counters */
Emeric Brunb982a3d2010-01-04 15:45:53 +0100392
Willy Tarreau07687c12011-07-24 23:55:06 +0200393 struct list listener_queue; /* list of the temporarily limited listeners because of lack of a proxy resource */
Willy Tarreau87b09662015-04-03 00:22:06 +0200394 struct stktable table; /* table for storing sticking streams */
Emeric Brunb982a3d2010-01-04 15:45:53 +0100395
Willy Tarreaud1a33e32012-10-04 00:14:33 +0200396 struct task *task; /* the associated task, mandatory to manage rate limiting, stopping and resource shortage, NULL if disabled */
Baptiste Assmann5ecb77f2013-10-06 23:24:13 +0200397 struct list tcpcheck_rules; /* tcp-check send / expect rules */
Willy Tarreau4edd6832014-08-28 14:36:36 +0200398 int grace; /* grace time after stop request */
Willy Tarreauf3c69202006-07-09 16:42:34 +0200399 int check_len; /* Length of the HTTP or SSL3 request */
Willy Tarreau4edd6832014-08-28 14:36:36 +0200400 char *check_req; /* HTTP or SSL request to use for PR_O_HTTP_CHK|PR_O_SSL3_CHK */
Simon Horman98637e52014-06-20 12:30:16 +0900401 char *check_command; /* Command to use for external agent checks */
402 char *check_path; /* PATH environment to use for external agent checks */
Willy Tarreau1ee51a62011-08-19 20:04:17 +0200403 char *expect_str; /* http-check expected content : string or text version of the regex */
Thierry FOURNIER09af0d62014-06-18 11:35:54 +0200404 struct my_regex *expect_regex; /* http-check expected content */
Willy Tarreau83061a82018-07-13 11:56:34 +0200405 struct buffer errmsg[HTTP_ERR_SIZE]; /* default or customized error messages for known errors */
Willy Tarreaudcd47712007-11-04 23:35:08 +0100406 int uuid; /* universally unique proxy ID, used for SNMP */
Willy Tarreauc73ce2b2008-01-06 10:55:10 +0100407 unsigned int backlog; /* force the frontend's listen backlog */
Willy Tarreaua9db57e2013-01-18 11:29:29 +0100408 unsigned long bind_proc; /* bitmask of processes using this proxy */
Willy Tarreau7b815632011-10-21 18:51:57 +0200409
410 /* warning: these structs are huge, keep them at the bottom */
411 struct sockaddr_storage dispatch_addr; /* the default address to connect to */
Willy Tarreauc55015e2018-09-07 19:02:32 +0200412 struct error_snapshot *invalid_req, *invalid_rep; /* captures of last errors */
Willy Tarreau84b57da2009-06-14 11:10:45 +0200413
414 /* used only during configuration parsing */
415 int no_options; /* PR_O_REDISP, PR_O_TRANSP, ... */
416 int no_options2; /* PR_O2_* */
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200417
Willy Tarreau90a570f2009-10-04 20:54:54 +0200418 struct {
Willy Tarreau8113a5d2012-10-04 08:01:43 +0200419 char *file; /* file where the section appears */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +0200420 struct eb32_node id; /* place in the tree of used IDs */
Willy Tarreaua5110842017-11-26 08:41:31 +0100421 int line; /* line where the section appears */
Willy Tarreau53fb4ae2009-10-04 23:04:08 +0200422 struct eb_root used_listener_id;/* list of listener IDs in use */
423 struct eb_root used_server_id; /* list of server IDs in use */
Willy Tarreau2a65ff02012-09-13 17:54:29 +0200424 struct list bind; /* list of bind settings */
Willy Tarreau4348fad2012-09-20 16:48:07 +0200425 struct list listeners; /* list of listeners belonging to this frontend */
Willy Tarreaua4312fa2013-04-02 16:34:32 +0200426 struct arg_list args; /* sample arg list that need to be resolved */
Willy Tarreauf79d9502014-03-15 07:22:35 +0100427 struct ebpt_node by_name; /* proxies are stored sorted by name here */
Willy Tarreau62a61232013-04-12 18:13:46 +0200428 char *logformat_string; /* log format string */
429 char *lfs_file; /* file name where the logformat string appears (strdup) */
430 int lfs_line; /* file name where the logformat string appears */
Willy Tarreau62a61232013-04-12 18:13:46 +0200431 int uif_line; /* file name where the unique-id-format string appears */
Willy Tarreau4edd6832014-08-28 14:36:36 +0200432 char *uif_file; /* file name where the unique-id-format string appears (strdup) */
433 char *uniqueid_format_string; /* unique-id format string */
Dragan Dosen0b85ece2015-09-25 19:17:44 +0200434 char *logformat_sd_string; /* log format string for the RFC5424 structured-data part */
435 char *lfsd_file; /* file name where the structured-data logformat string for RFC5424 appears (strdup) */
436 int lfsd_line; /* file name where the structured-data logformat string for RFC5424 appears */
Willy Tarreau90a570f2009-10-04 20:54:54 +0200437 } conf; /* config information */
Willy Tarreau258a14b2010-07-13 16:24:48 +0200438 void *parent; /* parent of the proxy when applicable */
William Lallemand82fe75c2012-10-23 10:25:10 +0200439 struct comp *comp; /* http compression */
Simon Horman9dc49962015-01-30 11:22:59 +0900440
441 struct {
442 union {
443 struct mailers *m; /* Mailer to send email alerts via */
444 char *name;
445 } mailers;
Simon Horman0ba0e4a2015-01-30 11:23:00 +0900446 char *from; /* Address to send email alerts from */
447 char *to; /* Address(es) to send email alerts to */
Simon Horman9dc49962015-01-30 11:22:59 +0900448 char *myhostname; /* Identity to use in HELO command sent to mailer */
Simon Horman64e34162015-02-06 11:11:57 +0900449 int level; /* Maximum syslog level of messages to send
450 * email alerts for */
451 int set; /* True if email_alert settings are present */
Simon Horman0ba0e4a2015-01-30 11:23:00 +0900452 struct email_alertq *queues; /* per-mailer alerts queues */
Simon Horman9dc49962015-01-30 11:22:59 +0900453 } email_alert;
Baptiste Assmanne11cfcd2015-08-19 16:44:03 +0200454
455 int load_server_state_from_file; /* location of the file containing server state.
456 * flag PR_SRV_STATE_FILE_* */
457 char *server_state_file_name; /* used when load_server_state_from_file is set to
458 * PR_SRV_STATE_FILE_LOCAL. Give a specific file name for
459 * this backend. If not specified or void, then the backend
460 * name is used
461 */
Christopher Faulet443ea1a2016-02-04 13:40:26 +0100462 struct list filter_configs; /* list of the filters that are declared on this proxy */
Christopher Faulet9dcf9b62017-11-13 10:34:01 +0100463 __decl_hathreads(HA_SPINLOCK_T lock);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200464};
465
Willy Tarreau55ea7572007-06-17 19:56:27 +0200466struct switching_rule {
467 struct list list; /* list linked to from the proxy */
468 struct acl_cond *cond; /* acl condition to meet */
Bertrand Jacquin702d44f2013-11-19 11:43:06 +0100469 int dynamic; /* this is a dynamic rule using the logformat expression */
Willy Tarreau55ea7572007-06-17 19:56:27 +0200470 union {
471 struct proxy *backend; /* target backend */
472 char *name; /* target backend name during config parsing */
Bertrand Jacquin702d44f2013-11-19 11:43:06 +0100473 struct list expr; /* logformat expression to use for dynamic rules */
Willy Tarreau55ea7572007-06-17 19:56:27 +0200474 } be;
Thierry FOURNIER / OZON.IO4ed1c952016-11-24 23:57:54 +0100475 char *file;
476 int line;
Willy Tarreau55ea7572007-06-17 19:56:27 +0200477};
478
Willy Tarreau4a5cade2012-04-05 21:09:48 +0200479struct server_rule {
480 struct list list; /* list linked to from the proxy */
481 struct acl_cond *cond; /* acl condition to meet */
482 union {
483 struct server *ptr; /* target server */
484 char *name; /* target server name during config parsing */
485 } srv;
486};
487
Cyril Bonté47fdd8e2010-04-25 00:00:51 +0200488struct persist_rule {
Willy Tarreau4de91492010-01-22 19:10:05 +0100489 struct list list; /* list linked to from the proxy */
490 struct acl_cond *cond; /* acl condition to meet */
Cyril Bonté47fdd8e2010-04-25 00:00:51 +0200491 int type;
Willy Tarreau4de91492010-01-22 19:10:05 +0100492};
493
Emeric Brunb982a3d2010-01-04 15:45:53 +0100494struct sticking_rule {
495 struct list list; /* list linked to from the proxy */
496 struct acl_cond *cond; /* acl condition to meet */
Willy Tarreau12785782012-04-27 21:37:17 +0200497 struct sample_expr *expr; /* fetch expr to fetch key */
Emeric Brunb982a3d2010-01-04 15:45:53 +0100498 int flags; /* STK_* */
499 union {
500 struct stktable *t; /* target table */
501 char *name; /* target table name during config parsing */
502 } table;
503};
504
505
Willy Tarreaub463dfb2008-06-07 23:08:56 +0200506struct redirect_rule {
507 struct list list; /* list linked to from the proxy */
508 struct acl_cond *cond; /* acl condition to meet */
509 int type;
510 int rdr_len;
511 char *rdr_str;
Thierry FOURNIERd18cd0f2013-11-29 12:15:45 +0100512 struct list rdr_fmt;
Willy Tarreaub463dfb2008-06-07 23:08:56 +0200513 int code;
Willy Tarreau79da4692008-11-19 20:03:04 +0100514 unsigned int flags;
Willy Tarreau0140f252008-11-19 21:07:09 +0100515 int cookie_len;
516 char *cookie_str;
Willy Tarreaub463dfb2008-06-07 23:08:56 +0200517};
518
Willy Tarreaubaaee002006-06-26 02:48:02 +0200519#endif /* _TYPES_PROXY_H */
520
521/*
522 * Local variables:
523 * c-indent-level: 8
524 * c-basic-offset: 8
525 * End:
526 */