blob: 0bbb9bf2f831197a04513c0c3b2ec02a598c3858 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
Willy Tarreau5b154472009-12-21 20:11:07 +01002 * include/types/session.h
3 * This file defines everything related to sessions.
4 *
Willy Tarreau4de91492010-01-22 19:10:05 +01005 * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
Willy Tarreau5b154472009-12-21 20:11:07 +01006 *
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_SESSION_H
23#define _TYPES_SESSION_H
24
25
26#include <sys/time.h>
27#include <unistd.h>
28#include <netinet/in.h>
29#include <arpa/inet.h>
30
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>
Willy Tarreaubaaee002006-06-26 02:48:02 +020033
34#include <types/buffers.h>
Willy Tarreau3bac9ff2007-03-18 17:31:28 +010035#include <types/proto_http.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020036#include <types/proxy.h>
37#include <types/queue.h>
38#include <types/server.h>
Willy Tarreaufa7e1022008-10-19 07:30:41 +020039#include <types/stream_interface.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020040#include <types/task.h>
Emeric Brunb982a3d2010-01-04 15:45:53 +010041#include <types/stick_table.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020042
43
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +010044/* various session flags, bits values 0x01 to 0x100 (shift 0) */
Willy Tarreaubaaee002006-06-26 02:48:02 +020045#define SN_DIRECT 0x00000001 /* connection made on the server matching the client cookie */
Willy Tarreau3d300592007-03-18 18:34:41 +010046#define SN_ASSIGNED 0x00000002 /* no need to assign a server to this session */
47#define SN_ADDR_SET 0x00000004 /* this session's server address has been set */
48#define SN_BE_ASSIGNED 0x00000008 /* a backend was assigned. Conns are accounted. */
Willy Tarreau5b154472009-12-21 20:11:07 +010049
Willy Tarreau4de91492010-01-22 19:10:05 +010050#define SN_FORCE_PRST 0x00000010 /* force persistence here, even if server is down */
Willy Tarreau3d300592007-03-18 18:34:41 +010051#define SN_MONITOR 0x00000020 /* this session comes from a monitoring system */
Willy Tarreau1e62de62008-11-11 20:20:02 +010052#define SN_CURR_SESS 0x00000040 /* a connection is currently being counted on the server */
Willy Tarreau14c8aac2007-05-08 19:46:30 +020053#define SN_FRT_ADDR_SET 0x00000080 /* set if the frontend address has been filled */
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +010054#define SN_REDISP 0x00000100 /* set if this session was redispatched from one server to another */
Willy Tarreau541b5c22008-01-06 23:34:21 +010055#define SN_CONN_TAR 0x00000200 /* set if this session is turning around before reconnecting */
Willy Tarreau21d2af32008-02-14 20:25:24 +010056#define SN_REDIRECTABLE 0x00000400 /* set if this session is redirectable (GET or HEAD) */
Willy Tarreaud0f06fc2009-11-30 12:19:56 +010057#define SN_TUNNEL 0x00000800 /* tunnel-mode session, nothing to catch after data */
Willy Tarreaubaaee002006-06-26 02:48:02 +020058
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +010059/* session termination conditions, bits values 0x1000 to 0x7000 (0-7 shift 12) */
60#define SN_ERR_NONE 0x00000000
61#define SN_ERR_CLITO 0x00001000 /* client time-out */
62#define SN_ERR_CLICL 0x00002000 /* client closed (read/write error) */
63#define SN_ERR_SRVTO 0x00003000 /* server time-out, connect time-out */
64#define SN_ERR_SRVCL 0x00004000 /* server closed (connect/read/write error) */
65#define SN_ERR_PRXCOND 0x00005000 /* the proxy decided to close (deny...) */
66#define SN_ERR_RESOURCE 0x00006000 /* the proxy encountered a lack of a local resources (fd, mem, ...) */
67#define SN_ERR_INTERNAL 0x00007000 /* the proxy encountered an internal error */
68#define SN_ERR_MASK 0x00007000 /* mask to get only session error flags */
69#define SN_ERR_SHIFT 12 /* bit shift */
Willy Tarreau0a4838c2010-08-06 20:11:05 +020070#define SN_BE_TRACK_SC1 0x00008000 /* backend tracks stick-counter 1 */
Willy Tarreaubaaee002006-06-26 02:48:02 +020071
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +010072/* session state at termination, bits values 0x10000 to 0x70000 (0-7 shift 16) */
73#define SN_FINST_R 0x00010000 /* session ended during client request */
74#define SN_FINST_C 0x00020000 /* session ended during server connect */
75#define SN_FINST_H 0x00030000 /* session ended during server headers */
76#define SN_FINST_D 0x00040000 /* session ended during data phase */
77#define SN_FINST_L 0x00050000 /* session ended while pushing last data to client */
78#define SN_FINST_Q 0x00060000 /* session ended while waiting in queue for a server slot */
79#define SN_FINST_T 0x00070000 /* session ended tarpitted */
80#define SN_FINST_MASK 0x00070000 /* mask to get only final session state flags */
81#define SN_FINST_SHIFT 16 /* bit shift */
Willy Tarreau0a4838c2010-08-06 20:11:05 +020082#define SN_BE_TRACK_SC2 0x00080000 /* backend tracks stick-counter 2 */
Krzysztof Piotr Oledzki25b501a2008-01-06 16:36:16 +010083
Cyril Bonté47fdd8e2010-04-25 00:00:51 +020084#define SN_IGNORE_PRST 0x00100000 /* ignore persistence */
85
Willy Tarreauf8533202008-08-16 14:55:08 +020086/* Termination sequence tracing.
87 *
88 * These values have to be set into the field term_trace of a session when
89 * closing a session (half or full). They are only meant for post-mortem
90 * analysis. The value must be assigned this way :
91 * trace_term(s, TT_XXX);
92 *
93 * One TT_XXX value is assigned to each location in the code which may be
94 * involved in a connection closing. Since a full session close generally
95 * involves 4 steps, we will be able to read these steps afterwards by simply
96 * checking the code. Value TT_NONE is zero and must never be set, as it means
97 * the connection was not closed. Value TT_ANON must be used when no value was
98 * assigned to a specific code part. Never ever reuse an already assigned code
99 * as it will defeat the purpose of this trace. It is wise to use a per-file
100 * anonymous value though.
101 */
102#define TT_BIT_SHIFT 8
103enum {
104 TT_NONE = 0,
105 TT_ANON = 1,
106 TT_CLIENT = 0x10,
107 TT_CLIENT_1,
108 TT_CLIENT_2,
109 TT_HTTP_CLI = 0x20,
110 TT_HTTP_CLI_1,
111 TT_HTTP_CLI_2,
112 TT_HTTP_CLI_3,
113 TT_HTTP_CLI_4,
114 TT_HTTP_CLI_5,
115 TT_HTTP_CLI_6,
116 TT_HTTP_CLI_7,
117 TT_HTTP_CLI_8,
118 TT_HTTP_CLI_9,
119 TT_HTTP_CLI_10,
120 TT_HTTP_SRV = 0x30,
121 TT_HTTP_SRV_1,
122 TT_HTTP_SRV_2,
123 TT_HTTP_SRV_3,
124 TT_HTTP_SRV_4,
125 TT_HTTP_SRV_5,
126 TT_HTTP_SRV_6,
127 TT_HTTP_SRV_7,
128 TT_HTTP_SRV_8,
129 TT_HTTP_SRV_9,
130 TT_HTTP_SRV_10,
131 TT_HTTP_SRV_11,
132 TT_HTTP_SRV_12,
133 TT_HTTP_SRV_13,
134 TT_HTTP_SRV_14,
135 TT_HTTP_CNT = 0x40,
136 TT_HTTP_CNT_1,
137 TT_HTTP_URI = 0x50,
138 TT_HTTP_URI_1,
139};
140
141
Willy Tarreau0a4838c2010-08-06 20:11:05 +0200142/* WARNING: if new fields are added, they must be initialized in event_accept()
143 * and freed in session_free() !
144 */
145
Willy Tarreau7c669d72008-06-20 15:04:11 +0200146/*
147 * Note: some session flags have dependencies :
148 * - SN_DIRECT cannot exist without SN_ASSIGNED, because a server is
149 * immediately assigned when SN_DIRECT is determined. Both must be cleared
150 * when clearing SN_DIRECT (eg: redispatch).
151 * - ->srv has no meaning without SN_ASSIGNED and must not be checked without
152 * it. ->prev_srv should be used to check previous ->srv. If SN_ASSIGNED is
153 * set and sess->srv is NULL, then it is a dispatch or proxy mode.
154 * - a session being processed has srv_conn set.
155 * - srv_conn might remain after SN_DIRECT has been reset, but the assigned
156 * server should eventually be released.
157 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200158struct session {
Willy Tarreauf54f8bd2008-11-23 19:53:55 +0100159 struct list list; /* position in global sessions list */
Willy Tarreau62e4f1d2008-12-07 20:16:23 +0100160 struct list back_refs; /* list of users tracking this session */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200161 struct task *task; /* the task associated with this session */
162 /* application specific below */
Willy Tarreaub5654f62008-12-07 16:45:10 +0100163 struct listener *listener; /* the listener by which the request arrived */
Willy Tarreau73de9892006-11-30 11:40:23 +0100164 struct proxy *fe; /* the proxy this session depends on for the client side */
Willy Tarreau73de9892006-11-30 11:40:23 +0100165 struct proxy *be; /* the proxy this session depends on for the server side */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200166 int flags; /* some flags describing the session */
Willy Tarreauf8533202008-08-16 14:55:08 +0200167 unsigned term_trace; /* term trace: 4*8 bits indicating which part of the code closed */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200168 struct buffer *req; /* request buffer */
169 struct buffer *rep; /* response buffer */
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200170 struct stream_interface si[2]; /* client and server stream interfaces */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200171 struct sockaddr_storage cli_addr; /* the client address */
Willy Tarreau14c8aac2007-05-08 19:46:30 +0200172 struct sockaddr_storage frt_addr; /* the frontend address reached by the client if SN_FRT_ADDR_SET is set */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200173 struct sockaddr_in srv_addr; /* the address to connect to */
Willy Tarreaub1d67742010-03-29 19:36:59 +0200174 struct sockaddr_in from_addr; /* the address to spoof when connecting to the server (transparent mode) */
Willy Tarreau7c669d72008-06-20 15:04:11 +0200175 struct server *srv; /* the server the session will be running or has been running on */
176 struct server *srv_conn; /* session already has a slot on a server and is not in queue */
177 struct server *prev_srv; /* the server the was running on, after a redispatch, otherwise NULL */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200178 struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */
Willy Tarreaub326fcc2007-03-03 13:54:32 +0100179 struct http_txn txn; /* current HTTP transaction being processed. Should become a list. */
Emeric Brunb982a3d2010-01-04 15:45:53 +0100180
181 struct {
182 struct stksess *ts;
183 struct stktable *table;
184 int flags;
185 } store[8]; /* tracked stickiness values to store */
186 int store_count;
Willy Tarreau56123282010-08-06 19:06:56 +0200187
188 struct stksess *stkctr1_entry; /* entry containing counters currently being tracked as set 1 by this session */
189 struct stktable *stkctr1_table; /* table the counters above belong to (undefined if counters are null) */
190 struct stksess *stkctr2_entry; /* entry containing counters currently being tracked as set 2 by this session */
191 struct stktable *stkctr2_table; /* table the counters above belong to (undefined if counters are null) */
Emeric Brunb982a3d2010-01-04 15:45:53 +0100192
Willy Tarreaubaaee002006-06-26 02:48:02 +0200193 struct {
194 int logwait; /* log fields waiting to be collected : LW_* */
Willy Tarreaub7f694f2008-06-22 17:18:02 +0200195 struct timeval accept_date; /* date of the accept() in user date */
196 struct timeval tv_accept; /* date of the accept() in internal date (monotonic) */
Willy Tarreau70089872008-06-13 21:12:51 +0200197 struct timeval tv_request; /* date the request arrives, {0,0} if never occurs */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200198 long t_queue; /* delay before the session gets out of the connect queue, -1 if never occurs */
199 long t_connect; /* delay before the connect() to the server succeeds, -1 if never occurs */
200 long t_data; /* delay before the first data byte from the server ... */
Willy Tarreau3bac9ff2007-03-18 17:31:28 +0100201 unsigned long t_close; /* total session duration */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200202 unsigned long srv_queue_size; /* number of sessions waiting for a connect slot on this server at accept() time (in direct assignment) */
203 unsigned long prx_queue_size; /* overall number of sessions waiting for a connect slot on this instance at accept() time */
Willy Tarreau35d66b02007-01-02 00:28:21 +0100204 long long bytes_in; /* number of bytes transferred from the client to the server */
205 long long bytes_out; /* number of bytes transferred from the server to the client */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200206 } logs;
Willy Tarreau0cac36f2008-11-30 20:44:17 +0100207 void (*do_log)(struct session *s); /* the function to call in order to log (or NULL) */
208 void (*srv_error)(struct session *s, /* the function to call upon unrecoverable server errors (or NULL) */
209 struct stream_interface *si);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200210 short int data_source; /* where to get the data we generate ourselves */
211 short int data_state; /* where to get the data we generate ourselves */
212 union {
213 struct {
214 struct proxy *px;
215 struct server *sv;
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +0200216 struct listener *l;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200217 short px_st, sv_st; /* DATA_ST_INIT or DATA_ST_DATA */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +0100218 unsigned int flags; /* STAT_* */
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +0100219 int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */
Cyril Bonté70be45d2010-10-12 00:14:35 +0200220 const char *st_code; /* pointer to the status code returned by an action */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200221 } stats;
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +0100222 struct {
Willy Tarreau66dc20a2010-03-05 17:53:32 +0100223 struct bref bref; /* back-reference from the session being dumped */
224 void *target; /* session we want to dump, or NULL for all */
225 unsigned int uid; /* if non-null, the uniq_id of the session being dumped */
226 int section; /* section of the session being dumped */
227 int pos; /* last position of the current session's buffer */
Willy Tarreau3dfe6cd2008-12-07 22:29:48 +0100228 } sess;
Willy Tarreau74808cb2009-03-04 15:53:18 +0100229 struct {
230 int iid; /* if >= 0, ID of the proxy to filter on */
231 struct proxy *px; /* current proxy being dumped, NULL = not started yet. */
232 unsigned int buf; /* buffer being dumped, 0 = req, 1 = rep */
233 unsigned int sid; /* session ID of error being dumped */
234 int ptr; /* <0: headers, >=0 : text pointer to restart from */
235 int bol; /* pointer to beginning of current line */
236 } errors;
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200237 struct {
Willy Tarreau69f58c82010-07-12 17:55:33 +0200238 void *target; /* table we want to dump, or NULL for all */
239 struct proxy *proxy; /* table being currently dumped (first if NULL) */
240 struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */
Willy Tarreau4f3f01f2010-07-18 11:46:20 +0200241 long long value; /* value to compare against */
242 signed char data_type; /* type of data to compare, or -1 if none */
243 signed char data_op; /* operator (STD_OP_*) when data_type set */
Willy Tarreau69f58c82010-07-12 17:55:33 +0200244 } table;
245 struct {
Willy Tarreauea1f5fe2009-10-11 23:12:51 +0200246 const char *msg; /* pointer to a persistent message to be returned in PRINT state */
247 } cli;
Willy Tarreaub0c9bc42009-10-04 15:56:38 +0200248 } data_ctx; /* used by stats I/O handlers to dump the stats */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200249 unsigned int uniq_id; /* unique ID used for the traces */
250};
251
Willy Tarreau9ba2dcc2010-06-14 21:04:55 +0200252/* parameters to configure tracked counters */
253struct track_ctr_prm {
254 int type; /* type of the key */
255 union {
256 struct stktable *t; /* a pointer to the table */
257 char *n; /* or its name during parsing. */
258 } table;
259};
260
Willy Tarreaubaaee002006-06-26 02:48:02 +0200261
Willy Tarreaubaaee002006-06-26 02:48:02 +0200262#endif /* _TYPES_SESSION_H */
263
264/*
265 * Local variables:
266 * c-indent-level: 8
267 * c-basic-offset: 8
268 * End:
269 */