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