Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 5b15447 | 2009-12-21 20:11:07 +0100 | [diff] [blame] | 2 | * include/types/session.h |
| 3 | * This file defines everything related to sessions. |
| 4 | * |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 5 | * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu |
Willy Tarreau | 5b15447 | 2009-12-21 20:11:07 +0100 | [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 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
| 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 Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 31 | #include <common/config.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 32 | #include <common/mini-clist.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 34 | #include <types/channel.h> |
Willy Tarreau | 3bac9ff | 2007-03-18 17:31:28 +0100 | [diff] [blame] | 35 | #include <types/proto_http.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 36 | #include <types/proxy.h> |
| 37 | #include <types/queue.h> |
| 38 | #include <types/server.h> |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 39 | #include <types/stream_interface.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 40 | #include <types/task.h> |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 41 | #include <types/stick_table.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | |
| 43 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 44 | /* various session flags, bits values 0x01 to 0x100 (shift 0) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | #define SN_DIRECT 0x00000001 /* connection made on the server matching the client cookie */ |
Willy Tarreau | 3d30059 | 2007-03-18 18:34:41 +0100 | [diff] [blame] | 46 | #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 Tarreau | 5b15447 | 2009-12-21 20:11:07 +0100 | [diff] [blame] | 49 | |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 50 | #define SN_FORCE_PRST 0x00000010 /* force persistence here, even if server is down */ |
Willy Tarreau | 3d30059 | 2007-03-18 18:34:41 +0100 | [diff] [blame] | 51 | #define SN_MONITOR 0x00000020 /* this session comes from a monitoring system */ |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 52 | #define SN_CURR_SESS 0x00000040 /* a connection is currently being counted on the server */ |
Willy Tarreau | 9b061e3 | 2012-04-07 18:03:52 +0200 | [diff] [blame] | 53 | /* unused: 0x00000080 */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 54 | #define SN_REDISP 0x00000100 /* set if this session was redispatched from one server to another */ |
Willy Tarreau | 541b5c2 | 2008-01-06 23:34:21 +0100 | [diff] [blame] | 55 | #define SN_CONN_TAR 0x00000200 /* set if this session is turning around before reconnecting */ |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 56 | #define SN_REDIRECTABLE 0x00000400 /* set if this session is redirectable (GET or HEAD) */ |
Willy Tarreau | d0f06fc | 2009-11-30 12:19:56 +0100 | [diff] [blame] | 57 | #define SN_TUNNEL 0x00000800 /* tunnel-mode session, nothing to catch after data */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 58 | |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 59 | /* session termination conditions, bits values 0x1000 to 0x7000 (0-9 shift 12) */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 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 */ |
Simon Horman | 752dc4a | 2011-06-21 14:34:59 +0900 | [diff] [blame] | 68 | #define SN_ERR_DOWN 0x00008000 /* the proxy killed a session because the backend became unavailable */ |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 69 | #define SN_ERR_KILLED 0x00009000 /* the proxy killed a session because it was asked to do so */ |
Justin Karneges | eb2c24a | 2012-05-24 15:28:52 -0700 | [diff] [blame] | 70 | #define SN_ERR_UP 0x0000a000 /* the proxy killed a session because a preferred backend became available */ |
Simon Horman | 752dc4a | 2011-06-21 14:34:59 +0900 | [diff] [blame] | 71 | #define SN_ERR_MASK 0x0000f000 /* mask to get only session error flags */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 72 | #define SN_ERR_SHIFT 12 /* bit shift */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 73 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 74 | /* session state at termination, bits values 0x10000 to 0x70000 (0-7 shift 16) */ |
| 75 | #define SN_FINST_R 0x00010000 /* session ended during client request */ |
| 76 | #define SN_FINST_C 0x00020000 /* session ended during server connect */ |
| 77 | #define SN_FINST_H 0x00030000 /* session ended during server headers */ |
| 78 | #define SN_FINST_D 0x00040000 /* session ended during data phase */ |
| 79 | #define SN_FINST_L 0x00050000 /* session ended while pushing last data to client */ |
| 80 | #define SN_FINST_Q 0x00060000 /* session ended while waiting in queue for a server slot */ |
| 81 | #define SN_FINST_T 0x00070000 /* session ended tarpitted */ |
| 82 | #define SN_FINST_MASK 0x00070000 /* mask to get only final session state flags */ |
| 83 | #define SN_FINST_SHIFT 16 /* bit shift */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 84 | |
Simon Horman | 752dc4a | 2011-06-21 14:34:59 +0900 | [diff] [blame] | 85 | #define SN_IGNORE_PRST 0x00080000 /* ignore persistence */ |
| 86 | #define SN_BE_TRACK_SC1 0x00100000 /* backend tracks stick-counter 1 */ |
| 87 | #define SN_BE_TRACK_SC2 0x00200000 /* backend tracks stick-counter 2 */ |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 88 | |
Willy Tarreau | f853320 | 2008-08-16 14:55:08 +0200 | [diff] [blame] | 89 | /* Termination sequence tracing. |
| 90 | * |
| 91 | * These values have to be set into the field term_trace of a session when |
| 92 | * closing a session (half or full). They are only meant for post-mortem |
| 93 | * analysis. The value must be assigned this way : |
| 94 | * trace_term(s, TT_XXX); |
| 95 | * |
| 96 | * One TT_XXX value is assigned to each location in the code which may be |
| 97 | * involved in a connection closing. Since a full session close generally |
| 98 | * involves 4 steps, we will be able to read these steps afterwards by simply |
| 99 | * checking the code. Value TT_NONE is zero and must never be set, as it means |
| 100 | * the connection was not closed. Value TT_ANON must be used when no value was |
| 101 | * assigned to a specific code part. Never ever reuse an already assigned code |
| 102 | * as it will defeat the purpose of this trace. It is wise to use a per-file |
| 103 | * anonymous value though. |
| 104 | */ |
| 105 | #define TT_BIT_SHIFT 8 |
| 106 | enum { |
| 107 | TT_NONE = 0, |
| 108 | TT_ANON = 1, |
| 109 | TT_CLIENT = 0x10, |
| 110 | TT_CLIENT_1, |
| 111 | TT_CLIENT_2, |
| 112 | TT_HTTP_CLI = 0x20, |
| 113 | TT_HTTP_CLI_1, |
| 114 | TT_HTTP_CLI_2, |
| 115 | TT_HTTP_CLI_3, |
| 116 | TT_HTTP_CLI_4, |
| 117 | TT_HTTP_CLI_5, |
| 118 | TT_HTTP_CLI_6, |
| 119 | TT_HTTP_CLI_7, |
| 120 | TT_HTTP_CLI_8, |
| 121 | TT_HTTP_CLI_9, |
| 122 | TT_HTTP_CLI_10, |
| 123 | TT_HTTP_SRV = 0x30, |
| 124 | TT_HTTP_SRV_1, |
| 125 | TT_HTTP_SRV_2, |
| 126 | TT_HTTP_SRV_3, |
| 127 | TT_HTTP_SRV_4, |
| 128 | TT_HTTP_SRV_5, |
| 129 | TT_HTTP_SRV_6, |
| 130 | TT_HTTP_SRV_7, |
| 131 | TT_HTTP_SRV_8, |
| 132 | TT_HTTP_SRV_9, |
| 133 | TT_HTTP_SRV_10, |
| 134 | TT_HTTP_SRV_11, |
| 135 | TT_HTTP_SRV_12, |
| 136 | TT_HTTP_SRV_13, |
| 137 | TT_HTTP_SRV_14, |
| 138 | TT_HTTP_CNT = 0x40, |
| 139 | TT_HTTP_CNT_1, |
| 140 | TT_HTTP_URI = 0x50, |
| 141 | TT_HTTP_URI_1, |
| 142 | }; |
| 143 | |
| 144 | |
Willy Tarreau | 0a4838c | 2010-08-06 20:11:05 +0200 | [diff] [blame] | 145 | /* WARNING: if new fields are added, they must be initialized in event_accept() |
| 146 | * and freed in session_free() ! |
| 147 | */ |
| 148 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 149 | /* |
| 150 | * Note: some session flags have dependencies : |
| 151 | * - SN_DIRECT cannot exist without SN_ASSIGNED, because a server is |
| 152 | * immediately assigned when SN_DIRECT is determined. Both must be cleared |
| 153 | * when clearing SN_DIRECT (eg: redispatch). |
| 154 | * - ->srv has no meaning without SN_ASSIGNED and must not be checked without |
Willy Tarreau | 3d80d91 | 2011-03-10 11:42:13 +0100 | [diff] [blame] | 155 | * it. ->target and ->target_type may be used to check previous ->srv after |
| 156 | * a failed connection attempt. |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 157 | * - a session being processed has srv_conn set. |
| 158 | * - srv_conn might remain after SN_DIRECT has been reset, but the assigned |
| 159 | * server should eventually be released. |
| 160 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 161 | struct session { |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 162 | struct list list; /* position in global sessions list */ |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 163 | struct list by_srv; /* position in server session list */ |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 164 | struct list back_refs; /* list of users tracking this session */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 165 | struct task *task; /* the task associated with this session */ |
| 166 | /* application specific below */ |
Willy Tarreau | b5654f6 | 2008-12-07 16:45:10 +0100 | [diff] [blame] | 167 | struct listener *listener; /* the listener by which the request arrived */ |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 168 | struct proxy *fe; /* the proxy this session depends on for the client side */ |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 169 | struct proxy *be; /* the proxy this session depends on for the server side */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 170 | int flags; /* some flags describing the session */ |
Willy Tarreau | f853320 | 2008-08-16 14:55:08 +0200 | [diff] [blame] | 171 | unsigned term_trace; /* term trace: 4*8 bits indicating which part of the code closed */ |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 172 | struct channel *req; /* request buffer */ |
| 173 | struct channel *rep; /* response buffer */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 174 | struct stream_interface si[2]; /* client and server stream interfaces */ |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 175 | struct server *srv_conn; /* session already has a slot on a server and is not in queue */ |
Willy Tarreau | 664beb8 | 2011-03-10 11:38:29 +0100 | [diff] [blame] | 176 | struct target target; /* target to use for this session */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 177 | struct pendconn *pend_pos; /* if not NULL, points to the position in the pending queue */ |
Willy Tarreau | b326fcc | 2007-03-03 13:54:32 +0100 | [diff] [blame] | 178 | struct http_txn txn; /* current HTTP transaction being processed. Should become a list. */ |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 179 | |
| 180 | struct { |
| 181 | struct stksess *ts; |
| 182 | struct stktable *table; |
| 183 | int flags; |
| 184 | } store[8]; /* tracked stickiness values to store */ |
| 185 | int store_count; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 186 | |
| 187 | struct stksess *stkctr1_entry; /* entry containing counters currently being tracked as set 1 by this session */ |
| 188 | struct stktable *stkctr1_table; /* table the counters above belong to (undefined if counters are null) */ |
| 189 | struct stksess *stkctr2_entry; /* entry containing counters currently being tracked as set 2 by this session */ |
| 190 | struct stktable *stkctr2_table; /* table the counters above belong to (undefined if counters are null) */ |
Emeric Brun | b982a3d | 2010-01-04 15:45:53 +0100 | [diff] [blame] | 191 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 192 | struct { |
| 193 | int logwait; /* log fields waiting to be collected : LW_* */ |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 194 | struct timeval accept_date; /* date of the accept() in user date */ |
| 195 | struct timeval tv_accept; /* date of the accept() in internal date (monotonic) */ |
Willy Tarreau | 7008987 | 2008-06-13 21:12:51 +0200 | [diff] [blame] | 196 | struct timeval tv_request; /* date the request arrives, {0,0} if never occurs */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 197 | long t_queue; /* delay before the session gets out of the connect queue, -1 if never occurs */ |
| 198 | long t_connect; /* delay before the connect() to the server succeeds, -1 if never occurs */ |
| 199 | long t_data; /* delay before the first data byte from the server ... */ |
Willy Tarreau | 3bac9ff | 2007-03-18 17:31:28 +0100 | [diff] [blame] | 200 | unsigned long t_close; /* total session duration */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 201 | unsigned long srv_queue_size; /* number of sessions waiting for a connect slot on this server at accept() time (in direct assignment) */ |
| 202 | unsigned long prx_queue_size; /* overall number of sessions waiting for a connect slot on this instance at accept() time */ |
Willy Tarreau | 35d66b0 | 2007-01-02 00:28:21 +0100 | [diff] [blame] | 203 | long long bytes_in; /* number of bytes transferred from the client to the server */ |
| 204 | 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] | 205 | } logs; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 206 | void (*do_log)(struct session *s); /* the function to call in order to log (or NULL) */ |
| 207 | void (*srv_error)(struct session *s, /* the function to call upon unrecoverable server errors (or NULL) */ |
| 208 | struct stream_interface *si); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 209 | unsigned int uniq_id; /* unique ID used for the traces */ |
William Lallemand | a73203e | 2012-03-12 12:48:57 +0100 | [diff] [blame] | 210 | char *unique_id; /* custom unique ID */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 211 | }; |
| 212 | |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 213 | /* parameters to configure tracked counters */ |
| 214 | struct track_ctr_prm { |
| 215 | int type; /* type of the key */ |
| 216 | union { |
| 217 | struct stktable *t; /* a pointer to the table */ |
| 218 | char *n; /* or its name during parsing. */ |
| 219 | } table; |
| 220 | }; |
| 221 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 222 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 223 | #endif /* _TYPES_SESSION_H */ |
| 224 | |
| 225 | /* |
| 226 | * Local variables: |
| 227 | * c-indent-level: 8 |
| 228 | * c-basic-offset: 8 |
| 229 | * End: |
| 230 | */ |