Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 2 | * Session management functions. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d28c353 | 2012-04-19 19:28:33 +0200 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <stdlib.h> |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 14 | #include <unistd.h> |
| 15 | #include <fcntl.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 16 | |
| 17 | #include <common/config.h> |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 18 | #include <common/debug.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 19 | #include <common/memory.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 20 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | #include <types/capture.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 22 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 23 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 24 | #include <proto/acl.h> |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 25 | #include <proto/arg.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 26 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 27 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 28 | #include <proto/checks.h> |
Willy Tarreau | d2274c6 | 2012-07-06 14:29:45 +0200 | [diff] [blame] | 29 | #include <proto/connection.h> |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 30 | #include <proto/dumpstats.h> |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 31 | #include <proto/freq_ctr.h> |
Willy Tarreau | 3041b9f | 2010-10-15 23:25:20 +0200 | [diff] [blame] | 32 | #include <proto/frontend.h> |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 33 | #include <proto/hdr_idx.h> |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 34 | #include <proto/log.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 35 | #include <proto/session.h> |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 36 | #include <proto/pipe.h> |
Willy Tarreau | 6279371 | 2011-07-24 19:23:38 +0200 | [diff] [blame] | 37 | #include <proto/protocols.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 38 | #include <proto/proto_http.h> |
| 39 | #include <proto/proto_tcp.h> |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 40 | #include <proto/proxy.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 41 | #include <proto/queue.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 42 | #include <proto/server.h> |
Willy Tarreau | cd3b094 | 2012-04-27 21:52:18 +0200 | [diff] [blame] | 43 | #include <proto/sample.h> |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 44 | #include <proto/stick_table.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 45 | #include <proto/stream_interface.h> |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 46 | #include <proto/task.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 47 | |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 48 | struct pool_head *pool2_session; |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 49 | struct list sessions; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 50 | |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 51 | static struct task *expire_mini_session(struct task *t); |
| 52 | int session_complete(struct session *s); |
| 53 | |
| 54 | /* This function is called from the protocol layer accept() in order to |
| 55 | * instanciate a new embryonic session on behalf of a given listener and |
| 56 | * frontend. It returns a positive value upon success, 0 if the connection |
| 57 | * can be ignored, or a negative value upon critical failure. The accepted |
| 58 | * file descriptor is closed if we return <= 0. |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 59 | */ |
| 60 | int session_accept(struct listener *l, int cfd, struct sockaddr_storage *addr) |
| 61 | { |
| 62 | struct proxy *p = l->frontend; |
| 63 | struct session *s; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 64 | struct task *t; |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 65 | int ret; |
| 66 | |
| 67 | |
| 68 | ret = -1; /* assume unrecoverable error by default */ |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 69 | |
Willy Tarreau | fffe132 | 2010-11-11 09:48:16 +0100 | [diff] [blame] | 70 | if (unlikely((s = pool_alloc2(pool2_session)) == NULL)) |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 71 | goto out_close; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 72 | |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 73 | /* minimum session initialization required for an embryonic session is |
| 74 | * fairly low. We need very little to execute L4 ACLs, then we need a |
| 75 | * task to make the client-side connection live on its own. |
| 76 | * - flags |
| 77 | * - stick-entry tracking |
| 78 | */ |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 79 | s->flags = 0; |
| 80 | s->logs.logwait = p->to_log; |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 81 | s->stkctr1_entry = NULL; |
| 82 | s->stkctr2_entry = NULL; |
| 83 | s->stkctr1_table = NULL; |
| 84 | s->stkctr2_table = NULL; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 85 | |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 86 | s->listener = l; |
| 87 | s->fe = p; |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 88 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 89 | /* OK, we're keeping the session, so let's properly initialize the session */ |
Willy Tarreau | 96596ae | 2012-06-08 22:57:36 +0200 | [diff] [blame] | 90 | s->si[0].conn.t.sock.fd = cfd; |
| 91 | s->si[0].conn.ctrl = l->proto; |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 92 | s->si[0].conn.flags = CO_FL_NONE; |
Willy Tarreau | 986a9d2 | 2012-08-30 21:11:38 +0200 | [diff] [blame] | 93 | s->si[0].conn.addr.from = *addr; |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 94 | set_target_client(&s->si[0].conn.target, l); |
| 95 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 96 | s->logs.accept_date = date; /* user-visible date for logging */ |
| 97 | s->logs.tv_accept = now; /* corrected date for internal use */ |
| 98 | s->uniq_id = totalconn; |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 99 | p->feconn++; |
| 100 | /* This session was accepted, count it now */ |
| 101 | if (p->feconn > p->fe_counters.conn_max) |
| 102 | p->fe_counters.conn_max = p->feconn; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 103 | |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 104 | proxy_inc_fe_conn_ctr(l, p); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 105 | |
Willy Tarreau | fe7f1ea | 2012-05-20 19:22:25 +0200 | [diff] [blame] | 106 | /* if this session comes from a known monitoring system, we want to ignore |
| 107 | * it as soon as possible, which means closing it immediately for TCP, but |
| 108 | * cleanly. |
| 109 | */ |
| 110 | if (unlikely((l->options & LI_O_CHK_MONNET) && |
| 111 | addr->ss_family == AF_INET && |
| 112 | (((struct sockaddr_in *)addr)->sin_addr.s_addr & p->mon_mask.s_addr) == p->mon_net.s_addr)) { |
| 113 | s->flags |= SN_MONITOR; |
| 114 | s->logs.logwait = 0; |
| 115 | } |
| 116 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 117 | /* now evaluate the tcp-request layer4 rules. Since we expect to be able |
| 118 | * to abort right here as soon as possible, we check the rules before |
| 119 | * even initializing the stream interfaces. |
| 120 | */ |
| 121 | if ((l->options & LI_O_TCP_RULES) && !tcp_exec_req_rules(s)) { |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 122 | /* let's do a no-linger now to close with a single RST. */ |
| 123 | setsockopt(cfd, SOL_SOCKET, SO_LINGER, (struct linger *) &nolinger, sizeof(struct linger)); |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 124 | ret = 0; /* successful termination */ |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 125 | goto out_free_session; |
| 126 | } |
| 127 | |
Willy Tarreau | 22cda21 | 2012-08-31 17:43:29 +0200 | [diff] [blame] | 128 | /* wait for a PROXY protocol header */ |
| 129 | if (l->options & LI_O_ACC_PROXY) { |
| 130 | s->si[0].conn.flags |= CO_FL_ACCEPT_PROXY; |
| 131 | conn_sock_want_recv(&s->si[0].conn); |
| 132 | } |
| 133 | |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 134 | /* Adjust some socket options */ |
| 135 | if (unlikely(fcntl(cfd, F_SETFL, O_NONBLOCK) == -1)) |
| 136 | goto out_free_session; |
| 137 | |
| 138 | if (unlikely((t = task_new()) == NULL)) |
| 139 | goto out_free_session; |
| 140 | |
| 141 | t->context = s; |
| 142 | t->nice = l->nice; |
| 143 | s->task = t; |
| 144 | |
| 145 | /* add the various callbacks. Right now the data layer is present but |
| 146 | * not initialized. Also note we need to be careful as the stream int |
| 147 | * is not initialized yet. |
| 148 | */ |
| 149 | si_prepare_conn(&s->si[0], l->proto, l->data); |
| 150 | |
| 151 | /* finish initialization of the accepted file descriptor */ |
| 152 | fd_insert(cfd); |
| 153 | fdtab[cfd].owner = &s->si[0].conn; |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 154 | fdtab[cfd].iocb = conn_fd_handler; |
| 155 | conn_data_want_recv(&s->si[0].conn); |
| 156 | if (conn_data_init(&s->si[0].conn) < 0) |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 157 | goto out_free_task; |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 158 | |
| 159 | /* OK, now either we have a pending handshake to execute with and |
| 160 | * then we must return to the I/O layer, or we can proceed with the |
| 161 | * end of the session initialization. In case of handshake, we also |
| 162 | * set the I/O timeout to the frontend's client timeout. |
| 163 | */ |
| 164 | |
| 165 | if (s->si[0].conn.flags & CO_FL_HANDSHAKE) { |
| 166 | t->process = expire_mini_session; |
| 167 | t->expire = tick_add_ifset(now_ms, p->timeout.client); |
| 168 | task_queue(t); |
| 169 | s->si[0].conn.flags |= CO_FL_INIT_SESS; |
| 170 | return 1; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 173 | /* OK let's complete session initialization */ |
| 174 | ret = session_complete(s); |
| 175 | if (ret > 0) |
| 176 | return ret; |
| 177 | |
| 178 | /* Error unrolling */ |
| 179 | out_free_task: |
| 180 | task_free(t); |
| 181 | out_free_session: |
| 182 | p->feconn--; |
| 183 | if (s->stkctr1_entry || s->stkctr2_entry) |
| 184 | session_store_counters(s); |
| 185 | pool_free2(pool2_session, s); |
| 186 | out_close: |
| 187 | if (ret < 0 && p->mode == PR_MODE_HTTP) { |
| 188 | /* critical error, no more memory, try to emit a 500 response */ |
| 189 | struct chunk *err_msg = error_message(s, HTTP_ERR_500); |
| 190 | send(cfd, err_msg->str, err_msg->len, MSG_DONTWAIT|MSG_NOSIGNAL); |
| 191 | } |
| 192 | |
| 193 | if (fdtab[cfd].owner) |
| 194 | fd_delete(cfd); |
| 195 | else |
| 196 | close(cfd); |
| 197 | return ret; |
| 198 | } |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 199 | |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 200 | /* This function kills an existing embryonic session. It stops the connection's |
| 201 | * data layer, releases assigned resources, resumes the listener if it was |
| 202 | * disabled and finally kills the file descriptor. |
| 203 | */ |
| 204 | static void kill_mini_session(struct session *s) |
| 205 | { |
| 206 | /* kill the connection now */ |
| 207 | conn_data_close(&s->si[0].conn); |
| 208 | |
| 209 | s->fe->feconn--; |
| 210 | if (s->stkctr1_entry || s->stkctr2_entry) |
| 211 | session_store_counters(s); |
| 212 | |
| 213 | if (!(s->listener->options & LI_O_UNLIMITED)) |
| 214 | actconn--; |
| 215 | jobs--; |
| 216 | s->listener->nbconn--; |
| 217 | if (s->listener->state == LI_FULL) |
| 218 | resume_listener(s->listener); |
| 219 | |
| 220 | /* Dequeues all of the listeners waiting for a resource */ |
| 221 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 222 | dequeue_all_listeners(&global_listener_queue); |
| 223 | |
| 224 | if (!LIST_ISEMPTY(&s->fe->listener_queue) && |
| 225 | (!s->fe->fe_sps_lim || freq_ctr_remain(&s->fe->fe_sess_per_sec, s->fe->fe_sps_lim, 0) > 0)) |
| 226 | dequeue_all_listeners(&s->fe->listener_queue); |
| 227 | |
| 228 | task_delete(s->task); |
| 229 | task_free(s->task); |
| 230 | |
| 231 | if (fdtab[s->si[0].conn.t.sock.fd].owner) |
| 232 | fd_delete(s->si[0].conn.t.sock.fd); |
| 233 | else |
| 234 | close(s->si[0].conn.t.sock.fd); |
| 235 | |
| 236 | pool_free2(pool2_session, s); |
| 237 | } |
| 238 | |
Willy Tarreau | 22cda21 | 2012-08-31 17:43:29 +0200 | [diff] [blame] | 239 | /* Finish initializing a session from a connection, or kills it if the |
| 240 | * connection shows and error. Returns <0 if the connection was killed. |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 241 | */ |
Willy Tarreau | 22cda21 | 2012-08-31 17:43:29 +0200 | [diff] [blame] | 242 | int conn_session_complete(struct connection *conn, int flag) |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 243 | { |
| 244 | struct session *s = container_of(conn, struct session, si[0].conn); |
| 245 | |
Willy Tarreau | 22cda21 | 2012-08-31 17:43:29 +0200 | [diff] [blame] | 246 | if (!(conn->flags & CO_FL_ERROR) && (session_complete(s) > 0)) { |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 247 | conn->flags &= ~flag; |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | /* kill the connection now */ |
| 252 | kill_mini_session(s); |
| 253 | return -1; |
| 254 | } |
| 255 | |
| 256 | /* Manages embryonic sessions timeout. It is only called when the timeout |
| 257 | * strikes and performs the required cleanup. |
| 258 | */ |
| 259 | static struct task *expire_mini_session(struct task *t) |
| 260 | { |
| 261 | struct session *s = t->context; |
| 262 | |
| 263 | if (!(t->state & TASK_WOKEN_TIMER)) |
| 264 | return t; |
| 265 | |
| 266 | kill_mini_session(s); |
| 267 | return NULL; |
| 268 | } |
| 269 | |
| 270 | /* This function is called from the I/O handler which detects the end of |
| 271 | * handshake, in order to complete initialization of a valid session. It must |
| 272 | * be called with an embryonic session. It returns a positive value upon |
| 273 | * success, 0 if the connection can be ignored, or a negative value upon |
| 274 | * critical failure. The accepted file descriptor is closed if we return <= 0. |
| 275 | */ |
| 276 | int session_complete(struct session *s) |
| 277 | { |
| 278 | struct listener *l = s->listener; |
| 279 | struct proxy *p = s->fe; |
| 280 | struct http_txn *txn; |
| 281 | struct task *t = s->task; |
| 282 | int ret; |
| 283 | |
| 284 | ret = -1; /* assume unrecoverable error by default */ |
| 285 | |
| 286 | /* OK, we're keeping the session, so let's properly initialize the session */ |
| 287 | LIST_ADDQ(&sessions, &s->list); |
| 288 | LIST_INIT(&s->back_refs); |
| 289 | s->flags |= SN_INITIALIZED; |
| 290 | |
| 291 | s->unique_id = NULL; |
| 292 | s->term_trace = 0; |
| 293 | |
| 294 | t->process = l->handler; |
| 295 | t->context = s; |
| 296 | t->expire = TICK_ETERNITY; |
| 297 | |
| 298 | /* Note: initially, the session's backend points to the frontend. |
| 299 | * This changes later when switching rules are executed or |
| 300 | * when the default backend is assigned. |
| 301 | */ |
| 302 | s->be = s->fe; |
| 303 | s->req = s->rep = NULL; /* will be allocated later */ |
| 304 | |
| 305 | /* Let's count a session now */ |
Willy Tarreau | b36b424 | 2010-06-04 20:59:39 +0200 | [diff] [blame] | 306 | proxy_inc_fe_sess_ctr(l, p); |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 307 | if (s->stkctr1_entry) { |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 308 | void *ptr; |
| 309 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 310 | ptr = stktable_data_ptr(s->stkctr1_table, s->stkctr1_entry, STKTABLE_DT_SESS_CNT); |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 311 | if (ptr) |
| 312 | stktable_data_cast(ptr, sess_cnt)++; |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 313 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 314 | ptr = stktable_data_ptr(s->stkctr1_table, s->stkctr1_entry, STKTABLE_DT_SESS_RATE); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 315 | if (ptr) |
| 316 | update_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 317 | s->stkctr1_table->data_arg[STKTABLE_DT_SESS_RATE].u, 1); |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 318 | } |
Willy Tarreau | b36b424 | 2010-06-04 20:59:39 +0200 | [diff] [blame] | 319 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 320 | if (s->stkctr2_entry) { |
Willy Tarreau | 9e9879a | 2010-08-06 15:25:22 +0200 | [diff] [blame] | 321 | void *ptr; |
| 322 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 323 | ptr = stktable_data_ptr(s->stkctr2_table, s->stkctr2_entry, STKTABLE_DT_SESS_CNT); |
Willy Tarreau | 9e9879a | 2010-08-06 15:25:22 +0200 | [diff] [blame] | 324 | if (ptr) |
| 325 | stktable_data_cast(ptr, sess_cnt)++; |
| 326 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 327 | ptr = stktable_data_ptr(s->stkctr2_table, s->stkctr2_entry, STKTABLE_DT_SESS_RATE); |
Willy Tarreau | 9e9879a | 2010-08-06 15:25:22 +0200 | [diff] [blame] | 328 | if (ptr) |
| 329 | update_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 330 | s->stkctr2_table->data_arg[STKTABLE_DT_SESS_RATE].u, 1); |
Willy Tarreau | 9e9879a | 2010-08-06 15:25:22 +0200 | [diff] [blame] | 331 | } |
| 332 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 333 | /* this part should be common with other protocols */ |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 334 | s->si[0].owner = t; |
| 335 | s->si[0].state = s->si[0].prev_state = SI_ST_EST; |
| 336 | s->si[0].err_type = SI_ET_NONE; |
| 337 | s->si[0].err_loc = NULL; |
Willy Tarreau | 0bd05ea | 2010-07-02 11:18:03 +0200 | [diff] [blame] | 338 | s->si[0].release = NULL; |
Willy Tarreau | 63e7fe3 | 2012-05-08 15:20:43 +0200 | [diff] [blame] | 339 | s->si[0].send_proxy_ofs = 0; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 340 | s->si[0].exp = TICK_ETERNITY; |
| 341 | s->si[0].flags = SI_FL_NONE; |
| 342 | |
| 343 | if (likely(s->fe->options2 & PR_O2_INDEPSTR)) |
| 344 | s->si[0].flags |= SI_FL_INDEP_STR; |
| 345 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 346 | /* pre-initialize the other side's stream interface to an INIT state. The |
| 347 | * callbacks will be initialized before attempting to connect. |
| 348 | */ |
Willy Tarreau | fb7508a | 2012-05-21 16:47:54 +0200 | [diff] [blame] | 349 | s->si[1].conn.t.sock.fd = -1; /* just to help with debugging */ |
Willy Tarreau | 505e34a | 2012-07-06 10:17:53 +0200 | [diff] [blame] | 350 | s->si[1].conn.flags = CO_FL_NONE; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 351 | s->si[1].owner = t; |
| 352 | s->si[1].state = s->si[1].prev_state = SI_ST_INI; |
| 353 | s->si[1].err_type = SI_ET_NONE; |
Willy Tarreau | 0b3a411 | 2011-03-27 19:16:56 +0200 | [diff] [blame] | 354 | s->si[1].conn_retries = 0; /* used for logging too */ |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 355 | s->si[1].err_loc = NULL; |
Willy Tarreau | 0bd05ea | 2010-07-02 11:18:03 +0200 | [diff] [blame] | 356 | s->si[1].release = NULL; |
Willy Tarreau | 63e7fe3 | 2012-05-08 15:20:43 +0200 | [diff] [blame] | 357 | s->si[1].send_proxy_ofs = 0; |
Willy Tarreau | 3cefd52 | 2012-08-30 15:49:18 +0200 | [diff] [blame] | 358 | clear_target(&s->si[1].conn.target); |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 359 | si_prepare_embedded(&s->si[1]); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 360 | s->si[1].exp = TICK_ETERNITY; |
| 361 | s->si[1].flags = SI_FL_NONE; |
| 362 | |
| 363 | if (likely(s->fe->options2 & PR_O2_INDEPSTR)) |
| 364 | s->si[1].flags |= SI_FL_INDEP_STR; |
| 365 | |
Willy Tarreau | 9bd0d74 | 2011-07-20 00:17:39 +0200 | [diff] [blame] | 366 | session_init_srv_conn(s); |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 367 | clear_target(&s->target); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 368 | s->pend_pos = NULL; |
| 369 | |
| 370 | /* init store persistence */ |
| 371 | s->store_count = 0; |
| 372 | |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 373 | if (unlikely((s->req = pool_alloc2(pool2_channel)) == NULL)) |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 374 | goto out_free_task; /* no memory */ |
| 375 | |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 376 | if (unlikely((s->rep = pool_alloc2(pool2_channel)) == NULL)) |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 377 | goto out_free_req; /* no memory */ |
| 378 | |
| 379 | /* initialize the request buffer */ |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 380 | s->req->buf.size = global.tune.bufsize; |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 381 | channel_init(s->req); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 382 | s->req->prod = &s->si[0]; |
| 383 | s->req->cons = &s->si[1]; |
| 384 | s->si[0].ib = s->si[1].ob = s->req; |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 385 | s->req->flags |= CF_READ_ATTACHED; /* the producer is already connected */ |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 386 | |
| 387 | /* activate default analysers enabled for this listener */ |
| 388 | s->req->analysers = l->analysers; |
| 389 | |
| 390 | s->req->wto = TICK_ETERNITY; |
| 391 | s->req->rto = TICK_ETERNITY; |
| 392 | s->req->rex = TICK_ETERNITY; |
| 393 | s->req->wex = TICK_ETERNITY; |
| 394 | s->req->analyse_exp = TICK_ETERNITY; |
| 395 | |
| 396 | /* initialize response buffer */ |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 397 | s->rep->buf.size = global.tune.bufsize; |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 398 | channel_init(s->rep); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 399 | s->rep->prod = &s->si[1]; |
| 400 | s->rep->cons = &s->si[0]; |
| 401 | s->si[0].ob = s->si[1].ib = s->rep; |
| 402 | s->rep->analysers = 0; |
| 403 | |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 404 | if (s->fe->options2 & PR_O2_NODELAY) { |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 405 | s->req->flags |= CF_NEVER_WAIT; |
| 406 | s->rep->flags |= CF_NEVER_WAIT; |
Willy Tarreau | 96e3121 | 2011-05-30 18:10:30 +0200 | [diff] [blame] | 407 | } |
| 408 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 409 | s->rep->rto = TICK_ETERNITY; |
| 410 | s->rep->wto = TICK_ETERNITY; |
| 411 | s->rep->rex = TICK_ETERNITY; |
| 412 | s->rep->wex = TICK_ETERNITY; |
| 413 | s->rep->analyse_exp = TICK_ETERNITY; |
| 414 | |
Willy Tarreau | 62f791e | 2012-03-09 11:32:30 +0100 | [diff] [blame] | 415 | txn = &s->txn; |
| 416 | /* Those variables will be checked and freed if non-NULL in |
| 417 | * session.c:session_free(). It is important that they are |
| 418 | * properly initialized. |
| 419 | */ |
| 420 | txn->sessid = NULL; |
| 421 | txn->srv_cookie = NULL; |
| 422 | txn->cli_cookie = NULL; |
| 423 | txn->uri = NULL; |
| 424 | txn->req.cap = NULL; |
| 425 | txn->rsp.cap = NULL; |
| 426 | txn->hdr_idx.v = NULL; |
| 427 | txn->hdr_idx.size = txn->hdr_idx.used = 0; |
| 428 | txn->req.flags = 0; |
| 429 | txn->rsp.flags = 0; |
| 430 | /* the HTTP messages need to know what buffer they're associated with */ |
| 431 | txn->req.buf = s->req; |
| 432 | txn->rsp.buf = s->rep; |
| 433 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 434 | /* finish initialization of the accepted file descriptor */ |
Willy Tarreau | f9dabec | 2012-08-17 17:33:53 +0200 | [diff] [blame] | 435 | conn_data_want_recv(&s->si[0].conn); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 436 | |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 437 | if (p->accept && (ret = p->accept(s)) <= 0) { |
| 438 | /* Either we had an unrecoverable error (<0) or work is |
| 439 | * finished (=0, eg: monitoring), in both situations, |
| 440 | * we can release everything and close. |
| 441 | */ |
| 442 | goto out_free_rep; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 443 | } |
| 444 | |
Willy Tarreau | 2542b53 | 2012-08-31 16:01:23 +0200 | [diff] [blame] | 445 | /* we want the connection handler to notify the stream interface about updates. */ |
| 446 | s->si[0].conn.flags |= CO_FL_NOTIFY_SI; |
| 447 | |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 448 | /* it is important not to call the wakeup function directly but to |
| 449 | * pass through task_wakeup(), because this one knows how to apply |
| 450 | * priorities to tasks. |
| 451 | */ |
| 452 | task_wakeup(t, TASK_WOKEN_INIT); |
| 453 | return 1; |
| 454 | |
| 455 | /* Error unrolling */ |
| 456 | out_free_rep: |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 457 | pool_free2(pool2_channel, s->rep); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 458 | out_free_req: |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 459 | pool_free2(pool2_channel, s->req); |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 460 | out_free_task: |
Willy Tarreau | abe8ea5 | 2010-11-11 10:56:04 +0100 | [diff] [blame] | 461 | return ret; |
Willy Tarreau | 81f9aa3 | 2010-06-01 17:45:26 +0200 | [diff] [blame] | 462 | } |
| 463 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 464 | /* |
| 465 | * frees the context associated to a session. It must have been removed first. |
| 466 | */ |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 467 | static void session_free(struct session *s) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 468 | { |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 469 | struct http_txn *txn = &s->txn; |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 470 | struct proxy *fe = s->fe; |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 471 | struct bref *bref, *back; |
Willy Tarreau | a4cda67 | 2010-06-06 18:28:49 +0200 | [diff] [blame] | 472 | int i; |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 473 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 474 | if (s->pend_pos) |
| 475 | pendconn_free(s->pend_pos); |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 476 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 477 | if (target_srv(&s->target)) { /* there may be requests left pending in queue */ |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 478 | if (s->flags & SN_CURR_SESS) { |
| 479 | s->flags &= ~SN_CURR_SESS; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 480 | target_srv(&s->target)->cur_sess--; |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 481 | } |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 482 | if (may_dequeue_tasks(target_srv(&s->target), s->be)) |
| 483 | process_srv_queue(target_srv(&s->target)); |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 484 | } |
Willy Tarreau | 922a806 | 2008-12-04 09:33:58 +0100 | [diff] [blame] | 485 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 486 | if (unlikely(s->srv_conn)) { |
| 487 | /* the session still has a reserved slot on a server, but |
| 488 | * it should normally be only the same as the one above, |
| 489 | * so this should not happen in fact. |
| 490 | */ |
| 491 | sess_change_server(s, NULL); |
| 492 | } |
| 493 | |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 494 | if (s->req->pipe) |
| 495 | put_pipe(s->req->pipe); |
Willy Tarreau | 259de1b | 2009-01-18 21:56:21 +0100 | [diff] [blame] | 496 | |
Willy Tarreau | 3eba98a | 2009-01-25 13:56:13 +0100 | [diff] [blame] | 497 | if (s->rep->pipe) |
| 498 | put_pipe(s->rep->pipe); |
Willy Tarreau | 259de1b | 2009-01-18 21:56:21 +0100 | [diff] [blame] | 499 | |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 500 | pool_free2(pool2_channel, s->req); |
| 501 | pool_free2(pool2_channel, s->rep); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 502 | |
Willy Tarreau | 4602363 | 2010-01-07 22:51:47 +0100 | [diff] [blame] | 503 | http_end_txn(s); |
| 504 | |
Willy Tarreau | a4cda67 | 2010-06-06 18:28:49 +0200 | [diff] [blame] | 505 | for (i = 0; i < s->store_count; i++) { |
| 506 | if (!s->store[i].ts) |
| 507 | continue; |
| 508 | stksess_free(s->store[i].table, s->store[i].ts); |
| 509 | s->store[i].ts = NULL; |
| 510 | } |
| 511 | |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 512 | pool_free2(pool2_hdr_idx, txn->hdr_idx.v); |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 513 | if (fe) { |
Willy Tarreau | 4602363 | 2010-01-07 22:51:47 +0100 | [diff] [blame] | 514 | pool_free2(fe->rsp_cap_pool, txn->rsp.cap); |
| 515 | pool_free2(fe->req_cap_pool, txn->req.cap); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 516 | } |
Willy Tarreau | 0937bc4 | 2009-12-22 15:03:09 +0100 | [diff] [blame] | 517 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 518 | if (s->stkctr1_entry || s->stkctr2_entry) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 519 | session_store_counters(s); |
| 520 | |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 521 | list_for_each_entry_safe(bref, back, &s->back_refs, users) { |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 522 | /* we have to unlink all watchers. We must not relink them if |
| 523 | * this session was the last one in the list. |
| 524 | */ |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 525 | LIST_DEL(&bref->users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 526 | LIST_INIT(&bref->users); |
| 527 | if (s->list.n != &sessions) |
| 528 | LIST_ADDQ(&LIST_ELEM(s->list.n, struct session *, list)->back_refs, &bref->users); |
Willy Tarreau | 62e4f1d | 2008-12-07 20:16:23 +0100 | [diff] [blame] | 529 | bref->ref = s->list.n; |
| 530 | } |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 531 | LIST_DEL(&s->list); |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 532 | pool_free2(pool2_session, s); |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 533 | |
| 534 | /* We may want to free the maximum amount of pools if the proxy is stopping */ |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 535 | if (fe && unlikely(fe->state == PR_STSTOPPED)) { |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 536 | pool_flush2(pool2_channel); |
Willy Tarreau | 34eb671 | 2011-10-24 18:15:04 +0200 | [diff] [blame] | 537 | pool_flush2(pool2_hdr_idx); |
Willy Tarreau | 48d63db | 2008-08-03 17:41:33 +0200 | [diff] [blame] | 538 | pool_flush2(pool2_requri); |
| 539 | pool_flush2(pool2_capture); |
| 540 | pool_flush2(pool2_session); |
| 541 | pool_flush2(fe->req_cap_pool); |
| 542 | pool_flush2(fe->rsp_cap_pool); |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 543 | } |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | |
| 547 | /* perform minimal intializations, report 0 in case of error, 1 if OK. */ |
| 548 | int init_session() |
| 549 | { |
Willy Tarreau | f54f8bd | 2008-11-23 19:53:55 +0100 | [diff] [blame] | 550 | LIST_INIT(&sessions); |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 551 | pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED); |
| 552 | return pool2_session != NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 553 | } |
| 554 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 555 | void session_process_counters(struct session *s) |
| 556 | { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 557 | unsigned long long bytes; |
| 558 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 559 | if (s->req) { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 560 | bytes = s->req->total - s->logs.bytes_in; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 561 | s->logs.bytes_in = s->req->total; |
| 562 | if (bytes) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 563 | s->fe->fe_counters.bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 564 | |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 565 | s->be->be_counters.bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 566 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 567 | if (target_srv(&s->target)) |
| 568 | target_srv(&s->target)->counters.bytes_in += bytes; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 569 | |
| 570 | if (s->listener->counters) |
| 571 | s->listener->counters->bytes_in += bytes; |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 572 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 573 | if (s->stkctr2_entry) { |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 574 | void *ptr; |
| 575 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 576 | ptr = stktable_data_ptr(s->stkctr2_table, |
| 577 | s->stkctr2_entry, |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 578 | STKTABLE_DT_BYTES_IN_CNT); |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 579 | if (ptr) |
| 580 | stktable_data_cast(ptr, bytes_in_cnt) += bytes; |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 581 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 582 | ptr = stktable_data_ptr(s->stkctr2_table, |
| 583 | s->stkctr2_entry, |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 584 | STKTABLE_DT_BYTES_IN_RATE); |
| 585 | if (ptr) |
| 586 | update_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 587 | s->stkctr2_table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u, bytes); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 588 | } |
| 589 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 590 | if (s->stkctr1_entry) { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 591 | void *ptr; |
| 592 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 593 | ptr = stktable_data_ptr(s->stkctr1_table, |
| 594 | s->stkctr1_entry, |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 595 | STKTABLE_DT_BYTES_IN_CNT); |
| 596 | if (ptr) |
| 597 | stktable_data_cast(ptr, bytes_in_cnt) += bytes; |
| 598 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 599 | ptr = stktable_data_ptr(s->stkctr1_table, |
| 600 | s->stkctr1_entry, |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 601 | STKTABLE_DT_BYTES_IN_RATE); |
| 602 | if (ptr) |
| 603 | update_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 604 | s->stkctr1_table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u, bytes); |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 605 | } |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 606 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 607 | } |
| 608 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 609 | if (s->rep) { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 610 | bytes = s->rep->total - s->logs.bytes_out; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 611 | s->logs.bytes_out = s->rep->total; |
| 612 | if (bytes) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 613 | s->fe->fe_counters.bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 614 | |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 615 | s->be->be_counters.bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 616 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 617 | if (target_srv(&s->target)) |
| 618 | target_srv(&s->target)->counters.bytes_out += bytes; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 619 | |
| 620 | if (s->listener->counters) |
| 621 | s->listener->counters->bytes_out += bytes; |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 622 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 623 | if (s->stkctr2_entry) { |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 624 | void *ptr; |
| 625 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 626 | ptr = stktable_data_ptr(s->stkctr2_table, |
| 627 | s->stkctr2_entry, |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 628 | STKTABLE_DT_BYTES_OUT_CNT); |
| 629 | if (ptr) |
| 630 | stktable_data_cast(ptr, bytes_out_cnt) += bytes; |
| 631 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 632 | ptr = stktable_data_ptr(s->stkctr2_table, |
| 633 | s->stkctr2_entry, |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 634 | STKTABLE_DT_BYTES_OUT_RATE); |
| 635 | if (ptr) |
| 636 | update_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 637 | s->stkctr2_table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u, bytes); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 638 | } |
| 639 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 640 | if (s->stkctr1_entry) { |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 641 | void *ptr; |
| 642 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 643 | ptr = stktable_data_ptr(s->stkctr1_table, |
| 644 | s->stkctr1_entry, |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 645 | STKTABLE_DT_BYTES_OUT_CNT); |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 646 | if (ptr) |
| 647 | stktable_data_cast(ptr, bytes_out_cnt) += bytes; |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 648 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 649 | ptr = stktable_data_ptr(s->stkctr1_table, |
| 650 | s->stkctr1_entry, |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 651 | STKTABLE_DT_BYTES_OUT_RATE); |
| 652 | if (ptr) |
| 653 | update_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 654 | s->stkctr1_table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u, bytes); |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 655 | } |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 656 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 657 | } |
| 658 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 659 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 660 | /* This function is called with (si->state == SI_ST_CON) meaning that a |
| 661 | * connection was attempted and that the file descriptor is already allocated. |
| 662 | * We must check for establishment, error and abort. Possible output states |
| 663 | * are SI_ST_EST (established), SI_ST_CER (error), SI_ST_DIS (abort), and |
| 664 | * SI_ST_CON (no change). The function returns 0 if it switches to SI_ST_CER, |
| 665 | * otherwise 1. |
| 666 | */ |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 667 | static int sess_update_st_con_tcp(struct session *s, struct stream_interface *si) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 668 | { |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 669 | struct channel *req = si->ob; |
| 670 | struct channel *rep = si->ib; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 671 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 672 | /* If we got an error, or if nothing happened and the connection timed |
| 673 | * out, we must give up. The CER state handler will take care of retry |
| 674 | * attempts and error reports. |
| 675 | */ |
| 676 | if (unlikely(si->flags & (SI_FL_EXP|SI_FL_ERR))) { |
Willy Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 677 | si->exp = TICK_ETERNITY; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 678 | si->state = SI_ST_CER; |
Willy Tarreau | fb7508a | 2012-05-21 16:47:54 +0200 | [diff] [blame] | 679 | fd_delete(si_fd(si)); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 680 | |
Willy Tarreau | 8b11708 | 2012-08-06 15:06:49 +0200 | [diff] [blame] | 681 | conn_data_close(&si->conn); |
Willy Tarreau | 0bd05ea | 2010-07-02 11:18:03 +0200 | [diff] [blame] | 682 | if (si->release) |
| 683 | si->release(si); |
| 684 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 685 | if (si->err_type) |
| 686 | return 0; |
| 687 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 688 | si->err_loc = target_srv(&s->target); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 689 | if (si->flags & SI_FL_ERR) |
| 690 | si->err_type = SI_ET_CONN_ERR; |
| 691 | else |
| 692 | si->err_type = SI_ET_CONN_TO; |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | /* OK, maybe we want to abort */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 697 | if (unlikely((rep->flags & CF_SHUTW) || |
| 698 | ((req->flags & CF_SHUTW_NOW) && /* FIXME: this should not prevent a connection from establishing */ |
| 699 | ((!(req->flags & CF_WRITE_ACTIVITY) && channel_is_empty(req)) || |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 700 | s->be->options & PR_O_ABRT_CLOSE)))) { |
| 701 | /* give up */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 702 | si_shutw(si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 703 | si->err_type |= SI_ET_CONN_ABRT; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 704 | si->err_loc = target_srv(&s->target); |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 705 | if (s->srv_error) |
| 706 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 707 | return 1; |
| 708 | } |
| 709 | |
| 710 | /* we need to wait a bit more if there was no activity either */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 711 | if (!(req->flags & CF_WRITE_ACTIVITY)) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 712 | return 1; |
| 713 | |
| 714 | /* OK, this means that a connection succeeded. The caller will be |
| 715 | * responsible for handling the transition from CON to EST. |
| 716 | */ |
| 717 | s->logs.t_connect = tv_ms_elapsed(&s->logs.tv_accept, &now); |
Willy Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 718 | si->exp = TICK_ETERNITY; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 719 | si->state = SI_ST_EST; |
| 720 | si->err_type = SI_ET_NONE; |
| 721 | si->err_loc = NULL; |
| 722 | return 1; |
| 723 | } |
| 724 | |
| 725 | /* This function is called with (si->state == SI_ST_CER) meaning that a |
| 726 | * previous connection attempt has failed and that the file descriptor |
| 727 | * has already been released. Possible causes include asynchronous error |
| 728 | * notification and time out. Possible output states are SI_ST_CLO when |
| 729 | * retries are exhausted, SI_ST_TAR when a delay is wanted before a new |
| 730 | * connection attempt, SI_ST_ASS when it's wise to retry on the same server, |
| 731 | * and SI_ST_REQ when an immediate redispatch is wanted. The buffers are |
| 732 | * marked as in error state. It returns 0. |
| 733 | */ |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 734 | static int sess_update_st_cer(struct session *s, struct stream_interface *si) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 735 | { |
| 736 | /* we probably have to release last session from the server */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 737 | if (target_srv(&s->target)) { |
| 738 | health_adjust(target_srv(&s->target), HANA_STATUS_L4_ERR); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 739 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 740 | if (s->flags & SN_CURR_SESS) { |
| 741 | s->flags &= ~SN_CURR_SESS; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 742 | target_srv(&s->target)->cur_sess--; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 743 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /* ensure that we have enough retries left */ |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 747 | si->conn_retries--; |
| 748 | if (si->conn_retries < 0) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 749 | if (!si->err_type) { |
| 750 | si->err_type = SI_ET_CONN_ERR; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 751 | si->err_loc = target_srv(&s->target); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 752 | } |
| 753 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 754 | if (target_srv(&s->target)) |
| 755 | target_srv(&s->target)->counters.failed_conns++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 756 | s->be->be_counters.failed_conns++; |
Willy Tarreau | b89cfca | 2010-12-29 14:32:28 +0100 | [diff] [blame] | 757 | sess_change_server(s, NULL); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 758 | if (may_dequeue_tasks(target_srv(&s->target), s->be)) |
| 759 | process_srv_queue(target_srv(&s->target)); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 760 | |
| 761 | /* shutw is enough so stop a connecting socket */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 762 | si_shutw(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 763 | si->ob->flags |= CF_WRITE_ERROR; |
| 764 | si->ib->flags |= CF_READ_ERROR; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 765 | |
| 766 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 767 | if (s->srv_error) |
| 768 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 769 | return 0; |
| 770 | } |
| 771 | |
| 772 | /* If the "redispatch" option is set on the backend, we are allowed to |
| 773 | * retry on another server for the last retry. In order to achieve this, |
| 774 | * we must mark the session unassigned, and eventually clear the DIRECT |
| 775 | * bit to ignore any persistence cookie. We won't count a retry nor a |
| 776 | * redispatch yet, because this will depend on what server is selected. |
| 777 | */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 778 | if (target_srv(&s->target) && si->conn_retries == 0 && |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 779 | s->be->options & PR_O_REDISP && !(s->flags & SN_FORCE_PRST)) { |
Willy Tarreau | b89cfca | 2010-12-29 14:32:28 +0100 | [diff] [blame] | 780 | sess_change_server(s, NULL); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 781 | if (may_dequeue_tasks(target_srv(&s->target), s->be)) |
| 782 | process_srv_queue(target_srv(&s->target)); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 783 | |
| 784 | s->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 785 | si->state = SI_ST_REQ; |
| 786 | } else { |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 787 | if (target_srv(&s->target)) |
| 788 | target_srv(&s->target)->counters.retries++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 789 | s->be->be_counters.retries++; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 790 | si->state = SI_ST_ASS; |
| 791 | } |
| 792 | |
| 793 | if (si->flags & SI_FL_ERR) { |
| 794 | /* The error was an asynchronous connection error, and we will |
| 795 | * likely have to retry connecting to the same server, most |
| 796 | * likely leading to the same result. To avoid this, we wait |
| 797 | * one second before retrying. |
| 798 | */ |
| 799 | |
| 800 | if (!si->err_type) |
| 801 | si->err_type = SI_ET_CONN_ERR; |
| 802 | |
| 803 | si->state = SI_ST_TAR; |
| 804 | si->exp = tick_add(now_ms, MS_TO_TICKS(1000)); |
| 805 | return 0; |
| 806 | } |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | /* |
| 811 | * This function handles the transition between the SI_ST_CON state and the |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 812 | * SI_ST_EST state. It must only be called after switching from SI_ST_CON (or |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 813 | * SI_ST_INI) to SI_ST_EST, but only when a ->proto is defined. |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 814 | */ |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 815 | static void sess_establish(struct session *s, struct stream_interface *si) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 816 | { |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 817 | struct channel *req = si->ob; |
| 818 | struct channel *rep = si->ib; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 819 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 820 | if (target_srv(&s->target)) |
| 821 | health_adjust(target_srv(&s->target), HANA_STATUS_L4_OK); |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 822 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 823 | if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 824 | /* if the user wants to log as soon as possible, without counting |
| 825 | * bytes from the server, then this is the right moment. */ |
| 826 | if (s->fe->to_log && !(s->logs.logwait & LW_BYTES)) { |
| 827 | s->logs.t_close = s->logs.t_connect; /* to get a valid end date */ |
Willy Tarreau | a5555ec | 2008-11-30 19:02:32 +0100 | [diff] [blame] | 828 | s->do_log(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 829 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 830 | } |
| 831 | else { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 832 | s->txn.rsp.msg_state = HTTP_MSG_RPBEFORE; |
| 833 | /* reset hdr_idx which was already initialized by the request. |
| 834 | * right now, the http parser does it. |
| 835 | * hdr_idx_init(&s->txn.hdr_idx); |
| 836 | */ |
| 837 | } |
| 838 | |
Willy Tarreau | 4e5b828 | 2009-08-16 22:57:50 +0200 | [diff] [blame] | 839 | rep->analysers |= s->fe->fe_rsp_ana | s->be->be_rsp_ana; |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 840 | rep->flags |= CF_READ_ATTACHED; /* producer is now attached */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 841 | if (si_ctrl(si)) { |
Willy Tarreau | d04e858 | 2010-05-31 12:31:35 +0200 | [diff] [blame] | 842 | /* real connections have timeouts */ |
| 843 | req->wto = s->be->timeout.server; |
| 844 | rep->rto = s->be->timeout.server; |
| 845 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 846 | req->wex = TICK_ETERNITY; |
| 847 | } |
| 848 | |
| 849 | /* Update stream interface status for input states SI_ST_ASS, SI_ST_QUE, SI_ST_TAR. |
| 850 | * Other input states are simply ignored. |
| 851 | * Possible output states are SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ, SI_ST_CON. |
| 852 | * Flags must have previously been updated for timeouts and other conditions. |
| 853 | */ |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 854 | static void sess_update_stream_int(struct session *s, struct stream_interface *si) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 855 | { |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 856 | struct server *srv = target_srv(&s->target); |
| 857 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 858 | DPRINTF(stderr,"[%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d\n", |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 859 | now_ms, __FUNCTION__, |
| 860 | s, |
| 861 | s->req, s->rep, |
| 862 | s->req->rex, s->rep->wex, |
| 863 | s->req->flags, s->rep->flags, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 864 | s->req->i, s->req->o, s->rep->i, s->rep->o, s->rep->cons->state, s->req->cons->state); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 865 | |
| 866 | if (si->state == SI_ST_ASS) { |
| 867 | /* Server assigned to connection request, we have to try to connect now */ |
| 868 | int conn_err; |
| 869 | |
| 870 | conn_err = connect_server(s); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 871 | srv = target_srv(&s->target); |
| 872 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 873 | if (conn_err == SN_ERR_NONE) { |
| 874 | /* state = SI_ST_CON now */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 875 | if (srv) |
| 876 | srv_inc_sess_ctr(srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 877 | return; |
| 878 | } |
| 879 | |
| 880 | /* We have received a synchronous error. We might have to |
| 881 | * abort, retry immediately or redispatch. |
| 882 | */ |
| 883 | if (conn_err == SN_ERR_INTERNAL) { |
| 884 | if (!si->err_type) { |
| 885 | si->err_type = SI_ET_CONN_OTHER; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 886 | si->err_loc = srv; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 887 | } |
| 888 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 889 | if (srv) |
| 890 | srv_inc_sess_ctr(srv); |
| 891 | if (srv) |
| 892 | srv->counters.failed_conns++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 893 | s->be->be_counters.failed_conns++; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 894 | |
| 895 | /* release other sessions waiting for this server */ |
Willy Tarreau | b89cfca | 2010-12-29 14:32:28 +0100 | [diff] [blame] | 896 | sess_change_server(s, NULL); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 897 | if (may_dequeue_tasks(srv, s->be)) |
| 898 | process_srv_queue(srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 899 | |
| 900 | /* Failed and not retryable. */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 901 | si_shutr(si); |
| 902 | si_shutw(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 903 | si->ob->flags |= CF_WRITE_ERROR; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 904 | |
| 905 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 906 | |
| 907 | /* no session was ever accounted for this server */ |
| 908 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 909 | if (s->srv_error) |
| 910 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 911 | return; |
| 912 | } |
| 913 | |
| 914 | /* We are facing a retryable error, but we don't want to run a |
| 915 | * turn-around now, as the problem is likely a source port |
| 916 | * allocation problem, so we want to retry now. |
| 917 | */ |
| 918 | si->state = SI_ST_CER; |
| 919 | si->flags &= ~SI_FL_ERR; |
| 920 | sess_update_st_cer(s, si); |
| 921 | /* now si->state is one of SI_ST_CLO, SI_ST_TAR, SI_ST_ASS, SI_ST_REQ */ |
| 922 | return; |
| 923 | } |
| 924 | else if (si->state == SI_ST_QUE) { |
| 925 | /* connection request was queued, check for any update */ |
| 926 | if (!s->pend_pos) { |
| 927 | /* The connection is not in the queue anymore. Either |
| 928 | * we have a server connection slot available and we |
| 929 | * go directly to the assigned state, or we need to |
| 930 | * load-balance first and go to the INI state. |
| 931 | */ |
| 932 | si->exp = TICK_ETERNITY; |
| 933 | if (unlikely(!(s->flags & SN_ASSIGNED))) |
| 934 | si->state = SI_ST_REQ; |
| 935 | else { |
| 936 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 937 | si->state = SI_ST_ASS; |
| 938 | } |
| 939 | return; |
| 940 | } |
| 941 | |
| 942 | /* Connection request still in queue... */ |
| 943 | if (si->flags & SI_FL_EXP) { |
| 944 | /* ... and timeout expired */ |
| 945 | si->exp = TICK_ETERNITY; |
| 946 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 947 | if (srv) |
| 948 | srv->counters.failed_conns++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 949 | s->be->be_counters.failed_conns++; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 950 | si_shutr(si); |
| 951 | si_shutw(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 952 | si->ob->flags |= CF_WRITE_TIMEOUT; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 953 | if (!si->err_type) |
| 954 | si->err_type = SI_ET_QUEUE_TO; |
| 955 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 956 | if (s->srv_error) |
| 957 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 958 | return; |
| 959 | } |
| 960 | |
| 961 | /* Connection remains in queue, check if we have to abort it */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 962 | if ((si->ob->flags & (CF_READ_ERROR)) || |
| 963 | ((si->ob->flags & CF_SHUTW_NOW) && /* empty and client aborted */ |
Willy Tarreau | 8e21bb9 | 2012-08-24 22:40:29 +0200 | [diff] [blame] | 964 | (channel_is_empty(si->ob) || s->be->options & PR_O_ABRT_CLOSE))) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 965 | /* give up */ |
| 966 | si->exp = TICK_ETERNITY; |
| 967 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 968 | si_shutr(si); |
| 969 | si_shutw(si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 970 | si->err_type |= SI_ET_QUEUE_ABRT; |
| 971 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 972 | if (s->srv_error) |
| 973 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 974 | return; |
| 975 | } |
| 976 | |
| 977 | /* Nothing changed */ |
| 978 | return; |
| 979 | } |
| 980 | else if (si->state == SI_ST_TAR) { |
| 981 | /* Connection request might be aborted */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 982 | if ((si->ob->flags & (CF_READ_ERROR)) || |
| 983 | ((si->ob->flags & CF_SHUTW_NOW) && /* empty and client aborted */ |
Willy Tarreau | 8e21bb9 | 2012-08-24 22:40:29 +0200 | [diff] [blame] | 984 | (channel_is_empty(si->ob) || s->be->options & PR_O_ABRT_CLOSE))) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 985 | /* give up */ |
| 986 | si->exp = TICK_ETERNITY; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 987 | si_shutr(si); |
| 988 | si_shutw(si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 989 | si->err_type |= SI_ET_CONN_ABRT; |
| 990 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 991 | if (s->srv_error) |
| 992 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 993 | return; |
| 994 | } |
| 995 | |
| 996 | if (!(si->flags & SI_FL_EXP)) |
| 997 | return; /* still in turn-around */ |
| 998 | |
| 999 | si->exp = TICK_ETERNITY; |
| 1000 | |
| 1001 | /* we keep trying on the same server as long as the session is |
| 1002 | * marked "assigned". |
| 1003 | * FIXME: Should we force a redispatch attempt when the server is down ? |
| 1004 | */ |
| 1005 | if (s->flags & SN_ASSIGNED) |
| 1006 | si->state = SI_ST_ASS; |
| 1007 | else |
| 1008 | si->state = SI_ST_REQ; |
| 1009 | return; |
| 1010 | } |
| 1011 | } |
| 1012 | |
Simon Horman | dec5be4 | 2011-06-08 09:19:07 +0900 | [diff] [blame] | 1013 | /* Set correct session termination flags in case no analyser has done it. It |
| 1014 | * also counts a failed request if the server state has not reached the request |
| 1015 | * stage. |
| 1016 | */ |
| 1017 | static void sess_set_term_flags(struct session *s) |
| 1018 | { |
| 1019 | if (!(s->flags & SN_FINST_MASK)) { |
| 1020 | if (s->si[1].state < SI_ST_REQ) { |
| 1021 | |
| 1022 | s->fe->fe_counters.failed_req++; |
| 1023 | if (s->listener->counters) |
| 1024 | s->listener->counters->failed_req++; |
| 1025 | |
| 1026 | s->flags |= SN_FINST_R; |
| 1027 | } |
| 1028 | else if (s->si[1].state == SI_ST_QUE) |
| 1029 | s->flags |= SN_FINST_Q; |
| 1030 | else if (s->si[1].state < SI_ST_EST) |
| 1031 | s->flags |= SN_FINST_C; |
| 1032 | else if (s->si[1].state == SI_ST_EST || s->si[1].prev_state == SI_ST_EST) |
| 1033 | s->flags |= SN_FINST_D; |
| 1034 | else |
| 1035 | s->flags |= SN_FINST_L; |
| 1036 | } |
| 1037 | } |
| 1038 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1039 | /* This function initiates a server connection request on a stream interface |
| 1040 | * already in SI_ST_REQ state. Upon success, the state goes to SI_ST_ASS, |
| 1041 | * indicating that a server has been assigned. It may also return SI_ST_QUE, |
| 1042 | * or SI_ST_CLO upon error. |
| 1043 | */ |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1044 | static void sess_prepare_conn_req(struct session *s, struct stream_interface *si) |
| 1045 | { |
| 1046 | DPRINTF(stderr,"[%u] %s: sess=%p rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d\n", |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1047 | now_ms, __FUNCTION__, |
| 1048 | s, |
| 1049 | s->req, s->rep, |
| 1050 | s->req->rex, s->rep->wex, |
| 1051 | s->req->flags, s->rep->flags, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1052 | s->req->i, s->req->o, s->rep->i, s->rep->o, s->rep->cons->state, s->req->cons->state); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1053 | |
| 1054 | if (si->state != SI_ST_REQ) |
| 1055 | return; |
| 1056 | |
| 1057 | /* Try to assign a server */ |
| 1058 | if (srv_redispatch_connect(s) != 0) { |
| 1059 | /* We did not get a server. Either we queued the |
| 1060 | * connection request, or we encountered an error. |
| 1061 | */ |
| 1062 | if (si->state == SI_ST_QUE) |
| 1063 | return; |
| 1064 | |
| 1065 | /* we did not get any server, let's check the cause */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1066 | si_shutr(si); |
| 1067 | si_shutw(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1068 | si->ob->flags |= CF_WRITE_ERROR; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1069 | if (!si->err_type) |
| 1070 | si->err_type = SI_ET_CONN_OTHER; |
| 1071 | si->state = SI_ST_CLO; |
Willy Tarreau | 0cac36f | 2008-11-30 20:44:17 +0100 | [diff] [blame] | 1072 | if (s->srv_error) |
| 1073 | s->srv_error(s, si); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1074 | return; |
| 1075 | } |
| 1076 | |
| 1077 | /* The server is assigned */ |
| 1078 | s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 1079 | si->state = SI_ST_ASS; |
| 1080 | } |
| 1081 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1082 | /* This stream analyser checks the switching rules and changes the backend |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1083 | * if appropriate. The default_backend rule is also considered, then the |
| 1084 | * target backend's forced persistence rules are also evaluated last if any. |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1085 | * It returns 1 if the processing can continue on next analysers, or zero if it |
| 1086 | * either needs more data or wants to immediately abort the request. |
| 1087 | */ |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1088 | static int process_switching_rules(struct session *s, struct channel *req, int an_bit) |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1089 | { |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1090 | struct persist_rule *prst_rule; |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1091 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1092 | req->analysers &= ~an_bit; |
| 1093 | req->analyse_exp = TICK_ETERNITY; |
| 1094 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1095 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n", |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1096 | now_ms, __FUNCTION__, |
| 1097 | s, |
| 1098 | req, |
| 1099 | req->rex, req->wex, |
| 1100 | req->flags, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1101 | req->i, |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1102 | req->analysers); |
| 1103 | |
| 1104 | /* now check whether we have some switching rules for this request */ |
| 1105 | if (!(s->flags & SN_BE_ASSIGNED)) { |
| 1106 | struct switching_rule *rule; |
| 1107 | |
| 1108 | list_for_each_entry(rule, &s->fe->switching_rules, list) { |
| 1109 | int ret; |
| 1110 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1111 | ret = acl_exec_cond(rule->cond, s->fe, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1112 | ret = acl_pass(ret); |
| 1113 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 1114 | ret = !ret; |
| 1115 | |
| 1116 | if (ret) { |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1117 | if (!session_set_backend(s, rule->be.backend)) |
| 1118 | goto sw_failed; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1119 | break; |
| 1120 | } |
| 1121 | } |
| 1122 | |
| 1123 | /* To ensure correct connection accounting on the backend, we |
| 1124 | * have to assign one if it was not set (eg: a listen). This |
| 1125 | * measure also takes care of correctly setting the default |
| 1126 | * backend if any. |
| 1127 | */ |
| 1128 | if (!(s->flags & SN_BE_ASSIGNED)) |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1129 | if (!session_set_backend(s, s->fe->defbe.be ? s->fe->defbe.be : s->be)) |
| 1130 | goto sw_failed; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1131 | } |
| 1132 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1133 | /* we don't want to run the TCP or HTTP filters again if the backend has not changed */ |
| 1134 | if (s->fe == s->be) { |
| 1135 | s->req->analysers &= ~AN_REQ_INSPECT_BE; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1136 | s->req->analysers &= ~AN_REQ_HTTP_PROCESS_BE; |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1137 | } |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1138 | |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1139 | /* as soon as we know the backend, we must check if we have a matching forced or ignored |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1140 | * persistence rule, and report that in the session. |
| 1141 | */ |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1142 | list_for_each_entry(prst_rule, &s->be->persist_rules, list) { |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1143 | int ret = 1; |
| 1144 | |
| 1145 | if (prst_rule->cond) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1146 | ret = acl_exec_cond(prst_rule->cond, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1147 | ret = acl_pass(ret); |
| 1148 | if (prst_rule->cond->pol == ACL_COND_UNLESS) |
| 1149 | ret = !ret; |
| 1150 | } |
| 1151 | |
| 1152 | if (ret) { |
| 1153 | /* no rule, or the rule matches */ |
Cyril Bonté | 47fdd8e | 2010-04-25 00:00:51 +0200 | [diff] [blame] | 1154 | if (prst_rule->type == PERSIST_TYPE_FORCE) { |
| 1155 | s->flags |= SN_FORCE_PRST; |
| 1156 | } else { |
| 1157 | s->flags |= SN_IGNORE_PRST; |
| 1158 | } |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1159 | break; |
| 1160 | } |
| 1161 | } |
| 1162 | |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1163 | return 1; |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1164 | |
| 1165 | sw_failed: |
| 1166 | /* immediately abort this request in case of allocation failure */ |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1167 | channel_abort(s->req); |
| 1168 | channel_abort(s->rep); |
Willy Tarreau | bedb9ba | 2009-07-12 08:27:39 +0200 | [diff] [blame] | 1169 | |
| 1170 | if (!(s->flags & SN_ERR_MASK)) |
| 1171 | s->flags |= SN_ERR_RESOURCE; |
| 1172 | if (!(s->flags & SN_FINST_MASK)) |
| 1173 | s->flags |= SN_FINST_R; |
| 1174 | |
| 1175 | s->txn.status = 500; |
| 1176 | s->req->analysers = 0; |
| 1177 | s->req->analyse_exp = TICK_ETERNITY; |
| 1178 | return 0; |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1179 | } |
| 1180 | |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1181 | /* This stream analyser works on a request. It applies all use-server rules on |
| 1182 | * it then returns 1. The data must already be present in the buffer otherwise |
| 1183 | * they won't match. It always returns 1. |
| 1184 | */ |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1185 | static int process_server_rules(struct session *s, struct channel *req, int an_bit) |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1186 | { |
| 1187 | struct proxy *px = s->be; |
| 1188 | struct server_rule *rule; |
| 1189 | |
| 1190 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bl=%d analysers=%02x\n", |
| 1191 | now_ms, __FUNCTION__, |
| 1192 | s, |
| 1193 | req, |
| 1194 | req->rex, req->wex, |
| 1195 | req->flags, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1196 | req->i + req->o, |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1197 | req->analysers); |
| 1198 | |
| 1199 | if (!(s->flags & SN_ASSIGNED)) { |
| 1200 | list_for_each_entry(rule, &px->server_rules, list) { |
| 1201 | int ret; |
| 1202 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1203 | ret = acl_exec_cond(rule->cond, s->be, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1204 | ret = acl_pass(ret); |
| 1205 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 1206 | ret = !ret; |
| 1207 | |
| 1208 | if (ret) { |
| 1209 | struct server *srv = rule->srv.ptr; |
| 1210 | |
| 1211 | if ((srv->state & SRV_RUNNING) || |
| 1212 | (px->options & PR_O_PERSIST) || |
| 1213 | (s->flags & SN_FORCE_PRST)) { |
| 1214 | s->flags |= SN_DIRECT | SN_ASSIGNED; |
| 1215 | set_target_server(&s->target, srv); |
| 1216 | break; |
| 1217 | } |
| 1218 | /* if the server is not UP, let's go on with next rules |
| 1219 | * just in case another one is suited. |
| 1220 | */ |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | req->analysers &= ~an_bit; |
| 1226 | req->analyse_exp = TICK_ETERNITY; |
| 1227 | return 1; |
| 1228 | } |
| 1229 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1230 | /* This stream analyser works on a request. It applies all sticking rules on |
| 1231 | * it then returns 1. The data must already be present in the buffer otherwise |
| 1232 | * they won't match. It always returns 1. |
| 1233 | */ |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1234 | static int process_sticking_rules(struct session *s, struct channel *req, int an_bit) |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1235 | { |
| 1236 | struct proxy *px = s->be; |
| 1237 | struct sticking_rule *rule; |
| 1238 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1239 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n", |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1240 | now_ms, __FUNCTION__, |
| 1241 | s, |
| 1242 | req, |
| 1243 | req->rex, req->wex, |
| 1244 | req->flags, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1245 | req->i, |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1246 | req->analysers); |
| 1247 | |
| 1248 | list_for_each_entry(rule, &px->sticking_rules, list) { |
| 1249 | int ret = 1 ; |
| 1250 | int i; |
| 1251 | |
| 1252 | for (i = 0; i < s->store_count; i++) { |
| 1253 | if (rule->table.t == s->store[i].table) |
| 1254 | break; |
| 1255 | } |
| 1256 | |
| 1257 | if (i != s->store_count) |
| 1258 | continue; |
| 1259 | |
| 1260 | if (rule->cond) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1261 | ret = acl_exec_cond(rule->cond, px, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1262 | ret = acl_pass(ret); |
| 1263 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 1264 | ret = !ret; |
| 1265 | } |
| 1266 | |
| 1267 | if (ret) { |
| 1268 | struct stktable_key *key; |
| 1269 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1270 | key = stktable_fetch_key(rule->table.t, px, s, &s->txn, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->expr); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1271 | if (!key) |
| 1272 | continue; |
| 1273 | |
| 1274 | if (rule->flags & STK_IS_MATCH) { |
| 1275 | struct stksess *ts; |
| 1276 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1277 | if ((ts = stktable_lookup_key(rule->table.t, key)) != NULL) { |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1278 | if (!(s->flags & SN_ASSIGNED)) { |
| 1279 | struct eb32_node *node; |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1280 | void *ptr; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1281 | |
| 1282 | /* srv found in table */ |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1283 | ptr = stktable_data_ptr(rule->table.t, ts, STKTABLE_DT_SERVER_ID); |
| 1284 | node = eb32_lookup(&px->conf.used_server_id, stktable_data_cast(ptr, server_id)); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1285 | if (node) { |
| 1286 | struct server *srv; |
| 1287 | |
| 1288 | srv = container_of(node, struct server, conf.id); |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1289 | if ((srv->state & SRV_RUNNING) || |
| 1290 | (px->options & PR_O_PERSIST) || |
| 1291 | (s->flags & SN_FORCE_PRST)) { |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1292 | s->flags |= SN_DIRECT | SN_ASSIGNED; |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 1293 | set_target_server(&s->target, srv); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1294 | } |
| 1295 | } |
| 1296 | } |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 1297 | stktable_touch(rule->table.t, ts, 1); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1298 | } |
| 1299 | } |
| 1300 | if (rule->flags & STK_IS_STORE) { |
| 1301 | if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) { |
| 1302 | struct stksess *ts; |
| 1303 | |
| 1304 | ts = stksess_new(rule->table.t, key); |
| 1305 | if (ts) { |
| 1306 | s->store[s->store_count].table = rule->table.t; |
| 1307 | s->store[s->store_count++].ts = ts; |
| 1308 | } |
| 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | req->analysers &= ~an_bit; |
| 1315 | req->analyse_exp = TICK_ETERNITY; |
| 1316 | return 1; |
| 1317 | } |
| 1318 | |
| 1319 | /* This stream analyser works on a response. It applies all store rules on it |
| 1320 | * then returns 1. The data must already be present in the buffer otherwise |
| 1321 | * they won't match. It always returns 1. |
| 1322 | */ |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1323 | static int process_store_rules(struct session *s, struct channel *rep, int an_bit) |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1324 | { |
| 1325 | struct proxy *px = s->be; |
| 1326 | struct sticking_rule *rule; |
| 1327 | int i; |
| 1328 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1329 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n", |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1330 | now_ms, __FUNCTION__, |
| 1331 | s, |
Willy Tarreau | 2e2b3eb | 2010-02-09 20:55:44 +0100 | [diff] [blame] | 1332 | rep, |
| 1333 | rep->rex, rep->wex, |
| 1334 | rep->flags, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1335 | rep->i, |
Willy Tarreau | 2e2b3eb | 2010-02-09 20:55:44 +0100 | [diff] [blame] | 1336 | rep->analysers); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1337 | |
| 1338 | list_for_each_entry(rule, &px->storersp_rules, list) { |
| 1339 | int ret = 1 ; |
| 1340 | int storereqidx = -1; |
| 1341 | |
| 1342 | for (i = 0; i < s->store_count; i++) { |
| 1343 | if (rule->table.t == s->store[i].table) { |
| 1344 | if (!(s->store[i].flags)) |
| 1345 | storereqidx = i; |
| 1346 | break; |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | if ((i != s->store_count) && (storereqidx == -1)) |
| 1351 | continue; |
| 1352 | |
| 1353 | if (rule->cond) { |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1354 | ret = acl_exec_cond(rule->cond, px, s, &s->txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1355 | ret = acl_pass(ret); |
| 1356 | if (rule->cond->pol == ACL_COND_UNLESS) |
| 1357 | ret = !ret; |
| 1358 | } |
| 1359 | |
| 1360 | if (ret) { |
| 1361 | struct stktable_key *key; |
| 1362 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1363 | key = stktable_fetch_key(rule->table.t, px, s, &s->txn, SMP_OPT_DIR_RES|SMP_OPT_FINAL, rule->expr); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1364 | if (!key) |
| 1365 | continue; |
| 1366 | |
| 1367 | if (storereqidx != -1) { |
Willy Tarreau | 393379c | 2010-06-06 12:11:37 +0200 | [diff] [blame] | 1368 | stksess_setkey(s->store[storereqidx].table, s->store[storereqidx].ts, key); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1369 | s->store[storereqidx].flags = 1; |
| 1370 | } |
| 1371 | else if (s->store_count < (sizeof(s->store) / sizeof(s->store[0]))) { |
| 1372 | struct stksess *ts; |
| 1373 | |
| 1374 | ts = stksess_new(rule->table.t, key); |
| 1375 | if (ts) { |
| 1376 | s->store[s->store_count].table = rule->table.t; |
| 1377 | s->store[s->store_count].flags = 1; |
| 1378 | s->store[s->store_count++].ts = ts; |
| 1379 | } |
| 1380 | } |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | /* process store request and store response */ |
| 1385 | for (i = 0; i < s->store_count; i++) { |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1386 | struct stksess *ts; |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1387 | void *ptr; |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1388 | |
Simon Horman | fa46168 | 2011-06-25 09:39:49 +0900 | [diff] [blame] | 1389 | if (target_srv(&s->target) && target_srv(&s->target)->state & SRV_NON_STICK) { |
| 1390 | stksess_free(s->store[i].table, s->store[i].ts); |
| 1391 | s->store[i].ts = NULL; |
| 1392 | continue; |
| 1393 | } |
| 1394 | |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1395 | ts = stktable_lookup(s->store[i].table, s->store[i].ts); |
| 1396 | if (ts) { |
| 1397 | /* the entry already existed, we can free ours */ |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 1398 | stktable_touch(s->store[i].table, ts, 1); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1399 | stksess_free(s->store[i].table, s->store[i].ts); |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1400 | } |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1401 | else |
Emeric Brun | 85e77c7 | 2010-09-23 18:16:52 +0200 | [diff] [blame] | 1402 | ts = stktable_store(s->store[i].table, s->store[i].ts, 1); |
Willy Tarreau | f16d2b8 | 2010-06-06 15:38:59 +0200 | [diff] [blame] | 1403 | |
| 1404 | s->store[i].ts = NULL; |
Willy Tarreau | 13c29de | 2010-06-06 16:40:39 +0200 | [diff] [blame] | 1405 | ptr = stktable_data_ptr(s->store[i].table, ts, STKTABLE_DT_SERVER_ID); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1406 | stktable_data_cast(ptr, server_id) = target_srv(&s->target)->puid; |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1407 | } |
Willy Tarreau | 2a164ee | 2010-06-18 09:57:45 +0200 | [diff] [blame] | 1408 | s->store_count = 0; /* everything is stored */ |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1409 | |
| 1410 | rep->analysers &= ~an_bit; |
| 1411 | rep->analyse_exp = TICK_ETERNITY; |
| 1412 | return 1; |
| 1413 | } |
| 1414 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1415 | /* This macro is very specific to the function below. See the comments in |
| 1416 | * process_session() below to understand the logic and the tests. |
| 1417 | */ |
| 1418 | #define UPDATE_ANALYSERS(real, list, back, flag) { \ |
| 1419 | list = (((list) & ~(flag)) | ~(back)) & (real); \ |
| 1420 | back = real; \ |
| 1421 | if (!(list)) \ |
| 1422 | break; \ |
| 1423 | if (((list) ^ ((list) & ((list) - 1))) < (flag)) \ |
| 1424 | continue; \ |
| 1425 | } |
| 1426 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1427 | /* Processes the client, server, request and response jobs of a session task, |
| 1428 | * then puts it back to the wait queue in a clean state, or cleans up its |
| 1429 | * resources if it must be deleted. Returns in <next> the date the task wants |
| 1430 | * to be woken up, or TICK_ETERNITY. In order not to call all functions for |
| 1431 | * nothing too many times, the request and response buffers flags are monitored |
| 1432 | * and each function is called only if at least another function has changed at |
| 1433 | * least one flag it is interested in. |
| 1434 | */ |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 1435 | struct task *process_session(struct task *t) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1436 | { |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1437 | struct server *srv; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1438 | struct session *s = t->context; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1439 | unsigned int rqf_last, rpf_last; |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1440 | unsigned int rq_prod_last, rq_cons_last; |
| 1441 | unsigned int rp_cons_last, rp_prod_last; |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1442 | unsigned int req_ana_back; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1443 | |
| 1444 | //DPRINTF(stderr, "%s:%d: cs=%d ss=%d(%d) rqf=0x%08x rpf=0x%08x\n", __FUNCTION__, __LINE__, |
| 1445 | // s->si[0].state, s->si[1].state, s->si[1].err_type, s->req->flags, s->rep->flags); |
| 1446 | |
Krzysztof Piotr Oledzki | f9423ae | 2010-01-29 19:26:18 +0100 | [diff] [blame] | 1447 | /* this data may be no longer valid, clear it */ |
| 1448 | memset(&s->txn.auth, 0, sizeof(s->txn.auth)); |
| 1449 | |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1450 | /* This flag must explicitly be set every time */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1451 | s->req->flags &= ~CF_READ_NOEXP; |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1452 | |
| 1453 | /* Keep a copy of req/rep flags so that we can detect shutdowns */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1454 | rqf_last = s->req->flags & ~CF_MASK_ANALYSER; |
| 1455 | rpf_last = s->rep->flags & ~CF_MASK_ANALYSER; |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1456 | |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 1457 | /* we don't want the stream interface functions to recursively wake us up */ |
| 1458 | if (s->req->prod->owner == t) |
| 1459 | s->req->prod->flags |= SI_FL_DONT_WAKE; |
| 1460 | if (s->req->cons->owner == t) |
| 1461 | s->req->cons->flags |= SI_FL_DONT_WAKE; |
| 1462 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1463 | /* 1a: Check for low level timeouts if needed. We just set a flag on |
| 1464 | * stream interfaces when their timeouts have expired. |
| 1465 | */ |
| 1466 | if (unlikely(t->state & TASK_WOKEN_TIMER)) { |
| 1467 | stream_int_check_timeouts(&s->si[0]); |
| 1468 | stream_int_check_timeouts(&s->si[1]); |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1469 | |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1470 | /* check channel timeouts, and close the corresponding stream interfaces |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1471 | * for future reads or writes. Note: this will also concern upper layers |
| 1472 | * but we do not touch any other flag. We must be careful and correctly |
| 1473 | * detect state changes when calling them. |
| 1474 | */ |
| 1475 | |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1476 | channel_check_timeouts(s->req); |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1477 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1478 | if (unlikely((s->req->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) { |
Willy Tarreau | 1464140 | 2009-12-29 14:49:56 +0100 | [diff] [blame] | 1479 | s->req->cons->flags |= SI_FL_NOLINGER; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1480 | si_shutw(s->req->cons); |
Willy Tarreau | 1464140 | 2009-12-29 14:49:56 +0100 | [diff] [blame] | 1481 | } |
| 1482 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1483 | if (unlikely((s->req->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) { |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 1484 | if (s->req->prod->flags & SI_FL_NOHALF) |
| 1485 | s->req->prod->flags |= SI_FL_NOLINGER; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1486 | si_shutr(s->req->prod); |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 1487 | } |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1488 | |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1489 | channel_check_timeouts(s->rep); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1490 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1491 | if (unlikely((s->rep->flags & (CF_SHUTW|CF_WRITE_TIMEOUT)) == CF_WRITE_TIMEOUT)) { |
Willy Tarreau | 1464140 | 2009-12-29 14:49:56 +0100 | [diff] [blame] | 1492 | s->rep->cons->flags |= SI_FL_NOLINGER; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1493 | si_shutw(s->rep->cons); |
Willy Tarreau | 1464140 | 2009-12-29 14:49:56 +0100 | [diff] [blame] | 1494 | } |
| 1495 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1496 | if (unlikely((s->rep->flags & (CF_SHUTR|CF_READ_TIMEOUT)) == CF_READ_TIMEOUT)) { |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 1497 | if (s->rep->prod->flags & SI_FL_NOHALF) |
| 1498 | s->rep->prod->flags |= SI_FL_NOLINGER; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1499 | si_shutr(s->rep->prod); |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 1500 | } |
Willy Tarreau | b67a9b8 | 2009-06-21 22:03:51 +0200 | [diff] [blame] | 1501 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1502 | |
| 1503 | /* 1b: check for low-level errors reported at the stream interface. |
| 1504 | * First we check if it's a retryable error (in which case we don't |
| 1505 | * want to tell the buffer). Otherwise we report the error one level |
| 1506 | * upper by setting flags into the buffers. Note that the side towards |
| 1507 | * the client cannot have connect (hence retryable) errors. Also, the |
| 1508 | * connection setup code must be able to deal with any type of abort. |
| 1509 | */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1510 | srv = target_srv(&s->target); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1511 | if (unlikely(s->si[0].flags & SI_FL_ERR)) { |
| 1512 | if (s->si[0].state == SI_ST_EST || s->si[0].state == SI_ST_DIS) { |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1513 | si_shutr(&s->si[0]); |
| 1514 | si_shutw(&s->si[0]); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1515 | stream_int_report_error(&s->si[0]); |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1516 | if (!(s->req->analysers) && !(s->rep->analysers)) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1517 | s->be->be_counters.cli_aborts++; |
| 1518 | s->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1519 | if (srv) |
| 1520 | srv->counters.cli_aborts++; |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1521 | if (!(s->flags & SN_ERR_MASK)) |
| 1522 | s->flags |= SN_ERR_CLICL; |
| 1523 | if (!(s->flags & SN_FINST_MASK)) |
| 1524 | s->flags |= SN_FINST_D; |
| 1525 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | if (unlikely(s->si[1].flags & SI_FL_ERR)) { |
| 1530 | if (s->si[1].state == SI_ST_EST || s->si[1].state == SI_ST_DIS) { |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1531 | si_shutr(&s->si[1]); |
| 1532 | si_shutw(&s->si[1]); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1533 | stream_int_report_error(&s->si[1]); |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1534 | s->be->be_counters.failed_resp++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1535 | if (srv) |
| 1536 | srv->counters.failed_resp++; |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1537 | if (!(s->req->analysers) && !(s->rep->analysers)) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1538 | s->be->be_counters.srv_aborts++; |
| 1539 | s->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1540 | if (srv) |
| 1541 | srv->counters.srv_aborts++; |
Willy Tarreau | 05cb29b | 2008-12-14 11:44:04 +0100 | [diff] [blame] | 1542 | if (!(s->flags & SN_ERR_MASK)) |
| 1543 | s->flags |= SN_ERR_SRVCL; |
| 1544 | if (!(s->flags & SN_FINST_MASK)) |
| 1545 | s->flags |= SN_FINST_D; |
| 1546 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1547 | } |
| 1548 | /* note: maybe we should process connection errors here ? */ |
| 1549 | } |
| 1550 | |
| 1551 | if (s->si[1].state == SI_ST_CON) { |
| 1552 | /* we were trying to establish a connection on the server side, |
| 1553 | * maybe it succeeded, maybe it failed, maybe we timed out, ... |
| 1554 | */ |
| 1555 | if (unlikely(!sess_update_st_con_tcp(s, &s->si[1]))) |
| 1556 | sess_update_st_cer(s, &s->si[1]); |
| 1557 | else if (s->si[1].state == SI_ST_EST) |
| 1558 | sess_establish(s, &s->si[1]); |
| 1559 | |
| 1560 | /* state is now one of SI_ST_CON (still in progress), SI_ST_EST |
| 1561 | * (established), SI_ST_DIS (abort), SI_ST_CLO (last error), |
| 1562 | * SI_ST_ASS/SI_ST_TAR/SI_ST_REQ for retryable errors. |
| 1563 | */ |
| 1564 | } |
| 1565 | |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1566 | rq_prod_last = s->si[0].state; |
| 1567 | rq_cons_last = s->si[1].state; |
| 1568 | rp_cons_last = s->si[0].state; |
| 1569 | rp_prod_last = s->si[1].state; |
| 1570 | |
| 1571 | resync_stream_interface: |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1572 | /* Check for connection closure */ |
| 1573 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1574 | DPRINTF(stderr, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1575 | "[%u] %s:%d: task=%p s=%p, sfl=0x%08x, rq=%p, rp=%p, exp(r,w)=%u,%u rqf=%08x rpf=%08x rqh=%d rqt=%d rph=%d rpt=%d cs=%d ss=%d, cet=0x%x set=0x%x retr=%d\n", |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1576 | now_ms, __FUNCTION__, __LINE__, |
| 1577 | t, |
| 1578 | s, s->flags, |
| 1579 | s->req, s->rep, |
| 1580 | s->req->rex, s->rep->wex, |
| 1581 | s->req->flags, s->rep->flags, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1582 | s->req->i, s->req->o, s->rep->i, s->rep->o, s->rep->cons->state, s->req->cons->state, |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1583 | s->rep->cons->err_type, s->req->cons->err_type, |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 1584 | s->req->cons->conn_retries); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1585 | |
| 1586 | /* nothing special to be done on client side */ |
| 1587 | if (unlikely(s->req->prod->state == SI_ST_DIS)) |
| 1588 | s->req->prod->state = SI_ST_CLO; |
| 1589 | |
| 1590 | /* When a server-side connection is released, we have to count it and |
| 1591 | * check for pending connections on this server. |
| 1592 | */ |
| 1593 | if (unlikely(s->req->cons->state == SI_ST_DIS)) { |
| 1594 | s->req->cons->state = SI_ST_CLO; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1595 | srv = target_srv(&s->target); |
| 1596 | if (srv) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1597 | if (s->flags & SN_CURR_SESS) { |
| 1598 | s->flags &= ~SN_CURR_SESS; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1599 | srv->cur_sess--; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1600 | } |
| 1601 | sess_change_server(s, NULL); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1602 | if (may_dequeue_tasks(srv, s->be)) |
| 1603 | process_srv_queue(srv); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | /* |
| 1608 | * Note: of the transient states (REQ, CER, DIS), only REQ may remain |
| 1609 | * at this point. |
| 1610 | */ |
| 1611 | |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 1612 | resync_request: |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1613 | /* Analyse request */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1614 | if (((s->req->flags & ~rqf_last) & CF_MASK_ANALYSER) || |
| 1615 | ((s->req->flags ^ rqf_last) & CF_MASK_STATIC) || |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1616 | s->si[0].state != rq_prod_last || |
| 1617 | s->si[1].state != rq_cons_last) { |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1618 | unsigned int flags = s->req->flags; |
| 1619 | |
| 1620 | if (s->req->prod->state >= SI_ST_EST) { |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1621 | int max_loops = global.tune.maxpollevents; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1622 | unsigned int ana_list; |
| 1623 | unsigned int ana_back; |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1624 | |
Willy Tarreau | 90deb18 | 2010-01-07 00:20:41 +0100 | [diff] [blame] | 1625 | /* it's up to the analysers to stop new connections, |
| 1626 | * disable reading or closing. Note: if an analyser |
| 1627 | * disables any of these bits, it is responsible for |
| 1628 | * enabling them again when it disables itself, so |
| 1629 | * that other analysers are called in similar conditions. |
| 1630 | */ |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1631 | channel_auto_read(s->req); |
| 1632 | channel_auto_connect(s->req); |
| 1633 | channel_auto_close(s->req); |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1634 | |
| 1635 | /* We will call all analysers for which a bit is set in |
| 1636 | * s->req->analysers, following the bit order from LSB |
| 1637 | * to MSB. The analysers must remove themselves from |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1638 | * the list when not needed. Any analyser may return 0 |
| 1639 | * to break out of the loop, either because of missing |
| 1640 | * data to take a decision, or because it decides to |
| 1641 | * kill the session. We loop at least once through each |
| 1642 | * analyser, and we may loop again if other analysers |
| 1643 | * are added in the middle. |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1644 | * |
| 1645 | * We build a list of analysers to run. We evaluate all |
| 1646 | * of these analysers in the order of the lower bit to |
| 1647 | * the higher bit. This ordering is very important. |
| 1648 | * An analyser will often add/remove other analysers, |
| 1649 | * including itself. Any changes to itself have no effect |
| 1650 | * on the loop. If it removes any other analysers, we |
| 1651 | * want those analysers not to be called anymore during |
| 1652 | * this loop. If it adds an analyser that is located |
| 1653 | * after itself, we want it to be scheduled for being |
| 1654 | * processed during the loop. If it adds an analyser |
| 1655 | * which is located before it, we want it to switch to |
| 1656 | * it immediately, even if it has already been called |
| 1657 | * once but removed since. |
| 1658 | * |
| 1659 | * In order to achieve this, we compare the analyser |
| 1660 | * list after the call with a copy of it before the |
| 1661 | * call. The work list is fed with analyser bits that |
| 1662 | * appeared during the call. Then we compare previous |
| 1663 | * work list with the new one, and check the bits that |
| 1664 | * appeared. If the lowest of these bits is lower than |
| 1665 | * the current bit, it means we have enabled a previous |
| 1666 | * analyser and must immediately loop again. |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1667 | */ |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1668 | |
| 1669 | ana_list = ana_back = s->req->analysers; |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1670 | while (ana_list && max_loops--) { |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1671 | /* Warning! ensure that analysers are always placed in ascending order! */ |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1672 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1673 | if (ana_list & AN_REQ_INSPECT_FE) { |
| 1674 | if (!tcp_inspect_request(s, s->req, AN_REQ_INSPECT_FE)) |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1675 | break; |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1676 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_INSPECT_FE); |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1677 | } |
Willy Tarreau | edcf668 | 2008-11-30 23:15:34 +0100 | [diff] [blame] | 1678 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1679 | if (ana_list & AN_REQ_WAIT_HTTP) { |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 1680 | if (!http_wait_for_request(s, s->req, AN_REQ_WAIT_HTTP)) |
Willy Tarreau | d787e66 | 2009-07-07 10:14:51 +0200 | [diff] [blame] | 1681 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1682 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_WAIT_HTTP); |
Willy Tarreau | d787e66 | 2009-07-07 10:14:51 +0200 | [diff] [blame] | 1683 | } |
| 1684 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1685 | if (ana_list & AN_REQ_HTTP_PROCESS_FE) { |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1686 | if (!http_process_req_common(s, s->req, AN_REQ_HTTP_PROCESS_FE, s->fe)) |
| 1687 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1688 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_PROCESS_FE); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1689 | } |
| 1690 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1691 | if (ana_list & AN_REQ_SWITCHING_RULES) { |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1692 | if (!process_switching_rules(s, s->req, AN_REQ_SWITCHING_RULES)) |
| 1693 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1694 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_SWITCHING_RULES); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1695 | } |
| 1696 | |
Willy Tarreau | fb35620 | 2010-08-03 14:02:05 +0200 | [diff] [blame] | 1697 | if (ana_list & AN_REQ_INSPECT_BE) { |
| 1698 | if (!tcp_inspect_request(s, s->req, AN_REQ_INSPECT_BE)) |
| 1699 | break; |
| 1700 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_INSPECT_BE); |
| 1701 | } |
| 1702 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1703 | if (ana_list & AN_REQ_HTTP_PROCESS_BE) { |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1704 | if (!http_process_req_common(s, s->req, AN_REQ_HTTP_PROCESS_BE, s->be)) |
| 1705 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1706 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_PROCESS_BE); |
Willy Tarreau | 1d0dfb1 | 2009-07-07 15:10:31 +0200 | [diff] [blame] | 1707 | } |
| 1708 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1709 | if (ana_list & AN_REQ_HTTP_TARPIT) { |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 1710 | if (!http_process_tarpit(s, s->req, AN_REQ_HTTP_TARPIT)) |
Willy Tarreau | 60b85b0 | 2008-11-30 23:28:40 +0100 | [diff] [blame] | 1711 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1712 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_TARPIT); |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1713 | } |
Willy Tarreau | 60b85b0 | 2008-11-30 23:28:40 +0100 | [diff] [blame] | 1714 | |
Willy Tarreau | 4a5cade | 2012-04-05 21:09:48 +0200 | [diff] [blame] | 1715 | if (ana_list & AN_REQ_SRV_RULES) { |
| 1716 | if (!process_server_rules(s, s->req, AN_REQ_SRV_RULES)) |
| 1717 | break; |
| 1718 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_SRV_RULES); |
| 1719 | } |
| 1720 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1721 | if (ana_list & AN_REQ_HTTP_INNER) { |
Willy Tarreau | c465fd7 | 2009-08-31 00:17:18 +0200 | [diff] [blame] | 1722 | if (!http_process_request(s, s->req, AN_REQ_HTTP_INNER)) |
| 1723 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1724 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_INNER); |
Willy Tarreau | c465fd7 | 2009-08-31 00:17:18 +0200 | [diff] [blame] | 1725 | } |
| 1726 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1727 | if (ana_list & AN_REQ_HTTP_BODY) { |
Willy Tarreau | 3a81629 | 2009-07-07 10:55:49 +0200 | [diff] [blame] | 1728 | if (!http_process_request_body(s, s->req, AN_REQ_HTTP_BODY)) |
Willy Tarreau | d34af78 | 2008-11-30 23:36:37 +0100 | [diff] [blame] | 1729 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1730 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_BODY); |
Willy Tarreau | 1a52dbd | 2009-06-28 19:37:53 +0200 | [diff] [blame] | 1731 | } |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1732 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1733 | if (ana_list & AN_REQ_PRST_RDP_COOKIE) { |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1734 | if (!tcp_persist_rdp_cookie(s, s->req, AN_REQ_PRST_RDP_COOKIE)) |
| 1735 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1736 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_PRST_RDP_COOKIE); |
Emeric Brun | 647caf1 | 2009-06-30 17:57:00 +0200 | [diff] [blame] | 1737 | } |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1738 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1739 | if (ana_list & AN_REQ_STICKING_RULES) { |
| 1740 | if (!process_sticking_rules(s, s->req, AN_REQ_STICKING_RULES)) |
| 1741 | break; |
| 1742 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_STICKING_RULES); |
| 1743 | } |
| 1744 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1745 | if (ana_list & AN_REQ_HTTP_XFER_BODY) { |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1746 | if (!http_request_forward_body(s, s->req, AN_REQ_HTTP_XFER_BODY)) |
| 1747 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1748 | UPDATE_ANALYSERS(s->req->analysers, ana_list, ana_back, AN_REQ_HTTP_XFER_BODY); |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1749 | } |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1750 | break; |
| 1751 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 1752 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1753 | |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1754 | rq_prod_last = s->si[0].state; |
| 1755 | rq_cons_last = s->si[1].state; |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1756 | s->req->flags &= ~CF_WAKE_ONCE; |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1757 | rqf_last = s->req->flags; |
| 1758 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1759 | if ((s->req->flags ^ flags) & CF_MASK_STATIC) |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1760 | goto resync_request; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1761 | } |
| 1762 | |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1763 | /* we'll monitor the request analysers while parsing the response, |
| 1764 | * because some response analysers may indirectly enable new request |
| 1765 | * analysers (eg: HTTP keep-alive). |
| 1766 | */ |
| 1767 | req_ana_back = s->req->analysers; |
| 1768 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1769 | resync_response: |
| 1770 | /* Analyse response */ |
| 1771 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1772 | if (unlikely(s->rep->flags & CF_HIJACK)) { |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1773 | /* In inject mode, we wake up everytime something has |
| 1774 | * happened on the write side of the buffer. |
| 1775 | */ |
| 1776 | unsigned int flags = s->rep->flags; |
| 1777 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1778 | if ((s->rep->flags & (CF_WRITE_PARTIAL|CF_WRITE_ERROR|CF_SHUTW)) && |
Willy Tarreau | 3bf1b2b | 2012-08-27 20:46:07 +0200 | [diff] [blame] | 1779 | !channel_full(s->rep)) { |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1780 | s->rep->hijacker(s, s->rep); |
| 1781 | } |
| 1782 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1783 | if ((s->rep->flags ^ flags) & CF_MASK_STATIC) { |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1784 | rpf_last = s->rep->flags; |
| 1785 | goto resync_response; |
| 1786 | } |
| 1787 | } |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1788 | else if (((s->rep->flags & ~rpf_last) & CF_MASK_ANALYSER) || |
| 1789 | (s->rep->flags ^ rpf_last) & CF_MASK_STATIC || |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1790 | s->si[0].state != rp_cons_last || |
| 1791 | s->si[1].state != rp_prod_last) { |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1792 | unsigned int flags = s->rep->flags; |
| 1793 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1794 | if ((s->rep->flags & CF_MASK_ANALYSER) && |
Willy Tarreau | 0499e35 | 2010-12-17 07:13:42 +0100 | [diff] [blame] | 1795 | (s->rep->analysers & AN_REQ_WAIT_HTTP)) { |
| 1796 | /* Due to HTTP pipelining, the HTTP request analyser might be waiting |
| 1797 | * for some free space in the response buffer, so we might need to call |
| 1798 | * it when something changes in the response buffer, but still we pass |
| 1799 | * it the request buffer. Note that the SI state might very well still |
| 1800 | * be zero due to us returning a flow of redirects! |
| 1801 | */ |
| 1802 | s->rep->analysers &= ~AN_REQ_WAIT_HTTP; |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1803 | s->req->flags |= CF_WAKE_ONCE; |
Willy Tarreau | 0499e35 | 2010-12-17 07:13:42 +0100 | [diff] [blame] | 1804 | } |
| 1805 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1806 | if (s->rep->prod->state >= SI_ST_EST) { |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1807 | int max_loops = global.tune.maxpollevents; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1808 | unsigned int ana_list; |
| 1809 | unsigned int ana_back; |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1810 | |
Willy Tarreau | 90deb18 | 2010-01-07 00:20:41 +0100 | [diff] [blame] | 1811 | /* it's up to the analysers to stop disable reading or |
| 1812 | * closing. Note: if an analyser disables any of these |
| 1813 | * bits, it is responsible for enabling them again when |
| 1814 | * it disables itself, so that other analysers are called |
| 1815 | * in similar conditions. |
| 1816 | */ |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1817 | channel_auto_read(s->rep); |
| 1818 | channel_auto_close(s->rep); |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1819 | |
| 1820 | /* We will call all analysers for which a bit is set in |
| 1821 | * s->rep->analysers, following the bit order from LSB |
| 1822 | * to MSB. The analysers must remove themselves from |
| 1823 | * the list when not needed. Any analyser may return 0 |
| 1824 | * to break out of the loop, either because of missing |
| 1825 | * data to take a decision, or because it decides to |
| 1826 | * kill the session. We loop at least once through each |
| 1827 | * analyser, and we may loop again if other analysers |
| 1828 | * are added in the middle. |
| 1829 | */ |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1830 | |
| 1831 | ana_list = ana_back = s->rep->analysers; |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1832 | while (ana_list && max_loops--) { |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1833 | /* Warning! ensure that analysers are always placed in ascending order! */ |
| 1834 | |
Emeric Brun | 97679e7 | 2010-09-23 17:56:44 +0200 | [diff] [blame] | 1835 | if (ana_list & AN_RES_INSPECT) { |
| 1836 | if (!tcp_inspect_response(s, s->rep, AN_RES_INSPECT)) |
| 1837 | break; |
| 1838 | UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_INSPECT); |
| 1839 | } |
| 1840 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1841 | if (ana_list & AN_RES_WAIT_HTTP) { |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1842 | if (!http_wait_for_response(s, s->rep, AN_RES_WAIT_HTTP)) |
| 1843 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1844 | UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_WAIT_HTTP); |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1845 | } |
| 1846 | |
Emeric Brun | 1d33b29 | 2010-01-04 15:47:17 +0100 | [diff] [blame] | 1847 | if (ana_list & AN_RES_STORE_RULES) { |
| 1848 | if (!process_store_rules(s, s->rep, AN_RES_STORE_RULES)) |
| 1849 | break; |
| 1850 | UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_STORE_RULES); |
| 1851 | } |
| 1852 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1853 | if (ana_list & AN_RES_HTTP_PROCESS_BE) { |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1854 | if (!http_process_res_common(s, s->rep, AN_RES_HTTP_PROCESS_BE, s->be)) |
| 1855 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1856 | UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_HTTP_PROCESS_BE); |
Willy Tarreau | b37c27e | 2009-10-18 22:53:08 +0200 | [diff] [blame] | 1857 | } |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1858 | |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1859 | if (ana_list & AN_RES_HTTP_XFER_BODY) { |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1860 | if (!http_response_forward_body(s, s->rep, AN_RES_HTTP_XFER_BODY)) |
| 1861 | break; |
Willy Tarreau | 1e0bbaf | 2010-01-06 23:53:24 +0100 | [diff] [blame] | 1862 | UPDATE_ANALYSERS(s->rep->analysers, ana_list, ana_back, AN_RES_HTTP_XFER_BODY); |
Willy Tarreau | d98cf93 | 2009-12-27 22:54:55 +0100 | [diff] [blame] | 1863 | } |
Willy Tarreau | e34070e | 2010-01-08 00:32:27 +0100 | [diff] [blame] | 1864 | break; |
| 1865 | } |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1866 | } |
| 1867 | |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 1868 | rp_cons_last = s->si[0].state; |
| 1869 | rp_prod_last = s->si[1].state; |
| 1870 | rpf_last = s->rep->flags; |
| 1871 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1872 | if ((s->rep->flags ^ flags) & CF_MASK_STATIC) |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1873 | goto resync_response; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1874 | } |
| 1875 | |
Willy Tarreau | 576507f | 2010-01-07 00:09:04 +0100 | [diff] [blame] | 1876 | /* maybe someone has added some request analysers, so we must check and loop */ |
| 1877 | if (s->req->analysers & ~req_ana_back) |
| 1878 | goto resync_request; |
| 1879 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1880 | if ((s->req->flags & ~rqf_last) & CF_MASK_ANALYSER) |
Willy Tarreau | 0499e35 | 2010-12-17 07:13:42 +0100 | [diff] [blame] | 1881 | goto resync_request; |
| 1882 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1883 | /* FIXME: here we should call protocol handlers which rely on |
| 1884 | * both buffers. |
| 1885 | */ |
| 1886 | |
| 1887 | |
| 1888 | /* |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1889 | * Now we propagate unhandled errors to the session. Normally |
| 1890 | * we're just in a data phase here since it means we have not |
| 1891 | * seen any analyser who could set an error status. |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1892 | */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1893 | srv = target_srv(&s->target); |
Willy Tarreau | 2f976e1 | 2010-11-11 14:28:47 +0100 | [diff] [blame] | 1894 | if (unlikely(!(s->flags & SN_ERR_MASK))) { |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1895 | if (s->req->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) { |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1896 | /* Report it if the client got an error or a read timeout expired */ |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1897 | s->req->analysers = 0; |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1898 | if (s->req->flags & CF_READ_ERROR) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1899 | s->be->be_counters.cli_aborts++; |
| 1900 | s->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1901 | if (srv) |
| 1902 | srv->counters.cli_aborts++; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1903 | s->flags |= SN_ERR_CLICL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1904 | } |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1905 | else if (s->req->flags & CF_READ_TIMEOUT) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1906 | s->be->be_counters.cli_aborts++; |
| 1907 | s->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1908 | if (srv) |
| 1909 | srv->counters.cli_aborts++; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1910 | s->flags |= SN_ERR_CLITO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1911 | } |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1912 | else if (s->req->flags & CF_WRITE_ERROR) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1913 | s->be->be_counters.srv_aborts++; |
| 1914 | s->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1915 | if (srv) |
| 1916 | srv->counters.srv_aborts++; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1917 | s->flags |= SN_ERR_SRVCL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1918 | } |
| 1919 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1920 | s->be->be_counters.srv_aborts++; |
| 1921 | s->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1922 | if (srv) |
| 1923 | srv->counters.srv_aborts++; |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1924 | s->flags |= SN_ERR_SRVTO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1925 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1926 | sess_set_term_flags(s); |
| 1927 | } |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1928 | else if (s->rep->flags & (CF_READ_ERROR|CF_READ_TIMEOUT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) { |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1929 | /* Report it if the server got an error or a read timeout expired */ |
| 1930 | s->rep->analysers = 0; |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1931 | if (s->rep->flags & CF_READ_ERROR) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1932 | s->be->be_counters.srv_aborts++; |
| 1933 | s->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1934 | if (srv) |
| 1935 | srv->counters.srv_aborts++; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1936 | s->flags |= SN_ERR_SRVCL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1937 | } |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1938 | else if (s->rep->flags & CF_READ_TIMEOUT) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1939 | s->be->be_counters.srv_aborts++; |
| 1940 | s->fe->fe_counters.srv_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1941 | if (srv) |
| 1942 | srv->counters.srv_aborts++; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1943 | s->flags |= SN_ERR_SRVTO; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1944 | } |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1945 | else if (s->rep->flags & CF_WRITE_ERROR) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1946 | s->be->be_counters.cli_aborts++; |
| 1947 | s->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1948 | if (srv) |
| 1949 | srv->counters.cli_aborts++; |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1950 | s->flags |= SN_ERR_CLICL; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1951 | } |
| 1952 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1953 | s->be->be_counters.cli_aborts++; |
| 1954 | s->fe->fe_counters.cli_aborts++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1955 | if (srv) |
| 1956 | srv->counters.cli_aborts++; |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 1957 | s->flags |= SN_ERR_CLITO; |
| 1958 | } |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1959 | sess_set_term_flags(s); |
| 1960 | } |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 1961 | } |
| 1962 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 1963 | /* |
| 1964 | * Here we take care of forwarding unhandled data. This also includes |
| 1965 | * connection establishments and shutdown requests. |
| 1966 | */ |
| 1967 | |
| 1968 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1969 | /* If noone is interested in analysing data, it's time to forward |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1970 | * everything. We configure the buffer to forward indefinitely. |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1971 | * Note that we're checking CF_SHUTR_NOW as an indication of a possible |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1972 | * recent call to channel_abort(). |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1973 | */ |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1974 | if (!s->req->analysers && |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1975 | !(s->req->flags & (CF_HIJACK|CF_SHUTW|CF_SHUTR_NOW)) && |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 1976 | (s->req->prod->state >= SI_ST_EST) && |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1977 | (s->req->to_forward != CHN_INFINITE_FORWARD)) { |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1978 | /* This buffer is freewheeling, there's no analyser nor hijacker |
| 1979 | * attached to it. If any data are left in, we'll permit them to |
| 1980 | * move. |
| 1981 | */ |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1982 | channel_auto_read(s->req); |
| 1983 | channel_auto_connect(s->req); |
| 1984 | channel_auto_close(s->req); |
Willy Tarreau | a75bcef | 2012-08-24 22:56:11 +0200 | [diff] [blame] | 1985 | buffer_flush(&s->req->buf); |
Willy Tarreau | 5bd8c37 | 2009-01-19 00:32:22 +0100 | [diff] [blame] | 1986 | |
Willy Tarreau | da4d9fe | 2010-11-07 20:26:56 +0100 | [diff] [blame] | 1987 | /* We'll let data flow between the producer (if still connected) |
| 1988 | * to the consumer (which might possibly not be connected yet). |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1989 | */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1990 | if (!(s->req->flags & (CF_SHUTR|CF_SHUTW_NOW))) |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 1991 | channel_forward(s->req, CHN_INFINITE_FORWARD); |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 1992 | } |
Willy Tarreau | f890dc9 | 2008-12-13 21:12:26 +0100 | [diff] [blame] | 1993 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1994 | /* check if it is wise to enable kernel splicing to forward request data */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 1995 | if (!(s->req->flags & (CF_KERN_SPLICING|CF_SHUTR)) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 1996 | s->req->to_forward && |
| 1997 | (global.tune.options & GTUNE_USE_SPLICE) && |
Willy Tarreau | 93b0f4f | 2012-08-30 21:23:53 +0200 | [diff] [blame] | 1998 | (s->si[0].conn.data && s->si[0].conn.data->rcv_pipe && s->si[0].conn.data->snd_pipe) && |
| 1999 | (s->si[1].conn.data && s->si[1].conn.data->rcv_pipe && s->si[1].conn.data->snd_pipe) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2000 | (pipes_used < global.maxpipes) && |
| 2001 | (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_REQ) || |
| 2002 | (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) && |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2003 | (s->req->flags & CF_STREAMER_FAST)))) { |
| 2004 | s->req->flags |= CF_KERN_SPLICING; |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2005 | } |
| 2006 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2007 | /* reflect what the L7 analysers have seen last */ |
| 2008 | rqf_last = s->req->flags; |
| 2009 | |
| 2010 | /* |
| 2011 | * Now forward all shutdown requests between both sides of the buffer |
| 2012 | */ |
| 2013 | |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2014 | /* first, let's check if the request buffer needs to shutdown(write), which may |
| 2015 | * happen either because the input is closed or because we want to force a close |
Willy Tarreau | e459976 | 2010-03-21 23:25:09 +0100 | [diff] [blame] | 2016 | * once the server has begun to respond. |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2017 | */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2018 | if (unlikely((s->req->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_HIJACK|CF_AUTO_CLOSE|CF_SHUTR)) == |
| 2019 | (CF_AUTO_CLOSE|CF_SHUTR))) |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2020 | channel_shutw_now(s->req); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2021 | |
| 2022 | /* shutdown(write) pending */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2023 | if (unlikely((s->req->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW && |
Willy Tarreau | 8e21bb9 | 2012-08-24 22:40:29 +0200 | [diff] [blame] | 2024 | channel_is_empty(s->req))) |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2025 | si_shutw(s->req->cons); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2026 | |
| 2027 | /* shutdown(write) done on server side, we must stop the client too */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2028 | if (unlikely((s->req->flags & (CF_SHUTW|CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTW && |
Willy Tarreau | 3dbc694 | 2008-12-07 13:05:04 +0100 | [diff] [blame] | 2029 | !s->req->analysers)) |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2030 | channel_shutr_now(s->req); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2031 | |
| 2032 | /* shutdown(read) pending */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2033 | if (unlikely((s->req->flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) { |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 2034 | if (s->req->prod->flags & SI_FL_NOHALF) |
| 2035 | s->req->prod->flags |= SI_FL_NOLINGER; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2036 | si_shutr(s->req->prod); |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 2037 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2038 | |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2039 | /* it's possible that an upper layer has requested a connection setup or abort. |
| 2040 | * There are 2 situations where we decide to establish a new connection : |
| 2041 | * - there are data scheduled for emission in the buffer |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2042 | * - the CF_AUTO_CONNECT flag is set (active connection) |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2043 | */ |
| 2044 | if (s->req->cons->state == SI_ST_INI) { |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2045 | if (!(s->req->flags & CF_SHUTW)) { |
| 2046 | if ((s->req->flags & CF_AUTO_CONNECT) || !channel_is_empty(s->req)) { |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 2047 | /* If we have an applet without a connect method, we immediately |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 2048 | * switch to the connected state, otherwise we perform a connection |
| 2049 | * request. |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2050 | */ |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 2051 | s->req->cons->state = SI_ST_REQ; /* new connection requested */ |
Willy Tarreau | 070ceb6 | 2010-06-01 10:36:43 +0200 | [diff] [blame] | 2052 | s->req->cons->conn_retries = s->be->conn_retries; |
Willy Tarreau | 3cefd52 | 2012-08-30 15:49:18 +0200 | [diff] [blame] | 2053 | if (unlikely(s->req->cons->conn.target.type == TARG_TYPE_APPLET && |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2054 | !(si_ctrl(s->req->cons) && si_ctrl(s->req->cons)->connect))) { |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2055 | s->req->cons->state = SI_ST_EST; /* connection established */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2056 | s->rep->flags |= CF_READ_ATTACHED; /* producer is now attached */ |
Willy Tarreau | 85e7d00 | 2010-05-31 11:57:51 +0200 | [diff] [blame] | 2057 | s->req->wex = TICK_ETERNITY; |
| 2058 | } |
Willy Tarreau | 520d95e | 2009-09-19 21:04:57 +0200 | [diff] [blame] | 2059 | } |
Willy Tarreau | 7320122 | 2009-08-16 18:27:24 +0200 | [diff] [blame] | 2060 | } |
Willy Tarreau | f41ffdc | 2009-09-20 08:19:25 +0200 | [diff] [blame] | 2061 | else { |
Willy Tarreau | 9279562 | 2009-03-06 12:51:23 +0100 | [diff] [blame] | 2062 | s->req->cons->state = SI_ST_CLO; /* shutw+ini = abort */ |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2063 | channel_shutw_now(s->req); /* fix buffer flags upon abort */ |
| 2064 | channel_shutr_now(s->rep); |
Willy Tarreau | f41ffdc | 2009-09-20 08:19:25 +0200 | [diff] [blame] | 2065 | } |
Willy Tarreau | 9279562 | 2009-03-06 12:51:23 +0100 | [diff] [blame] | 2066 | } |
| 2067 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2068 | |
| 2069 | /* we may have a pending connection request, or a connection waiting |
| 2070 | * for completion. |
| 2071 | */ |
| 2072 | if (s->si[1].state >= SI_ST_REQ && s->si[1].state < SI_ST_CON) { |
| 2073 | do { |
| 2074 | /* nb: step 1 might switch from QUE to ASS, but we first want |
| 2075 | * to give a chance to step 2 to perform a redirect if needed. |
| 2076 | */ |
| 2077 | if (s->si[1].state != SI_ST_REQ) |
| 2078 | sess_update_stream_int(s, &s->si[1]); |
| 2079 | if (s->si[1].state == SI_ST_REQ) |
| 2080 | sess_prepare_conn_req(s, &s->si[1]); |
| 2081 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 2082 | srv = target_srv(&s->target); |
| 2083 | if (s->si[1].state == SI_ST_ASS && srv && srv->rdr_len && (s->flags & SN_REDIRECTABLE)) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2084 | perform_http_redirect(s, &s->si[1]); |
| 2085 | } while (s->si[1].state == SI_ST_ASS); |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2086 | |
| 2087 | /* Now we can add the server name to a header (if requested) */ |
| 2088 | /* check for HTTP mode and proxy server_name_hdr_name != NULL */ |
Stathis Voukelatos | 09a030a | 2012-01-09 14:27:13 +0100 | [diff] [blame] | 2089 | if ((s->flags & SN_BE_ASSIGNED) && |
Willy Tarreau | 45c0d98 | 2012-03-09 12:11:57 +0100 | [diff] [blame] | 2090 | (s->be->mode == PR_MODE_HTTP) && |
| 2091 | (s->be->server_id_hdr_name != NULL)) { |
| 2092 | http_send_name_header(&s->txn, s->be, target_srv(&s->target)->id); |
Mark Lamourine | c2247f0 | 2012-01-04 13:02:01 -0500 | [diff] [blame] | 2093 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2094 | } |
| 2095 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 2096 | /* Benchmarks have shown that it's optimal to do a full resync now */ |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 2097 | if (s->req->prod->state == SI_ST_DIS || s->req->cons->state == SI_ST_DIS) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2098 | goto resync_stream_interface; |
| 2099 | |
Willy Tarreau | 815a9b2 | 2010-07-27 17:15:12 +0200 | [diff] [blame] | 2100 | /* otherwise we want to check if we need to resync the req buffer or not */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2101 | if ((s->req->flags ^ rqf_last) & CF_MASK_STATIC) |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 2102 | goto resync_request; |
| 2103 | |
Willy Tarreau | 3deb3d0 | 2009-06-21 22:43:05 +0200 | [diff] [blame] | 2104 | /* perform output updates to the response buffer */ |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2105 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2106 | /* If noone is interested in analysing data, it's time to forward |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 2107 | * everything. We configure the buffer to forward indefinitely. |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2108 | * Note that we're checking CF_SHUTR_NOW as an indication of a possible |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2109 | * recent call to channel_abort(). |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 2110 | */ |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2111 | if (!s->rep->analysers && |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2112 | !(s->rep->flags & (CF_HIJACK|CF_SHUTW|CF_SHUTR_NOW)) && |
Willy Tarreau | 31971e5 | 2009-09-20 12:07:52 +0200 | [diff] [blame] | 2113 | (s->rep->prod->state >= SI_ST_EST) && |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2114 | (s->rep->to_forward != CHN_INFINITE_FORWARD)) { |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2115 | /* This buffer is freewheeling, there's no analyser nor hijacker |
| 2116 | * attached to it. If any data are left in, we'll permit them to |
| 2117 | * move. |
| 2118 | */ |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2119 | channel_auto_read(s->rep); |
| 2120 | channel_auto_close(s->rep); |
Willy Tarreau | a75bcef | 2012-08-24 22:56:11 +0200 | [diff] [blame] | 2121 | buffer_flush(&s->rep->buf); |
Willy Tarreau | da4d9fe | 2010-11-07 20:26:56 +0100 | [diff] [blame] | 2122 | |
| 2123 | /* We'll let data flow between the producer (if still connected) |
| 2124 | * to the consumer. |
| 2125 | */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2126 | if (!(s->rep->flags & (CF_SHUTR|CF_SHUTW_NOW))) |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2127 | channel_forward(s->rep, CHN_INFINITE_FORWARD); |
Willy Tarreau | ce887fd | 2012-05-12 12:50:00 +0200 | [diff] [blame] | 2128 | |
| 2129 | /* if we have no analyser anymore in any direction and have a |
| 2130 | * tunnel timeout set, use it now. |
| 2131 | */ |
| 2132 | if (!s->req->analysers && s->be->timeout.tunnel) { |
| 2133 | s->req->rto = s->req->wto = s->rep->rto = s->rep->wto = |
| 2134 | s->be->timeout.tunnel; |
| 2135 | s->req->rex = s->req->wex = s->rep->rex = s->rep->wex = |
| 2136 | tick_add(now_ms, s->be->timeout.tunnel); |
| 2137 | } |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 2138 | } |
Willy Tarreau | f890dc9 | 2008-12-13 21:12:26 +0100 | [diff] [blame] | 2139 | |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2140 | /* check if it is wise to enable kernel splicing to forward response data */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2141 | if (!(s->rep->flags & (CF_KERN_SPLICING|CF_SHUTR)) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2142 | s->rep->to_forward && |
| 2143 | (global.tune.options & GTUNE_USE_SPLICE) && |
Willy Tarreau | 93b0f4f | 2012-08-30 21:23:53 +0200 | [diff] [blame] | 2144 | (s->si[0].conn.data && s->si[0].conn.data->rcv_pipe && s->si[0].conn.data->snd_pipe) && |
| 2145 | (s->si[1].conn.data && s->si[1].conn.data->rcv_pipe && s->si[1].conn.data->snd_pipe) && |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2146 | (pipes_used < global.maxpipes) && |
| 2147 | (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_RTR) || |
| 2148 | (((s->fe->options2|s->be->options2) & PR_O2_SPLIC_AUT) && |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2149 | (s->rep->flags & CF_STREAMER_FAST)))) { |
| 2150 | s->rep->flags |= CF_KERN_SPLICING; |
Willy Tarreau | 7c84bab | 2009-03-08 21:38:23 +0100 | [diff] [blame] | 2151 | } |
| 2152 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2153 | /* reflect what the L7 analysers have seen last */ |
| 2154 | rpf_last = s->rep->flags; |
| 2155 | |
| 2156 | /* |
| 2157 | * Now forward all shutdown requests between both sides of the buffer |
| 2158 | */ |
| 2159 | |
| 2160 | /* |
| 2161 | * FIXME: this is probably where we should produce error responses. |
| 2162 | */ |
| 2163 | |
Willy Tarreau | 6b66f3e | 2008-12-14 17:31:54 +0100 | [diff] [blame] | 2164 | /* first, let's check if the response buffer needs to shutdown(write) */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2165 | if (unlikely((s->rep->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_HIJACK|CF_AUTO_CLOSE|CF_SHUTR)) == |
| 2166 | (CF_AUTO_CLOSE|CF_SHUTR))) |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2167 | channel_shutw_now(s->rep); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2168 | |
| 2169 | /* shutdown(write) pending */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2170 | if (unlikely((s->rep->flags & (CF_SHUTW|CF_SHUTW_NOW)) == CF_SHUTW_NOW && |
Willy Tarreau | 8e21bb9 | 2012-08-24 22:40:29 +0200 | [diff] [blame] | 2171 | channel_is_empty(s->rep))) |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2172 | si_shutw(s->rep->cons); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2173 | |
| 2174 | /* shutdown(write) done on the client side, we must stop the server too */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2175 | if (unlikely((s->rep->flags & (CF_SHUTW|CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTW) && |
Willy Tarreau | 3dbc694 | 2008-12-07 13:05:04 +0100 | [diff] [blame] | 2176 | !s->rep->analysers) |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2177 | channel_shutr_now(s->rep); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2178 | |
| 2179 | /* shutdown(read) pending */ |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2180 | if (unlikely((s->rep->flags & (CF_SHUTR|CF_SHUTR_NOW)) == CF_SHUTR_NOW)) { |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 2181 | if (s->rep->prod->flags & SI_FL_NOHALF) |
| 2182 | s->rep->prod->flags |= SI_FL_NOLINGER; |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2183 | si_shutr(s->rep->prod); |
Willy Tarreau | 7bb68ab | 2012-05-13 14:48:59 +0200 | [diff] [blame] | 2184 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2185 | |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 2186 | if (s->req->prod->state == SI_ST_DIS || s->req->cons->state == SI_ST_DIS) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2187 | goto resync_stream_interface; |
| 2188 | |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 2189 | if (s->req->flags != rqf_last) |
| 2190 | goto resync_request; |
| 2191 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2192 | if ((s->rep->flags ^ rpf_last) & CF_MASK_STATIC) |
Willy Tarreau | 0be0ef9 | 2009-03-08 19:20:25 +0100 | [diff] [blame] | 2193 | goto resync_response; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2194 | |
Willy Tarreau | 89f7ef2 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 2195 | /* we're interested in getting wakeups again */ |
| 2196 | s->req->prod->flags &= ~SI_FL_DONT_WAKE; |
| 2197 | s->req->cons->flags &= ~SI_FL_DONT_WAKE; |
| 2198 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2199 | /* This is needed only when debugging is enabled, to indicate |
| 2200 | * client-side or server-side close. Please note that in the unlikely |
| 2201 | * event where both sides would close at once, the sequence is reported |
| 2202 | * on the server side first. |
| 2203 | */ |
| 2204 | if (unlikely((global.mode & MODE_DEBUG) && |
| 2205 | (!(global.mode & MODE_QUIET) || |
| 2206 | (global.mode & MODE_VERBOSE)))) { |
| 2207 | int len; |
| 2208 | |
| 2209 | if (s->si[1].state == SI_ST_CLO && |
| 2210 | s->si[1].prev_state == SI_ST_EST) { |
| 2211 | len = sprintf(trash, "%08x:%s.srvcls[%04x:%04x]\n", |
| 2212 | s->uniq_id, s->be->id, |
Willy Tarreau | fb7508a | 2012-05-21 16:47:54 +0200 | [diff] [blame] | 2213 | (unsigned short)si_fd(&s->si[0]), |
| 2214 | (unsigned short)si_fd(&s->si[1])); |
Willy Tarreau | 2133782 | 2012-04-29 14:11:38 +0200 | [diff] [blame] | 2215 | if (write(1, trash, len) < 0) /* shut gcc warning */; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2216 | } |
| 2217 | |
| 2218 | if (s->si[0].state == SI_ST_CLO && |
| 2219 | s->si[0].prev_state == SI_ST_EST) { |
| 2220 | len = sprintf(trash, "%08x:%s.clicls[%04x:%04x]\n", |
| 2221 | s->uniq_id, s->be->id, |
Willy Tarreau | fb7508a | 2012-05-21 16:47:54 +0200 | [diff] [blame] | 2222 | (unsigned short)si_fd(&s->si[0]), |
| 2223 | (unsigned short)si_fd(&s->si[1])); |
Willy Tarreau | 2133782 | 2012-04-29 14:11:38 +0200 | [diff] [blame] | 2224 | if (write(1, trash, len) < 0) /* shut gcc warning */; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | if (likely((s->rep->cons->state != SI_ST_CLO) || |
| 2229 | (s->req->cons->state > SI_ST_INI && s->req->cons->state < SI_ST_CLO))) { |
| 2230 | |
| 2231 | if ((s->fe->options & PR_O_CONTSTATS) && (s->flags & SN_BE_ASSIGNED)) |
| 2232 | session_process_counters(s); |
| 2233 | |
Willy Tarreau | 3cefd52 | 2012-08-30 15:49:18 +0200 | [diff] [blame] | 2234 | if (s->rep->cons->state == SI_ST_EST && s->rep->cons->conn.target.type != TARG_TYPE_APPLET) |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2235 | si_update(s->rep->cons); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2236 | |
Willy Tarreau | 3cefd52 | 2012-08-30 15:49:18 +0200 | [diff] [blame] | 2237 | if (s->req->cons->state == SI_ST_EST && s->req->cons->conn.target.type != TARG_TYPE_APPLET) |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2238 | si_update(s->req->cons); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2239 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2240 | s->req->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED); |
| 2241 | s->rep->flags &= ~(CF_READ_NULL|CF_READ_PARTIAL|CF_WRITE_NULL|CF_WRITE_PARTIAL|CF_READ_ATTACHED); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2242 | s->si[0].prev_state = s->si[0].state; |
| 2243 | s->si[1].prev_state = s->si[1].state; |
Willy Tarreau | b0ef735 | 2008-12-14 13:26:20 +0100 | [diff] [blame] | 2244 | s->si[0].flags &= ~(SI_FL_ERR|SI_FL_EXP); |
| 2245 | s->si[1].flags &= ~(SI_FL_ERR|SI_FL_EXP); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2246 | |
| 2247 | /* Trick: if a request is being waiting for the server to respond, |
| 2248 | * and if we know the server can timeout, we don't want the timeout |
| 2249 | * to expire on the client side first, but we're still interested |
| 2250 | * in passing data from the client to the server (eg: POST). Thus, |
| 2251 | * we can cancel the client's request timeout if the server's |
| 2252 | * request timeout is set and the server has not yet sent a response. |
| 2253 | */ |
| 2254 | |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2255 | if ((s->rep->flags & (CF_AUTO_CLOSE|CF_SHUTR)) == 0 && |
Willy Tarreau | 86491c3 | 2008-12-14 09:04:47 +0100 | [diff] [blame] | 2256 | (tick_isset(s->req->wex) || tick_isset(s->rep->rex))) { |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2257 | s->req->flags |= CF_READ_NOEXP; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2258 | s->req->rex = TICK_ETERNITY; |
Willy Tarreau | 86491c3 | 2008-12-14 09:04:47 +0100 | [diff] [blame] | 2259 | } |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2260 | |
Willy Tarreau | 7a20aa6 | 2010-07-13 16:30:45 +0200 | [diff] [blame] | 2261 | /* Call the stream interfaces' I/O handlers when embedded. |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 2262 | * Note that this one may wake the task up again. |
| 2263 | */ |
Willy Tarreau | 3cefd52 | 2012-08-30 15:49:18 +0200 | [diff] [blame] | 2264 | if (s->req->cons->conn.target.type == TARG_TYPE_APPLET || |
| 2265 | s->rep->cons->conn.target.type == TARG_TYPE_APPLET) { |
| 2266 | if (s->req->cons->conn.target.type == TARG_TYPE_APPLET) |
| 2267 | s->req->cons->conn.target.ptr.a->fct(s->req->cons); |
| 2268 | if (s->rep->cons->conn.target.type == TARG_TYPE_APPLET) |
| 2269 | s->rep->cons->conn.target.ptr.a->fct(s->rep->cons); |
Willy Tarreau | 1accfc0 | 2009-09-05 20:57:35 +0200 | [diff] [blame] | 2270 | if (task_in_rq(t)) { |
| 2271 | /* If we woke up, we don't want to requeue the |
| 2272 | * task to the wait queue, but rather requeue |
| 2273 | * it into the runqueue ASAP. |
| 2274 | */ |
| 2275 | t->expire = TICK_ETERNITY; |
| 2276 | return t; |
| 2277 | } |
| 2278 | } |
| 2279 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2280 | t->expire = tick_first(tick_first(s->req->rex, s->req->wex), |
| 2281 | tick_first(s->rep->rex, s->rep->wex)); |
| 2282 | if (s->req->analysers) |
| 2283 | t->expire = tick_first(t->expire, s->req->analyse_exp); |
| 2284 | |
| 2285 | if (s->si[0].exp) |
| 2286 | t->expire = tick_first(t->expire, s->si[0].exp); |
| 2287 | |
| 2288 | if (s->si[1].exp) |
| 2289 | t->expire = tick_first(t->expire, s->si[1].exp); |
| 2290 | |
| 2291 | #ifdef DEBUG_FULL |
Willy Tarreau | 127334e | 2009-03-28 10:47:26 +0100 | [diff] [blame] | 2292 | fprintf(stderr, |
| 2293 | "[%u] queuing with exp=%u req->rex=%u req->wex=%u req->ana_exp=%u" |
| 2294 | " rep->rex=%u rep->wex=%u, si[0].exp=%u, si[1].exp=%u, cs=%d, ss=%d\n", |
| 2295 | now_ms, t->expire, s->req->rex, s->req->wex, s->req->analyse_exp, |
| 2296 | s->rep->rex, s->rep->wex, s->si[0].exp, s->si[1].exp, s->si[0].state, s->si[1].state); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2297 | #endif |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2298 | |
| 2299 | #ifdef DEBUG_DEV |
| 2300 | /* this may only happen when no timeout is set or in case of an FSM bug */ |
Willy Tarreau | d0a201b | 2009-03-08 15:53:06 +0100 | [diff] [blame] | 2301 | if (!tick_isset(t->expire)) |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2302 | ABORT_NOW(); |
| 2303 | #endif |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 2304 | return t; /* nothing more to do */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | s->fe->feconn--; |
| 2308 | if (s->flags & SN_BE_ASSIGNED) |
| 2309 | s->be->beconn--; |
Willy Tarreau | 3c63fd8 | 2011-09-07 18:00:47 +0200 | [diff] [blame] | 2310 | if (!(s->listener->options & LI_O_UNLIMITED)) |
| 2311 | actconn--; |
Willy Tarreau | af7ad00 | 2010-08-31 15:39:26 +0200 | [diff] [blame] | 2312 | jobs--; |
Willy Tarreau | 6e6fb2b | 2009-08-16 18:20:44 +0200 | [diff] [blame] | 2313 | s->listener->nbconn--; |
Willy Tarreau | 6279371 | 2011-07-24 19:23:38 +0200 | [diff] [blame] | 2314 | if (s->listener->state == LI_FULL) |
| 2315 | resume_listener(s->listener); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2316 | |
Willy Tarreau | 08ceb10 | 2011-07-24 22:58:00 +0200 | [diff] [blame] | 2317 | /* Dequeues all of the listeners waiting for a resource */ |
| 2318 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2319 | dequeue_all_listeners(&global_listener_queue); |
| 2320 | |
Willy Tarreau | b32907b | 2011-07-25 08:37:44 +0200 | [diff] [blame] | 2321 | if (!LIST_ISEMPTY(&s->fe->listener_queue) && |
| 2322 | (!s->fe->fe_sps_lim || freq_ctr_remain(&s->fe->fe_sess_per_sec, s->fe->fe_sps_lim, 0) > 0)) |
Willy Tarreau | 07687c1 | 2011-07-24 23:55:06 +0200 | [diff] [blame] | 2323 | dequeue_all_listeners(&s->fe->listener_queue); |
| 2324 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2325 | if (unlikely((global.mode & MODE_DEBUG) && |
| 2326 | (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE)))) { |
| 2327 | int len; |
Willy Tarreau | ec22b2c | 2009-03-06 13:07:40 +0100 | [diff] [blame] | 2328 | len = sprintf(trash, "%08x:%s.closed[%04x:%04x]\n", |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2329 | s->uniq_id, s->be->id, |
Willy Tarreau | fb7508a | 2012-05-21 16:47:54 +0200 | [diff] [blame] | 2330 | (unsigned short)si_fd(s->req->prod), (unsigned short)si_fd(s->req->cons)); |
Willy Tarreau | 2133782 | 2012-04-29 14:11:38 +0200 | [diff] [blame] | 2331 | if (write(1, trash, len) < 0) /* shut gcc warning */; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | s->logs.t_close = tv_ms_elapsed(&s->logs.tv_accept, &now); |
| 2335 | session_process_counters(s); |
| 2336 | |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2337 | if (s->txn.status) { |
| 2338 | int n; |
| 2339 | |
| 2340 | n = s->txn.status / 100; |
| 2341 | if (n < 1 || n > 5) |
| 2342 | n = 0; |
| 2343 | |
| 2344 | if (s->fe->mode == PR_MODE_HTTP) |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2345 | s->fe->fe_counters.p.http.rsp[n]++; |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2346 | |
Willy Tarreau | 2465779 | 2010-02-26 10:30:28 +0100 | [diff] [blame] | 2347 | if ((s->flags & SN_BE_ASSIGNED) && |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2348 | (s->be->mode == PR_MODE_HTTP)) |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 2349 | s->be->be_counters.p.http.rsp[n]++; |
Krzysztof Piotr Oledzki | de71d16 | 2009-10-24 15:36:15 +0200 | [diff] [blame] | 2350 | } |
| 2351 | |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2352 | /* let's do a final log if we need it */ |
| 2353 | if (s->logs.logwait && |
| 2354 | !(s->flags & SN_MONITOR) && |
| 2355 | (!(s->fe->options & PR_O_NULLNOLOG) || s->req->total)) { |
Willy Tarreau | a5555ec | 2008-11-30 19:02:32 +0100 | [diff] [blame] | 2356 | s->do_log(s); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | /* the task MUST not be in the run queue anymore */ |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2360 | session_free(s); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 2361 | task_delete(t); |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2362 | task_free(t); |
Willy Tarreau | 26c2506 | 2009-03-08 09:38:41 +0100 | [diff] [blame] | 2363 | return NULL; |
Willy Tarreau | 55a8d0e | 2008-11-30 18:47:21 +0100 | [diff] [blame] | 2364 | } |
| 2365 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2366 | /* |
| 2367 | * This function adjusts sess->srv_conn and maintains the previous and new |
| 2368 | * server's served session counts. Setting newsrv to NULL is enough to release |
| 2369 | * current connection slot. This function also notifies any LB algo which might |
| 2370 | * expect to be informed about any change in the number of active sessions on a |
| 2371 | * server. |
| 2372 | */ |
| 2373 | void sess_change_server(struct session *sess, struct server *newsrv) |
| 2374 | { |
| 2375 | if (sess->srv_conn == newsrv) |
| 2376 | return; |
| 2377 | |
| 2378 | if (sess->srv_conn) { |
| 2379 | sess->srv_conn->served--; |
| 2380 | if (sess->srv_conn->proxy->lbprm.server_drop_conn) |
| 2381 | sess->srv_conn->proxy->lbprm.server_drop_conn(sess->srv_conn); |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 2382 | session_del_srv_conn(sess); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | if (newsrv) { |
| 2386 | newsrv->served++; |
| 2387 | if (newsrv->proxy->lbprm.server_take_conn) |
| 2388 | newsrv->proxy->lbprm.server_take_conn(newsrv); |
Simon Horman | af51495 | 2011-06-21 14:34:57 +0900 | [diff] [blame] | 2389 | session_add_srv_conn(sess, newsrv); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2390 | } |
| 2391 | } |
| 2392 | |
Willy Tarreau | 8445533 | 2009-03-15 22:34:05 +0100 | [diff] [blame] | 2393 | /* Handle server-side errors for default protocols. It is called whenever a a |
| 2394 | * connection setup is aborted or a request is aborted in queue. It sets the |
| 2395 | * session termination flags so that the caller does not have to worry about |
| 2396 | * them. It's installed as ->srv_error for the server-side stream_interface. |
| 2397 | */ |
| 2398 | void default_srv_error(struct session *s, struct stream_interface *si) |
| 2399 | { |
| 2400 | int err_type = si->err_type; |
| 2401 | int err = 0, fin = 0; |
| 2402 | |
| 2403 | if (err_type & SI_ET_QUEUE_ABRT) { |
| 2404 | err = SN_ERR_CLICL; |
| 2405 | fin = SN_FINST_Q; |
| 2406 | } |
| 2407 | else if (err_type & SI_ET_CONN_ABRT) { |
| 2408 | err = SN_ERR_CLICL; |
| 2409 | fin = SN_FINST_C; |
| 2410 | } |
| 2411 | else if (err_type & SI_ET_QUEUE_TO) { |
| 2412 | err = SN_ERR_SRVTO; |
| 2413 | fin = SN_FINST_Q; |
| 2414 | } |
| 2415 | else if (err_type & SI_ET_QUEUE_ERR) { |
| 2416 | err = SN_ERR_SRVCL; |
| 2417 | fin = SN_FINST_Q; |
| 2418 | } |
| 2419 | else if (err_type & SI_ET_CONN_TO) { |
| 2420 | err = SN_ERR_SRVTO; |
| 2421 | fin = SN_FINST_C; |
| 2422 | } |
| 2423 | else if (err_type & SI_ET_CONN_ERR) { |
| 2424 | err = SN_ERR_SRVCL; |
| 2425 | fin = SN_FINST_C; |
| 2426 | } |
| 2427 | else /* SI_ET_CONN_OTHER and others */ { |
| 2428 | err = SN_ERR_INTERNAL; |
| 2429 | fin = SN_FINST_C; |
| 2430 | } |
| 2431 | |
| 2432 | if (!(s->flags & SN_ERR_MASK)) |
| 2433 | s->flags |= err; |
| 2434 | if (!(s->flags & SN_FINST_MASK)) |
| 2435 | s->flags |= fin; |
| 2436 | } |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 2437 | |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 2438 | /* kill a session and set the termination flags to <why> (one of SN_ERR_*) */ |
| 2439 | void session_shutdown(struct session *session, int why) |
| 2440 | { |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2441 | if (session->req->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 2442 | return; |
| 2443 | |
Willy Tarreau | 8263d2b | 2012-08-28 00:06:31 +0200 | [diff] [blame] | 2444 | channel_shutw_now(session->req); |
| 2445 | channel_shutr_now(session->rep); |
Willy Tarreau | a2a64e9 | 2011-09-07 23:01:56 +0200 | [diff] [blame] | 2446 | session->task->nice = 1024; |
| 2447 | if (!(session->flags & SN_ERR_MASK)) |
| 2448 | session->flags |= why; |
| 2449 | task_wakeup(session->task, TASK_WOKEN_OTHER); |
| 2450 | } |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 2451 | |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2452 | /************************************************************************/ |
| 2453 | /* All supported ACL keywords must be declared here. */ |
| 2454 | /************************************************************************/ |
| 2455 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2456 | /* set temp integer to the General Purpose Counter 0 value in the stksess entry <ts> */ |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2457 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2458 | acl_fetch_get_gpc0(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2459 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2460 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2461 | smp->type = SMP_T_UINT; |
| 2462 | smp->data.uint = 0; |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2463 | if (ts != NULL) { |
| 2464 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0); |
| 2465 | if (!ptr) |
| 2466 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2467 | smp->data.uint = stktable_data_cast(ptr, gpc0); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2468 | } |
| 2469 | return 1; |
| 2470 | } |
| 2471 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2472 | /* set temp integer to the General Purpose Counter 0 value from the session's tracked |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2473 | * frontend counters. |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2474 | */ |
| 2475 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2476 | acl_fetch_sc1_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2477 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2478 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2479 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2480 | return 0; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2481 | return acl_fetch_get_gpc0(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2482 | } |
| 2483 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2484 | /* set temp integer to the General Purpose Counter 0 value from the session's tracked |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2485 | * backend counters. |
| 2486 | */ |
| 2487 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2488 | acl_fetch_sc2_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2489 | const struct arg *args, struct sample *smp) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2490 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2491 | if (!l4->stkctr2_entry) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2492 | return 0; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2493 | return acl_fetch_get_gpc0(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2494 | } |
| 2495 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2496 | /* set temp integer to the General Purpose Counter 0 value from the session's source |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2497 | * address in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2498 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2499 | */ |
| 2500 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2501 | acl_fetch_src_get_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2502 | const struct arg *args, struct sample *smp) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2503 | { |
| 2504 | struct stktable_key *key; |
| 2505 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 2506 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2507 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 2508 | return 0; |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2509 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2510 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2511 | return acl_fetch_get_gpc0(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | /* Increment the General Purpose Counter 0 value in the stksess entry <ts> and |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2515 | * return it into temp integer. |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2516 | */ |
| 2517 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2518 | acl_fetch_inc_gpc0(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2519 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2520 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2521 | smp->type = SMP_T_UINT; |
| 2522 | smp->data.uint = 0; |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2523 | if (ts != NULL) { |
| 2524 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0); |
| 2525 | if (!ptr) |
| 2526 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2527 | smp->data.uint = ++stktable_data_cast(ptr, gpc0); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2528 | } |
| 2529 | return 1; |
| 2530 | } |
| 2531 | |
| 2532 | /* Increment the General Purpose Counter 0 value from the session's tracked |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2533 | * frontend counters and return it into temp integer. |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2534 | */ |
| 2535 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2536 | acl_fetch_sc1_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2537 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2538 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2539 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2540 | return 0; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2541 | return acl_fetch_inc_gpc0(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | /* Increment the General Purpose Counter 0 value from the session's tracked |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2545 | * backend counters and return it into temp integer. |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2546 | */ |
| 2547 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2548 | acl_fetch_sc2_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2549 | const struct arg *args, struct sample *smp) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2550 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2551 | if (!l4->stkctr2_entry) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2552 | return 0; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2553 | return acl_fetch_inc_gpc0(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | /* Increment the General Purpose Counter 0 value from the session's source |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2557 | * address in the table pointed to by expr, and return it into temp integer. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2558 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2559 | */ |
| 2560 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2561 | acl_fetch_src_inc_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2562 | const struct arg *args, struct sample *smp) |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2563 | { |
| 2564 | struct stktable_key *key; |
| 2565 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 2566 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2567 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 2568 | return 0; |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2569 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2570 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2571 | return acl_fetch_inc_gpc0(&px->table, smp, stktable_update_key(&px->table, key)); |
Willy Tarreau | c3bd972 | 2010-06-20 12:47:25 +0200 | [diff] [blame] | 2572 | } |
| 2573 | |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2574 | /* Clear the General Purpose Counter 0 value in the stksess entry <ts> and |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2575 | * return its previous value into temp integer. |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2576 | */ |
| 2577 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2578 | acl_fetch_clr_gpc0(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2579 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2580 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2581 | smp->type = SMP_T_UINT; |
| 2582 | smp->data.uint = 0; |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2583 | if (ts != NULL) { |
| 2584 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_GPC0); |
| 2585 | if (!ptr) |
| 2586 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2587 | smp->data.uint = stktable_data_cast(ptr, gpc0); |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2588 | stktable_data_cast(ptr, gpc0) = 0; |
| 2589 | } |
| 2590 | return 1; |
| 2591 | } |
| 2592 | |
| 2593 | /* Clear the General Purpose Counter 0 value from the session's tracked |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2594 | * frontend counters and return its previous value into temp integer. |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2595 | */ |
| 2596 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2597 | acl_fetch_sc1_clr_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2598 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2599 | { |
| 2600 | if (!l4->stkctr1_entry) |
| 2601 | return 0; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2602 | return acl_fetch_clr_gpc0(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | /* Clear the General Purpose Counter 0 value from the session's tracked |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2606 | * backend counters and return its previous value into temp integer. |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2607 | */ |
| 2608 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2609 | acl_fetch_sc2_clr_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2610 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2611 | { |
| 2612 | if (!l4->stkctr2_entry) |
| 2613 | return 0; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2614 | return acl_fetch_clr_gpc0(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | /* Clear the General Purpose Counter 0 value from the session's source address |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2618 | * in the table pointed to by expr, and return its previous value into temp integer. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2619 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2620 | */ |
| 2621 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2622 | acl_fetch_src_clr_gpc0(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2623 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2624 | { |
| 2625 | struct stktable_key *key; |
| 2626 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 2627 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2628 | if (!key) |
| 2629 | return 0; |
| 2630 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2631 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2632 | return acl_fetch_clr_gpc0(&px->table, smp, stktable_update_key(&px->table, key)); |
Willy Tarreau | f73cd11 | 2011-08-13 01:45:16 +0200 | [diff] [blame] | 2633 | } |
| 2634 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2635 | /* set temp integer to the cumulated number of connections in the stksess entry <ts> */ |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2636 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2637 | acl_fetch_conn_cnt(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2638 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2639 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2640 | smp->type = SMP_T_UINT; |
| 2641 | smp->data.uint = 0; |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2642 | if (ts != NULL) { |
| 2643 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_CNT); |
| 2644 | if (!ptr) |
| 2645 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2646 | smp->data.uint = stktable_data_cast(ptr, conn_cnt); |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2647 | } |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2648 | return 1; |
| 2649 | } |
| 2650 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2651 | /* set temp integer to the cumulated number of connections from the session's tracked FE counters */ |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2652 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2653 | acl_fetch_sc1_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2654 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2655 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2656 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2657 | return 0; |
| 2658 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2659 | return acl_fetch_conn_cnt(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2660 | } |
| 2661 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2662 | /* set temp integer to the cumulated number of connections from the session's tracked BE counters */ |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2663 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2664 | acl_fetch_sc2_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2665 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2666 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2667 | if (!l4->stkctr2_entry) |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2668 | return 0; |
| 2669 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2670 | return acl_fetch_conn_cnt(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2671 | } |
| 2672 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2673 | /* set temp integer to the cumulated number of connections from the session's source |
Willy Tarreau | 9a3f849 | 2010-06-18 19:53:25 +0200 | [diff] [blame] | 2674 | * address in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2675 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2676 | */ |
| 2677 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2678 | acl_fetch_src_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2679 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2680 | { |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2681 | struct stktable_key *key; |
| 2682 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 2683 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2684 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 2685 | return 0; |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2686 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2687 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2688 | return acl_fetch_conn_cnt(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2689 | } |
| 2690 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2691 | /* set temp integer to the connection rate in the stksess entry <ts> over the configured period */ |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2692 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2693 | acl_fetch_conn_rate(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2694 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2695 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2696 | smp->type = SMP_T_UINT; |
| 2697 | smp->data.uint = 0; |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2698 | if (ts != NULL) { |
| 2699 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_RATE); |
| 2700 | if (!ptr) |
| 2701 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2702 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2703 | table->data_arg[STKTABLE_DT_CONN_RATE].u); |
| 2704 | } |
| 2705 | return 1; |
| 2706 | } |
| 2707 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2708 | /* set temp integer to the connection rate from the session's tracked FE counters over |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2709 | * the configured period. |
| 2710 | */ |
| 2711 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2712 | acl_fetch_sc1_conn_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2713 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2714 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2715 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2716 | return 0; |
| 2717 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2718 | return acl_fetch_conn_rate(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2719 | } |
| 2720 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2721 | /* set temp integer to the connection rate from the session's tracked BE counters over |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2722 | * the configured period. |
| 2723 | */ |
| 2724 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2725 | acl_fetch_sc2_conn_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2726 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2727 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2728 | if (!l4->stkctr2_entry) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2729 | return 0; |
| 2730 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2731 | return acl_fetch_conn_rate(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2732 | } |
| 2733 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2734 | /* set temp integer to the connection rate from the session's source address in the |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2735 | * table pointed to by expr, over the configured period. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2736 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2737 | */ |
| 2738 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2739 | acl_fetch_src_conn_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2740 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2741 | { |
| 2742 | struct stktable_key *key; |
| 2743 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 2744 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2745 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 2746 | return 0; |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2747 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2748 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2749 | return acl_fetch_conn_rate(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2750 | } |
| 2751 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2752 | /* set temp integer to the number of connections from the session's source address |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2753 | * in the table pointed to by expr, after updating it. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2754 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2755 | */ |
| 2756 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2757 | acl_fetch_src_updt_conn_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2758 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2759 | { |
| 2760 | struct stksess *ts; |
| 2761 | struct stktable_key *key; |
| 2762 | void *ptr; |
| 2763 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 2764 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2765 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 2766 | return 0; |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2767 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2768 | px = args->data.prx; |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2769 | |
Willy Tarreau | 1f7e925 | 2010-06-20 12:27:21 +0200 | [diff] [blame] | 2770 | if ((ts = stktable_update_key(&px->table, key)) == NULL) |
| 2771 | /* entry does not exist and could not be created */ |
| 2772 | return 0; |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2773 | |
| 2774 | ptr = stktable_data_ptr(&px->table, ts, STKTABLE_DT_CONN_CNT); |
| 2775 | if (!ptr) |
| 2776 | return 0; /* parameter not stored in this table */ |
| 2777 | |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2778 | smp->type = SMP_T_UINT; |
| 2779 | smp->data.uint = ++stktable_data_cast(ptr, conn_cnt); |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2780 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 2781 | return 1; |
| 2782 | } |
| 2783 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2784 | /* set temp integer to the number of concurrent connections in the stksess entry <ts> */ |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2785 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2786 | acl_fetch_conn_cur(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2787 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2788 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2789 | smp->type = SMP_T_UINT; |
| 2790 | smp->data.uint = 0; |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2791 | |
| 2792 | if (ts != NULL) { |
| 2793 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_CONN_CUR); |
| 2794 | if (!ptr) |
| 2795 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2796 | smp->data.uint = stktable_data_cast(ptr, conn_cur); |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2797 | } |
| 2798 | return 1; |
| 2799 | } |
| 2800 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2801 | /* set temp integer to the number of concurrent connections from the session's tracked FE counters */ |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2802 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2803 | acl_fetch_sc1_conn_cur(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2804 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2805 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2806 | if (!l4->stkctr1_entry) |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2807 | return 0; |
| 2808 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2809 | return acl_fetch_conn_cur(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | 9b0ddcf | 2010-06-18 21:14:36 +0200 | [diff] [blame] | 2810 | } |
| 2811 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2812 | /* set temp integer to the number of concurrent connections from the session's tracked BE counters */ |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2813 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2814 | acl_fetch_sc2_conn_cur(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2815 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2816 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2817 | if (!l4->stkctr2_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2818 | return 0; |
| 2819 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2820 | return acl_fetch_conn_cur(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2821 | } |
| 2822 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2823 | /* set temp integer to the number of concurrent connections from the session's source |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame] | 2824 | * address in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2825 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame] | 2826 | */ |
| 2827 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2828 | acl_fetch_src_conn_cur(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2829 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame] | 2830 | { |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame] | 2831 | struct stktable_key *key; |
| 2832 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 2833 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame] | 2834 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 2835 | return 0; |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame] | 2836 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2837 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2838 | return acl_fetch_conn_cur(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | 38285c1 | 2010-06-18 16:35:43 +0200 | [diff] [blame] | 2839 | } |
| 2840 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2841 | /* set temp integer to the cumulated number of sessions in the stksess entry <ts> */ |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2842 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2843 | acl_fetch_sess_cnt(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2844 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2845 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2846 | smp->type = SMP_T_UINT; |
| 2847 | smp->data.uint = 0; |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2848 | if (ts != NULL) { |
| 2849 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_SESS_CNT); |
| 2850 | if (!ptr) |
| 2851 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2852 | smp->data.uint = stktable_data_cast(ptr, sess_cnt); |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2853 | } |
| 2854 | return 1; |
| 2855 | } |
| 2856 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2857 | /* set temp integer to the cumulated number of sessions from the session's tracked FE counters */ |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2858 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2859 | acl_fetch_sc1_sess_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2860 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2861 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2862 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2863 | return 0; |
| 2864 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2865 | return acl_fetch_sess_cnt(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2866 | } |
| 2867 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2868 | /* set temp integer to the cumulated number of sessions from the session's tracked BE counters */ |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2869 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2870 | acl_fetch_sc2_sess_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2871 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2872 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2873 | if (!l4->stkctr2_entry) |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2874 | return 0; |
| 2875 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2876 | return acl_fetch_sess_cnt(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2877 | } |
| 2878 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2879 | /* set temp integer to the cumulated number of session from the session's source |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2880 | * address in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2881 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2882 | */ |
| 2883 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2884 | acl_fetch_src_sess_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2885 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2886 | { |
| 2887 | struct stktable_key *key; |
| 2888 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 2889 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2890 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 2891 | return 0; |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2892 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2893 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2894 | return acl_fetch_sess_cnt(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | f4d17d9 | 2010-06-18 22:10:12 +0200 | [diff] [blame] | 2895 | } |
| 2896 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2897 | /* set temp integer to the session rate in the stksess entry <ts> over the configured period */ |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2898 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2899 | acl_fetch_sess_rate(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2900 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2901 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2902 | smp->type = SMP_T_UINT; |
| 2903 | smp->data.uint = 0; |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2904 | if (ts != NULL) { |
| 2905 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_SESS_RATE); |
| 2906 | if (!ptr) |
| 2907 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2908 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2909 | table->data_arg[STKTABLE_DT_SESS_RATE].u); |
| 2910 | } |
| 2911 | return 1; |
| 2912 | } |
| 2913 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2914 | /* set temp integer to the session rate from the session's tracked FE counters over |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2915 | * the configured period. |
| 2916 | */ |
| 2917 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2918 | acl_fetch_sc1_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2919 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2920 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2921 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2922 | return 0; |
| 2923 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2924 | return acl_fetch_sess_rate(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2925 | } |
| 2926 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2927 | /* set temp integer to the session rate from the session's tracked BE counters over |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2928 | * the configured period. |
| 2929 | */ |
| 2930 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2931 | acl_fetch_sc2_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2932 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2933 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2934 | if (!l4->stkctr2_entry) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2935 | return 0; |
| 2936 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2937 | return acl_fetch_sess_rate(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2938 | } |
| 2939 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2940 | /* set temp integer to the session rate from the session's source address in the |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2941 | * table pointed to by expr, over the configured period. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2942 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2943 | */ |
| 2944 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2945 | acl_fetch_src_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2946 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2947 | { |
| 2948 | struct stktable_key *key; |
| 2949 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 2950 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2951 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 2952 | return 0; |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2953 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2954 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2955 | return acl_fetch_sess_rate(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | 91c43d7 | 2010-06-20 11:19:22 +0200 | [diff] [blame] | 2956 | } |
| 2957 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2958 | /* set temp integer to the cumulated number of sessions in the stksess entry <ts> */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2959 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2960 | acl_fetch_http_req_cnt(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2961 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2962 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2963 | smp->type = SMP_T_UINT; |
| 2964 | smp->data.uint = 0; |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2965 | if (ts != NULL) { |
| 2966 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_REQ_CNT); |
| 2967 | if (!ptr) |
| 2968 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 2969 | smp->data.uint = stktable_data_cast(ptr, http_req_cnt); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2970 | } |
| 2971 | return 1; |
| 2972 | } |
| 2973 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2974 | /* set temp integer to the cumulated number of sessions from the session's tracked FE counters */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2975 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2976 | acl_fetch_sc1_http_req_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2977 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2978 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2979 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2980 | return 0; |
| 2981 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2982 | return acl_fetch_http_req_cnt(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2983 | } |
| 2984 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2985 | /* set temp integer to the cumulated number of sessions from the session's tracked BE counters */ |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 2986 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 2987 | acl_fetch_sc2_http_req_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 2988 | const struct arg *args, struct sample *smp) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2989 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 2990 | if (!l4->stkctr2_entry) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2991 | return 0; |
| 2992 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 2993 | return acl_fetch_http_req_cnt(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2994 | } |
| 2995 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 2996 | /* set temp integer to the cumulated number of session from the session's source |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2997 | * address in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 2998 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 2999 | */ |
| 3000 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3001 | acl_fetch_src_http_req_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3002 | const struct arg *args, struct sample *smp) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3003 | { |
| 3004 | struct stktable_key *key; |
| 3005 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 3006 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3007 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 3008 | return 0; |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3009 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3010 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3011 | return acl_fetch_http_req_cnt(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3012 | } |
| 3013 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3014 | /* set temp integer to the session rate in the stksess entry <ts> over the configured period */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3015 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3016 | acl_fetch_http_req_rate(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3017 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3018 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3019 | smp->type = SMP_T_UINT; |
| 3020 | smp->data.uint = 0; |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3021 | if (ts != NULL) { |
| 3022 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_REQ_RATE); |
| 3023 | if (!ptr) |
| 3024 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3025 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3026 | table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); |
| 3027 | } |
| 3028 | return 1; |
| 3029 | } |
| 3030 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3031 | /* set temp integer to the session rate from the session's tracked FE counters over |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3032 | * the configured period. |
| 3033 | */ |
| 3034 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3035 | acl_fetch_sc1_http_req_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3036 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3037 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3038 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3039 | return 0; |
| 3040 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3041 | return acl_fetch_http_req_rate(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3042 | } |
| 3043 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3044 | /* set temp integer to the session rate from the session's tracked BE counters over |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3045 | * the configured period. |
| 3046 | */ |
| 3047 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3048 | acl_fetch_sc2_http_req_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3049 | const struct arg *args, struct sample *smp) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3050 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3051 | if (!l4->stkctr2_entry) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3052 | return 0; |
| 3053 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3054 | return acl_fetch_http_req_rate(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3055 | } |
| 3056 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3057 | /* set temp integer to the session rate from the session's source address in the |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3058 | * table pointed to by expr, over the configured period. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3059 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3060 | */ |
| 3061 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3062 | acl_fetch_src_http_req_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3063 | const struct arg *args, struct sample *smp) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3064 | { |
| 3065 | struct stktable_key *key; |
| 3066 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 3067 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3068 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 3069 | return 0; |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3070 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3071 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3072 | return acl_fetch_http_req_rate(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3073 | } |
| 3074 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3075 | /* set temp integer to the cumulated number of sessions in the stksess entry <ts> */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3076 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3077 | acl_fetch_http_err_cnt(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3078 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3079 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3080 | smp->type = SMP_T_UINT; |
| 3081 | smp->data.uint = 0; |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3082 | if (ts != NULL) { |
| 3083 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_ERR_CNT); |
| 3084 | if (!ptr) |
| 3085 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3086 | smp->data.uint = stktable_data_cast(ptr, http_err_cnt); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3087 | } |
| 3088 | return 1; |
| 3089 | } |
| 3090 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3091 | /* set temp integer to the cumulated number of sessions from the session's tracked FE counters */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3092 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3093 | acl_fetch_sc1_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3094 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3095 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3096 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3097 | return 0; |
| 3098 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3099 | return acl_fetch_http_err_cnt(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3100 | } |
| 3101 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3102 | /* set temp integer to the cumulated number of sessions from the session's tracked BE counters */ |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3103 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3104 | acl_fetch_sc2_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3105 | const struct arg *args, struct sample *smp) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3106 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3107 | if (!l4->stkctr2_entry) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3108 | return 0; |
| 3109 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3110 | return acl_fetch_http_err_cnt(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3111 | } |
| 3112 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3113 | /* set temp integer to the cumulated number of session from the session's source |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3114 | * address in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3115 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3116 | */ |
| 3117 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3118 | acl_fetch_src_http_err_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3119 | const struct arg *args, struct sample *smp) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3120 | { |
| 3121 | struct stktable_key *key; |
| 3122 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 3123 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3124 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 3125 | return 0; |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3126 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3127 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3128 | return acl_fetch_http_err_cnt(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3129 | } |
| 3130 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3131 | /* set temp integer to the session rate in the stksess entry <ts> over the configured period */ |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3132 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3133 | acl_fetch_http_err_rate(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3134 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3135 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3136 | smp->type = SMP_T_UINT; |
| 3137 | smp->data.uint = 0; |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3138 | if (ts != NULL) { |
| 3139 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_HTTP_ERR_RATE); |
| 3140 | if (!ptr) |
| 3141 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3142 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3143 | table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); |
| 3144 | } |
| 3145 | return 1; |
| 3146 | } |
| 3147 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3148 | /* set temp integer to the session rate from the session's tracked FE counters over |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3149 | * the configured period. |
| 3150 | */ |
| 3151 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3152 | acl_fetch_sc1_http_err_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3153 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3154 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3155 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3156 | return 0; |
| 3157 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3158 | return acl_fetch_http_err_rate(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3159 | } |
| 3160 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3161 | /* set temp integer to the session rate from the session's tracked BE counters over |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3162 | * the configured period. |
| 3163 | */ |
| 3164 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3165 | acl_fetch_sc2_http_err_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3166 | const struct arg *args, struct sample *smp) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3167 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3168 | if (!l4->stkctr2_entry) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3169 | return 0; |
| 3170 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3171 | return acl_fetch_http_err_rate(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3172 | } |
| 3173 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3174 | /* set temp integer to the session rate from the session's source address in the |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3175 | * table pointed to by expr, over the configured period. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3176 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3177 | */ |
| 3178 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3179 | acl_fetch_src_http_err_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3180 | const struct arg *args, struct sample *smp) |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3181 | { |
| 3182 | struct stktable_key *key; |
| 3183 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 3184 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3185 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 3186 | return 0; |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3187 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3188 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3189 | return acl_fetch_http_err_rate(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | da7ff64 | 2010-06-23 11:44:09 +0200 | [diff] [blame] | 3190 | } |
| 3191 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3192 | /* set temp integer to the number of kbytes received from clients matching the stksess entry <ts> */ |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3193 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3194 | acl_fetch_kbytes_in(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3195 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3196 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3197 | smp->type = SMP_T_UINT; |
| 3198 | smp->data.uint = 0; |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3199 | |
| 3200 | if (ts != NULL) { |
| 3201 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_IN_CNT); |
| 3202 | if (!ptr) |
| 3203 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3204 | smp->data.uint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3205 | } |
| 3206 | return 1; |
| 3207 | } |
| 3208 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3209 | /* set temp integer to the number of kbytes received from clients according to the |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3210 | * session's tracked FE counters. |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3211 | */ |
| 3212 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3213 | acl_fetch_sc1_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3214 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3215 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3216 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3217 | return 0; |
| 3218 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3219 | return acl_fetch_kbytes_in(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3220 | } |
| 3221 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3222 | /* set temp integer to the number of kbytes received from clients according to the |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3223 | * session's tracked BE counters. |
| 3224 | */ |
| 3225 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3226 | acl_fetch_sc2_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3227 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3228 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3229 | if (!l4->stkctr2_entry) |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3230 | return 0; |
| 3231 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3232 | return acl_fetch_kbytes_in(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3233 | } |
| 3234 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3235 | /* set temp integer to the number of kbytes received from the session's source |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3236 | * address in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3237 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3238 | */ |
| 3239 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3240 | acl_fetch_src_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3241 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3242 | { |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3243 | struct stktable_key *key; |
| 3244 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 3245 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3246 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 3247 | return 0; |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3248 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3249 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3250 | return acl_fetch_kbytes_in(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3251 | } |
| 3252 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3253 | /* set temp integer to the bytes rate from clients in the stksess entry <ts> over the |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3254 | * configured period. |
| 3255 | */ |
| 3256 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3257 | acl_fetch_bytes_in_rate(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3258 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3259 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3260 | smp->type = SMP_T_UINT; |
| 3261 | smp->data.uint = 0; |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3262 | if (ts != NULL) { |
| 3263 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_IN_RATE); |
| 3264 | if (!ptr) |
| 3265 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3266 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3267 | table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); |
| 3268 | } |
| 3269 | return 1; |
| 3270 | } |
| 3271 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3272 | /* set temp integer to the bytes rate from clients from the session's tracked FE |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3273 | * counters over the configured period. |
| 3274 | */ |
| 3275 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3276 | acl_fetch_sc1_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3277 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3278 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3279 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3280 | return 0; |
| 3281 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3282 | return acl_fetch_bytes_in_rate(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3283 | } |
| 3284 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3285 | /* set temp integer to the bytes rate from clients from the session's tracked BE |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3286 | * counters over the configured period. |
| 3287 | */ |
| 3288 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3289 | acl_fetch_sc2_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3290 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3291 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3292 | if (!l4->stkctr2_entry) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3293 | return 0; |
| 3294 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3295 | return acl_fetch_bytes_in_rate(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3296 | } |
| 3297 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3298 | /* set temp integer to the bytes rate from clients from the session's source address |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3299 | * in the table pointed to by expr, over the configured period. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3300 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3301 | */ |
| 3302 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3303 | acl_fetch_src_bytes_in_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3304 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3305 | { |
| 3306 | struct stktable_key *key; |
| 3307 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 3308 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3309 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 3310 | return 0; |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3311 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3312 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3313 | return acl_fetch_bytes_in_rate(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3314 | } |
| 3315 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3316 | /* set temp integer to the number of kbytes sent to clients matching the stksess entry <ts> */ |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3317 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3318 | acl_fetch_kbytes_out(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3319 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3320 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3321 | smp->type = SMP_T_UINT; |
| 3322 | smp->data.uint = 0; |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3323 | |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3324 | if (ts != NULL) { |
| 3325 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_OUT_CNT); |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3326 | if (!ptr) |
| 3327 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3328 | smp->data.uint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3329 | } |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3330 | return 1; |
| 3331 | } |
| 3332 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3333 | /* set temp integer to the number of kbytes sent to clients according to the session's |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3334 | * tracked FE counters. |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3335 | */ |
| 3336 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3337 | acl_fetch_sc1_kbytes_out(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3338 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3339 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3340 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3341 | return 0; |
| 3342 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3343 | return acl_fetch_kbytes_out(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3344 | } |
| 3345 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3346 | /* set temp integer to the number of kbytes sent to clients according to the session's |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3347 | * tracked BE counters. |
| 3348 | */ |
| 3349 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3350 | acl_fetch_sc2_kbytes_out(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3351 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3352 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3353 | if (!l4->stkctr2_entry) |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3354 | return 0; |
| 3355 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3356 | return acl_fetch_kbytes_out(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | 1aa006f | 2010-06-18 21:52:52 +0200 | [diff] [blame] | 3357 | } |
| 3358 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3359 | /* set temp integer to the number of kbytes sent to the session's source address in |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3360 | * the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3361 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3362 | */ |
| 3363 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3364 | acl_fetch_src_kbytes_out(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3365 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3366 | { |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3367 | struct stktable_key *key; |
| 3368 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 3369 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3370 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 3371 | return 0; |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3372 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3373 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3374 | return acl_fetch_kbytes_out(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | 855e4bb | 2010-06-18 18:33:32 +0200 | [diff] [blame] | 3375 | } |
| 3376 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3377 | /* set temp integer to the bytes rate to clients in the stksess entry <ts> over the |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3378 | * configured period. |
| 3379 | */ |
| 3380 | static int |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3381 | acl_fetch_bytes_out_rate(struct stktable *table, struct sample *smp, struct stksess *ts) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3382 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3383 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3384 | smp->type = SMP_T_UINT; |
| 3385 | smp->data.uint = 0; |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3386 | if (ts != NULL) { |
| 3387 | void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_OUT_RATE); |
| 3388 | if (!ptr) |
| 3389 | return 0; /* parameter not stored */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3390 | smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3391 | table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); |
| 3392 | } |
| 3393 | return 1; |
| 3394 | } |
| 3395 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3396 | /* set temp integer to the bytes rate to clients from the session's tracked FE counters |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3397 | * over the configured period. |
| 3398 | */ |
| 3399 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3400 | acl_fetch_sc1_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3401 | const struct arg *args, struct sample *smp) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3402 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3403 | if (!l4->stkctr1_entry) |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3404 | return 0; |
| 3405 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3406 | return acl_fetch_bytes_out_rate(l4->stkctr1_table, smp, l4->stkctr1_entry); |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3407 | } |
| 3408 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3409 | /* set temp integer to the bytes rate to clients from the session's tracked BE counters |
Willy Tarreau | f059a0f | 2010-08-03 16:29:52 +0200 | [diff] [blame] | 3410 | * over the configured period. |
| 3411 | */ |
| 3412 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3413 | acl_fetch_sc2_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3414 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3415 | { |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3416 | if (!l4->stkctr2_entry) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3417 | return 0; |
| 3418 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3419 | return acl_fetch_bytes_out_rate(l4->stkctr2_table, smp, l4->stkctr2_entry); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3420 | } |
| 3421 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 3422 | /* set temp integer to the bytes rate to client from the session's source address in |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3423 | * the table pointed to by expr, over the configured period. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3424 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3425 | */ |
| 3426 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3427 | acl_fetch_src_bytes_out_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3428 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3429 | { |
| 3430 | struct stktable_key *key; |
| 3431 | |
Willy Tarreau | 64ee491 | 2012-08-30 22:59:48 +0200 | [diff] [blame] | 3432 | key = addr_to_stktable_key(&l4->si[0].conn.addr.from); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3433 | if (!key) |
David du Colombier | 4f92d32 | 2011-03-24 11:09:31 +0100 | [diff] [blame] | 3434 | return 0; |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3435 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3436 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3437 | return acl_fetch_bytes_out_rate(&px->table, smp, stktable_lookup_key(&px->table, key)); |
Willy Tarreau | 6c59e0a | 2010-06-20 11:56:30 +0200 | [diff] [blame] | 3438 | } |
| 3439 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 3440 | /* set temp integer to the number of used entries in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3441 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 3442 | */ |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3443 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3444 | acl_fetch_table_cnt(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3445 | const struct arg *args, struct sample *smp) |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3446 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3447 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3448 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3449 | smp->data.uint = args->data.prx->table.current; |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3450 | return 1; |
| 3451 | } |
| 3452 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 3453 | /* set temp integer to the number of free entries in the table pointed to by expr. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 3454 | * Accepts exactly 1 argument of type table. |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 3455 | */ |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3456 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 3457 | acl_fetch_table_avl(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3458 | const struct arg *args, struct sample *smp) |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3459 | { |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 3460 | px = args->data.prx; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 3461 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 3462 | smp->type = SMP_T_UINT; |
| 3463 | smp->data.uint = px->table.size - px->table.current; |
Willy Tarreau | c735a07 | 2011-03-29 00:57:02 +0200 | [diff] [blame] | 3464 | return 1; |
| 3465 | } |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 3466 | |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 3467 | /* Note: must not be declared <const> as its list will be overwritten. |
| 3468 | * Please take care of keeping this list alphabetically sorted. |
| 3469 | */ |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 3470 | static struct acl_kw_list acl_kws = {{ },{ |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 3471 | { "sc1_bytes_in_rate", acl_parse_int, acl_fetch_sc1_bytes_in_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3472 | { "sc1_bytes_out_rate", acl_parse_int, acl_fetch_sc1_bytes_out_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3473 | { "sc1_clr_gpc0", acl_parse_int, acl_fetch_sc1_clr_gpc0, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3474 | { "sc1_conn_cnt", acl_parse_int, acl_fetch_sc1_conn_cnt, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3475 | { "sc1_conn_cur", acl_parse_int, acl_fetch_sc1_conn_cur, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3476 | { "sc1_conn_rate", acl_parse_int, acl_fetch_sc1_conn_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3477 | { "sc1_get_gpc0", acl_parse_int, acl_fetch_sc1_get_gpc0, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3478 | { "sc1_http_err_cnt", acl_parse_int, acl_fetch_sc1_http_err_cnt, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3479 | { "sc1_http_err_rate", acl_parse_int, acl_fetch_sc1_http_err_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3480 | { "sc1_http_req_cnt", acl_parse_int, acl_fetch_sc1_http_req_cnt, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3481 | { "sc1_http_req_rate", acl_parse_int, acl_fetch_sc1_http_req_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3482 | { "sc1_inc_gpc0", acl_parse_int, acl_fetch_sc1_inc_gpc0, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3483 | { "sc1_kbytes_in", acl_parse_int, acl_fetch_sc1_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE, 0 }, |
| 3484 | { "sc1_kbytes_out", acl_parse_int, acl_fetch_sc1_kbytes_out, acl_match_int, ACL_USE_TCP4_VOLATILE, 0 }, |
| 3485 | { "sc1_sess_cnt", acl_parse_int, acl_fetch_sc1_sess_cnt, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3486 | { "sc1_sess_rate", acl_parse_int, acl_fetch_sc1_sess_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3487 | { "sc2_bytes_in_rate", acl_parse_int, acl_fetch_sc2_bytes_in_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3488 | { "sc2_bytes_out_rate", acl_parse_int, acl_fetch_sc2_bytes_out_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3489 | { "sc2_clr_gpc0", acl_parse_int, acl_fetch_sc2_clr_gpc0, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3490 | { "sc2_conn_cnt", acl_parse_int, acl_fetch_sc2_conn_cnt, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3491 | { "sc2_conn_cur", acl_parse_int, acl_fetch_sc2_conn_cur, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3492 | { "sc2_conn_rate", acl_parse_int, acl_fetch_sc2_conn_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3493 | { "sc2_get_gpc0", acl_parse_int, acl_fetch_sc2_get_gpc0, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3494 | { "sc2_http_err_cnt", acl_parse_int, acl_fetch_sc2_http_err_cnt, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3495 | { "sc2_http_err_rate", acl_parse_int, acl_fetch_sc2_http_err_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3496 | { "sc2_http_req_cnt", acl_parse_int, acl_fetch_sc2_http_req_cnt, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3497 | { "sc2_http_req_rate", acl_parse_int, acl_fetch_sc2_http_req_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3498 | { "sc2_inc_gpc0", acl_parse_int, acl_fetch_sc2_inc_gpc0, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3499 | { "sc2_kbytes_in", acl_parse_int, acl_fetch_sc2_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE, 0 }, |
| 3500 | { "sc2_kbytes_out", acl_parse_int, acl_fetch_sc2_kbytes_out, acl_match_int, ACL_USE_TCP4_VOLATILE, 0 }, |
| 3501 | { "sc2_sess_cnt", acl_parse_int, acl_fetch_sc2_sess_cnt, acl_match_int, ACL_USE_NOTHING, 0 }, |
| 3502 | { "sc2_sess_rate", acl_parse_int, acl_fetch_sc2_sess_rate, acl_match_int, ACL_USE_NOTHING, 0 }, |
Willy Tarreau | fc2c1fd | 2012-04-19 23:35:54 +0200 | [diff] [blame] | 3503 | { "src_bytes_in_rate", acl_parse_int, acl_fetch_src_bytes_in_rate, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3504 | { "src_bytes_out_rate", acl_parse_int, acl_fetch_src_bytes_out_rate, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3505 | { "src_clr_gpc0", acl_parse_int, acl_fetch_src_clr_gpc0, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3506 | { "src_conn_cnt", acl_parse_int, acl_fetch_src_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3507 | { "src_conn_cur", acl_parse_int, acl_fetch_src_conn_cur, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3508 | { "src_conn_rate", acl_parse_int, acl_fetch_src_conn_rate, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3509 | { "src_get_gpc0", acl_parse_int, acl_fetch_src_get_gpc0, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3510 | { "src_http_err_cnt", acl_parse_int, acl_fetch_src_http_err_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3511 | { "src_http_err_rate", acl_parse_int, acl_fetch_src_http_err_rate, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3512 | { "src_http_req_cnt", acl_parse_int, acl_fetch_src_http_req_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3513 | { "src_http_req_rate", acl_parse_int, acl_fetch_src_http_req_rate, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3514 | { "src_inc_gpc0", acl_parse_int, acl_fetch_src_inc_gpc0, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3515 | { "src_kbytes_in", acl_parse_int, acl_fetch_src_kbytes_in, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3516 | { "src_kbytes_out", acl_parse_int, acl_fetch_src_kbytes_out, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3517 | { "src_sess_cnt", acl_parse_int, acl_fetch_src_sess_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3518 | { "src_sess_rate", acl_parse_int, acl_fetch_src_sess_rate, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3519 | { "src_updt_conn_cnt", acl_parse_int, acl_fetch_src_updt_conn_cnt, acl_match_int, ACL_USE_TCP4_VOLATILE, ARG1(1,TAB) }, |
| 3520 | { "table_avl", acl_parse_int, acl_fetch_table_avl, acl_match_int, ACL_USE_NOTHING, ARG1(1,TAB) }, |
| 3521 | { "table_cnt", acl_parse_int, acl_fetch_table_cnt, acl_match_int, ACL_USE_NOTHING, ARG1(1,TAB) }, |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 3522 | { NULL, NULL, NULL, NULL }, |
| 3523 | }}; |
| 3524 | |
| 3525 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3526 | /* Parse a "track-sc[12]" line starting with "track-sc[12]" in args[arg-1]. |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 3527 | * Returns the number of warnings emitted, or -1 in case of fatal errors. The |
| 3528 | * <prm> struct is fed with the table name if any. If unspecified, the caller |
| 3529 | * will assume that the current proxy's table is used. |
| 3530 | */ |
| 3531 | int parse_track_counters(char **args, int *arg, |
| 3532 | int section_type, struct proxy *curpx, |
| 3533 | struct track_ctr_prm *prm, |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 3534 | struct proxy *defpx, char **err) |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 3535 | { |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3536 | int sample_type = 0; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 3537 | |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3538 | /* parse the arguments of "track-sc[12]" before the condition in the |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 3539 | * following form : |
Willy Tarreau | 5612328 | 2010-08-06 19:06:56 +0200 | [diff] [blame] | 3540 | * track-sc[12] src [ table xxx ] [ if|unless ... ] |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 3541 | */ |
| 3542 | while (args[*arg]) { |
| 3543 | if (strcmp(args[*arg], "src") == 0) { |
| 3544 | prm->type = STKTABLE_TYPE_IP; |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3545 | sample_type = 1; |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 3546 | } |
| 3547 | else if (strcmp(args[*arg], "table") == 0) { |
| 3548 | if (!args[*arg + 1]) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 3549 | memprintf(err, "missing table name"); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 3550 | return -1; |
| 3551 | } |
| 3552 | /* we copy the table name for now, it will be resolved later */ |
| 3553 | prm->table.n = strdup(args[*arg + 1]); |
| 3554 | (*arg)++; |
| 3555 | } |
| 3556 | else { |
| 3557 | /* unhandled keywords are handled by the caller */ |
| 3558 | break; |
| 3559 | } |
| 3560 | (*arg)++; |
| 3561 | } |
| 3562 | |
Willy Tarreau | 1278578 | 2012-04-27 21:37:17 +0200 | [diff] [blame] | 3563 | if (!sample_type) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 3564 | memprintf(err, |
| 3565 | "tracking key not specified (found %s, only 'src' is supported)", |
| 3566 | quote_arg(args[*arg])); |
Willy Tarreau | 9ba2dcc | 2010-06-14 21:04:55 +0200 | [diff] [blame] | 3567 | return -1; |
| 3568 | } |
| 3569 | |
| 3570 | return 0; |
| 3571 | } |
| 3572 | |
Willy Tarreau | 8b22a71 | 2010-06-18 17:46:06 +0200 | [diff] [blame] | 3573 | __attribute__((constructor)) |
| 3574 | static void __session_init(void) |
| 3575 | { |
| 3576 | acl_register_keywords(&acl_kws); |
| 3577 | } |
| 3578 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 3579 | /* |
| 3580 | * Local variables: |
| 3581 | * c-indent-level: 8 |
| 3582 | * c-basic-offset: 8 |
| 3583 | * End: |
| 3584 | */ |