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