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