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