Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Backend variables and functions. |
| 3 | * |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <errno.h> |
| 14 | #include <fcntl.h> |
| 15 | #include <stdio.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <syslog.h> |
Willy Tarreau | f19cf37 | 2006-11-14 15:40:51 +0100 | [diff] [blame] | 18 | #include <string.h> |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 19 | #include <ctype.h> |
Dmitry Sivachenko | caf5898 | 2009-08-24 15:11:06 +0400 | [diff] [blame] | 20 | #include <sys/types.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 22 | #include <common/buffer.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 23 | #include <common/compat.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 24 | #include <common/config.h> |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 25 | #include <common/debug.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 26 | #include <common/ticks.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 27 | #include <common/time.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 28 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 29 | #include <types/global.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 30 | |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 31 | #include <proto/acl.h> |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 32 | #include <proto/arg.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 33 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 34 | #include <proto/channel.h> |
Willy Tarreau | 03fa5df | 2010-05-24 21:02:37 +0200 | [diff] [blame] | 35 | #include <proto/frontend.h> |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 36 | #include <proto/lb_chash.h> |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 37 | #include <proto/lb_fas.h> |
Willy Tarreau | f89c187 | 2009-10-01 11:19:37 +0200 | [diff] [blame] | 38 | #include <proto/lb_fwlc.h> |
| 39 | #include <proto/lb_fwrr.h> |
| 40 | #include <proto/lb_map.h> |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 41 | #include <proto/protocols.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 42 | #include <proto/proto_http.h> |
Willy Tarreau | a8f55d5 | 2010-05-31 17:44:19 +0200 | [diff] [blame] | 43 | #include <proto/proto_tcp.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 44 | #include <proto/queue.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 45 | #include <proto/server.h> |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 46 | #include <proto/session.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 47 | #include <proto/raw_sock.h> |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 48 | #include <proto/stream_interface.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 49 | #include <proto/task.h> |
| 50 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 51 | /* |
| 52 | * This function recounts the number of usable active and backup servers for |
| 53 | * proxy <p>. These numbers are returned into the p->srv_act and p->srv_bck. |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 54 | * This function also recomputes the total active and backup weights. However, |
Willy Tarreau | f4cca45 | 2008-03-08 21:42:54 +0100 | [diff] [blame] | 55 | * it does not update tot_weight nor tot_used. Use update_backend_weight() for |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 56 | * this. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 57 | */ |
Willy Tarreau | c5d9c80 | 2009-10-01 09:17:05 +0200 | [diff] [blame] | 58 | void recount_servers(struct proxy *px) |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 59 | { |
| 60 | struct server *srv; |
| 61 | |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 62 | px->srv_act = px->srv_bck = 0; |
| 63 | px->lbprm.tot_wact = px->lbprm.tot_wbck = 0; |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 64 | px->lbprm.fbck = NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 65 | for (srv = px->srv; srv != NULL; srv = srv->next) { |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 66 | if (!srv_is_usable(srv->state, srv->eweight)) |
| 67 | continue; |
| 68 | |
| 69 | if (srv->state & SRV_BACKUP) { |
| 70 | if (!px->srv_bck && |
Willy Tarreau | f4cca45 | 2008-03-08 21:42:54 +0100 | [diff] [blame] | 71 | !(px->options & PR_O_USE_ALL_BK)) |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 72 | px->lbprm.fbck = srv; |
| 73 | px->srv_bck++; |
| 74 | px->lbprm.tot_wbck += srv->eweight; |
| 75 | } else { |
| 76 | px->srv_act++; |
| 77 | px->lbprm.tot_wact += srv->eweight; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 78 | } |
| 79 | } |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 80 | } |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 81 | |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 82 | /* This function simply updates the backend's tot_weight and tot_used values |
| 83 | * after servers weights have been updated. It is designed to be used after |
| 84 | * recount_servers() or equivalent. |
| 85 | */ |
Willy Tarreau | c5d9c80 | 2009-10-01 09:17:05 +0200 | [diff] [blame] | 86 | void update_backend_weight(struct proxy *px) |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 87 | { |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 88 | if (px->srv_act) { |
| 89 | px->lbprm.tot_weight = px->lbprm.tot_wact; |
| 90 | px->lbprm.tot_used = px->srv_act; |
| 91 | } |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 92 | else if (px->lbprm.fbck) { |
| 93 | /* use only the first backup server */ |
| 94 | px->lbprm.tot_weight = px->lbprm.fbck->eweight; |
| 95 | px->lbprm.tot_used = 1; |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 96 | } |
| 97 | else { |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 98 | px->lbprm.tot_weight = px->lbprm.tot_wbck; |
| 99 | px->lbprm.tot_used = px->srv_bck; |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 100 | } |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 103 | /* |
| 104 | * This function tries to find a running server for the proxy <px> following |
| 105 | * the source hash method. Depending on the number of active/backup servers, |
| 106 | * it will either look for active servers, or for backup servers. |
| 107 | * If any server is found, it will be returned. If no valid server is found, |
| 108 | * NULL is returned. |
| 109 | */ |
| 110 | struct server *get_server_sh(struct proxy *px, const char *addr, int len) |
| 111 | { |
| 112 | unsigned int h, l; |
| 113 | |
| 114 | if (px->lbprm.tot_weight == 0) |
| 115 | return NULL; |
| 116 | |
| 117 | l = h = 0; |
| 118 | |
| 119 | /* note: we won't hash if there's only one server left */ |
| 120 | if (px->lbprm.tot_used == 1) |
| 121 | goto hash_done; |
| 122 | |
| 123 | while ((l + sizeof (int)) <= len) { |
| 124 | h ^= ntohl(*(unsigned int *)(&addr[l])); |
| 125 | l += sizeof (int); |
| 126 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 127 | if ((px->lbprm.algo & BE_LB_HASH_TYPE) != BE_LB_HASH_MAP) |
| 128 | h = full_hash(h); |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 129 | hash_done: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 130 | if (px->lbprm.algo & BE_LB_LKUP_CHTREE) |
| 131 | return chash_get_server_hash(px, h); |
| 132 | else |
| 133 | return map_get_server_hash(px, h); |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* |
| 137 | * This function tries to find a running server for the proxy <px> following |
| 138 | * the URI hash method. In order to optimize cache hits, the hash computation |
| 139 | * ends at the question mark. Depending on the number of active/backup servers, |
| 140 | * it will either look for active servers, or for backup servers. |
| 141 | * If any server is found, it will be returned. If no valid server is found, |
| 142 | * NULL is returned. |
| 143 | * |
| 144 | * This code was contributed by Guillaume Dallaire, who also selected this hash |
| 145 | * algorithm out of a tens because it gave him the best results. |
| 146 | * |
| 147 | */ |
| 148 | struct server *get_server_uh(struct proxy *px, char *uri, int uri_len) |
| 149 | { |
| 150 | unsigned long hash = 0; |
| 151 | int c; |
| 152 | int slashes = 0; |
| 153 | |
| 154 | if (px->lbprm.tot_weight == 0) |
| 155 | return NULL; |
| 156 | |
| 157 | /* note: we won't hash if there's only one server left */ |
| 158 | if (px->lbprm.tot_used == 1) |
| 159 | goto hash_done; |
| 160 | |
| 161 | if (px->uri_len_limit) |
| 162 | uri_len = MIN(uri_len, px->uri_len_limit); |
| 163 | |
| 164 | while (uri_len--) { |
| 165 | c = *uri++; |
| 166 | if (c == '/') { |
| 167 | slashes++; |
| 168 | if (slashes == px->uri_dirs_depth1) /* depth+1 */ |
| 169 | break; |
| 170 | } |
Oskar Stolc | 8dc4184 | 2012-05-19 10:19:54 +0100 | [diff] [blame] | 171 | else if (c == '?' && !px->uri_whole) |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 172 | break; |
| 173 | |
| 174 | hash = c + (hash << 6) + (hash << 16) - hash; |
| 175 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 176 | if ((px->lbprm.algo & BE_LB_HASH_TYPE) != BE_LB_HASH_MAP) |
| 177 | hash = full_hash(hash); |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 178 | hash_done: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 179 | if (px->lbprm.algo & BE_LB_LKUP_CHTREE) |
| 180 | return chash_get_server_hash(px, hash); |
| 181 | else |
| 182 | return map_get_server_hash(px, hash); |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 185 | /* |
| 186 | * This function tries to find a running server for the proxy <px> following |
| 187 | * the URL parameter hash method. It looks for a specific parameter in the |
| 188 | * URL and hashes it to compute the server ID. This is useful to optimize |
| 189 | * performance by avoiding bounces between servers in contexts where sessions |
| 190 | * are shared but cookies are not usable. If the parameter is not found, NULL |
| 191 | * is returned. If any server is found, it will be returned. If no valid server |
| 192 | * is found, NULL is returned. |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 193 | */ |
| 194 | struct server *get_server_ph(struct proxy *px, const char *uri, int uri_len) |
| 195 | { |
| 196 | unsigned long hash = 0; |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 197 | const char *p; |
| 198 | const char *params; |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 199 | int plen; |
| 200 | |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 201 | /* when tot_weight is 0 then so is srv_count */ |
Willy Tarreau | 2069704 | 2007-11-15 23:26:18 +0100 | [diff] [blame] | 202 | if (px->lbprm.tot_weight == 0) |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 203 | return NULL; |
| 204 | |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 205 | if ((p = memchr(uri, '?', uri_len)) == NULL) |
| 206 | return NULL; |
| 207 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 208 | p++; |
| 209 | |
| 210 | uri_len -= (p - uri); |
| 211 | plen = px->url_param_len; |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 212 | params = p; |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 213 | |
| 214 | while (uri_len > plen) { |
| 215 | /* Look for the parameter name followed by an equal symbol */ |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 216 | if (params[plen] == '=') { |
| 217 | if (memcmp(params, px->url_param_name, plen) == 0) { |
| 218 | /* OK, we have the parameter here at <params>, and |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 219 | * the value after the equal sign, at <p> |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 220 | * skip the equal symbol |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 221 | */ |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 222 | p += plen + 1; |
| 223 | uri_len -= plen + 1; |
| 224 | |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 225 | while (uri_len && *p != '&') { |
| 226 | hash = *p + (hash << 6) + (hash << 16) - hash; |
| 227 | uri_len--; |
| 228 | p++; |
| 229 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 230 | if ((px->lbprm.algo & BE_LB_HASH_TYPE) != BE_LB_HASH_MAP) |
| 231 | hash = full_hash(hash); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 232 | if (px->lbprm.algo & BE_LB_LKUP_CHTREE) |
| 233 | return chash_get_server_hash(px, hash); |
| 234 | else |
| 235 | return map_get_server_hash(px, hash); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 236 | } |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 237 | } |
| 238 | /* skip to next parameter */ |
| 239 | p = memchr(params, '&', uri_len); |
| 240 | if (!p) |
| 241 | return NULL; |
| 242 | p++; |
| 243 | uri_len -= (p - params); |
| 244 | params = p; |
| 245 | } |
| 246 | return NULL; |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * this does the same as the previous server_ph, but check the body contents |
| 251 | */ |
| 252 | struct server *get_server_ph_post(struct session *s) |
| 253 | { |
| 254 | unsigned long hash = 0; |
| 255 | struct http_txn *txn = &s->txn; |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 256 | struct channel *req = s->req; |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 257 | struct http_msg *msg = &txn->req; |
| 258 | struct proxy *px = s->be; |
| 259 | unsigned int plen = px->url_param_len; |
Willy Tarreau | 124d991 | 2011-03-01 20:30:48 +0100 | [diff] [blame] | 260 | unsigned long len = msg->body_len; |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 261 | const char *params = b_ptr(&req->buf, (int)(msg->sov - req->buf.o)); |
Willy Tarreau | 157dd63 | 2009-12-06 19:18:09 +0100 | [diff] [blame] | 262 | const char *p = params; |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 263 | |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 264 | if (len > buffer_len(&req->buf) - msg->sov) |
| 265 | len = buffer_len(&req->buf) - msg->sov; |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 266 | |
Willy Tarreau | 157dd63 | 2009-12-06 19:18:09 +0100 | [diff] [blame] | 267 | if (len == 0) |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 268 | return NULL; |
| 269 | |
Willy Tarreau | 157dd63 | 2009-12-06 19:18:09 +0100 | [diff] [blame] | 270 | if (px->lbprm.tot_weight == 0) |
| 271 | return NULL; |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 272 | |
| 273 | while (len > plen) { |
| 274 | /* Look for the parameter name followed by an equal symbol */ |
| 275 | if (params[plen] == '=') { |
| 276 | if (memcmp(params, px->url_param_name, plen) == 0) { |
| 277 | /* OK, we have the parameter here at <params>, and |
| 278 | * the value after the equal sign, at <p> |
| 279 | * skip the equal symbol |
| 280 | */ |
| 281 | p += plen + 1; |
| 282 | len -= plen + 1; |
| 283 | |
| 284 | while (len && *p != '&') { |
| 285 | if (unlikely(!HTTP_IS_TOKEN(*p))) { |
Willy Tarreau | 157dd63 | 2009-12-06 19:18:09 +0100 | [diff] [blame] | 286 | /* if in a POST, body must be URI encoded or it's not a URI. |
| 287 | * Do not interprete any possible binary data as a parameter. |
| 288 | */ |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 289 | if (likely(HTTP_IS_LWS(*p))) /* eol, uncertain uri len */ |
| 290 | break; |
| 291 | return NULL; /* oh, no; this is not uri-encoded. |
| 292 | * This body does not contain parameters. |
| 293 | */ |
| 294 | } |
| 295 | hash = *p + (hash << 6) + (hash << 16) - hash; |
| 296 | len--; |
| 297 | p++; |
| 298 | /* should we break if vlen exceeds limit? */ |
| 299 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 300 | if ((px->lbprm.algo & BE_LB_HASH_TYPE) != BE_LB_HASH_MAP) |
| 301 | hash = full_hash(hash); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 302 | if (px->lbprm.algo & BE_LB_LKUP_CHTREE) |
| 303 | return chash_get_server_hash(px, hash); |
| 304 | else |
| 305 | return map_get_server_hash(px, hash); |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 306 | } |
| 307 | } |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 308 | /* skip to next parameter */ |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 309 | p = memchr(params, '&', len); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 310 | if (!p) |
| 311 | return NULL; |
| 312 | p++; |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 313 | len -= (p - params); |
| 314 | params = p; |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 315 | } |
| 316 | return NULL; |
| 317 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 318 | |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 319 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 320 | /* |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 321 | * This function tries to find a running server for the proxy <px> following |
| 322 | * the Header parameter hash method. It looks for a specific parameter in the |
| 323 | * URL and hashes it to compute the server ID. This is useful to optimize |
| 324 | * performance by avoiding bounces between servers in contexts where sessions |
| 325 | * are shared but cookies are not usable. If the parameter is not found, NULL |
| 326 | * is returned. If any server is found, it will be returned. If no valid server |
| 327 | * is found, NULL is returned. |
| 328 | */ |
| 329 | struct server *get_server_hh(struct session *s) |
| 330 | { |
| 331 | unsigned long hash = 0; |
| 332 | struct http_txn *txn = &s->txn; |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 333 | struct proxy *px = s->be; |
| 334 | unsigned int plen = px->hh_len; |
| 335 | unsigned long len; |
| 336 | struct hdr_ctx ctx; |
| 337 | const char *p; |
| 338 | |
| 339 | /* tot_weight appears to mean srv_count */ |
| 340 | if (px->lbprm.tot_weight == 0) |
| 341 | return NULL; |
| 342 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 343 | ctx.idx = 0; |
| 344 | |
| 345 | /* if the message is chunked, we skip the chunk size, but use the value as len */ |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 346 | http_find_header2(px->hh_name, plen, b_ptr(&s->req->buf, s->req->buf.o), &txn->hdr_idx, &ctx); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 347 | |
| 348 | /* if the header is not found or empty, let's fallback to round robin */ |
| 349 | if (!ctx.idx || !ctx.vlen) |
| 350 | return NULL; |
| 351 | |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 352 | /* note: we won't hash if there's only one server left */ |
| 353 | if (px->lbprm.tot_used == 1) |
| 354 | goto hash_done; |
| 355 | |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 356 | /* Found a the hh_name in the headers. |
| 357 | * we will compute the hash based on this value ctx.val. |
| 358 | */ |
| 359 | len = ctx.vlen; |
| 360 | p = (char *)ctx.line + ctx.val; |
| 361 | if (!px->hh_match_domain) { |
| 362 | while (len) { |
| 363 | hash = *p + (hash << 6) + (hash << 16) - hash; |
| 364 | len--; |
| 365 | p++; |
| 366 | } |
| 367 | } else { |
| 368 | int dohash = 0; |
| 369 | p += len - 1; |
| 370 | /* special computation, use only main domain name, not tld/host |
| 371 | * going back from the end of string, start hashing at first |
| 372 | * dot stop at next. |
| 373 | * This is designed to work with the 'Host' header, and requires |
| 374 | * a special option to activate this. |
| 375 | */ |
| 376 | while (len) { |
| 377 | if (*p == '.') { |
| 378 | if (!dohash) |
| 379 | dohash = 1; |
| 380 | else |
| 381 | break; |
| 382 | } else { |
| 383 | if (dohash) |
| 384 | hash = *p + (hash << 6) + (hash << 16) - hash; |
| 385 | } |
| 386 | len--; |
| 387 | p--; |
| 388 | } |
| 389 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 390 | if ((px->lbprm.algo & BE_LB_HASH_TYPE) != BE_LB_HASH_MAP) |
| 391 | hash = full_hash(hash); |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 392 | hash_done: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 393 | if (px->lbprm.algo & BE_LB_LKUP_CHTREE) |
| 394 | return chash_get_server_hash(px, hash); |
| 395 | else |
| 396 | return map_get_server_hash(px, hash); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 397 | } |
| 398 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 399 | /* RDP Cookie HASH. */ |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 400 | struct server *get_server_rch(struct session *s) |
| 401 | { |
| 402 | unsigned long hash = 0; |
| 403 | struct proxy *px = s->be; |
| 404 | unsigned long len; |
| 405 | const char *p; |
| 406 | int ret; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 407 | struct sample smp; |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 408 | struct arg args[2]; |
Willy Tarreau | d1de8af | 2012-05-18 22:12:14 +0200 | [diff] [blame] | 409 | int rewind; |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 410 | |
| 411 | /* tot_weight appears to mean srv_count */ |
| 412 | if (px->lbprm.tot_weight == 0) |
| 413 | return NULL; |
| 414 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 415 | memset(&smp, 0, sizeof(smp)); |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 416 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 417 | args[0].type = ARGT_STR; |
| 418 | args[0].data.str.str = px->hh_name; |
| 419 | args[0].data.str.len = px->hh_len; |
| 420 | args[1].type = ARGT_STOP; |
| 421 | |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 422 | b_rew(s->req, rewind = s->req->buf.o); |
Willy Tarreau | d1de8af | 2012-05-18 22:12:14 +0200 | [diff] [blame] | 423 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 424 | ret = smp_fetch_rdp_cookie(px, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, args, &smp); |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 425 | len = smp.data.str.len; |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 426 | |
Willy Tarreau | d1de8af | 2012-05-18 22:12:14 +0200 | [diff] [blame] | 427 | b_adv(s->req, rewind); |
| 428 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 429 | if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || len == 0) |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 430 | return NULL; |
| 431 | |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 432 | /* note: we won't hash if there's only one server left */ |
| 433 | if (px->lbprm.tot_used == 1) |
| 434 | goto hash_done; |
| 435 | |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 436 | /* Found a the hh_name in the headers. |
| 437 | * we will compute the hash based on this value ctx.val. |
| 438 | */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 439 | p = smp.data.str.str; |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 440 | while (len) { |
| 441 | hash = *p + (hash << 6) + (hash << 16) - hash; |
| 442 | len--; |
| 443 | p++; |
| 444 | } |
Willy Tarreau | 798a39c | 2010-11-24 15:04:29 +0100 | [diff] [blame] | 445 | if ((px->lbprm.algo & BE_LB_HASH_TYPE) != BE_LB_HASH_MAP) |
| 446 | hash = full_hash(hash); |
Willy Tarreau | 39c9ba7 | 2009-10-01 21:11:15 +0200 | [diff] [blame] | 447 | hash_done: |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 448 | if (px->lbprm.algo & BE_LB_LKUP_CHTREE) |
| 449 | return chash_get_server_hash(px, hash); |
| 450 | else |
| 451 | return map_get_server_hash(px, hash); |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 452 | } |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 453 | |
| 454 | /* |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 455 | * This function applies the load-balancing algorithm to the session, as |
| 456 | * defined by the backend it is assigned to. The session is then marked as |
| 457 | * 'assigned'. |
| 458 | * |
| 459 | * This function MAY NOT be called with SN_ASSIGNED already set. If the session |
| 460 | * had a server previously assigned, it is rebalanced, trying to avoid the same |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 461 | * server, which should still be present in target_srv(&s->target) before the call. |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 462 | * The function tries to keep the original connection slot if it reconnects to |
| 463 | * the same server, otherwise it releases it and tries to offer it. |
| 464 | * |
| 465 | * It is illegal to call this function with a session in a queue. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 466 | * |
| 467 | * It may return : |
Willy Tarreau | 664beb8 | 2011-03-10 11:38:29 +0100 | [diff] [blame] | 468 | * SRV_STATUS_OK if everything is OK. ->srv and ->target are assigned. |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 469 | * SRV_STATUS_NOSRV if no server is available. Session is not ASSIGNED |
| 470 | * SRV_STATUS_FULL if all servers are saturated. Session is not ASSIGNED |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 471 | * SRV_STATUS_INTERNAL for other unrecoverable errors. |
| 472 | * |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 473 | * Upon successful return, the session flag SN_ASSIGNED is set to indicate that |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 474 | * it does not need to be called anymore. This means that target_srv(&s->target) |
| 475 | * can be trusted in balance and direct modes. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 476 | * |
| 477 | */ |
| 478 | |
| 479 | int assign_server(struct session *s) |
| 480 | { |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 481 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 482 | struct server *conn_slot; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 483 | struct server *srv, *prev_srv; |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 484 | int err; |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 485 | |
Simon Horman | 8effd3d | 2011-08-13 08:03:52 +0900 | [diff] [blame] | 486 | DPRINTF(stderr,"assign_server : s=%p\n",s); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 487 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 488 | err = SRV_STATUS_INTERNAL; |
| 489 | if (unlikely(s->pend_pos || s->flags & SN_ASSIGNED)) |
| 490 | goto out_err; |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 491 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 492 | prev_srv = target_srv(&s->target); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 493 | conn_slot = s->srv_conn; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 494 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 495 | /* We have to release any connection slot before applying any LB algo, |
| 496 | * otherwise we may erroneously end up with no available slot. |
| 497 | */ |
| 498 | if (conn_slot) |
| 499 | sess_change_server(s, NULL); |
| 500 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 501 | /* We will now try to find the good server and store it into <target_srv(&s->target)>. |
| 502 | * Note that <target_srv(&s->target)> may be NULL in case of dispatch or proxy mode, |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 503 | * as well as if no server is available (check error code). |
| 504 | */ |
Willy Tarreau | 1a20a5d | 2007-11-01 21:08:19 +0100 | [diff] [blame] | 505 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 506 | srv = NULL; |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 507 | clear_target(&s->target); |
Willy Tarreau | 664beb8 | 2011-03-10 11:38:29 +0100 | [diff] [blame] | 508 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 509 | if (s->be->lbprm.algo & BE_LB_KIND) { |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 510 | /* we must check if we have at least one server available */ |
| 511 | if (!s->be->lbprm.tot_weight) { |
| 512 | err = SRV_STATUS_NOSRV; |
| 513 | goto out; |
| 514 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 515 | |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 516 | /* First check whether we need to fetch some data or simply call |
| 517 | * the LB lookup function. Only the hashing functions will need |
| 518 | * some input data in fact, and will support multiple algorithms. |
| 519 | */ |
| 520 | switch (s->be->lbprm.algo & BE_LB_LKUP) { |
| 521 | case BE_LB_LKUP_RRTREE: |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 522 | srv = fwrr_get_next_server(s->be, prev_srv); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 523 | break; |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 524 | |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 525 | case BE_LB_LKUP_FSTREE: |
| 526 | srv = fas_get_next_server(s->be, prev_srv); |
| 527 | break; |
| 528 | |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 529 | case BE_LB_LKUP_LCTREE: |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 530 | srv = fwlc_get_next_server(s->be, prev_srv); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 531 | break; |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 532 | |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 533 | case BE_LB_LKUP_CHTREE: |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 534 | case BE_LB_LKUP_MAP: |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 535 | if ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR) { |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 536 | if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE) |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 537 | srv = chash_get_next_server(s->be, prev_srv); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 538 | else |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 539 | srv = map_get_server_rr(s->be, prev_srv); |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 540 | break; |
| 541 | } |
| 542 | else if ((s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_HI) { |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 543 | /* unknown balancing algorithm */ |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 544 | err = SRV_STATUS_INTERNAL; |
| 545 | goto out; |
| 546 | } |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 547 | |
| 548 | switch (s->be->lbprm.algo & BE_LB_PARM) { |
| 549 | case BE_LB_HASH_SRC: |
Willy Tarreau | 5dd7fa1 | 2012-03-31 19:53:37 +0200 | [diff] [blame] | 550 | if (s->req->prod->addr.from.ss_family == AF_INET) { |
| 551 | srv = get_server_sh(s->be, |
| 552 | (void *)&((struct sockaddr_in *)&s->req->prod->addr.from)->sin_addr, |
| 553 | 4); |
| 554 | } |
| 555 | else if (s->req->prod->addr.from.ss_family == AF_INET6) { |
| 556 | srv = get_server_sh(s->be, |
| 557 | (void *)&((struct sockaddr_in6 *)&s->req->prod->addr.from)->sin6_addr, |
| 558 | 16); |
| 559 | } |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 560 | else { |
| 561 | /* unknown IP family */ |
| 562 | err = SRV_STATUS_INTERNAL; |
| 563 | goto out; |
| 564 | } |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 565 | break; |
| 566 | |
| 567 | case BE_LB_HASH_URI: |
| 568 | /* URI hashing */ |
Willy Tarreau | eaed5a1 | 2010-03-24 14:54:30 +0100 | [diff] [blame] | 569 | if (s->txn.req.msg_state < HTTP_MSG_BODY) |
| 570 | break; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 571 | srv = get_server_uh(s->be, |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 572 | b_ptr(&s->req->buf, (int)(s->txn.req.sl.rq.u - s->req->buf.o)), |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 573 | s->txn.req.sl.rq.u_l); |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 574 | break; |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 575 | |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 576 | case BE_LB_HASH_PRM: |
| 577 | /* URL Parameter hashing */ |
Willy Tarreau | eaed5a1 | 2010-03-24 14:54:30 +0100 | [diff] [blame] | 578 | if (s->txn.req.msg_state < HTTP_MSG_BODY) |
| 579 | break; |
Willy Tarreau | 61a21a3 | 2011-03-01 20:35:49 +0100 | [diff] [blame] | 580 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 581 | srv = get_server_ph(s->be, |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 582 | b_ptr(&s->req->buf, (int)(s->txn.req.sl.rq.u - s->req->buf.o)), |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 583 | s->txn.req.sl.rq.u_l); |
Willy Tarreau | 61a21a3 | 2011-03-01 20:35:49 +0100 | [diff] [blame] | 584 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 585 | if (!srv && s->txn.meth == HTTP_METH_POST) |
| 586 | srv = get_server_ph_post(s); |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 587 | break; |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 588 | |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 589 | case BE_LB_HASH_HDR: |
| 590 | /* Header Parameter hashing */ |
Willy Tarreau | eaed5a1 | 2010-03-24 14:54:30 +0100 | [diff] [blame] | 591 | if (s->txn.req.msg_state < HTTP_MSG_BODY) |
| 592 | break; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 593 | srv = get_server_hh(s); |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 594 | break; |
| 595 | |
| 596 | case BE_LB_HASH_RDP: |
| 597 | /* RDP Cookie hashing */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 598 | srv = get_server_rch(s); |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 599 | break; |
| 600 | |
| 601 | default: |
| 602 | /* unknown balancing algorithm */ |
| 603 | err = SRV_STATUS_INTERNAL; |
| 604 | goto out; |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 605 | } |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 606 | |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 607 | /* If the hashing parameter was not found, let's fall |
| 608 | * back to round robin on the map. |
| 609 | */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 610 | if (!srv) { |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 611 | if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE) |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 612 | srv = chash_get_next_server(s->be, prev_srv); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 613 | else |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 614 | srv = map_get_server_rr(s->be, prev_srv); |
Willy Tarreau | 6b2e11b | 2009-10-01 07:52:15 +0200 | [diff] [blame] | 615 | } |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 616 | |
| 617 | /* end of map-based LB */ |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 618 | break; |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 619 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 620 | default: |
| 621 | /* unknown balancing algorithm */ |
| 622 | err = SRV_STATUS_INTERNAL; |
| 623 | goto out; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 624 | } |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 625 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 626 | if (!srv) { |
Willy Tarreau | da76f4f | 2009-10-03 12:36:05 +0200 | [diff] [blame] | 627 | err = SRV_STATUS_FULL; |
| 628 | goto out; |
| 629 | } |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 630 | else if (srv != prev_srv) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 631 | s->be->be_counters.cum_lbconn++; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 632 | srv->counters.cum_lbconn++; |
Alexandre Cassen | 5eb1a90 | 2007-11-29 15:43:32 +0100 | [diff] [blame] | 633 | } |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 634 | set_target_server(&s->target, srv); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 635 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 636 | else if (s->be->options & (PR_O_DISPATCH | PR_O_TRANSP)) { |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 637 | set_target_proxy(&s->target, s->be); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 638 | } |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 639 | else if ((s->be->options & PR_O_HTTP_PROXY) && |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 640 | is_addr(&s->req->cons->addr.to)) { |
Willy Tarreau | 664beb8 | 2011-03-10 11:38:29 +0100 | [diff] [blame] | 641 | /* in proxy mode, we need a valid destination address */ |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 642 | set_target_proxy(&s->target, s->be); |
Willy Tarreau | 664beb8 | 2011-03-10 11:38:29 +0100 | [diff] [blame] | 643 | } |
| 644 | else { |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 645 | err = SRV_STATUS_NOSRV; |
| 646 | goto out; |
| 647 | } |
| 648 | |
| 649 | s->flags |= SN_ASSIGNED; |
| 650 | err = SRV_STATUS_OK; |
| 651 | out: |
| 652 | |
| 653 | /* Either we take back our connection slot, or we offer it to someone |
| 654 | * else if we don't need it anymore. |
| 655 | */ |
| 656 | if (conn_slot) { |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 657 | if (conn_slot == srv) { |
| 658 | sess_change_server(s, srv); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 659 | } else { |
| 660 | if (may_dequeue_tasks(conn_slot, s->be)) |
| 661 | process_srv_queue(conn_slot); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | out_err: |
| 666 | return err; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | |
| 670 | /* |
| 671 | * This function assigns a server address to a session, and sets SN_ADDR_SET. |
| 672 | * The address is taken from the currently assigned server, or from the |
| 673 | * dispatch or transparent address. |
| 674 | * |
| 675 | * It may return : |
| 676 | * SRV_STATUS_OK if everything is OK. |
| 677 | * SRV_STATUS_INTERNAL for other unrecoverable errors. |
| 678 | * |
| 679 | * Upon successful return, the session flag SN_ADDR_SET is set. This flag is |
| 680 | * not cleared, so it's to the caller to clear it if required. |
| 681 | * |
| 682 | */ |
| 683 | int assign_server_address(struct session *s) |
| 684 | { |
| 685 | #ifdef DEBUG_FULL |
| 686 | fprintf(stderr,"assign_server_address : s=%p\n",s); |
| 687 | #endif |
| 688 | |
Willy Tarreau | f3e49f9 | 2009-10-03 12:21:20 +0200 | [diff] [blame] | 689 | if ((s->flags & SN_DIRECT) || (s->be->lbprm.algo & BE_LB_KIND)) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 690 | /* A server is necessarily known for this session */ |
| 691 | if (!(s->flags & SN_ASSIGNED)) |
| 692 | return SRV_STATUS_INTERNAL; |
| 693 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 694 | s->req->cons->addr.to = target_srv(&s->target)->addr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 695 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 696 | if (!is_addr(&s->req->cons->addr.to)) { |
Willy Tarreau | d669a4f | 2010-07-13 14:49:50 +0200 | [diff] [blame] | 697 | /* if the server has no address, we use the same address |
| 698 | * the client asked, which is handy for remapping ports |
| 699 | * locally on multiple addresses at once. |
| 700 | */ |
Willy Tarreau | 9b061e3 | 2012-04-07 18:03:52 +0200 | [diff] [blame] | 701 | if (!(s->be->options & PR_O_TRANSP)) |
Willy Tarreau | 59b9479 | 2012-05-11 16:16:40 +0200 | [diff] [blame] | 702 | si_get_to_addr(s->req->prod); |
Willy Tarreau | d669a4f | 2010-07-13 14:49:50 +0200 | [diff] [blame] | 703 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 704 | if (s->req->prod->addr.to.ss_family == AF_INET) { |
| 705 | ((struct sockaddr_in *)&s->req->cons->addr.to)->sin_addr = ((struct sockaddr_in *)&s->req->prod->addr.to)->sin_addr; |
| 706 | } else if (s->req->prod->addr.to.ss_family == AF_INET6) { |
| 707 | ((struct sockaddr_in6 *)&s->req->cons->addr.to)->sin6_addr = ((struct sockaddr_in6 *)&s->req->prod->addr.to)->sin6_addr; |
Emeric Brun | ec810d1 | 2010-10-22 16:36:33 +0200 | [diff] [blame] | 708 | } |
Willy Tarreau | d669a4f | 2010-07-13 14:49:50 +0200 | [diff] [blame] | 709 | } |
| 710 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 711 | /* if this server remaps proxied ports, we'll use |
| 712 | * the port the client connected to with an offset. */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 713 | if (target_srv(&s->target)->state & SRV_MAPPORTS) { |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 714 | int base_port; |
| 715 | |
Willy Tarreau | 9b061e3 | 2012-04-07 18:03:52 +0200 | [diff] [blame] | 716 | if (!(s->be->options & PR_O_TRANSP)) |
Willy Tarreau | 59b9479 | 2012-05-11 16:16:40 +0200 | [diff] [blame] | 717 | si_get_to_addr(s->req->prod); |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 718 | |
| 719 | /* First, retrieve the port from the incoming connection */ |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 720 | base_port = get_host_port(&s->req->prod->addr.to); |
David du Colombier | 6f5ccb1 | 2011-03-10 22:26:24 +0100 | [diff] [blame] | 721 | |
| 722 | /* Second, assign the outgoing connection's port */ |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 723 | base_port += get_host_port(&s->req->cons->addr.to); |
| 724 | set_host_port(&s->req->cons->addr.to, base_port); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 725 | } |
| 726 | } |
Willy Tarreau | 1620ec3 | 2011-08-06 17:05:02 +0200 | [diff] [blame] | 727 | else if (s->be->options & PR_O_DISPATCH) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 728 | /* connect to the defined dispatch addr */ |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 729 | s->req->cons->addr.to = s->be->dispatch_addr; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 730 | } |
Willy Tarreau | 4b1f859 | 2008-12-23 23:13:55 +0100 | [diff] [blame] | 731 | else if (s->be->options & PR_O_TRANSP) { |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 732 | /* in transparent mode, use the original dest addr if no dispatch specified */ |
Willy Tarreau | 59b9479 | 2012-05-11 16:16:40 +0200 | [diff] [blame] | 733 | si_get_to_addr(s->req->prod); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 734 | |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 735 | if (s->req->prod->addr.to.ss_family == AF_INET || s->req->prod->addr.to.ss_family == AF_INET6) { |
| 736 | memcpy(&s->req->cons->addr.to, &s->req->prod->addr.to, MIN(sizeof(s->req->cons->addr.to), sizeof(s->req->prod->addr.to))); |
Emeric Brun | ec810d1 | 2010-10-22 16:36:33 +0200 | [diff] [blame] | 737 | } |
Willy Tarreau | bd41428 | 2008-01-19 13:46:35 +0100 | [diff] [blame] | 738 | /* when we support IPv6 on the backend, we may add other tests */ |
| 739 | //qfprintf(stderr, "Cannot get original server address.\n"); |
| 740 | //return SRV_STATUS_INTERNAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 741 | } |
Alexandre Cassen | 5eb1a90 | 2007-11-29 15:43:32 +0100 | [diff] [blame] | 742 | else if (s->be->options & PR_O_HTTP_PROXY) { |
| 743 | /* If HTTP PROXY option is set, then server is already assigned |
| 744 | * during incoming client request parsing. */ |
| 745 | } |
Willy Tarreau | 1a1158b | 2007-01-20 11:07:46 +0100 | [diff] [blame] | 746 | else { |
| 747 | /* no server and no LB algorithm ! */ |
| 748 | return SRV_STATUS_INTERNAL; |
| 749 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 750 | |
| 751 | s->flags |= SN_ADDR_SET; |
| 752 | return SRV_STATUS_OK; |
| 753 | } |
| 754 | |
| 755 | |
| 756 | /* This function assigns a server to session <s> if required, and can add the |
| 757 | * connection to either the assigned server's queue or to the proxy's queue. |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 758 | * If ->srv_conn is set, the session is first released from the server. |
| 759 | * It may also be called with SN_DIRECT and/or SN_ASSIGNED though. It will |
| 760 | * be called before any connection and after any retry or redispatch occurs. |
| 761 | * |
| 762 | * It is not allowed to call this function with a session in a queue. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 763 | * |
| 764 | * Returns : |
| 765 | * |
| 766 | * SRV_STATUS_OK if everything is OK. |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 767 | * SRV_STATUS_NOSRV if no server is available. target_srv(&s->target) = NULL. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 768 | * SRV_STATUS_QUEUED if the connection has been queued. |
| 769 | * SRV_STATUS_FULL if the server(s) is/are saturated and the |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 770 | * connection could not be queued at the server's, |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 771 | * which may be NULL if we queue on the backend. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 772 | * SRV_STATUS_INTERNAL for other unrecoverable errors. |
| 773 | * |
| 774 | */ |
| 775 | int assign_server_and_queue(struct session *s) |
| 776 | { |
| 777 | struct pendconn *p; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 778 | struct server *srv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 779 | int err; |
| 780 | |
| 781 | if (s->pend_pos) |
| 782 | return SRV_STATUS_INTERNAL; |
| 783 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 784 | err = SRV_STATUS_OK; |
| 785 | if (!(s->flags & SN_ASSIGNED)) { |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 786 | struct server *prev_srv = target_srv(&s->target); |
Willy Tarreau | 3d80d91 | 2011-03-10 11:42:13 +0100 | [diff] [blame] | 787 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 788 | err = assign_server(s); |
Willy Tarreau | 3d80d91 | 2011-03-10 11:42:13 +0100 | [diff] [blame] | 789 | if (prev_srv) { |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 790 | /* This session was previously assigned to a server. We have to |
| 791 | * update the session's and the server's stats : |
| 792 | * - if the server changed : |
| 793 | * - set TX_CK_DOWN if txn.flags was TX_CK_VALID |
| 794 | * - set SN_REDISP if it was successfully redispatched |
| 795 | * - increment srv->redispatches and be->redispatches |
| 796 | * - if the server remained the same : update retries. |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 797 | */ |
| 798 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 799 | if (prev_srv != target_srv(&s->target)) { |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 800 | if ((s->txn.flags & TX_CK_MASK) == TX_CK_VALID) { |
| 801 | s->txn.flags &= ~TX_CK_MASK; |
| 802 | s->txn.flags |= TX_CK_DOWN; |
| 803 | } |
| 804 | s->flags |= SN_REDISP; |
Willy Tarreau | 3d80d91 | 2011-03-10 11:42:13 +0100 | [diff] [blame] | 805 | prev_srv->counters.redispatches++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 806 | s->be->be_counters.redispatches++; |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 807 | } else { |
Willy Tarreau | 3d80d91 | 2011-03-10 11:42:13 +0100 | [diff] [blame] | 808 | prev_srv->counters.retries++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 809 | s->be->be_counters.retries++; |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 810 | } |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 814 | switch (err) { |
| 815 | case SRV_STATUS_OK: |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 816 | /* we have SN_ASSIGNED set */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 817 | srv = target_srv(&s->target); |
| 818 | if (!srv) |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 819 | return SRV_STATUS_OK; /* dispatch or proxy mode */ |
| 820 | |
| 821 | /* If we already have a connection slot, no need to check any queue */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 822 | if (s->srv_conn == srv) |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 823 | return SRV_STATUS_OK; |
| 824 | |
| 825 | /* OK, this session already has an assigned server, but no |
| 826 | * connection slot yet. Either it is a redispatch, or it was |
| 827 | * assigned from persistence information (direct mode). |
| 828 | */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 829 | if ((s->flags & SN_REDIRECTABLE) && srv->rdr_len) { |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 830 | /* server scheduled for redirection, and already assigned. We |
| 831 | * don't want to go further nor check the queue. |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 832 | */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 833 | sess_change_server(s, srv); /* not really needed in fact */ |
Willy Tarreau | 21d2af3 | 2008-02-14 20:25:24 +0100 | [diff] [blame] | 834 | return SRV_STATUS_OK; |
| 835 | } |
| 836 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 837 | /* We might have to queue this session if the assigned server is full. |
| 838 | * We know we have to queue it into the server's queue, so if a maxqueue |
| 839 | * is set on the server, we must also check that the server's queue is |
| 840 | * not full, in which case we have to return FULL. |
| 841 | */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 842 | if (srv->maxconn && |
| 843 | (srv->nbpend || srv->served >= srv_dynamic_maxconn(srv))) { |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 844 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 845 | if (srv->maxqueue > 0 && srv->nbpend >= srv->maxqueue) |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 846 | return SRV_STATUS_FULL; |
| 847 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 848 | p = pendconn_add(s); |
| 849 | if (p) |
| 850 | return SRV_STATUS_QUEUED; |
| 851 | else |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 852 | return SRV_STATUS_INTERNAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 853 | } |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 854 | |
| 855 | /* OK, we can use this server. Let's reserve our place */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 856 | sess_change_server(s, srv); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 857 | return SRV_STATUS_OK; |
| 858 | |
| 859 | case SRV_STATUS_FULL: |
| 860 | /* queue this session into the proxy's queue */ |
| 861 | p = pendconn_add(s); |
| 862 | if (p) |
| 863 | return SRV_STATUS_QUEUED; |
| 864 | else |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 865 | return SRV_STATUS_INTERNAL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 866 | |
| 867 | case SRV_STATUS_NOSRV: |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 868 | return err; |
| 869 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 870 | case SRV_STATUS_INTERNAL: |
| 871 | return err; |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 872 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 873 | default: |
| 874 | return SRV_STATUS_INTERNAL; |
| 875 | } |
Willy Tarreau | 5b6995c | 2008-01-13 16:31:17 +0100 | [diff] [blame] | 876 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 877 | |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 878 | /* If an explicit source binding is specified on the server and/or backend, and |
| 879 | * this source makes use of the transparent proxy, then it is extracted now and |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 880 | * assigned to the session's req->cons->addr.from entry. |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 881 | */ |
| 882 | static void assign_tproxy_address(struct session *s) |
| 883 | { |
| 884 | #if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY) |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 885 | struct server *srv = target_srv(&s->target); |
| 886 | |
| 887 | if (srv && srv->state & SRV_BIND_SRC) { |
| 888 | switch (srv->state & SRV_TPROXY_MASK) { |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 889 | case SRV_TPROXY_ADDR: |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 890 | s->req->cons->addr.from = srv->tproxy_addr; |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 891 | break; |
| 892 | case SRV_TPROXY_CLI: |
| 893 | case SRV_TPROXY_CIP: |
Emeric Brun | ec810d1 | 2010-10-22 16:36:33 +0200 | [diff] [blame] | 894 | /* FIXME: what can we do if the client connects in IPv6 or unix socket ? */ |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 895 | s->req->cons->addr.from = s->req->prod->addr.from; |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 896 | break; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 897 | case SRV_TPROXY_DYN: |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 898 | if (srv->bind_hdr_occ) { |
Willy Tarreau | 294c473 | 2011-12-16 21:35:50 +0100 | [diff] [blame] | 899 | char *vptr; |
| 900 | int vlen; |
Willy Tarreau | d1de8af | 2012-05-18 22:12:14 +0200 | [diff] [blame] | 901 | int rewind; |
Willy Tarreau | 294c473 | 2011-12-16 21:35:50 +0100 | [diff] [blame] | 902 | |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 903 | /* bind to the IP in a header */ |
Willy Tarreau | 5dc1e98 | 2011-12-16 21:25:11 +0100 | [diff] [blame] | 904 | ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_family = AF_INET; |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 905 | ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0; |
Willy Tarreau | 294c473 | 2011-12-16 21:35:50 +0100 | [diff] [blame] | 906 | ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = 0; |
| 907 | |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 908 | b_rew(s->req, rewind = s->req->buf.o); |
Willy Tarreau | 294c473 | 2011-12-16 21:35:50 +0100 | [diff] [blame] | 909 | if (http_get_hdr(&s->txn.req, srv->bind_hdr_name, srv->bind_hdr_len, |
| 910 | &s->txn.hdr_idx, srv->bind_hdr_occ, NULL, &vptr, &vlen)) { |
| 911 | ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = |
| 912 | htonl(inetaddr_host_lim(vptr, vptr + vlen)); |
| 913 | } |
Willy Tarreau | d1de8af | 2012-05-18 22:12:14 +0200 | [diff] [blame] | 914 | b_adv(s->req, rewind); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 915 | } |
| 916 | break; |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 917 | default: |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 918 | memset(&s->req->cons->addr.from, 0, sizeof(s->req->cons->addr.from)); |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | else if (s->be->options & PR_O_BIND_SRC) { |
| 922 | switch (s->be->options & PR_O_TPXY_MASK) { |
| 923 | case PR_O_TPXY_ADDR: |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 924 | s->req->cons->addr.from = s->be->tproxy_addr; |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 925 | break; |
| 926 | case PR_O_TPXY_CLI: |
| 927 | case PR_O_TPXY_CIP: |
Emeric Brun | ec810d1 | 2010-10-22 16:36:33 +0200 | [diff] [blame] | 928 | /* FIXME: what can we do if the client connects in IPv6 or socket unix? */ |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 929 | s->req->cons->addr.from = s->req->prod->addr.from; |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 930 | break; |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 931 | case PR_O_TPXY_DYN: |
| 932 | if (s->be->bind_hdr_occ) { |
Willy Tarreau | 294c473 | 2011-12-16 21:35:50 +0100 | [diff] [blame] | 933 | char *vptr; |
| 934 | int vlen; |
Willy Tarreau | d1de8af | 2012-05-18 22:12:14 +0200 | [diff] [blame] | 935 | int rewind; |
Willy Tarreau | 294c473 | 2011-12-16 21:35:50 +0100 | [diff] [blame] | 936 | |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 937 | /* bind to the IP in a header */ |
Willy Tarreau | 5dc1e98 | 2011-12-16 21:25:11 +0100 | [diff] [blame] | 938 | ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_family = AF_INET; |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 939 | ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_port = 0; |
Willy Tarreau | 294c473 | 2011-12-16 21:35:50 +0100 | [diff] [blame] | 940 | ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = 0; |
| 941 | |
Willy Tarreau | 572bf90 | 2012-07-02 17:01:20 +0200 | [diff] [blame] | 942 | b_rew(s->req, rewind = s->req->buf.o); |
Willy Tarreau | 294c473 | 2011-12-16 21:35:50 +0100 | [diff] [blame] | 943 | if (http_get_hdr(&s->txn.req, s->be->bind_hdr_name, s->be->bind_hdr_len, |
| 944 | &s->txn.hdr_idx, s->be->bind_hdr_occ, NULL, &vptr, &vlen)) { |
| 945 | ((struct sockaddr_in *)&s->req->cons->addr.from)->sin_addr.s_addr = |
| 946 | htonl(inetaddr_host_lim(vptr, vptr + vlen)); |
| 947 | } |
Willy Tarreau | d1de8af | 2012-05-18 22:12:14 +0200 | [diff] [blame] | 948 | b_adv(s->req, rewind); |
Willy Tarreau | bce7088 | 2009-09-07 11:51:47 +0200 | [diff] [blame] | 949 | } |
| 950 | break; |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 951 | default: |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 952 | memset(&s->req->cons->addr.from, 0, sizeof(s->req->cons->addr.from)); |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | #endif |
| 956 | } |
| 957 | |
| 958 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 959 | /* |
| 960 | * This function initiates a connection to the server assigned to this session |
Willy Tarreau | 6471afb | 2011-09-23 10:54:59 +0200 | [diff] [blame] | 961 | * (s->target, s->req->cons->addr.to). It will assign a server if none |
Willy Tarreau | 664beb8 | 2011-03-10 11:38:29 +0100 | [diff] [blame] | 962 | * is assigned yet. |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 963 | * It can return one of : |
| 964 | * - SN_ERR_NONE if everything's OK |
| 965 | * - SN_ERR_SRVTO if there are no more servers |
| 966 | * - SN_ERR_SRVCL if the connection was refused by the server |
| 967 | * - SN_ERR_PRXCOND if the connection has been limited by the proxy (maxconn) |
| 968 | * - SN_ERR_RESOURCE if a system resource is lacking (eg: fd limits, ports, ...) |
| 969 | * - SN_ERR_INTERNAL for any other purely internal errors |
| 970 | * Additionnally, in the case of SN_ERR_RESOURCE, an emergency log will be emitted. |
| 971 | */ |
| 972 | int connect_server(struct session *s) |
| 973 | { |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 974 | struct server *srv; |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 975 | int err; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 976 | |
| 977 | if (!(s->flags & SN_ADDR_SET)) { |
| 978 | err = assign_server_address(s); |
| 979 | if (err != SRV_STATUS_OK) |
| 980 | return SN_ERR_INTERNAL; |
| 981 | } |
| 982 | |
Willy Tarreau | 7b7a8e9 | 2011-03-27 19:53:06 +0200 | [diff] [blame] | 983 | /* the target was only on the session, assign it to the SI now */ |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 984 | copy_target(&s->req->cons->target, &s->target); |
Willy Tarreau | d88edf2 | 2009-06-14 15:48:17 +0200 | [diff] [blame] | 985 | |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 986 | /* set the correct protocol on the output stream interface */ |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 987 | if (s->target.type == TARG_TYPE_SERVER) { |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 988 | si_prepare_conn(s->req->cons, target_srv(&s->target)->proto, target_srv(&s->target)->data); |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 989 | } |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 990 | else if (s->target.type == TARG_TYPE_PROXY) { |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 991 | /* proxies exclusively run on raw_sock right now */ |
Willy Tarreau | c578891 | 2012-08-24 18:12:41 +0200 | [diff] [blame] | 992 | si_prepare_conn(s->req->cons, protocol_by_family(s->req->cons->addr.to.ss_family), &raw_sock); |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 993 | if (!si_ctrl(s->req->cons)) |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 994 | return SN_ERR_INTERNAL; |
| 995 | } |
Willy Tarreau | d02394b | 2012-05-11 18:32:18 +0200 | [diff] [blame] | 996 | else |
| 997 | return SN_ERR_INTERNAL; /* how did we get there ? */ |
| 998 | |
| 999 | /* process the case where the server requires the PROXY protocol to be sent */ |
| 1000 | s->req->cons->send_proxy_ofs = 0; |
| 1001 | if (s->target.type == TARG_TYPE_SERVER && (s->target.ptr.s->state & SRV_SEND_PROXY)) { |
| 1002 | s->req->cons->send_proxy_ofs = 1; /* must compute size */ |
| 1003 | si_get_to_addr(s->req->prod); |
| 1004 | } |
Willy Tarreau | 26d8c59 | 2012-05-07 18:12:14 +0200 | [diff] [blame] | 1005 | |
Willy Tarreau | b1d6774 | 2010-03-29 19:36:59 +0200 | [diff] [blame] | 1006 | assign_tproxy_address(s); |
| 1007 | |
William Lallemand | b7ff6a3 | 2012-03-02 14:35:21 +0100 | [diff] [blame] | 1008 | /* flag for logging source ip/port */ |
| 1009 | if (s->fe->options2 & PR_O2_SRC_ADDR) |
| 1010 | s->req->cons->flags |= SI_FL_SRC_ADDR; |
| 1011 | |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 1012 | err = si_connect(s->req->cons); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1013 | |
Willy Tarreau | 9650f37 | 2009-08-16 14:02:45 +0200 | [diff] [blame] | 1014 | if (err != SN_ERR_NONE) |
| 1015 | return err; |
Willy Tarreau | 788e284 | 2008-08-26 13:25:39 +0200 | [diff] [blame] | 1016 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1017 | srv = target_srv(&s->target); |
| 1018 | if (srv) { |
Willy Tarreau | 1e62de6 | 2008-11-11 20:20:02 +0100 | [diff] [blame] | 1019 | s->flags |= SN_CURR_SESS; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1020 | srv->cur_sess++; |
| 1021 | if (srv->cur_sess > srv->counters.cur_sess_max) |
| 1022 | srv->counters.cur_sess_max = srv->cur_sess; |
Willy Tarreau | 5140623 | 2008-03-10 22:04:20 +0100 | [diff] [blame] | 1023 | if (s->be->lbprm.server_take_conn) |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1024 | s->be->lbprm.server_take_conn(srv); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1025 | } |
| 1026 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1027 | return SN_ERR_NONE; /* connection is OK */ |
| 1028 | } |
| 1029 | |
| 1030 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1031 | /* This function performs the "redispatch" part of a connection attempt. It |
| 1032 | * will assign a server if required, queue the connection if required, and |
| 1033 | * handle errors that might arise at this level. It can change the server |
| 1034 | * state. It will return 1 if it encounters an error, switches the server |
| 1035 | * state, or has to queue a connection. Otherwise, it will return 0 indicating |
| 1036 | * that the connection is ready to use. |
| 1037 | */ |
| 1038 | |
| 1039 | int srv_redispatch_connect(struct session *t) |
| 1040 | { |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1041 | struct server *srv; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1042 | int conn_err; |
| 1043 | |
| 1044 | /* We know that we don't have any connection pending, so we will |
| 1045 | * try to get a new one, and wait in this state if it's queued |
| 1046 | */ |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1047 | redispatch: |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1048 | conn_err = assign_server_and_queue(t); |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1049 | srv = target_srv(&t->target); |
| 1050 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1051 | switch (conn_err) { |
| 1052 | case SRV_STATUS_OK: |
| 1053 | break; |
| 1054 | |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1055 | case SRV_STATUS_FULL: |
| 1056 | /* The server has reached its maxqueue limit. Either PR_O_REDISP is set |
| 1057 | * and we can redispatch to another server, or it is not and we return |
| 1058 | * 503. This only makes sense in DIRECT mode however, because normal LB |
| 1059 | * algorithms would never select such a server, and hash algorithms |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1060 | * would bring us on the same server again. Note that t->target is set |
| 1061 | * in this case. |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1062 | */ |
Willy Tarreau | 4de9149 | 2010-01-22 19:10:05 +0100 | [diff] [blame] | 1063 | if (((t->flags & (SN_DIRECT|SN_FORCE_PRST)) == SN_DIRECT) && |
| 1064 | (t->be->options & PR_O_REDISP)) { |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1065 | t->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET); |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1066 | goto redispatch; |
| 1067 | } |
| 1068 | |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 1069 | if (!t->req->cons->err_type) { |
| 1070 | t->req->cons->err_type = SI_ET_QUEUE_ERR; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1071 | t->req->cons->err_loc = srv; |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 1072 | } |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1073 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1074 | srv->counters.failed_conns++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1075 | t->be->be_counters.failed_conns++; |
Willy Tarreau | 7c669d7 | 2008-06-20 15:04:11 +0200 | [diff] [blame] | 1076 | return 1; |
| 1077 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1078 | case SRV_STATUS_NOSRV: |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1079 | /* note: it is guaranteed that srv == NULL here */ |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 1080 | if (!t->req->cons->err_type) { |
| 1081 | t->req->cons->err_type = SI_ET_CONN_ERR; |
| 1082 | t->req->cons->err_loc = NULL; |
| 1083 | } |
Krzysztof Piotr Oledzki | 5a329cf | 2008-02-22 03:50:19 +0100 | [diff] [blame] | 1084 | |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1085 | t->be->be_counters.failed_conns++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1086 | return 1; |
| 1087 | |
| 1088 | case SRV_STATUS_QUEUED: |
Willy Tarreau | 3537467 | 2008-09-03 18:11:02 +0200 | [diff] [blame] | 1089 | t->req->cons->exp = tick_add_ifset(now_ms, t->be->timeout.queue); |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 1090 | t->req->cons->state = SI_ST_QUE; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1091 | /* do nothing else and do not wake any other session up */ |
| 1092 | return 1; |
| 1093 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1094 | case SRV_STATUS_INTERNAL: |
| 1095 | default: |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 1096 | if (!t->req->cons->err_type) { |
| 1097 | t->req->cons->err_type = SI_ET_CONN_OTHER; |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1098 | t->req->cons->err_loc = srv; |
Willy Tarreau | fa7e102 | 2008-10-19 07:30:41 +0200 | [diff] [blame] | 1099 | } |
| 1100 | |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1101 | if (srv) |
| 1102 | srv_inc_sess_ctr(srv); |
| 1103 | if (srv) |
| 1104 | srv->counters.failed_conns++; |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1105 | t->be->be_counters.failed_conns++; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1106 | |
| 1107 | /* release other sessions waiting for this server */ |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1108 | if (may_dequeue_tasks(srv, t->be)) |
| 1109 | process_srv_queue(srv); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1110 | return 1; |
| 1111 | } |
| 1112 | /* if we get here, it's because we got SRV_STATUS_OK, which also |
| 1113 | * means that the connection has not been queued. |
| 1114 | */ |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1118 | /* Apply RDP cookie persistence to the current session. For this, the function |
| 1119 | * tries to extract an RDP cookie from the request buffer, and look for the |
| 1120 | * matching server in the list. If the server is found, it is assigned to the |
| 1121 | * session. This always returns 1, and the analyser removes itself from the |
| 1122 | * list. Nothing is performed if a server was already assigned. |
| 1123 | */ |
Willy Tarreau | 7421efb | 2012-07-02 15:11:27 +0200 | [diff] [blame] | 1124 | int tcp_persist_rdp_cookie(struct session *s, struct channel *req, int an_bit) |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1125 | { |
| 1126 | struct proxy *px = s->be; |
| 1127 | int ret; |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1128 | struct sample smp; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1129 | struct server *srv = px->srv; |
| 1130 | struct sockaddr_in addr; |
| 1131 | char *p; |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1132 | struct arg args[2]; |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1133 | |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1134 | DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n", |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1135 | now_ms, __FUNCTION__, |
| 1136 | s, |
| 1137 | req, |
| 1138 | req->rex, req->wex, |
| 1139 | req->flags, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 1140 | req->i, |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1141 | req->analysers); |
| 1142 | |
| 1143 | if (s->flags & SN_ASSIGNED) |
| 1144 | goto no_cookie; |
| 1145 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1146 | memset(&smp, 0, sizeof(smp)); |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1147 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1148 | args[0].type = ARGT_STR; |
| 1149 | args[0].data.str.str = s->be->rdp_cookie_name; |
| 1150 | args[0].data.str.len = s->be->rdp_cookie_len; |
| 1151 | args[1].type = ARGT_STOP; |
| 1152 | |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1153 | ret = smp_fetch_rdp_cookie(px, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, args, &smp); |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1154 | if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || smp.data.str.len == 0) |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1155 | goto no_cookie; |
| 1156 | |
| 1157 | memset(&addr, 0, sizeof(addr)); |
| 1158 | addr.sin_family = AF_INET; |
| 1159 | |
Willy Tarreau | 664092c | 2011-12-16 19:11:42 +0100 | [diff] [blame] | 1160 | /* Considering an rdp cookie detected using acl, str ended with <cr><lf> and should return */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1161 | addr.sin_addr.s_addr = strtoul(smp.data.str.str, &p, 10); |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1162 | if (*p != '.') |
| 1163 | goto no_cookie; |
| 1164 | p++; |
| 1165 | addr.sin_port = (unsigned short)strtoul(p, &p, 10); |
| 1166 | if (*p != '.') |
| 1167 | goto no_cookie; |
| 1168 | |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 1169 | clear_target(&s->target); |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1170 | while (srv) { |
| 1171 | if (memcmp(&addr, &(srv->addr), sizeof(addr)) == 0) { |
| 1172 | if ((srv->state & SRV_RUNNING) || (px->options & PR_O_PERSIST)) { |
| 1173 | /* we found the server and it is usable */ |
| 1174 | s->flags |= SN_DIRECT | SN_ASSIGNED; |
Willy Tarreau | 9e000c6 | 2011-03-10 14:03:36 +0100 | [diff] [blame] | 1175 | set_target_server(&s->target, srv); |
Willy Tarreau | 44b90cc | 2010-05-24 20:27:29 +0200 | [diff] [blame] | 1176 | break; |
| 1177 | } |
| 1178 | } |
| 1179 | srv = srv->next; |
| 1180 | } |
| 1181 | |
| 1182 | no_cookie: |
| 1183 | req->analysers &= ~an_bit; |
| 1184 | req->analyse_exp = TICK_ETERNITY; |
| 1185 | return 1; |
| 1186 | } |
| 1187 | |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1188 | int be_downtime(struct proxy *px) { |
Willy Tarreau | b625a08 | 2007-11-26 01:15:43 +0100 | [diff] [blame] | 1189 | if (px->lbprm.tot_weight && px->last_change < now.tv_sec) // ignore negative time |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 1190 | return px->down_time; |
| 1191 | |
| 1192 | return now.tv_sec - px->last_change + px->down_time; |
| 1193 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1194 | |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 1195 | /* |
| 1196 | * This function returns a string containing the balancing |
| 1197 | * mode of the proxy in a format suitable for stats. |
| 1198 | */ |
| 1199 | |
| 1200 | const char *backend_lb_algo_str(int algo) { |
| 1201 | |
| 1202 | if (algo == BE_LB_ALGO_RR) |
| 1203 | return "roundrobin"; |
| 1204 | else if (algo == BE_LB_ALGO_SRR) |
| 1205 | return "static-rr"; |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 1206 | else if (algo == BE_LB_ALGO_FAS) |
| 1207 | return "first"; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 1208 | else if (algo == BE_LB_ALGO_LC) |
| 1209 | return "leastconn"; |
| 1210 | else if (algo == BE_LB_ALGO_SH) |
| 1211 | return "source"; |
| 1212 | else if (algo == BE_LB_ALGO_UH) |
| 1213 | return "uri"; |
| 1214 | else if (algo == BE_LB_ALGO_PH) |
| 1215 | return "url_param"; |
| 1216 | else if (algo == BE_LB_ALGO_HH) |
| 1217 | return "hdr"; |
| 1218 | else if (algo == BE_LB_ALGO_RCH) |
| 1219 | return "rdp-cookie"; |
| 1220 | else |
| 1221 | return NULL; |
| 1222 | } |
| 1223 | |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1224 | /* This function parses a "balance" statement in a backend section describing |
| 1225 | * <curproxy>. It returns -1 if there is any error, otherwise zero. If it |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1226 | * returns -1, it will write an error message into the <err> buffer which will |
| 1227 | * automatically be allocated and must be passed as NULL. The trailing '\n' |
| 1228 | * will not be written. The function must be called with <args> pointing to the |
| 1229 | * first word after "balance". |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1230 | */ |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1231 | int backend_parse_balance(const char **args, char **err, struct proxy *curproxy) |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1232 | { |
| 1233 | if (!*(args[0])) { |
| 1234 | /* if no option is set, use round-robin by default */ |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1235 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1236 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | if (!strcmp(args[0], "roundrobin")) { |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1241 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1242 | curproxy->lbprm.algo |= BE_LB_ALGO_RR; |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1243 | } |
Willy Tarreau | 9757a38 | 2009-10-03 12:56:50 +0200 | [diff] [blame] | 1244 | else if (!strcmp(args[0], "static-rr")) { |
| 1245 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1246 | curproxy->lbprm.algo |= BE_LB_ALGO_SRR; |
| 1247 | } |
Willy Tarreau | f09c660 | 2012-02-13 17:12:08 +0100 | [diff] [blame] | 1248 | else if (!strcmp(args[0], "first")) { |
| 1249 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1250 | curproxy->lbprm.algo |= BE_LB_ALGO_FAS; |
| 1251 | } |
Willy Tarreau | 5140623 | 2008-03-10 22:04:20 +0100 | [diff] [blame] | 1252 | else if (!strcmp(args[0], "leastconn")) { |
| 1253 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1254 | curproxy->lbprm.algo |= BE_LB_ALGO_LC; |
| 1255 | } |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1256 | else if (!strcmp(args[0], "source")) { |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1257 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1258 | curproxy->lbprm.algo |= BE_LB_ALGO_SH; |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1259 | } |
| 1260 | else if (!strcmp(args[0], "uri")) { |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 1261 | int arg = 1; |
| 1262 | |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1263 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1264 | curproxy->lbprm.algo |= BE_LB_ALGO_UH; |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 1265 | |
Oskar Stolc | 8dc4184 | 2012-05-19 10:19:54 +0100 | [diff] [blame] | 1266 | curproxy->uri_whole = 0; |
| 1267 | |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 1268 | while (*args[arg]) { |
| 1269 | if (!strcmp(args[arg], "len")) { |
| 1270 | if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) { |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1271 | memprintf(err, "%s : '%s' expects a positive integer (got '%s').", args[0], args[arg], args[arg+1]); |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 1272 | return -1; |
| 1273 | } |
| 1274 | curproxy->uri_len_limit = atoi(args[arg+1]); |
| 1275 | arg += 2; |
| 1276 | } |
| 1277 | else if (!strcmp(args[arg], "depth")) { |
| 1278 | if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) { |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1279 | memprintf(err, "%s : '%s' expects a positive integer (got '%s').", args[0], args[arg], args[arg+1]); |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 1280 | return -1; |
| 1281 | } |
| 1282 | /* hint: we store the position of the ending '/' (depth+1) so |
| 1283 | * that we avoid a comparison while computing the hash. |
| 1284 | */ |
| 1285 | curproxy->uri_dirs_depth1 = atoi(args[arg+1]) + 1; |
| 1286 | arg += 2; |
| 1287 | } |
Oskar Stolc | 8dc4184 | 2012-05-19 10:19:54 +0100 | [diff] [blame] | 1288 | else if (!strcmp(args[arg], "whole")) { |
| 1289 | curproxy->uri_whole = 1; |
| 1290 | arg += 1; |
| 1291 | } |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 1292 | else { |
Oskar Stolc | 8dc4184 | 2012-05-19 10:19:54 +0100 | [diff] [blame] | 1293 | memprintf(err, "%s only accepts parameters 'len', 'depth', and 'whole' (got '%s').", args[0], args[arg]); |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 1294 | return -1; |
| 1295 | } |
| 1296 | } |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1297 | } |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1298 | else if (!strcmp(args[0], "url_param")) { |
| 1299 | if (!*args[1]) { |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1300 | memprintf(err, "%s requires an URL parameter name.", args[0]); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1301 | return -1; |
| 1302 | } |
Willy Tarreau | 3168223 | 2007-11-29 15:38:04 +0100 | [diff] [blame] | 1303 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1304 | curproxy->lbprm.algo |= BE_LB_ALGO_PH; |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1305 | |
| 1306 | free(curproxy->url_param_name); |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1307 | curproxy->url_param_name = strdup(args[1]); |
Willy Tarreau | a534fea | 2008-08-03 12:19:50 +0200 | [diff] [blame] | 1308 | curproxy->url_param_len = strlen(args[1]); |
Marek Majkowski | 9c30fc1 | 2008-04-27 23:25:55 +0200 | [diff] [blame] | 1309 | if (*args[2]) { |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 1310 | if (strcmp(args[2], "check_post")) { |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1311 | memprintf(err, "%s only accepts 'check_post' modifier (got '%s').", args[0], args[2]); |
matt.farnsworth@nokia.com | 1c2ab96 | 2008-04-14 20:47:37 +0200 | [diff] [blame] | 1312 | return -1; |
| 1313 | } |
| 1314 | if (*args[3]) { |
| 1315 | /* TODO: maybe issue a warning if there is no value, no digits or too long */ |
| 1316 | curproxy->url_param_post_limit = str2ui(args[3]); |
| 1317 | } |
| 1318 | /* if no limit, or faul value in args[3], then default to a moderate wordlen */ |
| 1319 | if (!curproxy->url_param_post_limit) |
| 1320 | curproxy->url_param_post_limit = 48; |
| 1321 | else if ( curproxy->url_param_post_limit < 3 ) |
| 1322 | curproxy->url_param_post_limit = 3; /* minimum example: S=3 or \r\nS=6& */ |
| 1323 | } |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1324 | } |
| 1325 | else if (!strncmp(args[0], "hdr(", 4)) { |
| 1326 | const char *beg, *end; |
| 1327 | |
| 1328 | beg = args[0] + 4; |
| 1329 | end = strchr(beg, ')'); |
| 1330 | |
| 1331 | if (!end || end == beg) { |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1332 | memprintf(err, "hdr requires an http header field name."); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1333 | return -1; |
| 1334 | } |
| 1335 | |
| 1336 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1337 | curproxy->lbprm.algo |= BE_LB_ALGO_HH; |
| 1338 | |
| 1339 | free(curproxy->hh_name); |
| 1340 | curproxy->hh_len = end - beg; |
| 1341 | curproxy->hh_name = my_strndup(beg, end - beg); |
| 1342 | curproxy->hh_match_domain = 0; |
| 1343 | |
| 1344 | if (*args[1]) { |
| 1345 | if (strcmp(args[1], "use_domain_only")) { |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1346 | memprintf(err, "%s only accepts 'use_domain_only' modifier (got '%s').", args[0], args[1]); |
Benoit | affb481 | 2009-03-25 13:02:10 +0100 | [diff] [blame] | 1347 | return -1; |
| 1348 | } |
| 1349 | curproxy->hh_match_domain = 1; |
| 1350 | } |
| 1351 | |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 1352 | } |
| 1353 | else if (!strncmp(args[0], "rdp-cookie", 10)) { |
| 1354 | curproxy->lbprm.algo &= ~BE_LB_ALGO; |
| 1355 | curproxy->lbprm.algo |= BE_LB_ALGO_RCH; |
| 1356 | |
| 1357 | if ( *(args[0] + 10 ) == '(' ) { /* cookie name */ |
| 1358 | const char *beg, *end; |
| 1359 | |
| 1360 | beg = args[0] + 11; |
| 1361 | end = strchr(beg, ')'); |
| 1362 | |
| 1363 | if (!end || end == beg) { |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1364 | memprintf(err, "rdp-cookie : missing cookie name."); |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 1365 | return -1; |
| 1366 | } |
| 1367 | |
| 1368 | free(curproxy->hh_name); |
| 1369 | curproxy->hh_name = my_strndup(beg, end - beg); |
| 1370 | curproxy->hh_len = end - beg; |
| 1371 | } |
| 1372 | else if ( *(args[0] + 10 ) == '\0' ) { /* default cookie name 'mstshash' */ |
| 1373 | free(curproxy->hh_name); |
| 1374 | curproxy->hh_name = strdup("mstshash"); |
| 1375 | curproxy->hh_len = strlen(curproxy->hh_name); |
| 1376 | } |
| 1377 | else { /* syntax */ |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1378 | memprintf(err, "rdp-cookie : missing cookie name."); |
Emeric Brun | 736aa23 | 2009-06-30 17:56:00 +0200 | [diff] [blame] | 1379 | return -1; |
| 1380 | } |
Willy Tarreau | 0173280 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 1381 | } |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1382 | else { |
Willy Tarreau | a93c74b | 2012-05-08 18:14:39 +0200 | [diff] [blame] | 1383 | memprintf(err, "only supports 'roundrobin', 'static-rr', 'leastconn', 'source', 'uri', 'url_param', 'hdr(name)' and 'rdp-cookie(name)' options."); |
Willy Tarreau | a0cbda6 | 2007-11-01 21:39:54 +0100 | [diff] [blame] | 1384 | return -1; |
| 1385 | } |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1389 | |
| 1390 | /************************************************************************/ |
| 1391 | /* All supported keywords must be declared here. */ |
| 1392 | /************************************************************************/ |
| 1393 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1394 | /* set temp integer to the number of enabled servers on the proxy. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 1395 | * Accepts exactly 1 argument. Argument is a backend, other types will lead to |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1396 | * undefined behaviour. |
| 1397 | */ |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1398 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1399 | acl_fetch_nbsrv(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1400 | const struct arg *args, struct sample *smp) |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1401 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1402 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1403 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1404 | px = args->data.prx; |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1405 | |
| 1406 | if (px->srv_act) |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1407 | smp->data.uint = px->srv_act; |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1408 | else if (px->lbprm.fbck) |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1409 | smp->data.uint = 1; |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1410 | else |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1411 | smp->data.uint = px->srv_bck; |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1412 | |
| 1413 | return 1; |
| 1414 | } |
| 1415 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1416 | /* report in smp->flags a success or failure depending on the designated |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1417 | * server's state. There is no match function involved since there's no pattern. |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1418 | * Accepts exactly 1 argument. Argument is a server, other types will lead to |
| 1419 | * undefined behaviour. |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1420 | */ |
| 1421 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1422 | acl_fetch_srv_is_up(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1423 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1424 | { |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1425 | struct server *srv = args->data.srv; |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1426 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1427 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1428 | smp->type = SMP_T_BOOL; |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1429 | if (!(srv->state & SRV_MAINTAIN) && |
| 1430 | (!(srv->state & SRV_CHECKED) || (srv->state & SRV_RUNNING))) |
Willy Tarreau | 197e10a | 2012-04-23 19:18:42 +0200 | [diff] [blame] | 1431 | smp->data.uint = 1; |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1432 | else |
Willy Tarreau | 197e10a | 2012-04-23 19:18:42 +0200 | [diff] [blame] | 1433 | smp->data.uint = 0; |
Willy Tarreau | 0b1cd94 | 2010-05-16 22:18:27 +0200 | [diff] [blame] | 1434 | return 1; |
| 1435 | } |
| 1436 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1437 | /* set temp integer to the number of enabled servers on the proxy. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 1438 | * Accepts exactly 1 argument. Argument is a backend, other types will lead to |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1439 | * undefined behaviour. |
| 1440 | */ |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 1441 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1442 | acl_fetch_connslots(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1443 | const struct arg *args, struct sample *smp) |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 1444 | { |
| 1445 | struct server *iterator; |
Willy Tarreau | d28c353 | 2012-04-19 19:28:33 +0200 | [diff] [blame] | 1446 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1447 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1448 | smp->type = SMP_T_UINT; |
| 1449 | smp->data.uint = 0; |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 1450 | |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1451 | for (iterator = args->data.prx->srv; iterator; iterator = iterator->next) { |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 1452 | if ((iterator->state & SRV_RUNNING) == 0) |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 1453 | continue; |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 1454 | |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 1455 | if (iterator->maxconn == 0 || iterator->maxqueue == 0) { |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 1456 | /* configuration is stupid */ |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1457 | smp->data.uint = -1; /* FIXME: stupid value! */ |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 1458 | return 1; |
| 1459 | } |
| 1460 | |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1461 | smp->data.uint += (iterator->maxconn - iterator->cur_sess) |
Willy Tarreau | 422aa07 | 2012-04-20 20:49:27 +0200 | [diff] [blame] | 1462 | + (iterator->maxqueue - iterator->nbpend); |
Jeffrey 'jf' Lim | 5051d7b | 2008-09-04 01:03:03 +0800 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | return 1; |
| 1466 | } |
| 1467 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 1468 | /* set temp integer to the id of the backend */ |
Hervé COMMOWICK | 35ed801 | 2010-12-15 14:04:51 +0100 | [diff] [blame] | 1469 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1470 | acl_fetch_be_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1471 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1472 | { |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1473 | smp->flags = SMP_F_VOL_TXN; |
| 1474 | smp->type = SMP_T_UINT; |
| 1475 | smp->data.uint = l4->be->uuid; |
Hervé COMMOWICK | 35ed801 | 2010-12-15 14:04:51 +0100 | [diff] [blame] | 1476 | return 1; |
| 1477 | } |
| 1478 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 1479 | /* set temp integer to the id of the server */ |
Hervé COMMOWICK | 35ed801 | 2010-12-15 14:04:51 +0100 | [diff] [blame] | 1480 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1481 | acl_fetch_srv_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1482 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1483 | { |
Willy Tarreau | 827aee9 | 2011-03-10 16:55:02 +0100 | [diff] [blame] | 1484 | if (!target_srv(&l4->target)) |
Willy Tarreau | 17af419 | 2011-02-23 14:27:06 +0100 | [diff] [blame] | 1485 | return 0; |
| 1486 | |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1487 | smp->type = SMP_T_UINT; |
| 1488 | smp->data.uint = target_srv(&l4->target)->puid; |
Hervé COMMOWICK | 35ed801 | 2010-12-15 14:04:51 +0100 | [diff] [blame] | 1489 | |
| 1490 | return 1; |
| 1491 | } |
| 1492 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1493 | /* set temp integer to the number of connections per second reaching the backend. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 1494 | * Accepts exactly 1 argument. Argument is a backend, other types will lead to |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1495 | * undefined behaviour. |
| 1496 | */ |
Willy Tarreau | 079ff0a | 2009-03-05 21:34:28 +0100 | [diff] [blame] | 1497 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1498 | acl_fetch_be_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1499 | const struct arg *args, struct sample *smp) |
Willy Tarreau | 079ff0a | 2009-03-05 21:34:28 +0100 | [diff] [blame] | 1500 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1501 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1502 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1503 | smp->data.uint = read_freq_ctr(&args->data.prx->be_sess_per_sec); |
Willy Tarreau | 079ff0a | 2009-03-05 21:34:28 +0100 | [diff] [blame] | 1504 | return 1; |
| 1505 | } |
| 1506 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1507 | /* set temp integer to the number of concurrent connections on the backend. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 1508 | * Accepts exactly 1 argument. Argument is a backend, other types will lead to |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1509 | * undefined behaviour. |
| 1510 | */ |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1511 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1512 | acl_fetch_be_conn(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1513 | const struct arg *args, struct sample *smp) |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1514 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1515 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1516 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1517 | smp->data.uint = args->data.prx->beconn; |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1518 | return 1; |
| 1519 | } |
| 1520 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1521 | /* set temp integer to the total number of queued connections on the backend. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 1522 | * Accepts exactly 1 argument. Argument is a backend, other types will lead to |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1523 | * undefined behaviour. |
| 1524 | */ |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1525 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1526 | acl_fetch_queue_size(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1527 | const struct arg *args, struct sample *smp) |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1528 | { |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1529 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1530 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1531 | smp->data.uint = args->data.prx->totpend; |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1532 | return 1; |
| 1533 | } |
| 1534 | |
Willy Tarreau | a5e3756 | 2011-12-16 17:06:15 +0100 | [diff] [blame] | 1535 | /* set temp integer to the total number of queued connections on the backend divided |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1536 | * by the number of running servers and rounded up. If there is no running |
| 1537 | * server, we return twice the total, just as if we had half a running server. |
| 1538 | * This is more or less correct anyway, since we expect the last server to come |
| 1539 | * back soon. |
Willy Tarreau | 0146c2e | 2012-04-20 11:37:56 +0200 | [diff] [blame] | 1540 | * Accepts exactly 1 argument. Argument is a backend, other types will lead to |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1541 | * undefined behaviour. |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1542 | */ |
| 1543 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1544 | acl_fetch_avg_queue_size(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1545 | const struct arg *args, struct sample *smp) |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1546 | { |
| 1547 | int nbsrv; |
| 1548 | |
Willy Tarreau | 3740635 | 2012-04-23 16:16:37 +0200 | [diff] [blame] | 1549 | smp->flags = SMP_F_VOL_TEST; |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1550 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1551 | px = args->data.prx; |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1552 | |
| 1553 | if (px->srv_act) |
| 1554 | nbsrv = px->srv_act; |
| 1555 | else if (px->lbprm.fbck) |
| 1556 | nbsrv = 1; |
| 1557 | else |
| 1558 | nbsrv = px->srv_bck; |
| 1559 | |
| 1560 | if (nbsrv > 0) |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1561 | smp->data.uint = (px->totpend + nbsrv - 1) / nbsrv; |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1562 | else |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1563 | smp->data.uint = px->totpend * 2; |
Willy Tarreau | a36af91 | 2009-10-10 12:02:45 +0200 | [diff] [blame] | 1564 | |
| 1565 | return 1; |
| 1566 | } |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1567 | |
Willy Tarreau | 34db108 | 2012-04-19 17:16:54 +0200 | [diff] [blame] | 1568 | /* set temp integer to the number of concurrent connections on the server in the backend. |
| 1569 | * Accepts exactly 1 argument. Argument is a server, other types will lead to |
| 1570 | * undefined behaviour. |
| 1571 | */ |
Hervé COMMOWICK | daa824e | 2011-08-05 12:09:44 +0200 | [diff] [blame] | 1572 | static int |
Willy Tarreau | 32a6f2e | 2012-04-25 10:13:36 +0200 | [diff] [blame] | 1573 | acl_fetch_srv_conn(struct proxy *px, struct session *l4, void *l7, unsigned int opt, |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1574 | const struct arg *args, struct sample *smp) |
Hervé COMMOWICK | daa824e | 2011-08-05 12:09:44 +0200 | [diff] [blame] | 1575 | { |
Willy Tarreau | f853c46 | 2012-04-23 18:53:56 +0200 | [diff] [blame] | 1576 | smp->flags = SMP_F_VOL_TEST; |
| 1577 | smp->type = SMP_T_UINT; |
Willy Tarreau | 24e32d8 | 2012-04-23 23:55:44 +0200 | [diff] [blame] | 1578 | smp->data.uint = args->data.srv->cur_sess; |
Hervé COMMOWICK | daa824e | 2011-08-05 12:09:44 +0200 | [diff] [blame] | 1579 | return 1; |
| 1580 | } |
| 1581 | |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 1582 | /* Note: must not be declared <const> as its list will be overwritten. |
| 1583 | * Please take care of keeping this list alphabetically sorted. |
| 1584 | */ |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1585 | static struct acl_kw_list acl_kws = {{ },{ |
Willy Tarreau | fc2c1fd | 2012-04-19 23:35:54 +0200 | [diff] [blame] | 1586 | { "avg_queue", acl_parse_int, acl_fetch_avg_queue_size, acl_match_int, ACL_USE_NOTHING, ARG1(1,BE) }, |
| 1587 | { "be_conn", acl_parse_int, acl_fetch_be_conn, acl_match_int, ACL_USE_NOTHING, ARG1(1,BE) }, |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 1588 | { "be_id", acl_parse_int, acl_fetch_be_id, acl_match_int, ACL_USE_NOTHING, 0 }, |
Willy Tarreau | fc2c1fd | 2012-04-19 23:35:54 +0200 | [diff] [blame] | 1589 | { "be_sess_rate", acl_parse_int, acl_fetch_be_sess_rate, acl_match_int, ACL_USE_NOTHING, ARG1(1,BE) }, |
| 1590 | { "connslots", acl_parse_int, acl_fetch_connslots, acl_match_int, ACL_USE_NOTHING, ARG1(1,BE) }, |
| 1591 | { "nbsrv", acl_parse_int, acl_fetch_nbsrv, acl_match_int, ACL_USE_NOTHING, ARG1(1,BE) }, |
| 1592 | { "queue", acl_parse_int, acl_fetch_queue_size, acl_match_int, ACL_USE_NOTHING, ARG1(1,BE) }, |
Willy Tarreau | 61612d4 | 2012-04-19 18:42:05 +0200 | [diff] [blame] | 1593 | { "srv_conn", acl_parse_int, acl_fetch_srv_conn, acl_match_int, ACL_USE_NOTHING, ARG1(1,SRV) }, |
| 1594 | { "srv_id", acl_parse_int, acl_fetch_srv_id, acl_match_int, ACL_USE_RTR_INTERNAL, 0 }, |
| 1595 | { "srv_is_up", acl_parse_nothing, acl_fetch_srv_is_up, acl_match_nothing, ACL_USE_NOTHING, ARG1(1,SRV) }, |
Willy Tarreau | a9d3c1e | 2007-11-30 20:48:53 +0100 | [diff] [blame] | 1596 | { NULL, NULL, NULL, NULL }, |
| 1597 | }}; |
| 1598 | |
| 1599 | |
| 1600 | __attribute__((constructor)) |
| 1601 | static void __backend_init(void) |
| 1602 | { |
| 1603 | acl_register_keywords(&acl_kws); |
| 1604 | } |
| 1605 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1606 | /* |
| 1607 | * Local variables: |
| 1608 | * c-indent-level: 8 |
| 1609 | * c-basic-offset: 8 |
| 1610 | * End: |
| 1611 | */ |