Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | include/types/session.h |
| 3 | This file defines everything related to sessions. |
| 4 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 5 | Copyright (C) 2000-2008 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_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 | |
| 34 | #include <types/buffers.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> |
| 39 | #include <types/task.h> |
| 40 | |
| 41 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 42 | /* various session flags, bits values 0x01 to 0x100 (shift 0) */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 43 | #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] | 44 | #define SN_ASSIGNED 0x00000002 /* no need to assign a server to this session */ |
| 45 | #define SN_ADDR_SET 0x00000004 /* this session's server address has been set */ |
| 46 | #define SN_BE_ASSIGNED 0x00000008 /* a backend was assigned. Conns are accounted. */ |
| 47 | #define SN_CONN_CLOSED 0x00000010 /* "Connection: close" was present or added */ |
| 48 | #define SN_MONITOR 0x00000020 /* this session comes from a monitoring system */ |
| 49 | #define SN_SELF_GEN 0x00000040 /* the proxy generates data for the client (eg: stats) */ |
Willy Tarreau | 14c8aac | 2007-05-08 19:46:30 +0200 | [diff] [blame] | 50 | #define SN_FRT_ADDR_SET 0x00000080 /* set if the frontend address has been filled */ |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 51 | #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] | 52 | #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] | 53 | #define SN_REDIRECTABLE 0x00000400 /* set if this session is redirectable (GET or HEAD) */ |
Willy Tarreau | 3d30059 | 2007-03-18 18:34:41 +0100 | [diff] [blame] | 54 | /* unused: 0x00000800 */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 55 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 56 | /* session termination conditions, bits values 0x1000 to 0x7000 (0-7 shift 12) */ |
| 57 | #define SN_ERR_NONE 0x00000000 |
| 58 | #define SN_ERR_CLITO 0x00001000 /* client time-out */ |
| 59 | #define SN_ERR_CLICL 0x00002000 /* client closed (read/write error) */ |
| 60 | #define SN_ERR_SRVTO 0x00003000 /* server time-out, connect time-out */ |
| 61 | #define SN_ERR_SRVCL 0x00004000 /* server closed (connect/read/write error) */ |
| 62 | #define SN_ERR_PRXCOND 0x00005000 /* the proxy decided to close (deny...) */ |
| 63 | #define SN_ERR_RESOURCE 0x00006000 /* the proxy encountered a lack of a local resources (fd, mem, ...) */ |
| 64 | #define SN_ERR_INTERNAL 0x00007000 /* the proxy encountered an internal error */ |
| 65 | #define SN_ERR_MASK 0x00007000 /* mask to get only session error flags */ |
| 66 | #define SN_ERR_SHIFT 12 /* bit shift */ |
Willy Tarreau | 3d30059 | 2007-03-18 18:34:41 +0100 | [diff] [blame] | 67 | /* unused: 0x00008000 */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 68 | |
Krzysztof Piotr Oledzki | 25b501a | 2008-01-06 16:36:16 +0100 | [diff] [blame] | 69 | /* session state at termination, bits values 0x10000 to 0x70000 (0-7 shift 16) */ |
| 70 | #define SN_FINST_R 0x00010000 /* session ended during client request */ |
| 71 | #define SN_FINST_C 0x00020000 /* session ended during server connect */ |
| 72 | #define SN_FINST_H 0x00030000 /* session ended during server headers */ |
| 73 | #define SN_FINST_D 0x00040000 /* session ended during data phase */ |
| 74 | #define SN_FINST_L 0x00050000 /* session ended while pushing last data to client */ |
| 75 | #define SN_FINST_Q 0x00060000 /* session ended while waiting in queue for a server slot */ |
| 76 | #define SN_FINST_T 0x00070000 /* session ended tarpitted */ |
| 77 | #define SN_FINST_MASK 0x00070000 /* mask to get only final session state flags */ |
| 78 | #define SN_FINST_SHIFT 16 /* bit shift */ |
| 79 | /* unused: 0x00080000 */ |
| 80 | |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 81 | /* WARNING: if new fields are added, they must be initialized in event_accept() |
| 82 | * and freed in session_free() ! |
| 83 | */ |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * Note: some session flags have dependencies : |
| 87 | * - SN_DIRECT cannot exist without SN_ASSIGNED, because a server is |
| 88 | * immediately assigned when SN_DIRECT is determined. Both must be cleared |
| 89 | * when clearing SN_DIRECT (eg: redispatch). |
| 90 | * - ->srv has no meaning without SN_ASSIGNED and must not be checked without |
| 91 | * it. ->prev_srv should be used to check previous ->srv. If SN_ASSIGNED is |
| 92 | * set and sess->srv is NULL, then it is a dispatch or proxy mode. |
| 93 | * - a session being processed has srv_conn set. |
| 94 | * - srv_conn might remain after SN_DIRECT has been reset, but the assigned |
| 95 | * server should eventually be released. |
| 96 | */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 97 | struct session { |
| 98 | struct task *task; /* the task associated with this session */ |
| 99 | /* application specific below */ |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 100 | 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] | 101 | 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] | 102 | int cli_fd; /* the client side fd */ |
| 103 | int srv_fd; /* the server side fd */ |
| 104 | int cli_state; /* state of the client side */ |
| 105 | int srv_state; /* state of the server side */ |
| 106 | int conn_retries; /* number of connect retries left */ |
| 107 | int flags; /* some flags describing the session */ |
| 108 | struct buffer *req; /* request buffer */ |
| 109 | struct buffer *rep; /* response buffer */ |
| 110 | struct sockaddr_storage cli_addr; /* the client address */ |
Willy Tarreau | 14c8aac | 2007-05-08 19:46:30 +0200 | [diff] [blame] | 111 | struct sockaddr_storage frt_addr; /* the frontend address reached by the client if SN_FRT_ADDR_SET is set */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 112 | struct sockaddr_in srv_addr; /* the address to connect to */ |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 113 | struct server *srv; /* the server the session will be running or has been running on */ |
| 114 | struct server *srv_conn; /* session already has a slot on a server and is not in queue */ |
| 115 | struct server *prev_srv; /* the server the was running on, after a redispatch, otherwise NULL */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 116 | 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] | 117 | struct http_txn txn; /* current HTTP transaction being processed. Should become a list. */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 118 | struct { |
| 119 | int logwait; /* log fields waiting to be collected : LW_* */ |
Willy Tarreau | b7f694f | 2008-06-22 17:18:02 +0200 | [diff] [blame] | 120 | struct timeval accept_date; /* date of the accept() in user date */ |
| 121 | struct timeval tv_accept; /* date of the accept() in internal date (monotonic) */ |
Willy Tarreau | 7008987 | 2008-06-13 21:12:51 +0200 | [diff] [blame] | 122 | 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] | 123 | long t_queue; /* delay before the session gets out of the connect queue, -1 if never occurs */ |
| 124 | long t_connect; /* delay before the connect() to the server succeeds, -1 if never occurs */ |
| 125 | long t_data; /* delay before the first data byte from the server ... */ |
Willy Tarreau | 3bac9ff | 2007-03-18 17:31:28 +0100 | [diff] [blame] | 126 | unsigned long t_close; /* total session duration */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 127 | unsigned long srv_queue_size; /* number of sessions waiting for a connect slot on this server at accept() time (in direct assignment) */ |
| 128 | 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] | 129 | long long bytes_in; /* number of bytes transferred from the client to the server */ |
| 130 | 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] | 131 | } logs; |
| 132 | short int data_source; /* where to get the data we generate ourselves */ |
| 133 | short int data_state; /* where to get the data we generate ourselves */ |
| 134 | union { |
| 135 | struct { |
| 136 | struct proxy *px; |
| 137 | struct server *sv; |
| 138 | short px_st, sv_st; /* DATA_ST_INIT or DATA_ST_DATA */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 139 | unsigned int flags; /* STAT_* */ |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 140 | int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 141 | } stats; |
Willy Tarreau | 73de989 | 2006-11-30 11:40:23 +0100 | [diff] [blame] | 142 | } data_ctx; /* used by produce_content to dump the stats right now */ |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 143 | unsigned int uniq_id; /* unique ID used for the traces */ |
| 144 | }; |
| 145 | |
| 146 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 147 | #endif /* _TYPES_SESSION_H */ |
| 148 | |
| 149 | /* |
| 150 | * Local variables: |
| 151 | * c-indent-level: 8 |
| 152 | * c-basic-offset: 8 |
| 153 | * End: |
| 154 | */ |