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