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