blob: 26f558971f74b19a50b98839f67688815db9d8d2 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Backend variables and functions.
3 *
Willy Tarreau1a7eca12013-01-07 22:38:03 +01004 * Copyright 2000-2013 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
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 Tarreauf19cf372006-11-14 15:40:51 +010018#include <string.h>
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +020019#include <ctype.h>
Dmitry Sivachenkocaf58982009-08-24 15:11:06 +040020#include <sys/types.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020021
Willy Tarreauc7e42382012-08-24 19:22:53 +020022#include <common/buffer.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020023#include <common/compat.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020024#include <common/config.h>
Willy Tarreau7c669d72008-06-20 15:04:11 +020025#include <common/debug.h>
Bhaskar98634f02013-10-29 23:30:51 -040026#include <common/hash.h>
Willy Tarreau0c303ee2008-07-07 00:09:58 +020027#include <common/ticks.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020028#include <common/time.h>
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +010029#include <common/namespace.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020030
Willy Tarreaubaaee002006-06-26 02:48:02 +020031#include <types/global.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020032
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +010033#include <proto/acl.h>
Willy Tarreau34db1082012-04-19 17:16:54 +020034#include <proto/arg.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020035#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020036#include <proto/channel.h>
Willy Tarreau03fa5df2010-05-24 21:02:37 +020037#include <proto/frontend.h>
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020038#include <proto/lb_chash.h>
Willy Tarreauf09c6602012-02-13 17:12:08 +010039#include <proto/lb_fas.h>
Willy Tarreauf89c1872009-10-01 11:19:37 +020040#include <proto/lb_fwlc.h>
41#include <proto/lb_fwrr.h>
42#include <proto/lb_map.h>
Willy Tarreau4aac7db2014-05-16 11:48:10 +020043#include <proto/log.h>
Willy Tarreau3fdb3662012-11-12 00:42:33 +010044#include <proto/obj_type.h>
Willy Tarreaud4c33c82013-01-07 21:59:07 +010045#include <proto/payload.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020046#include <proto/protocol.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020047#include <proto/proto_http.h>
Willy Tarreaua8f55d52010-05-31 17:44:19 +020048#include <proto/proto_tcp.h>
Willy Tarreau4aac7db2014-05-16 11:48:10 +020049#include <proto/proxy.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020050#include <proto/queue.h>
Willy Tarreaud4c33c82013-01-07 21:59:07 +010051#include <proto/sample.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010052#include <proto/server.h>
Willy Tarreau87b09662015-04-03 00:22:06 +020053#include <proto/stream.h>
Willy Tarreau75bf2c92012-08-20 17:01:35 +020054#include <proto/raw_sock.h>
Willy Tarreau9e000c62011-03-10 14:03:36 +010055#include <proto/stream_interface.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020056#include <proto/task.h>
57
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -050058int be_lastsession(const struct proxy *be)
59{
60 if (be->be_counters.last_sess)
61 return now.tv_sec - be->be_counters.last_sess;
62
63 return -1;
64}
65
Bhaskar98634f02013-10-29 23:30:51 -040066/* helper function to invoke the correct hash method */
Dan Dubovikbd57a9f2014-07-08 08:51:03 -070067static unsigned int gen_hash(const struct proxy* px, const char* key, unsigned long len)
Bhaskar98634f02013-10-29 23:30:51 -040068{
Dan Dubovikbd57a9f2014-07-08 08:51:03 -070069 unsigned int hash;
Bhaskar98634f02013-10-29 23:30:51 -040070
71 switch (px->lbprm.algo & BE_LB_HASH_FUNC) {
72 case BE_LB_HFCN_DJB2:
73 hash = hash_djb2(key, len);
74 break;
Willy Tarreaua0f42712013-11-14 14:30:35 +010075 case BE_LB_HFCN_WT6:
76 hash = hash_wt6(key, len);
77 break;
Willy Tarreau324f07f2015-01-20 19:44:50 +010078 case BE_LB_HFCN_CRC32:
79 hash = hash_crc32(key, len);
80 break;
Bhaskar98634f02013-10-29 23:30:51 -040081 case BE_LB_HFCN_SDBM:
82 /* this is the default hash function */
83 default:
84 hash = hash_sdbm(key, len);
85 break;
86 }
87
88 return hash;
89}
90
Willy Tarreaubaaee002006-06-26 02:48:02 +020091/*
92 * This function recounts the number of usable active and backup servers for
93 * proxy <p>. These numbers are returned into the p->srv_act and p->srv_bck.
Willy Tarreaub625a082007-11-26 01:15:43 +010094 * This function also recomputes the total active and backup weights. However,
Willy Tarreauf4cca452008-03-08 21:42:54 +010095 * it does not update tot_weight nor tot_used. Use update_backend_weight() for
Willy Tarreaub625a082007-11-26 01:15:43 +010096 * this.
Willy Tarreaubaaee002006-06-26 02:48:02 +020097 */
Willy Tarreauc5d9c802009-10-01 09:17:05 +020098void recount_servers(struct proxy *px)
Willy Tarreaubaaee002006-06-26 02:48:02 +020099{
100 struct server *srv;
101
Willy Tarreau20697042007-11-15 23:26:18 +0100102 px->srv_act = px->srv_bck = 0;
103 px->lbprm.tot_wact = px->lbprm.tot_wbck = 0;
Willy Tarreaub625a082007-11-26 01:15:43 +0100104 px->lbprm.fbck = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200105 for (srv = px->srv; srv != NULL; srv = srv->next) {
Willy Tarreau87eb1d62014-05-13 18:51:40 +0200106 if (!srv_is_usable(srv))
Willy Tarreaub625a082007-11-26 01:15:43 +0100107 continue;
108
Willy Tarreauc93cd162014-05-13 15:54:22 +0200109 if (srv->flags & SRV_F_BACKUP) {
Willy Tarreaub625a082007-11-26 01:15:43 +0100110 if (!px->srv_bck &&
Willy Tarreauf4cca452008-03-08 21:42:54 +0100111 !(px->options & PR_O_USE_ALL_BK))
Willy Tarreaub625a082007-11-26 01:15:43 +0100112 px->lbprm.fbck = srv;
113 px->srv_bck++;
114 px->lbprm.tot_wbck += srv->eweight;
115 } else {
116 px->srv_act++;
117 px->lbprm.tot_wact += srv->eweight;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200118 }
119 }
Willy Tarreaub625a082007-11-26 01:15:43 +0100120}
Willy Tarreau20697042007-11-15 23:26:18 +0100121
Willy Tarreaub625a082007-11-26 01:15:43 +0100122/* This function simply updates the backend's tot_weight and tot_used values
123 * after servers weights have been updated. It is designed to be used after
124 * recount_servers() or equivalent.
125 */
Willy Tarreauc5d9c802009-10-01 09:17:05 +0200126void update_backend_weight(struct proxy *px)
Willy Tarreaub625a082007-11-26 01:15:43 +0100127{
Willy Tarreau20697042007-11-15 23:26:18 +0100128 if (px->srv_act) {
129 px->lbprm.tot_weight = px->lbprm.tot_wact;
130 px->lbprm.tot_used = px->srv_act;
131 }
Willy Tarreaub625a082007-11-26 01:15:43 +0100132 else if (px->lbprm.fbck) {
133 /* use only the first backup server */
134 px->lbprm.tot_weight = px->lbprm.fbck->eweight;
135 px->lbprm.tot_used = 1;
Willy Tarreau20697042007-11-15 23:26:18 +0100136 }
137 else {
Willy Tarreaub625a082007-11-26 01:15:43 +0100138 px->lbprm.tot_weight = px->lbprm.tot_wbck;
139 px->lbprm.tot_used = px->srv_bck;
Willy Tarreau20697042007-11-15 23:26:18 +0100140 }
Willy Tarreaub625a082007-11-26 01:15:43 +0100141}
142
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200143/*
144 * This function tries to find a running server for the proxy <px> following
145 * the source hash method. Depending on the number of active/backup servers,
146 * it will either look for active servers, or for backup servers.
147 * If any server is found, it will be returned. If no valid server is found,
148 * NULL is returned.
149 */
150struct server *get_server_sh(struct proxy *px, const char *addr, int len)
151{
152 unsigned int h, l;
153
154 if (px->lbprm.tot_weight == 0)
155 return NULL;
156
157 l = h = 0;
158
159 /* note: we won't hash if there's only one server left */
160 if (px->lbprm.tot_used == 1)
161 goto hash_done;
162
163 while ((l + sizeof (int)) <= len) {
164 h ^= ntohl(*(unsigned int *)(&addr[l]));
165 l += sizeof (int);
166 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500167 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100168 h = full_hash(h);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200169 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200170 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
171 return chash_get_server_hash(px, h);
172 else
173 return map_get_server_hash(px, h);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200174}
175
176/*
177 * This function tries to find a running server for the proxy <px> following
178 * the URI hash method. In order to optimize cache hits, the hash computation
179 * ends at the question mark. Depending on the number of active/backup servers,
180 * it will either look for active servers, or for backup servers.
181 * If any server is found, it will be returned. If no valid server is found,
182 * NULL is returned.
183 *
184 * This code was contributed by Guillaume Dallaire, who also selected this hash
185 * algorithm out of a tens because it gave him the best results.
186 *
187 */
188struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
189{
Dan Dubovikbd57a9f2014-07-08 08:51:03 -0700190 unsigned int hash = 0;
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200191 int c;
192 int slashes = 0;
Bhaskar98634f02013-10-29 23:30:51 -0400193 const char *start, *end;
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200194
195 if (px->lbprm.tot_weight == 0)
196 return NULL;
197
198 /* note: we won't hash if there's only one server left */
199 if (px->lbprm.tot_used == 1)
200 goto hash_done;
201
202 if (px->uri_len_limit)
203 uri_len = MIN(uri_len, px->uri_len_limit);
204
Bhaskar98634f02013-10-29 23:30:51 -0400205 start = end = uri;
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200206 while (uri_len--) {
Willy Tarreaufad4ffc2014-10-17 12:11:50 +0200207 c = *end;
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200208 if (c == '/') {
209 slashes++;
210 if (slashes == px->uri_dirs_depth1) /* depth+1 */
211 break;
212 }
Oskar Stolc8dc41842012-05-19 10:19:54 +0100213 else if (c == '?' && !px->uri_whole)
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200214 break;
Willy Tarreaufad4ffc2014-10-17 12:11:50 +0200215 end++;
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200216 }
Bhaskar98634f02013-10-29 23:30:51 -0400217
218 hash = gen_hash(px, start, (end - start));
219
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500220 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100221 hash = full_hash(hash);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200222 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200223 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
224 return chash_get_server_hash(px, hash);
225 else
226 return map_get_server_hash(px, hash);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200227}
228
Willy Tarreau01732802007-11-01 22:48:15 +0100229/*
230 * This function tries to find a running server for the proxy <px> following
231 * the URL parameter hash method. It looks for a specific parameter in the
232 * URL and hashes it to compute the server ID. This is useful to optimize
233 * performance by avoiding bounces between servers in contexts where sessions
234 * are shared but cookies are not usable. If the parameter is not found, NULL
235 * is returned. If any server is found, it will be returned. If no valid server
236 * is found, NULL is returned.
Willy Tarreau01732802007-11-01 22:48:15 +0100237 */
238struct server *get_server_ph(struct proxy *px, const char *uri, int uri_len)
239{
Dan Dubovikbd57a9f2014-07-08 08:51:03 -0700240 unsigned int hash = 0;
Bhaskar98634f02013-10-29 23:30:51 -0400241 const char *start, *end;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200242 const char *p;
243 const char *params;
Willy Tarreau01732802007-11-01 22:48:15 +0100244 int plen;
245
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200246 /* when tot_weight is 0 then so is srv_count */
Willy Tarreau20697042007-11-15 23:26:18 +0100247 if (px->lbprm.tot_weight == 0)
Willy Tarreau01732802007-11-01 22:48:15 +0100248 return NULL;
249
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200250 if ((p = memchr(uri, '?', uri_len)) == NULL)
251 return NULL;
252
Willy Tarreau01732802007-11-01 22:48:15 +0100253 p++;
254
255 uri_len -= (p - uri);
256 plen = px->url_param_len;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200257 params = p;
Willy Tarreau01732802007-11-01 22:48:15 +0100258
259 while (uri_len > plen) {
260 /* Look for the parameter name followed by an equal symbol */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200261 if (params[plen] == '=') {
262 if (memcmp(params, px->url_param_name, plen) == 0) {
263 /* OK, we have the parameter here at <params>, and
Willy Tarreau01732802007-11-01 22:48:15 +0100264 * the value after the equal sign, at <p>
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200265 * skip the equal symbol
Willy Tarreau01732802007-11-01 22:48:15 +0100266 */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200267 p += plen + 1;
Bhaskar98634f02013-10-29 23:30:51 -0400268 start = end = p;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200269 uri_len -= plen + 1;
270
Bhaskar98634f02013-10-29 23:30:51 -0400271 while (uri_len && *end != '&') {
Willy Tarreau01732802007-11-01 22:48:15 +0100272 uri_len--;
Bhaskar98634f02013-10-29 23:30:51 -0400273 end++;
Willy Tarreau01732802007-11-01 22:48:15 +0100274 }
Bhaskar98634f02013-10-29 23:30:51 -0400275 hash = gen_hash(px, start, (end - start));
276
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500277 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100278 hash = full_hash(hash);
Bhaskar98634f02013-10-29 23:30:51 -0400279
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200280 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
281 return chash_get_server_hash(px, hash);
282 else
283 return map_get_server_hash(px, hash);
Willy Tarreau01732802007-11-01 22:48:15 +0100284 }
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200285 }
286 /* skip to next parameter */
287 p = memchr(params, '&', uri_len);
288 if (!p)
289 return NULL;
290 p++;
291 uri_len -= (p - params);
292 params = p;
293 }
294 return NULL;
295}
296
297/*
298 * this does the same as the previous server_ph, but check the body contents
299 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200300struct server *get_server_ph_post(struct stream *s)
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200301{
Dan Dubovikbd57a9f2014-07-08 08:51:03 -0700302 unsigned int hash = 0;
Willy Tarreaueee5b512015-04-03 23:46:31 +0200303 struct http_txn *txn = s->txn;
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100304 struct channel *req = &s->req;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200305 struct http_msg *msg = &txn->req;
306 struct proxy *px = s->be;
307 unsigned int plen = px->url_param_len;
Willy Tarreau2d8e4852014-04-17 20:08:17 +0200308 unsigned long len = http_body_bytes(msg);
Willy Tarreau0d090502014-04-17 20:31:44 +0200309 const char *params = b_ptr(req->buf, -http_data_rewind(msg));
Willy Tarreau157dd632009-12-06 19:18:09 +0100310 const char *p = params;
Bhaskar98634f02013-10-29 23:30:51 -0400311 const char *start, *end;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200312
Willy Tarreau157dd632009-12-06 19:18:09 +0100313 if (len == 0)
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200314 return NULL;
315
Willy Tarreauf69d4ff2015-05-02 00:05:47 +0200316 if (len > req->buf->data + req->buf->size - p)
317 len = req->buf->data + req->buf->size - p;
318
Willy Tarreau157dd632009-12-06 19:18:09 +0100319 if (px->lbprm.tot_weight == 0)
320 return NULL;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200321
322 while (len > plen) {
323 /* Look for the parameter name followed by an equal symbol */
324 if (params[plen] == '=') {
325 if (memcmp(params, px->url_param_name, plen) == 0) {
326 /* OK, we have the parameter here at <params>, and
327 * the value after the equal sign, at <p>
328 * skip the equal symbol
329 */
330 p += plen + 1;
Bhaskar98634f02013-10-29 23:30:51 -0400331 start = end = p;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200332 len -= plen + 1;
333
Bhaskar98634f02013-10-29 23:30:51 -0400334 while (len && *end != '&') {
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200335 if (unlikely(!HTTP_IS_TOKEN(*p))) {
Willy Tarreau157dd632009-12-06 19:18:09 +0100336 /* if in a POST, body must be URI encoded or it's not a URI.
Bhaskar98634f02013-10-29 23:30:51 -0400337 * Do not interpret any possible binary data as a parameter.
Willy Tarreau157dd632009-12-06 19:18:09 +0100338 */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200339 if (likely(HTTP_IS_LWS(*p))) /* eol, uncertain uri len */
340 break;
341 return NULL; /* oh, no; this is not uri-encoded.
342 * This body does not contain parameters.
343 */
344 }
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200345 len--;
Bhaskar98634f02013-10-29 23:30:51 -0400346 end++;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200347 /* should we break if vlen exceeds limit? */
348 }
Bhaskar98634f02013-10-29 23:30:51 -0400349 hash = gen_hash(px, start, (end - start));
350
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500351 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100352 hash = full_hash(hash);
Bhaskar98634f02013-10-29 23:30:51 -0400353
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200354 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
355 return chash_get_server_hash(px, hash);
356 else
357 return map_get_server_hash(px, hash);
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200358 }
359 }
Willy Tarreau01732802007-11-01 22:48:15 +0100360 /* skip to next parameter */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200361 p = memchr(params, '&', len);
Willy Tarreau01732802007-11-01 22:48:15 +0100362 if (!p)
363 return NULL;
364 p++;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200365 len -= (p - params);
366 params = p;
Willy Tarreau01732802007-11-01 22:48:15 +0100367 }
368 return NULL;
369}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200370
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200371
Willy Tarreaubaaee002006-06-26 02:48:02 +0200372/*
Benoitaffb4812009-03-25 13:02:10 +0100373 * This function tries to find a running server for the proxy <px> following
374 * the Header parameter hash method. It looks for a specific parameter in the
375 * URL and hashes it to compute the server ID. This is useful to optimize
376 * performance by avoiding bounces between servers in contexts where sessions
377 * are shared but cookies are not usable. If the parameter is not found, NULL
378 * is returned. If any server is found, it will be returned. If no valid server
379 * is found, NULL is returned.
380 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200381struct server *get_server_hh(struct stream *s)
Benoitaffb4812009-03-25 13:02:10 +0100382{
Dan Dubovikbd57a9f2014-07-08 08:51:03 -0700383 unsigned int hash = 0;
Willy Tarreaueee5b512015-04-03 23:46:31 +0200384 struct http_txn *txn = s->txn;
Benoitaffb4812009-03-25 13:02:10 +0100385 struct proxy *px = s->be;
386 unsigned int plen = px->hh_len;
387 unsigned long len;
388 struct hdr_ctx ctx;
389 const char *p;
Bhaskar98634f02013-10-29 23:30:51 -0400390 const char *start, *end;
Benoitaffb4812009-03-25 13:02:10 +0100391
392 /* tot_weight appears to mean srv_count */
393 if (px->lbprm.tot_weight == 0)
394 return NULL;
395
Benoitaffb4812009-03-25 13:02:10 +0100396 ctx.idx = 0;
397
398 /* if the message is chunked, we skip the chunk size, but use the value as len */
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100399 http_find_header2(px->hh_name, plen, b_ptr(s->req.buf, -http_hdr_rewind(&txn->req)), &txn->hdr_idx, &ctx);
Benoitaffb4812009-03-25 13:02:10 +0100400
401 /* if the header is not found or empty, let's fallback to round robin */
402 if (!ctx.idx || !ctx.vlen)
403 return NULL;
404
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200405 /* note: we won't hash if there's only one server left */
406 if (px->lbprm.tot_used == 1)
407 goto hash_done;
408
Benoitaffb4812009-03-25 13:02:10 +0100409 /* Found a the hh_name in the headers.
410 * we will compute the hash based on this value ctx.val.
411 */
412 len = ctx.vlen;
413 p = (char *)ctx.line + ctx.val;
414 if (!px->hh_match_domain) {
Bhaskar98634f02013-10-29 23:30:51 -0400415 hash = gen_hash(px, p, len);
Benoitaffb4812009-03-25 13:02:10 +0100416 } else {
417 int dohash = 0;
Cyril Bontéf607d812015-01-04 15:17:36 +0100418 p += len;
Benoitaffb4812009-03-25 13:02:10 +0100419 /* special computation, use only main domain name, not tld/host
420 * going back from the end of string, start hashing at first
421 * dot stop at next.
422 * This is designed to work with the 'Host' header, and requires
423 * a special option to activate this.
424 */
Cyril Bontéf607d812015-01-04 15:17:36 +0100425 end = p;
Benoitaffb4812009-03-25 13:02:10 +0100426 while (len) {
Cyril Bontéf607d812015-01-04 15:17:36 +0100427 if (dohash) {
428 /* Rewind the pointer until the previous char
429 * is a dot, this will allow to set the start
430 * position of the domain. */
431 if (*(p - 1) == '.')
Benoitaffb4812009-03-25 13:02:10 +0100432 break;
Benoitaffb4812009-03-25 13:02:10 +0100433 }
Cyril Bontéf607d812015-01-04 15:17:36 +0100434 else if (*p == '.') {
435 /* The pointer is rewinded to the dot before the
436 * tld, we memorize the end of the domain and
437 * can enter the domain processing. */
438 end = p;
439 dohash = 1;
440 }
Benoitaffb4812009-03-25 13:02:10 +0100441 p--;
Cyril Bontéf607d812015-01-04 15:17:36 +0100442 len--;
Benoitaffb4812009-03-25 13:02:10 +0100443 }
Cyril Bontéf607d812015-01-04 15:17:36 +0100444 start = p;
Bhaskar98634f02013-10-29 23:30:51 -0400445 hash = gen_hash(px, start, (end - start));
Benoitaffb4812009-03-25 13:02:10 +0100446 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500447 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100448 hash = full_hash(hash);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200449 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200450 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
451 return chash_get_server_hash(px, hash);
452 else
453 return map_get_server_hash(px, hash);
Benoitaffb4812009-03-25 13:02:10 +0100454}
455
Willy Tarreau34db1082012-04-19 17:16:54 +0200456/* RDP Cookie HASH. */
Willy Tarreau87b09662015-04-03 00:22:06 +0200457struct server *get_server_rch(struct stream *s)
Emeric Brun736aa232009-06-30 17:56:00 +0200458{
Dan Dubovikbd57a9f2014-07-08 08:51:03 -0700459 unsigned int hash = 0;
Emeric Brun736aa232009-06-30 17:56:00 +0200460 struct proxy *px = s->be;
461 unsigned long len;
Emeric Brun736aa232009-06-30 17:56:00 +0200462 int ret;
Willy Tarreau37406352012-04-23 16:16:37 +0200463 struct sample smp;
Willy Tarreaud1de8af2012-05-18 22:12:14 +0200464 int rewind;
Emeric Brun736aa232009-06-30 17:56:00 +0200465
466 /* tot_weight appears to mean srv_count */
467 if (px->lbprm.tot_weight == 0)
468 return NULL;
469
Willy Tarreau37406352012-04-23 16:16:37 +0200470 memset(&smp, 0, sizeof(smp));
Emeric Brun736aa232009-06-30 17:56:00 +0200471
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100472 b_rew(s->req.buf, rewind = s->req.buf->o);
Willy Tarreaud1de8af2012-05-18 22:12:14 +0200473
Willy Tarreaucadd8c92013-07-22 18:09:52 +0200474 ret = fetch_rdp_cookie_name(s, &smp, px->hh_name, px->hh_len);
Willy Tarreauf853c462012-04-23 18:53:56 +0200475 len = smp.data.str.len;
Willy Tarreau664092c2011-12-16 19:11:42 +0100476
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100477 b_adv(s->req.buf, rewind);
Willy Tarreaud1de8af2012-05-18 22:12:14 +0200478
Willy Tarreau37406352012-04-23 16:16:37 +0200479 if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || len == 0)
Emeric Brun736aa232009-06-30 17:56:00 +0200480 return NULL;
481
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200482 /* note: we won't hash if there's only one server left */
483 if (px->lbprm.tot_used == 1)
484 goto hash_done;
485
Emeric Brun736aa232009-06-30 17:56:00 +0200486 /* Found a the hh_name in the headers.
487 * we will compute the hash based on this value ctx.val.
488 */
Bhaskar98634f02013-10-29 23:30:51 -0400489 hash = gen_hash(px, smp.data.str.str, len);
490
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500491 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100492 hash = full_hash(hash);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200493 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200494 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
495 return chash_get_server_hash(px, hash);
496 else
497 return map_get_server_hash(px, hash);
Emeric Brun736aa232009-06-30 17:56:00 +0200498}
Benoitaffb4812009-03-25 13:02:10 +0100499
500/*
Willy Tarreau87b09662015-04-03 00:22:06 +0200501 * This function applies the load-balancing algorithm to the stream, as
502 * defined by the backend it is assigned to. The stream is then marked as
Willy Tarreau7c669d72008-06-20 15:04:11 +0200503 * 'assigned'.
504 *
Willy Tarreaue7dff022015-04-03 01:14:29 +0200505 * This function MAY NOT be called with SF_ASSIGNED already set. If the stream
Willy Tarreau7c669d72008-06-20 15:04:11 +0200506 * had a server previously assigned, it is rebalanced, trying to avoid the same
Willy Tarreau827aee92011-03-10 16:55:02 +0100507 * server, which should still be present in target_srv(&s->target) before the call.
Willy Tarreau7c669d72008-06-20 15:04:11 +0200508 * The function tries to keep the original connection slot if it reconnects to
509 * the same server, otherwise it releases it and tries to offer it.
510 *
Willy Tarreau87b09662015-04-03 00:22:06 +0200511 * It is illegal to call this function with a stream in a queue.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200512 *
513 * It may return :
Willy Tarreau664beb82011-03-10 11:38:29 +0100514 * SRV_STATUS_OK if everything is OK. ->srv and ->target are assigned.
Willy Tarreau87b09662015-04-03 00:22:06 +0200515 * SRV_STATUS_NOSRV if no server is available. Stream is not ASSIGNED
516 * SRV_STATUS_FULL if all servers are saturated. Stream is not ASSIGNED
Willy Tarreaubaaee002006-06-26 02:48:02 +0200517 * SRV_STATUS_INTERNAL for other unrecoverable errors.
518 *
Willy Tarreaue7dff022015-04-03 01:14:29 +0200519 * Upon successful return, the stream flag SF_ASSIGNED is set to indicate that
Willy Tarreau827aee92011-03-10 16:55:02 +0100520 * it does not need to be called anymore. This means that target_srv(&s->target)
521 * can be trusted in balance and direct modes.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200522 *
523 */
524
Willy Tarreau87b09662015-04-03 00:22:06 +0200525int assign_server(struct stream *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200526{
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200527 struct connection *conn;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200528 struct server *conn_slot;
Willy Tarreau827aee92011-03-10 16:55:02 +0100529 struct server *srv, *prev_srv;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200530 int err;
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100531
Simon Horman8effd3d2011-08-13 08:03:52 +0900532 DPRINTF(stderr,"assign_server : s=%p\n",s);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200533
Willy Tarreau7c669d72008-06-20 15:04:11 +0200534 err = SRV_STATUS_INTERNAL;
Willy Tarreaue7dff022015-04-03 01:14:29 +0200535 if (unlikely(s->pend_pos || s->flags & SF_ASSIGNED))
Willy Tarreau7c669d72008-06-20 15:04:11 +0200536 goto out_err;
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100537
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100538 prev_srv = objt_server(s->target);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200539 conn_slot = s->srv_conn;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200540
Willy Tarreau7c669d72008-06-20 15:04:11 +0200541 /* We have to release any connection slot before applying any LB algo,
542 * otherwise we may erroneously end up with no available slot.
543 */
544 if (conn_slot)
545 sess_change_server(s, NULL);
546
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100547 /* We will now try to find the good server and store it into <objt_server(s->target)>.
548 * Note that <objt_server(s->target)> may be NULL in case of dispatch or proxy mode,
Willy Tarreau7c669d72008-06-20 15:04:11 +0200549 * as well as if no server is available (check error code).
550 */
Willy Tarreau1a20a5d2007-11-01 21:08:19 +0100551
Willy Tarreau827aee92011-03-10 16:55:02 +0100552 srv = NULL;
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100553 s->target = NULL;
Willy Tarreau350f4872014-11-28 14:42:25 +0100554 conn = objt_conn(s->si[1].end);
Willy Tarreau664beb82011-03-10 11:38:29 +0100555
Willy Tarreau068621e2013-12-23 15:11:25 +0100556 if (conn &&
Willy Tarreau2481d162014-02-19 18:40:43 +0100557 (conn->flags & CO_FL_CONNECTED) &&
Willy Tarreau9420b122013-12-15 18:58:25 +0100558 objt_server(conn->target) && __objt_server(conn->target)->proxy == s->be &&
Willy Tarreaueee5b512015-04-03 23:46:31 +0200559 ((s->txn && s->txn->flags & TX_PREFER_LAST) ||
Willy Tarreauc35362a2014-04-25 13:58:37 +0200560 ((s->be->options & PR_O_PREF_LAST) &&
561 (!s->be->max_ka_queue ||
562 server_has_room(__objt_server(conn->target)) ||
563 (__objt_server(conn->target)->nbpend + 1) < s->be->max_ka_queue))) &&
Willy Tarreau87eb1d62014-05-13 18:51:40 +0200564 srv_is_usable(__objt_server(conn->target))) {
Willy Tarreau87b09662015-04-03 00:22:06 +0200565 /* This stream was relying on a server in a previous request
Godbachf2dd68d2014-12-10 10:21:30 +0800566 * and the proxy has "option prefer-last-server" set, so
Willy Tarreau9420b122013-12-15 18:58:25 +0100567 * let's try to reuse the same server.
568 */
569 srv = __objt_server(conn->target);
570 s->target = &srv->obj_type;
571 }
572 else if (s->be->lbprm.algo & BE_LB_KIND) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200573 /* we must check if we have at least one server available */
574 if (!s->be->lbprm.tot_weight) {
575 err = SRV_STATUS_NOSRV;
576 goto out;
577 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200578
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200579 /* First check whether we need to fetch some data or simply call
580 * the LB lookup function. Only the hashing functions will need
581 * some input data in fact, and will support multiple algorithms.
582 */
583 switch (s->be->lbprm.algo & BE_LB_LKUP) {
584 case BE_LB_LKUP_RRTREE:
Willy Tarreau827aee92011-03-10 16:55:02 +0100585 srv = fwrr_get_next_server(s->be, prev_srv);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200586 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200587
Willy Tarreauf09c6602012-02-13 17:12:08 +0100588 case BE_LB_LKUP_FSTREE:
589 srv = fas_get_next_server(s->be, prev_srv);
590 break;
591
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200592 case BE_LB_LKUP_LCTREE:
Willy Tarreau827aee92011-03-10 16:55:02 +0100593 srv = fwlc_get_next_server(s->be, prev_srv);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200594 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200595
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200596 case BE_LB_LKUP_CHTREE:
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200597 case BE_LB_LKUP_MAP:
Willy Tarreau9757a382009-10-03 12:56:50 +0200598 if ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR) {
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200599 if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
Willy Tarreau827aee92011-03-10 16:55:02 +0100600 srv = chash_get_next_server(s->be, prev_srv);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200601 else
Willy Tarreau827aee92011-03-10 16:55:02 +0100602 srv = map_get_server_rr(s->be, prev_srv);
Willy Tarreau9757a382009-10-03 12:56:50 +0200603 break;
604 }
605 else if ((s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_HI) {
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200606 /* unknown balancing algorithm */
Willy Tarreau7c669d72008-06-20 15:04:11 +0200607 err = SRV_STATUS_INTERNAL;
608 goto out;
609 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200610
611 switch (s->be->lbprm.algo & BE_LB_PARM) {
612 case BE_LB_HASH_SRC:
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200613 conn = objt_conn(strm_orig(s));
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200614 if (conn && conn->addr.from.ss_family == AF_INET) {
Willy Tarreau5dd7fa12012-03-31 19:53:37 +0200615 srv = get_server_sh(s->be,
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200616 (void *)&((struct sockaddr_in *)&conn->addr.from)->sin_addr,
Willy Tarreau5dd7fa12012-03-31 19:53:37 +0200617 4);
618 }
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200619 else if (conn && conn->addr.from.ss_family == AF_INET6) {
Willy Tarreau5dd7fa12012-03-31 19:53:37 +0200620 srv = get_server_sh(s->be,
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200621 (void *)&((struct sockaddr_in6 *)&conn->addr.from)->sin6_addr,
Willy Tarreau5dd7fa12012-03-31 19:53:37 +0200622 16);
623 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200624 else {
625 /* unknown IP family */
626 err = SRV_STATUS_INTERNAL;
627 goto out;
628 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200629 break;
630
631 case BE_LB_HASH_URI:
632 /* URI hashing */
Willy Tarreaueee5b512015-04-03 23:46:31 +0200633 if (!s->txn || s->txn->req.msg_state < HTTP_MSG_BODY)
Willy Tarreaueaed5a12010-03-24 14:54:30 +0100634 break;
Willy Tarreau827aee92011-03-10 16:55:02 +0100635 srv = get_server_uh(s->be,
Willy Tarreaueee5b512015-04-03 23:46:31 +0200636 b_ptr(s->req.buf, -http_uri_rewind(&s->txn->req)),
637 s->txn->req.sl.rq.u_l);
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200638 break;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200639
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200640 case BE_LB_HASH_PRM:
641 /* URL Parameter hashing */
Willy Tarreaueee5b512015-04-03 23:46:31 +0200642 if (!s->txn || s->txn->req.msg_state < HTTP_MSG_BODY)
Willy Tarreaueaed5a12010-03-24 14:54:30 +0100643 break;
Willy Tarreau61a21a32011-03-01 20:35:49 +0100644
Willy Tarreau827aee92011-03-10 16:55:02 +0100645 srv = get_server_ph(s->be,
Willy Tarreaueee5b512015-04-03 23:46:31 +0200646 b_ptr(s->req.buf, -http_uri_rewind(&s->txn->req)),
647 s->txn->req.sl.rq.u_l);
Willy Tarreau61a21a32011-03-01 20:35:49 +0100648
Willy Tarreaueee5b512015-04-03 23:46:31 +0200649 if (!srv && s->txn->meth == HTTP_METH_POST)
Willy Tarreau827aee92011-03-10 16:55:02 +0100650 srv = get_server_ph_post(s);
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200651 break;
Benoitaffb4812009-03-25 13:02:10 +0100652
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200653 case BE_LB_HASH_HDR:
654 /* Header Parameter hashing */
Willy Tarreaueee5b512015-04-03 23:46:31 +0200655 if (!s->txn || s->txn->req.msg_state < HTTP_MSG_BODY)
Willy Tarreaueaed5a12010-03-24 14:54:30 +0100656 break;
Willy Tarreau827aee92011-03-10 16:55:02 +0100657 srv = get_server_hh(s);
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200658 break;
659
660 case BE_LB_HASH_RDP:
661 /* RDP Cookie hashing */
Willy Tarreau827aee92011-03-10 16:55:02 +0100662 srv = get_server_rch(s);
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200663 break;
664
665 default:
666 /* unknown balancing algorithm */
667 err = SRV_STATUS_INTERNAL;
668 goto out;
Benoitaffb4812009-03-25 13:02:10 +0100669 }
Emeric Brun736aa232009-06-30 17:56:00 +0200670
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200671 /* If the hashing parameter was not found, let's fall
672 * back to round robin on the map.
673 */
Willy Tarreau827aee92011-03-10 16:55:02 +0100674 if (!srv) {
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200675 if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
Willy Tarreau827aee92011-03-10 16:55:02 +0100676 srv = chash_get_next_server(s->be, prev_srv);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200677 else
Willy Tarreau827aee92011-03-10 16:55:02 +0100678 srv = map_get_server_rr(s->be, prev_srv);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200679 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200680
681 /* end of map-based LB */
Emeric Brun736aa232009-06-30 17:56:00 +0200682 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200683
Willy Tarreau7c669d72008-06-20 15:04:11 +0200684 default:
685 /* unknown balancing algorithm */
686 err = SRV_STATUS_INTERNAL;
687 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200688 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200689
Willy Tarreau827aee92011-03-10 16:55:02 +0100690 if (!srv) {
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200691 err = SRV_STATUS_FULL;
692 goto out;
693 }
Willy Tarreau827aee92011-03-10 16:55:02 +0100694 else if (srv != prev_srv) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100695 s->be->be_counters.cum_lbconn++;
Willy Tarreau827aee92011-03-10 16:55:02 +0100696 srv->counters.cum_lbconn++;
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100697 }
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100698 s->target = &srv->obj_type;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200699 }
Willy Tarreau1620ec32011-08-06 17:05:02 +0200700 else if (s->be->options & (PR_O_DISPATCH | PR_O_TRANSP)) {
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100701 s->target = &s->be->obj_type;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200702 }
David du Colombier6f5ccb12011-03-10 22:26:24 +0100703 else if ((s->be->options & PR_O_HTTP_PROXY) &&
Willy Tarreau350f4872014-11-28 14:42:25 +0100704 (conn = objt_conn(s->si[1].end)) &&
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200705 is_addr(&conn->addr.to)) {
Willy Tarreau664beb82011-03-10 11:38:29 +0100706 /* in proxy mode, we need a valid destination address */
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100707 s->target = &s->be->obj_type;
Willy Tarreau664beb82011-03-10 11:38:29 +0100708 }
709 else {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200710 err = SRV_STATUS_NOSRV;
711 goto out;
712 }
713
Willy Tarreaue7dff022015-04-03 01:14:29 +0200714 s->flags |= SF_ASSIGNED;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200715 err = SRV_STATUS_OK;
716 out:
717
718 /* Either we take back our connection slot, or we offer it to someone
719 * else if we don't need it anymore.
720 */
721 if (conn_slot) {
Willy Tarreau827aee92011-03-10 16:55:02 +0100722 if (conn_slot == srv) {
723 sess_change_server(s, srv);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200724 } else {
725 if (may_dequeue_tasks(conn_slot, s->be))
726 process_srv_queue(conn_slot);
727 }
728 }
729
730 out_err:
731 return err;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200732}
733
Willy Tarreaubaaee002006-06-26 02:48:02 +0200734/*
Willy Tarreaue7dff022015-04-03 01:14:29 +0200735 * This function assigns a server address to a stream, and sets SF_ADDR_SET.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200736 * The address is taken from the currently assigned server, or from the
737 * dispatch or transparent address.
738 *
739 * It may return :
740 * SRV_STATUS_OK if everything is OK.
741 * SRV_STATUS_INTERNAL for other unrecoverable errors.
742 *
Willy Tarreaue7dff022015-04-03 01:14:29 +0200743 * Upon successful return, the stream flag SF_ADDR_SET is set. This flag is
Willy Tarreaubaaee002006-06-26 02:48:02 +0200744 * not cleared, so it's to the caller to clear it if required.
745 *
Willy Tarreau32e3c6a2013-10-11 19:34:20 +0200746 * The caller is responsible for having already assigned a connection
747 * to si->end.
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200748 *
Willy Tarreaubaaee002006-06-26 02:48:02 +0200749 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200750int assign_server_address(struct stream *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200751{
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200752 struct connection *cli_conn = objt_conn(strm_orig(s));
Willy Tarreau350f4872014-11-28 14:42:25 +0100753 struct connection *srv_conn = objt_conn(s->si[1].end);
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200754
Willy Tarreaubaaee002006-06-26 02:48:02 +0200755#ifdef DEBUG_FULL
756 fprintf(stderr,"assign_server_address : s=%p\n",s);
757#endif
758
Willy Tarreaue7dff022015-04-03 01:14:29 +0200759 if ((s->flags & SF_DIRECT) || (s->be->lbprm.algo & BE_LB_KIND)) {
Willy Tarreau87b09662015-04-03 00:22:06 +0200760 /* A server is necessarily known for this stream */
Willy Tarreaue7dff022015-04-03 01:14:29 +0200761 if (!(s->flags & SF_ASSIGNED))
Willy Tarreaubaaee002006-06-26 02:48:02 +0200762 return SRV_STATUS_INTERNAL;
763
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200764 srv_conn->addr.to = objt_server(s->target)->addr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200765
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200766 if (!is_addr(&srv_conn->addr.to) && cli_conn) {
Willy Tarreaud669a4f2010-07-13 14:49:50 +0200767 /* if the server has no address, we use the same address
768 * the client asked, which is handy for remapping ports
Willy Tarreau9cf8d3f2014-05-09 22:56:10 +0200769 * locally on multiple addresses at once. Nothing is done
770 * for AF_UNIX addresses.
Willy Tarreaud669a4f2010-07-13 14:49:50 +0200771 */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200772 conn_get_to_addr(cli_conn);
Willy Tarreaud669a4f2010-07-13 14:49:50 +0200773
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200774 if (cli_conn->addr.to.ss_family == AF_INET) {
775 ((struct sockaddr_in *)&srv_conn->addr.to)->sin_addr = ((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr;
776 } else if (cli_conn->addr.to.ss_family == AF_INET6) {
777 ((struct sockaddr_in6 *)&srv_conn->addr.to)->sin6_addr = ((struct sockaddr_in6 *)&cli_conn->addr.to)->sin6_addr;
Emeric Brunec810d12010-10-22 16:36:33 +0200778 }
Willy Tarreaud669a4f2010-07-13 14:49:50 +0200779 }
780
Willy Tarreaubaaee002006-06-26 02:48:02 +0200781 /* if this server remaps proxied ports, we'll use
782 * the port the client connected to with an offset. */
Willy Tarreauc93cd162014-05-13 15:54:22 +0200783 if ((objt_server(s->target)->flags & SRV_F_MAPPORTS) && cli_conn) {
David du Colombier6f5ccb12011-03-10 22:26:24 +0100784 int base_port;
785
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200786 conn_get_to_addr(cli_conn);
David du Colombier6f5ccb12011-03-10 22:26:24 +0100787
788 /* First, retrieve the port from the incoming connection */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200789 base_port = get_host_port(&cli_conn->addr.to);
David du Colombier6f5ccb12011-03-10 22:26:24 +0100790
791 /* Second, assign the outgoing connection's port */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200792 base_port += get_host_port(&srv_conn->addr.to);
793 set_host_port(&srv_conn->addr.to, base_port);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200794 }
795 }
Willy Tarreau1620ec32011-08-06 17:05:02 +0200796 else if (s->be->options & PR_O_DISPATCH) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200797 /* connect to the defined dispatch addr */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200798 srv_conn->addr.to = s->be->dispatch_addr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200799 }
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200800 else if ((s->be->options & PR_O_TRANSP) && cli_conn) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200801 /* in transparent mode, use the original dest addr if no dispatch specified */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200802 conn_get_to_addr(cli_conn);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200803
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200804 if (cli_conn->addr.to.ss_family == AF_INET || cli_conn->addr.to.ss_family == AF_INET6)
805 srv_conn->addr.to = cli_conn->addr.to;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200806 }
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100807 else if (s->be->options & PR_O_HTTP_PROXY) {
808 /* If HTTP PROXY option is set, then server is already assigned
809 * during incoming client request parsing. */
810 }
Willy Tarreau1a1158b2007-01-20 11:07:46 +0100811 else {
812 /* no server and no LB algorithm ! */
813 return SRV_STATUS_INTERNAL;
814 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200815
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +0100816 /* Copy network namespace from client connection */
Thierry FOURNIERfe1ebcd2014-12-19 13:37:11 +0100817 srv_conn->proxy_netns = cli_conn ? cli_conn->proxy_netns : NULL;
KOVACS Krisztianb3e54fe2014-11-17 15:11:45 +0100818
Willy Tarreaue7dff022015-04-03 01:14:29 +0200819 s->flags |= SF_ADDR_SET;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200820 return SRV_STATUS_OK;
821}
822
Willy Tarreau87b09662015-04-03 00:22:06 +0200823/* This function assigns a server to stream <s> if required, and can add the
Willy Tarreaubaaee002006-06-26 02:48:02 +0200824 * connection to either the assigned server's queue or to the proxy's queue.
Willy Tarreau87b09662015-04-03 00:22:06 +0200825 * If ->srv_conn is set, the stream is first released from the server.
Willy Tarreaue7dff022015-04-03 01:14:29 +0200826 * It may also be called with SF_DIRECT and/or SF_ASSIGNED though. It will
Willy Tarreau7c669d72008-06-20 15:04:11 +0200827 * be called before any connection and after any retry or redispatch occurs.
828 *
Willy Tarreau87b09662015-04-03 00:22:06 +0200829 * It is not allowed to call this function with a stream in a queue.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200830 *
831 * Returns :
832 *
833 * SRV_STATUS_OK if everything is OK.
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100834 * SRV_STATUS_NOSRV if no server is available. objt_server(s->target) = NULL.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200835 * SRV_STATUS_QUEUED if the connection has been queued.
836 * SRV_STATUS_FULL if the server(s) is/are saturated and the
Willy Tarreau827aee92011-03-10 16:55:02 +0100837 * connection could not be queued at the server's,
Willy Tarreau7c669d72008-06-20 15:04:11 +0200838 * which may be NULL if we queue on the backend.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200839 * SRV_STATUS_INTERNAL for other unrecoverable errors.
840 *
841 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200842int assign_server_and_queue(struct stream *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200843{
844 struct pendconn *p;
Willy Tarreau827aee92011-03-10 16:55:02 +0100845 struct server *srv;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200846 int err;
847
848 if (s->pend_pos)
849 return SRV_STATUS_INTERNAL;
850
Willy Tarreau7c669d72008-06-20 15:04:11 +0200851 err = SRV_STATUS_OK;
Willy Tarreaue7dff022015-04-03 01:14:29 +0200852 if (!(s->flags & SF_ASSIGNED)) {
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100853 struct server *prev_srv = objt_server(s->target);
Willy Tarreau3d80d912011-03-10 11:42:13 +0100854
Willy Tarreau7c669d72008-06-20 15:04:11 +0200855 err = assign_server(s);
Willy Tarreau3d80d912011-03-10 11:42:13 +0100856 if (prev_srv) {
Willy Tarreau87b09662015-04-03 00:22:06 +0200857 /* This stream was previously assigned to a server. We have to
858 * update the stream's and the server's stats :
Willy Tarreau7c669d72008-06-20 15:04:11 +0200859 * - if the server changed :
860 * - set TX_CK_DOWN if txn.flags was TX_CK_VALID
Willy Tarreaue7dff022015-04-03 01:14:29 +0200861 * - set SF_REDISP if it was successfully redispatched
Willy Tarreau7c669d72008-06-20 15:04:11 +0200862 * - increment srv->redispatches and be->redispatches
863 * - if the server remained the same : update retries.
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100864 */
865
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100866 if (prev_srv != objt_server(s->target)) {
Willy Tarreaueee5b512015-04-03 23:46:31 +0200867 if (s->txn && (s->txn->flags & TX_CK_MASK) == TX_CK_VALID) {
868 s->txn->flags &= ~TX_CK_MASK;
869 s->txn->flags |= TX_CK_DOWN;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200870 }
Willy Tarreaue7dff022015-04-03 01:14:29 +0200871 s->flags |= SF_REDISP;
Willy Tarreau3d80d912011-03-10 11:42:13 +0100872 prev_srv->counters.redispatches++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100873 s->be->be_counters.redispatches++;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200874 } else {
Willy Tarreau3d80d912011-03-10 11:42:13 +0100875 prev_srv->counters.retries++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100876 s->be->be_counters.retries++;
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100877 }
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100878 }
879 }
880
Willy Tarreaubaaee002006-06-26 02:48:02 +0200881 switch (err) {
882 case SRV_STATUS_OK:
Willy Tarreaue7dff022015-04-03 01:14:29 +0200883 /* we have SF_ASSIGNED set */
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100884 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +0100885 if (!srv)
Willy Tarreau7c669d72008-06-20 15:04:11 +0200886 return SRV_STATUS_OK; /* dispatch or proxy mode */
887
888 /* If we already have a connection slot, no need to check any queue */
Willy Tarreau827aee92011-03-10 16:55:02 +0100889 if (s->srv_conn == srv)
Willy Tarreau7c669d72008-06-20 15:04:11 +0200890 return SRV_STATUS_OK;
891
Willy Tarreau87b09662015-04-03 00:22:06 +0200892 /* OK, this stream already has an assigned server, but no
Willy Tarreau7c669d72008-06-20 15:04:11 +0200893 * connection slot yet. Either it is a redispatch, or it was
894 * assigned from persistence information (direct mode).
895 */
Willy Tarreaue7dff022015-04-03 01:14:29 +0200896 if ((s->flags & SF_REDIRECTABLE) && srv->rdr_len) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200897 /* server scheduled for redirection, and already assigned. We
898 * don't want to go further nor check the queue.
Willy Tarreau21d2af32008-02-14 20:25:24 +0100899 */
Willy Tarreau827aee92011-03-10 16:55:02 +0100900 sess_change_server(s, srv); /* not really needed in fact */
Willy Tarreau21d2af32008-02-14 20:25:24 +0100901 return SRV_STATUS_OK;
902 }
903
Willy Tarreau87b09662015-04-03 00:22:06 +0200904 /* We might have to queue this stream if the assigned server is full.
Willy Tarreau7c669d72008-06-20 15:04:11 +0200905 * We know we have to queue it into the server's queue, so if a maxqueue
906 * is set on the server, we must also check that the server's queue is
907 * not full, in which case we have to return FULL.
908 */
Willy Tarreau827aee92011-03-10 16:55:02 +0100909 if (srv->maxconn &&
910 (srv->nbpend || srv->served >= srv_dynamic_maxconn(srv))) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200911
Willy Tarreau827aee92011-03-10 16:55:02 +0100912 if (srv->maxqueue > 0 && srv->nbpend >= srv->maxqueue)
Willy Tarreau7c669d72008-06-20 15:04:11 +0200913 return SRV_STATUS_FULL;
914
Willy Tarreaubaaee002006-06-26 02:48:02 +0200915 p = pendconn_add(s);
916 if (p)
917 return SRV_STATUS_QUEUED;
918 else
Willy Tarreau7c669d72008-06-20 15:04:11 +0200919 return SRV_STATUS_INTERNAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200920 }
Willy Tarreau7c669d72008-06-20 15:04:11 +0200921
922 /* OK, we can use this server. Let's reserve our place */
Willy Tarreau827aee92011-03-10 16:55:02 +0100923 sess_change_server(s, srv);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200924 return SRV_STATUS_OK;
925
926 case SRV_STATUS_FULL:
Willy Tarreau87b09662015-04-03 00:22:06 +0200927 /* queue this stream into the proxy's queue */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200928 p = pendconn_add(s);
929 if (p)
930 return SRV_STATUS_QUEUED;
931 else
Willy Tarreau7c669d72008-06-20 15:04:11 +0200932 return SRV_STATUS_INTERNAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200933
934 case SRV_STATUS_NOSRV:
Willy Tarreau7c669d72008-06-20 15:04:11 +0200935 return err;
936
Willy Tarreaubaaee002006-06-26 02:48:02 +0200937 case SRV_STATUS_INTERNAL:
938 return err;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200939
Willy Tarreaubaaee002006-06-26 02:48:02 +0200940 default:
941 return SRV_STATUS_INTERNAL;
942 }
Willy Tarreau5b6995c2008-01-13 16:31:17 +0100943}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200944
Willy Tarreaub1d67742010-03-29 19:36:59 +0200945/* If an explicit source binding is specified on the server and/or backend, and
946 * this source makes use of the transparent proxy, then it is extracted now and
Willy Tarreau87b09662015-04-03 00:22:06 +0200947 * assigned to the stream's pending connection. This function assumes that an
Willy Tarreau350f4872014-11-28 14:42:25 +0100948 * outgoing connection has already been assigned to s->si[1].end.
Willy Tarreaub1d67742010-03-29 19:36:59 +0200949 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200950static void assign_tproxy_address(struct stream *s)
Willy Tarreaub1d67742010-03-29 19:36:59 +0200951{
Pieter Baauwd551fb52013-05-08 22:49:23 +0200952#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100953 struct server *srv = objt_server(s->target);
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +0100954 struct conn_src *src;
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200955 struct connection *cli_conn;
Willy Tarreau350f4872014-11-28 14:42:25 +0100956 struct connection *srv_conn = objt_conn(s->si[1].end);
Willy Tarreau827aee92011-03-10 16:55:02 +0100957
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +0100958 if (srv && srv->conn_src.opts & CO_SRC_BIND)
959 src = &srv->conn_src;
960 else if (s->be->conn_src.opts & CO_SRC_BIND)
961 src = &s->be->conn_src;
962 else
963 return;
Willy Tarreau294c4732011-12-16 21:35:50 +0100964
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +0100965 switch (src->opts & CO_SRC_TPROXY_MASK) {
966 case CO_SRC_TPROXY_ADDR:
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200967 srv_conn->addr.from = src->tproxy_addr;
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +0100968 break;
969 case CO_SRC_TPROXY_CLI:
970 case CO_SRC_TPROXY_CIP:
971 /* FIXME: what can we do if the client connects in IPv6 or unix socket ? */
Willy Tarreaud0d8da92015-04-04 02:10:38 +0200972 cli_conn = objt_conn(strm_orig(s));
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200973 if (cli_conn)
974 srv_conn->addr.from = cli_conn->addr.from;
975 else
976 memset(&srv_conn->addr.from, 0, sizeof(srv_conn->addr.from));
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +0100977 break;
978 case CO_SRC_TPROXY_DYN:
Willy Tarreaueee5b512015-04-03 23:46:31 +0200979 if (src->bind_hdr_occ && s->txn) {
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +0100980 char *vptr;
981 int vlen;
982 int rewind;
Willy Tarreau294c4732011-12-16 21:35:50 +0100983
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +0100984 /* bind to the IP in a header */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200985 ((struct sockaddr_in *)&srv_conn->addr.from)->sin_family = AF_INET;
986 ((struct sockaddr_in *)&srv_conn->addr.from)->sin_port = 0;
987 ((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr = 0;
Willy Tarreau294c4732011-12-16 21:35:50 +0100988
Willy Tarreaueee5b512015-04-03 23:46:31 +0200989 b_rew(s->req.buf, rewind = http_hdr_rewind(&s->txn->req));
990 if (http_get_hdr(&s->txn->req, src->bind_hdr_name, src->bind_hdr_len,
991 &s->txn->hdr_idx, src->bind_hdr_occ, NULL, &vptr, &vlen)) {
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200992 ((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr =
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +0100993 htonl(inetaddr_host_lim(vptr, vptr + vlen));
Willy Tarreaubce70882009-09-07 11:51:47 +0200994 }
Willy Tarreau22ec1ea2014-11-27 20:45:39 +0100995 b_adv(s->req.buf, rewind);
Willy Tarreaub1d67742010-03-29 19:36:59 +0200996 }
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +0100997 break;
998 default:
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200999 memset(&srv_conn->addr.from, 0, sizeof(srv_conn->addr.from));
Willy Tarreaub1d67742010-03-29 19:36:59 +02001000 }
1001#endif
1002}
1003
1004
Willy Tarreaubaaee002006-06-26 02:48:02 +02001005/*
Willy Tarreau87b09662015-04-03 00:22:06 +02001006 * This function initiates a connection to the server assigned to this stream
Willy Tarreau350f4872014-11-28 14:42:25 +01001007 * (s->target, s->si[1].addr.to). It will assign a server if none
Willy Tarreau664beb82011-03-10 11:38:29 +01001008 * is assigned yet.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001009 * It can return one of :
Willy Tarreaue7dff022015-04-03 01:14:29 +02001010 * - SF_ERR_NONE if everything's OK
1011 * - SF_ERR_SRVTO if there are no more servers
1012 * - SF_ERR_SRVCL if the connection was refused by the server
1013 * - SF_ERR_PRXCOND if the connection has been limited by the proxy (maxconn)
1014 * - SF_ERR_RESOURCE if a system resource is lacking (eg: fd limits, ports, ...)
1015 * - SF_ERR_INTERNAL for any other purely internal errors
1016 * Additionnally, in the case of SF_ERR_RESOURCE, an emergency log will be emitted.
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001017 * The server-facing stream interface is expected to hold a pre-allocated connection
Willy Tarreau350f4872014-11-28 14:42:25 +01001018 * in s->si[1].conn.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001019 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001020int connect_server(struct stream *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +02001021{
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001022 struct connection *cli_conn;
Willy Tarreau34601a82013-12-15 16:33:46 +01001023 struct connection *srv_conn;
Willy Tarreau827aee92011-03-10 16:55:02 +01001024 struct server *srv;
Willy Tarreau34601a82013-12-15 16:33:46 +01001025 int reuse = 0;
Willy Tarreau9650f372009-08-16 14:02:45 +02001026 int err;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001027
Willy Tarreau350f4872014-11-28 14:42:25 +01001028 srv_conn = objt_conn(s->si[1].end);
Willy Tarreau34601a82013-12-15 16:33:46 +01001029 if (srv_conn)
1030 reuse = s->target == srv_conn->target;
1031
1032 if (reuse) {
1033 /* Disable connection reuse if a dynamic source is used.
1034 * As long as we don't share connections between servers,
1035 * we don't need to disable connection reuse on no-idempotent
1036 * requests nor when PROXY protocol is used.
1037 */
1038 srv = objt_server(s->target);
1039 if (srv && srv->conn_src.opts & CO_SRC_BIND) {
1040 if ((srv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_DYN)
1041 reuse = 0;
1042 }
1043 else if (s->be->conn_src.opts & CO_SRC_BIND) {
1044 if ((s->be->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_DYN)
1045 reuse = 0;
1046 }
1047 }
1048
Willy Tarreau350f4872014-11-28 14:42:25 +01001049 srv_conn = si_alloc_conn(&s->si[1], reuse);
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02001050 if (!srv_conn)
Willy Tarreaue7dff022015-04-03 01:14:29 +02001051 return SF_ERR_RESOURCE;
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02001052
Willy Tarreaue7dff022015-04-03 01:14:29 +02001053 if (!(s->flags & SF_ADDR_SET)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001054 err = assign_server_address(s);
1055 if (err != SRV_STATUS_OK)
Willy Tarreaue7dff022015-04-03 01:14:29 +02001056 return SF_ERR_INTERNAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001057 }
1058
Willy Tarreauff605db2013-12-20 11:09:51 +01001059 if (!conn_xprt_ready(srv_conn)) {
Willy Tarreau87b09662015-04-03 00:22:06 +02001060 /* the target was only on the stream, assign it to the SI now */
Willy Tarreauff605db2013-12-20 11:09:51 +01001061 srv_conn->target = s->target;
Willy Tarreaud88edf22009-06-14 15:48:17 +02001062
Willy Tarreauff605db2013-12-20 11:09:51 +01001063 /* set the correct protocol on the output stream interface */
1064 if (objt_server(s->target)) {
Thierry FOURNIERbb2ae642015-01-14 11:31:49 +01001065 conn_prepare(srv_conn, protocol_by_family(srv_conn->addr.to.ss_family), objt_server(s->target)->xprt);
Willy Tarreauff605db2013-12-20 11:09:51 +01001066 }
1067 else if (obj_type(s->target) == OBJ_TYPE_PROXY) {
1068 /* proxies exclusively run on raw_sock right now */
1069 conn_prepare(srv_conn, protocol_by_family(srv_conn->addr.to.ss_family), &raw_sock);
Willy Tarreau350f4872014-11-28 14:42:25 +01001070 if (!objt_conn(s->si[1].end) || !objt_conn(s->si[1].end)->ctrl)
Willy Tarreaue7dff022015-04-03 01:14:29 +02001071 return SF_ERR_INTERNAL;
Willy Tarreauff605db2013-12-20 11:09:51 +01001072 }
1073 else
Willy Tarreaue7dff022015-04-03 01:14:29 +02001074 return SF_ERR_INTERNAL; /* how did we get there ? */
Willy Tarreaud02394b2012-05-11 18:32:18 +02001075
Willy Tarreauff605db2013-12-20 11:09:51 +01001076 /* process the case where the server requires the PROXY protocol to be sent */
1077 srv_conn->send_proxy_ofs = 0;
David Safb76832014-05-08 23:42:08 -04001078 if (objt_server(s->target) && objt_server(s->target)->pp_opts) {
Willy Tarreauff605db2013-12-20 11:09:51 +01001079 srv_conn->send_proxy_ofs = 1; /* must compute size */
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001080 cli_conn = objt_conn(strm_orig(s));
Willy Tarreauff605db2013-12-20 11:09:51 +01001081 if (cli_conn)
1082 conn_get_to_addr(cli_conn);
1083 }
Willy Tarreau2a6e8802013-10-24 15:50:53 +02001084
Willy Tarreau350f4872014-11-28 14:42:25 +01001085 si_attach_conn(&s->si[1], srv_conn);
Willy Tarreau26d8c592012-05-07 18:12:14 +02001086
Willy Tarreauff605db2013-12-20 11:09:51 +01001087 assign_tproxy_address(s);
1088 }
1089 else {
1090 /* the connection is being reused, just re-attach it */
Willy Tarreau350f4872014-11-28 14:42:25 +01001091 si_attach_conn(&s->si[1], srv_conn);
Willy Tarreaue7dff022015-04-03 01:14:29 +02001092 s->flags |= SF_SRV_REUSED;
Willy Tarreauff605db2013-12-20 11:09:51 +01001093 }
Willy Tarreaub1d67742010-03-29 19:36:59 +02001094
William Lallemandb7ff6a32012-03-02 14:35:21 +01001095 /* flag for logging source ip/port */
Willy Tarreaud0d8da92015-04-04 02:10:38 +02001096 if (strm_fe(s)->options2 & PR_O2_SRC_ADDR)
Willy Tarreau350f4872014-11-28 14:42:25 +01001097 s->si[1].flags |= SI_FL_SRC_ADDR;
William Lallemandb7ff6a32012-03-02 14:35:21 +01001098
Willy Tarreau14f8e862012-08-30 22:23:13 +02001099 /* disable lingering */
1100 if (s->be->options & PR_O_TCP_NOLING)
Willy Tarreau350f4872014-11-28 14:42:25 +01001101 s->si[1].flags |= SI_FL_NOLINGER;
Willy Tarreau14f8e862012-08-30 22:23:13 +02001102
Willy Tarreau350f4872014-11-28 14:42:25 +01001103 err = si_connect(&s->si[1]);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001104
Willy Tarreaue7dff022015-04-03 01:14:29 +02001105 if (err != SF_ERR_NONE)
Willy Tarreau9650f372009-08-16 14:02:45 +02001106 return err;
Willy Tarreau788e2842008-08-26 13:25:39 +02001107
Willy Tarreau14f8e862012-08-30 22:23:13 +02001108 /* set connect timeout */
Willy Tarreau350f4872014-11-28 14:42:25 +01001109 s->si[1].exp = tick_add_ifset(now_ms, s->be->timeout.connect);
Willy Tarreau14f8e862012-08-30 22:23:13 +02001110
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001111 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +01001112 if (srv) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001113 s->flags |= SF_CURR_SESS;
Willy Tarreau827aee92011-03-10 16:55:02 +01001114 srv->cur_sess++;
1115 if (srv->cur_sess > srv->counters.cur_sess_max)
1116 srv->counters.cur_sess_max = srv->cur_sess;
Willy Tarreau51406232008-03-10 22:04:20 +01001117 if (s->be->lbprm.server_take_conn)
Willy Tarreau827aee92011-03-10 16:55:02 +01001118 s->be->lbprm.server_take_conn(srv);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001119 }
1120
Willy Tarreaue7dff022015-04-03 01:14:29 +02001121 return SF_ERR_NONE; /* connection is OK */
Willy Tarreaubaaee002006-06-26 02:48:02 +02001122}
1123
1124
Willy Tarreaubaaee002006-06-26 02:48:02 +02001125/* This function performs the "redispatch" part of a connection attempt. It
1126 * will assign a server if required, queue the connection if required, and
1127 * handle errors that might arise at this level. It can change the server
1128 * state. It will return 1 if it encounters an error, switches the server
1129 * state, or has to queue a connection. Otherwise, it will return 0 indicating
1130 * that the connection is ready to use.
1131 */
1132
Willy Tarreau87b09662015-04-03 00:22:06 +02001133int srv_redispatch_connect(struct stream *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +02001134{
Willy Tarreau827aee92011-03-10 16:55:02 +01001135 struct server *srv;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001136 int conn_err;
1137
1138 /* We know that we don't have any connection pending, so we will
1139 * try to get a new one, and wait in this state if it's queued
1140 */
Willy Tarreau7c669d72008-06-20 15:04:11 +02001141 redispatch:
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001142 conn_err = assign_server_and_queue(s);
1143 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +01001144
Willy Tarreaubaaee002006-06-26 02:48:02 +02001145 switch (conn_err) {
1146 case SRV_STATUS_OK:
1147 break;
1148
Willy Tarreau7c669d72008-06-20 15:04:11 +02001149 case SRV_STATUS_FULL:
1150 /* The server has reached its maxqueue limit. Either PR_O_REDISP is set
1151 * and we can redispatch to another server, or it is not and we return
1152 * 503. This only makes sense in DIRECT mode however, because normal LB
1153 * algorithms would never select such a server, and hash algorithms
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001154 * would bring us on the same server again. Note that s->target is set
Willy Tarreau827aee92011-03-10 16:55:02 +01001155 * in this case.
Willy Tarreau7c669d72008-06-20 15:04:11 +02001156 */
Willy Tarreaue7dff022015-04-03 01:14:29 +02001157 if (((s->flags & (SF_DIRECT|SF_FORCE_PRST)) == SF_DIRECT) &&
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001158 (s->be->options & PR_O_REDISP)) {
Willy Tarreaue7dff022015-04-03 01:14:29 +02001159 s->flags &= ~(SF_DIRECT | SF_ASSIGNED | SF_ADDR_SET);
Willy Tarreau7c669d72008-06-20 15:04:11 +02001160 goto redispatch;
1161 }
1162
Willy Tarreau350f4872014-11-28 14:42:25 +01001163 if (!s->si[1].err_type) {
1164 s->si[1].err_type = SI_ET_QUEUE_ERR;
Willy Tarreaufa7e1022008-10-19 07:30:41 +02001165 }
Willy Tarreau7c669d72008-06-20 15:04:11 +02001166
Willy Tarreau827aee92011-03-10 16:55:02 +01001167 srv->counters.failed_conns++;
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001168 s->be->be_counters.failed_conns++;
Willy Tarreau7c669d72008-06-20 15:04:11 +02001169 return 1;
1170
Willy Tarreaubaaee002006-06-26 02:48:02 +02001171 case SRV_STATUS_NOSRV:
Willy Tarreau827aee92011-03-10 16:55:02 +01001172 /* note: it is guaranteed that srv == NULL here */
Willy Tarreau350f4872014-11-28 14:42:25 +01001173 if (!s->si[1].err_type) {
1174 s->si[1].err_type = SI_ET_CONN_ERR;
Willy Tarreaufa7e1022008-10-19 07:30:41 +02001175 }
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +01001176
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001177 s->be->be_counters.failed_conns++;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001178 return 1;
1179
1180 case SRV_STATUS_QUEUED:
Willy Tarreau350f4872014-11-28 14:42:25 +01001181 s->si[1].exp = tick_add_ifset(now_ms, s->be->timeout.queue);
1182 s->si[1].state = SI_ST_QUE;
Willy Tarreau87b09662015-04-03 00:22:06 +02001183 /* do nothing else and do not wake any other stream up */
Willy Tarreaubaaee002006-06-26 02:48:02 +02001184 return 1;
1185
Willy Tarreaubaaee002006-06-26 02:48:02 +02001186 case SRV_STATUS_INTERNAL:
1187 default:
Willy Tarreau350f4872014-11-28 14:42:25 +01001188 if (!s->si[1].err_type) {
1189 s->si[1].err_type = SI_ET_CONN_OTHER;
Willy Tarreaufa7e1022008-10-19 07:30:41 +02001190 }
1191
Willy Tarreau827aee92011-03-10 16:55:02 +01001192 if (srv)
1193 srv_inc_sess_ctr(srv);
1194 if (srv)
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05001195 srv_set_sess_last(srv);
1196 if (srv)
Willy Tarreau827aee92011-03-10 16:55:02 +01001197 srv->counters.failed_conns++;
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001198 s->be->be_counters.failed_conns++;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001199
Willy Tarreau87b09662015-04-03 00:22:06 +02001200 /* release other streams waiting for this server */
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001201 if (may_dequeue_tasks(srv, s->be))
Willy Tarreau827aee92011-03-10 16:55:02 +01001202 process_srv_queue(srv);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001203 return 1;
1204 }
1205 /* if we get here, it's because we got SRV_STATUS_OK, which also
1206 * means that the connection has not been queued.
1207 */
1208 return 0;
1209}
1210
Willy Tarreau4aac7db2014-05-16 11:48:10 +02001211/* sends a log message when a backend goes down, and also sets last
1212 * change date.
1213 */
1214void set_backend_down(struct proxy *be)
1215{
1216 be->last_change = now.tv_sec;
1217 be->down_trans++;
1218
1219 Alert("%s '%s' has no server available!\n", proxy_type_str(be), be->id);
1220 send_log(be, LOG_EMERG, "%s %s has no server available!\n", proxy_type_str(be), be->id);
1221}
1222
Willy Tarreau87b09662015-04-03 00:22:06 +02001223/* Apply RDP cookie persistence to the current stream. For this, the function
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001224 * tries to extract an RDP cookie from the request buffer, and look for the
1225 * matching server in the list. If the server is found, it is assigned to the
Willy Tarreau87b09662015-04-03 00:22:06 +02001226 * stream. This always returns 1, and the analyser removes itself from the
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001227 * list. Nothing is performed if a server was already assigned.
1228 */
Willy Tarreau87b09662015-04-03 00:22:06 +02001229int tcp_persist_rdp_cookie(struct stream *s, struct channel *req, int an_bit)
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001230{
1231 struct proxy *px = s->be;
1232 int ret;
Willy Tarreau37406352012-04-23 16:16:37 +02001233 struct sample smp;
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001234 struct server *srv = px->srv;
1235 struct sockaddr_in addr;
1236 char *p;
1237
Willy Tarreau87b09662015-04-03 00:22:06 +02001238 DPRINTF(stderr,"[%u] %s: stream=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001239 now_ms, __FUNCTION__,
1240 s,
1241 req,
1242 req->rex, req->wex,
1243 req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001244 req->buf->i,
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001245 req->analysers);
1246
Willy Tarreaue7dff022015-04-03 01:14:29 +02001247 if (s->flags & SF_ASSIGNED)
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001248 goto no_cookie;
1249
Willy Tarreau37406352012-04-23 16:16:37 +02001250 memset(&smp, 0, sizeof(smp));
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001251
Willy Tarreaucadd8c92013-07-22 18:09:52 +02001252 ret = fetch_rdp_cookie_name(s, &smp, s->be->rdp_cookie_name, s->be->rdp_cookie_len);
Willy Tarreauf853c462012-04-23 18:53:56 +02001253 if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || smp.data.str.len == 0)
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001254 goto no_cookie;
1255
1256 memset(&addr, 0, sizeof(addr));
1257 addr.sin_family = AF_INET;
1258
Willy Tarreau664092c2011-12-16 19:11:42 +01001259 /* Considering an rdp cookie detected using acl, str ended with <cr><lf> and should return */
Willy Tarreauf853c462012-04-23 18:53:56 +02001260 addr.sin_addr.s_addr = strtoul(smp.data.str.str, &p, 10);
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001261 if (*p != '.')
1262 goto no_cookie;
1263 p++;
1264 addr.sin_port = (unsigned short)strtoul(p, &p, 10);
1265 if (*p != '.')
1266 goto no_cookie;
1267
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001268 s->target = NULL;
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001269 while (srv) {
Willy Tarreau28e9d062014-05-09 22:47:50 +02001270 if (srv->addr.ss_family == AF_INET &&
1271 memcmp(&addr, &(srv->addr), sizeof(addr)) == 0) {
Willy Tarreau892337c2014-05-13 23:41:20 +02001272 if ((srv->state != SRV_ST_STOPPED) || (px->options & PR_O_PERSIST)) {
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001273 /* we found the server and it is usable */
Willy Tarreaue7dff022015-04-03 01:14:29 +02001274 s->flags |= SF_DIRECT | SF_ASSIGNED;
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001275 s->target = &srv->obj_type;
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001276 break;
1277 }
1278 }
1279 srv = srv->next;
1280 }
1281
1282no_cookie:
1283 req->analysers &= ~an_bit;
1284 req->analyse_exp = TICK_ETERNITY;
1285 return 1;
1286}
1287
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001288int be_downtime(struct proxy *px) {
Willy Tarreaub625a082007-11-26 01:15:43 +01001289 if (px->lbprm.tot_weight && px->last_change < now.tv_sec) // ignore negative time
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001290 return px->down_time;
1291
1292 return now.tv_sec - px->last_change + px->down_time;
1293}
Willy Tarreaubaaee002006-06-26 02:48:02 +02001294
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001295/*
1296 * This function returns a string containing the balancing
1297 * mode of the proxy in a format suitable for stats.
1298 */
1299
1300const char *backend_lb_algo_str(int algo) {
1301
1302 if (algo == BE_LB_ALGO_RR)
1303 return "roundrobin";
1304 else if (algo == BE_LB_ALGO_SRR)
1305 return "static-rr";
Willy Tarreauf09c6602012-02-13 17:12:08 +01001306 else if (algo == BE_LB_ALGO_FAS)
1307 return "first";
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001308 else if (algo == BE_LB_ALGO_LC)
1309 return "leastconn";
1310 else if (algo == BE_LB_ALGO_SH)
1311 return "source";
1312 else if (algo == BE_LB_ALGO_UH)
1313 return "uri";
1314 else if (algo == BE_LB_ALGO_PH)
1315 return "url_param";
1316 else if (algo == BE_LB_ALGO_HH)
1317 return "hdr";
1318 else if (algo == BE_LB_ALGO_RCH)
1319 return "rdp-cookie";
1320 else
1321 return NULL;
1322}
1323
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001324/* This function parses a "balance" statement in a backend section describing
1325 * <curproxy>. It returns -1 if there is any error, otherwise zero. If it
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001326 * returns -1, it will write an error message into the <err> buffer which will
1327 * automatically be allocated and must be passed as NULL. The trailing '\n'
1328 * will not be written. The function must be called with <args> pointing to the
1329 * first word after "balance".
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001330 */
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001331int backend_parse_balance(const char **args, char **err, struct proxy *curproxy)
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001332{
1333 if (!*(args[0])) {
1334 /* if no option is set, use round-robin by default */
Willy Tarreau31682232007-11-29 15:38:04 +01001335 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1336 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001337 return 0;
1338 }
1339
1340 if (!strcmp(args[0], "roundrobin")) {
Willy Tarreau31682232007-11-29 15:38:04 +01001341 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1342 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001343 }
Willy Tarreau9757a382009-10-03 12:56:50 +02001344 else if (!strcmp(args[0], "static-rr")) {
1345 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1346 curproxy->lbprm.algo |= BE_LB_ALGO_SRR;
1347 }
Willy Tarreauf09c6602012-02-13 17:12:08 +01001348 else if (!strcmp(args[0], "first")) {
1349 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1350 curproxy->lbprm.algo |= BE_LB_ALGO_FAS;
1351 }
Willy Tarreau51406232008-03-10 22:04:20 +01001352 else if (!strcmp(args[0], "leastconn")) {
1353 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1354 curproxy->lbprm.algo |= BE_LB_ALGO_LC;
1355 }
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001356 else if (!strcmp(args[0], "source")) {
Willy Tarreau31682232007-11-29 15:38:04 +01001357 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1358 curproxy->lbprm.algo |= BE_LB_ALGO_SH;
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001359 }
1360 else if (!strcmp(args[0], "uri")) {
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001361 int arg = 1;
1362
Willy Tarreau31682232007-11-29 15:38:04 +01001363 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1364 curproxy->lbprm.algo |= BE_LB_ALGO_UH;
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001365
Oskar Stolc8dc41842012-05-19 10:19:54 +01001366 curproxy->uri_whole = 0;
1367
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001368 while (*args[arg]) {
1369 if (!strcmp(args[arg], "len")) {
1370 if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001371 memprintf(err, "%s : '%s' expects a positive integer (got '%s').", args[0], args[arg], args[arg+1]);
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001372 return -1;
1373 }
1374 curproxy->uri_len_limit = atoi(args[arg+1]);
1375 arg += 2;
1376 }
1377 else if (!strcmp(args[arg], "depth")) {
1378 if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001379 memprintf(err, "%s : '%s' expects a positive integer (got '%s').", args[0], args[arg], args[arg+1]);
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001380 return -1;
1381 }
1382 /* hint: we store the position of the ending '/' (depth+1) so
1383 * that we avoid a comparison while computing the hash.
1384 */
1385 curproxy->uri_dirs_depth1 = atoi(args[arg+1]) + 1;
1386 arg += 2;
1387 }
Oskar Stolc8dc41842012-05-19 10:19:54 +01001388 else if (!strcmp(args[arg], "whole")) {
1389 curproxy->uri_whole = 1;
1390 arg += 1;
1391 }
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001392 else {
Oskar Stolc8dc41842012-05-19 10:19:54 +01001393 memprintf(err, "%s only accepts parameters 'len', 'depth', and 'whole' (got '%s').", args[0], args[arg]);
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001394 return -1;
1395 }
1396 }
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001397 }
Willy Tarreau01732802007-11-01 22:48:15 +01001398 else if (!strcmp(args[0], "url_param")) {
1399 if (!*args[1]) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001400 memprintf(err, "%s requires an URL parameter name.", args[0]);
Willy Tarreau01732802007-11-01 22:48:15 +01001401 return -1;
1402 }
Willy Tarreau31682232007-11-29 15:38:04 +01001403 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1404 curproxy->lbprm.algo |= BE_LB_ALGO_PH;
Willy Tarreaua534fea2008-08-03 12:19:50 +02001405
1406 free(curproxy->url_param_name);
Willy Tarreau01732802007-11-01 22:48:15 +01001407 curproxy->url_param_name = strdup(args[1]);
Willy Tarreaua534fea2008-08-03 12:19:50 +02001408 curproxy->url_param_len = strlen(args[1]);
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001409 if (*args[2]) {
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001410 if (strcmp(args[2], "check_post")) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001411 memprintf(err, "%s only accepts 'check_post' modifier (got '%s').", args[0], args[2]);
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001412 return -1;
1413 }
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001414 }
Benoitaffb4812009-03-25 13:02:10 +01001415 }
1416 else if (!strncmp(args[0], "hdr(", 4)) {
1417 const char *beg, *end;
1418
1419 beg = args[0] + 4;
1420 end = strchr(beg, ')');
1421
1422 if (!end || end == beg) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001423 memprintf(err, "hdr requires an http header field name.");
Benoitaffb4812009-03-25 13:02:10 +01001424 return -1;
1425 }
1426
1427 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1428 curproxy->lbprm.algo |= BE_LB_ALGO_HH;
1429
1430 free(curproxy->hh_name);
1431 curproxy->hh_len = end - beg;
1432 curproxy->hh_name = my_strndup(beg, end - beg);
1433 curproxy->hh_match_domain = 0;
1434
1435 if (*args[1]) {
1436 if (strcmp(args[1], "use_domain_only")) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001437 memprintf(err, "%s only accepts 'use_domain_only' modifier (got '%s').", args[0], args[1]);
Benoitaffb4812009-03-25 13:02:10 +01001438 return -1;
1439 }
1440 curproxy->hh_match_domain = 1;
1441 }
Emeric Brun736aa232009-06-30 17:56:00 +02001442 }
1443 else if (!strncmp(args[0], "rdp-cookie", 10)) {
1444 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1445 curproxy->lbprm.algo |= BE_LB_ALGO_RCH;
1446
1447 if ( *(args[0] + 10 ) == '(' ) { /* cookie name */
1448 const char *beg, *end;
1449
1450 beg = args[0] + 11;
1451 end = strchr(beg, ')');
1452
1453 if (!end || end == beg) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001454 memprintf(err, "rdp-cookie : missing cookie name.");
Emeric Brun736aa232009-06-30 17:56:00 +02001455 return -1;
1456 }
1457
1458 free(curproxy->hh_name);
1459 curproxy->hh_name = my_strndup(beg, end - beg);
1460 curproxy->hh_len = end - beg;
1461 }
1462 else if ( *(args[0] + 10 ) == '\0' ) { /* default cookie name 'mstshash' */
1463 free(curproxy->hh_name);
1464 curproxy->hh_name = strdup("mstshash");
1465 curproxy->hh_len = strlen(curproxy->hh_name);
1466 }
1467 else { /* syntax */
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001468 memprintf(err, "rdp-cookie : missing cookie name.");
Emeric Brun736aa232009-06-30 17:56:00 +02001469 return -1;
1470 }
Willy Tarreau01732802007-11-01 22:48:15 +01001471 }
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001472 else {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001473 memprintf(err, "only supports 'roundrobin', 'static-rr', 'leastconn', 'source', 'uri', 'url_param', 'hdr(name)' and 'rdp-cookie(name)' options.");
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001474 return -1;
1475 }
1476 return 0;
1477}
1478
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001479
1480/************************************************************************/
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001481/* All supported sample and ACL keywords must be declared here. */
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001482/************************************************************************/
1483
Willy Tarreau34db1082012-04-19 17:16:54 +02001484/* set temp integer to the number of enabled servers on the proxy.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001485 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001486 * undefined behaviour.
1487 */
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001488static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001489smp_fetch_nbsrv(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001490{
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001491 struct proxy *px;
1492
Willy Tarreau37406352012-04-23 16:16:37 +02001493 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001494 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001495 px = args->data.prx;
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001496
1497 if (px->srv_act)
Willy Tarreauf853c462012-04-23 18:53:56 +02001498 smp->data.uint = px->srv_act;
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001499 else if (px->lbprm.fbck)
Willy Tarreauf853c462012-04-23 18:53:56 +02001500 smp->data.uint = 1;
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001501 else
Willy Tarreauf853c462012-04-23 18:53:56 +02001502 smp->data.uint = px->srv_bck;
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001503
1504 return 1;
1505}
1506
Willy Tarreau37406352012-04-23 16:16:37 +02001507/* report in smp->flags a success or failure depending on the designated
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001508 * server's state. There is no match function involved since there's no pattern.
Willy Tarreau34db1082012-04-19 17:16:54 +02001509 * Accepts exactly 1 argument. Argument is a server, other types will lead to
1510 * undefined behaviour.
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001511 */
1512static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001513smp_fetch_srv_is_up(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001514{
Willy Tarreau24e32d82012-04-23 23:55:44 +02001515 struct server *srv = args->data.srv;
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001516
Willy Tarreau37406352012-04-23 16:16:37 +02001517 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001518 smp->type = SMP_T_BOOL;
Willy Tarreau20125212014-05-13 19:44:56 +02001519 if (!(srv->admin & SRV_ADMF_MAINT) &&
Willy Tarreau892337c2014-05-13 23:41:20 +02001520 (!(srv->check.state & CHK_ST_CONFIGURED) || (srv->state != SRV_ST_STOPPED)))
Willy Tarreau197e10a2012-04-23 19:18:42 +02001521 smp->data.uint = 1;
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001522 else
Willy Tarreau197e10a2012-04-23 19:18:42 +02001523 smp->data.uint = 0;
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001524 return 1;
1525}
1526
Willy Tarreau34db1082012-04-19 17:16:54 +02001527/* set temp integer to the number of enabled servers on the proxy.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001528 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001529 * undefined behaviour.
1530 */
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001531static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001532smp_fetch_connslots(const struct arg *args, struct sample *smp, const char *kw, void *private)
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001533{
1534 struct server *iterator;
Willy Tarreaud28c3532012-04-19 19:28:33 +02001535
Willy Tarreau37406352012-04-23 16:16:37 +02001536 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001537 smp->type = SMP_T_UINT;
1538 smp->data.uint = 0;
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001539
Willy Tarreau24e32d82012-04-23 23:55:44 +02001540 for (iterator = args->data.prx->srv; iterator; iterator = iterator->next) {
Willy Tarreau892337c2014-05-13 23:41:20 +02001541 if (iterator->state == SRV_ST_STOPPED)
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001542 continue;
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001543
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001544 if (iterator->maxconn == 0 || iterator->maxqueue == 0) {
Willy Tarreaua5e37562011-12-16 17:06:15 +01001545 /* configuration is stupid */
Willy Tarreauf853c462012-04-23 18:53:56 +02001546 smp->data.uint = -1; /* FIXME: stupid value! */
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001547 return 1;
1548 }
1549
Willy Tarreauf853c462012-04-23 18:53:56 +02001550 smp->data.uint += (iterator->maxconn - iterator->cur_sess)
Willy Tarreau422aa072012-04-20 20:49:27 +02001551 + (iterator->maxqueue - iterator->nbpend);
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001552 }
1553
1554 return 1;
1555}
1556
Willy Tarreaua5e37562011-12-16 17:06:15 +01001557/* set temp integer to the id of the backend */
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +01001558static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001559smp_fetch_be_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau37406352012-04-23 16:16:37 +02001560{
Willy Tarreauf853c462012-04-23 18:53:56 +02001561 smp->flags = SMP_F_VOL_TXN;
1562 smp->type = SMP_T_UINT;
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001563 smp->data.uint = smp->strm->be->uuid;
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +01001564 return 1;
1565}
1566
Willy Tarreaua5e37562011-12-16 17:06:15 +01001567/* set temp integer to the id of the server */
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +01001568static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001569smp_fetch_srv_id(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau37406352012-04-23 16:16:37 +02001570{
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001571 if (!objt_server(smp->strm->target))
Willy Tarreau17af4192011-02-23 14:27:06 +01001572 return 0;
1573
Willy Tarreauf853c462012-04-23 18:53:56 +02001574 smp->type = SMP_T_UINT;
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001575 smp->data.uint = objt_server(smp->strm->target)->puid;
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +01001576
1577 return 1;
1578}
1579
Willy Tarreau34db1082012-04-19 17:16:54 +02001580/* set temp integer to the number of connections per second reaching the backend.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001581 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001582 * undefined behaviour.
1583 */
Willy Tarreau079ff0a2009-03-05 21:34:28 +01001584static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001585smp_fetch_be_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreau079ff0a2009-03-05 21:34:28 +01001586{
Willy Tarreau37406352012-04-23 16:16:37 +02001587 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001588 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001589 smp->data.uint = read_freq_ctr(&args->data.prx->be_sess_per_sec);
Willy Tarreau079ff0a2009-03-05 21:34:28 +01001590 return 1;
1591}
1592
Willy Tarreau34db1082012-04-19 17:16:54 +02001593/* set temp integer to the number of concurrent connections on the backend.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001594 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001595 * undefined behaviour.
1596 */
Willy Tarreaua36af912009-10-10 12:02:45 +02001597static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001598smp_fetch_be_conn(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreaua36af912009-10-10 12:02:45 +02001599{
Willy Tarreau37406352012-04-23 16:16:37 +02001600 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001601 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001602 smp->data.uint = args->data.prx->beconn;
Willy Tarreaua36af912009-10-10 12:02:45 +02001603 return 1;
1604}
1605
Willy Tarreau34db1082012-04-19 17:16:54 +02001606/* set temp integer to the total number of queued connections on the backend.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001607 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001608 * undefined behaviour.
1609 */
Willy Tarreaua36af912009-10-10 12:02:45 +02001610static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001611smp_fetch_queue_size(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreaua36af912009-10-10 12:02:45 +02001612{
Willy Tarreau37406352012-04-23 16:16:37 +02001613 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001614 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001615 smp->data.uint = args->data.prx->totpend;
Willy Tarreaua36af912009-10-10 12:02:45 +02001616 return 1;
1617}
1618
Willy Tarreaua5e37562011-12-16 17:06:15 +01001619/* set temp integer to the total number of queued connections on the backend divided
Willy Tarreaua36af912009-10-10 12:02:45 +02001620 * by the number of running servers and rounded up. If there is no running
1621 * server, we return twice the total, just as if we had half a running server.
1622 * This is more or less correct anyway, since we expect the last server to come
1623 * back soon.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001624 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001625 * undefined behaviour.
Willy Tarreaua36af912009-10-10 12:02:45 +02001626 */
1627static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001628smp_fetch_avg_queue_size(const struct arg *args, struct sample *smp, const char *kw, void *private)
Willy Tarreaua36af912009-10-10 12:02:45 +02001629{
1630 int nbsrv;
Thierry FOURNIER0a9a2b82015-05-11 15:20:49 +02001631 struct proxy *px;
Willy Tarreaua36af912009-10-10 12:02:45 +02001632
Willy Tarreau37406352012-04-23 16:16:37 +02001633 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001634 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001635 px = args->data.prx;
Willy Tarreaua36af912009-10-10 12:02:45 +02001636
1637 if (px->srv_act)
1638 nbsrv = px->srv_act;
1639 else if (px->lbprm.fbck)
1640 nbsrv = 1;
1641 else
1642 nbsrv = px->srv_bck;
1643
1644 if (nbsrv > 0)
Willy Tarreauf853c462012-04-23 18:53:56 +02001645 smp->data.uint = (px->totpend + nbsrv - 1) / nbsrv;
Willy Tarreaua36af912009-10-10 12:02:45 +02001646 else
Willy Tarreauf853c462012-04-23 18:53:56 +02001647 smp->data.uint = px->totpend * 2;
Willy Tarreaua36af912009-10-10 12:02:45 +02001648
1649 return 1;
1650}
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001651
Willy Tarreau34db1082012-04-19 17:16:54 +02001652/* set temp integer to the number of concurrent connections on the server in the backend.
1653 * Accepts exactly 1 argument. Argument is a server, other types will lead to
1654 * undefined behaviour.
1655 */
Hervé COMMOWICKdaa824e2011-08-05 12:09:44 +02001656static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001657smp_fetch_srv_conn(const struct arg *args, struct sample *smp, const char *kw, void *private)
Hervé COMMOWICKdaa824e2011-08-05 12:09:44 +02001658{
Willy Tarreauf853c462012-04-23 18:53:56 +02001659 smp->flags = SMP_F_VOL_TEST;
1660 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001661 smp->data.uint = args->data.srv->cur_sess;
Hervé COMMOWICKdaa824e2011-08-05 12:09:44 +02001662 return 1;
1663}
1664
Tait Clarridge7896d522012-12-05 21:39:31 -05001665/* set temp integer to the number of enabled servers on the proxy.
1666 * Accepts exactly 1 argument. Argument is a server, other types will lead to
1667 * undefined behaviour.
1668 */
1669static int
Thierry FOURNIER0786d052015-05-11 15:42:45 +02001670smp_fetch_srv_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private)
Tait Clarridge7896d522012-12-05 21:39:31 -05001671{
1672 smp->flags = SMP_F_VOL_TEST;
1673 smp->type = SMP_T_UINT;
1674 smp->data.uint = read_freq_ctr(&args->data.srv->sess_per_sec);
1675 return 1;
1676}
1677
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001678
1679/* Note: must not be declared <const> as its list will be overwritten.
1680 * Please take care of keeping this list alphabetically sorted.
1681 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001682static struct sample_fetch_kw_list smp_kws = {ILH, {
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001683 { "avg_queue", smp_fetch_avg_queue_size, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1684 { "be_conn", smp_fetch_be_conn, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1685 { "be_id", smp_fetch_be_id, 0, NULL, SMP_T_UINT, SMP_USE_BKEND, },
1686 { "be_sess_rate", smp_fetch_be_sess_rate, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1687 { "connslots", smp_fetch_connslots, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1688 { "nbsrv", smp_fetch_nbsrv, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1689 { "queue", smp_fetch_queue_size, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1690 { "srv_conn", smp_fetch_srv_conn, ARG1(1,SRV), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1691 { "srv_id", smp_fetch_srv_id, 0, NULL, SMP_T_UINT, SMP_USE_SERVR, },
1692 { "srv_is_up", smp_fetch_srv_is_up, ARG1(1,SRV), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
1693 { "srv_sess_rate", smp_fetch_srv_sess_rate, ARG1(1,SRV), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1694 { /* END */ },
1695}};
1696
1697
Willy Tarreau61612d42012-04-19 18:42:05 +02001698/* Note: must not be declared <const> as its list will be overwritten.
1699 * Please take care of keeping this list alphabetically sorted.
1700 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001701static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001702 { /* END */ },
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001703}};
1704
1705
1706__attribute__((constructor))
1707static void __backend_init(void)
1708{
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001709 sample_register_fetches(&smp_kws);
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001710 acl_register_keywords(&acl_kws);
1711}
1712
Willy Tarreaubaaee002006-06-26 02:48:02 +02001713/*
1714 * Local variables:
1715 * c-indent-level: 8
1716 * c-basic-offset: 8
1717 * End:
1718 */