blob: 8f95f5ad4420bbaf8d9d1a075d6be203f3b35e35 [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>
Willy Tarreaubaaee002006-06-26 02:48:02 +020029
Willy Tarreaubaaee002006-06-26 02:48:02 +020030#include <types/global.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020031
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +010032#include <proto/acl.h>
Willy Tarreau34db1082012-04-19 17:16:54 +020033#include <proto/arg.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020034#include <proto/backend.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020035#include <proto/channel.h>
Willy Tarreau03fa5df2010-05-24 21:02:37 +020036#include <proto/frontend.h>
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020037#include <proto/lb_chash.h>
Willy Tarreauf09c6602012-02-13 17:12:08 +010038#include <proto/lb_fas.h>
Willy Tarreauf89c1872009-10-01 11:19:37 +020039#include <proto/lb_fwlc.h>
40#include <proto/lb_fwrr.h>
41#include <proto/lb_map.h>
Willy Tarreau4aac7db2014-05-16 11:48:10 +020042#include <proto/log.h>
Willy Tarreau3fdb3662012-11-12 00:42:33 +010043#include <proto/obj_type.h>
Willy Tarreaud4c33c82013-01-07 21:59:07 +010044#include <proto/payload.h>
Willy Tarreaud1d54542012-09-12 22:58:11 +020045#include <proto/protocol.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020046#include <proto/proto_http.h>
Willy Tarreaua8f55d52010-05-31 17:44:19 +020047#include <proto/proto_tcp.h>
Willy Tarreau4aac7db2014-05-16 11:48:10 +020048#include <proto/proxy.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020049#include <proto/queue.h>
Willy Tarreaud4c33c82013-01-07 21:59:07 +010050#include <proto/sample.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010051#include <proto/server.h>
Willy Tarreau7c669d72008-06-20 15:04:11 +020052#include <proto/session.h>
Willy Tarreau75bf2c92012-08-20 17:01:35 +020053#include <proto/raw_sock.h>
Willy Tarreau9e000c62011-03-10 14:03:36 +010054#include <proto/stream_interface.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020055#include <proto/task.h>
56
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -050057int be_lastsession(const struct proxy *be)
58{
59 if (be->be_counters.last_sess)
60 return now.tv_sec - be->be_counters.last_sess;
61
62 return -1;
63}
64
Bhaskar98634f02013-10-29 23:30:51 -040065/* helper function to invoke the correct hash method */
Dan Dubovik82456752014-07-08 08:51:03 -070066static unsigned int gen_hash(const struct proxy* px, const char* key, unsigned long len)
Bhaskar98634f02013-10-29 23:30:51 -040067{
Dan Dubovik82456752014-07-08 08:51:03 -070068 unsigned int hash;
Bhaskar98634f02013-10-29 23:30:51 -040069
70 switch (px->lbprm.algo & BE_LB_HASH_FUNC) {
71 case BE_LB_HFCN_DJB2:
72 hash = hash_djb2(key, len);
73 break;
Willy Tarreaua0f42712013-11-14 14:30:35 +010074 case BE_LB_HFCN_WT6:
75 hash = hash_wt6(key, len);
76 break;
Bhaskar98634f02013-10-29 23:30:51 -040077 case BE_LB_HFCN_SDBM:
78 /* this is the default hash function */
79 default:
80 hash = hash_sdbm(key, len);
81 break;
82 }
83
84 return hash;
85}
86
Willy Tarreaubaaee002006-06-26 02:48:02 +020087/*
88 * This function recounts the number of usable active and backup servers for
89 * proxy <p>. These numbers are returned into the p->srv_act and p->srv_bck.
Willy Tarreaub625a082007-11-26 01:15:43 +010090 * This function also recomputes the total active and backup weights. However,
Willy Tarreauf4cca452008-03-08 21:42:54 +010091 * it does not update tot_weight nor tot_used. Use update_backend_weight() for
Willy Tarreaub625a082007-11-26 01:15:43 +010092 * this.
Willy Tarreaubaaee002006-06-26 02:48:02 +020093 */
Willy Tarreauc5d9c802009-10-01 09:17:05 +020094void recount_servers(struct proxy *px)
Willy Tarreaubaaee002006-06-26 02:48:02 +020095{
96 struct server *srv;
97
Willy Tarreau20697042007-11-15 23:26:18 +010098 px->srv_act = px->srv_bck = 0;
99 px->lbprm.tot_wact = px->lbprm.tot_wbck = 0;
Willy Tarreaub625a082007-11-26 01:15:43 +0100100 px->lbprm.fbck = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200101 for (srv = px->srv; srv != NULL; srv = srv->next) {
Willy Tarreau87eb1d62014-05-13 18:51:40 +0200102 if (!srv_is_usable(srv))
Willy Tarreaub625a082007-11-26 01:15:43 +0100103 continue;
104
Willy Tarreauc93cd162014-05-13 15:54:22 +0200105 if (srv->flags & SRV_F_BACKUP) {
Willy Tarreaub625a082007-11-26 01:15:43 +0100106 if (!px->srv_bck &&
Willy Tarreauf4cca452008-03-08 21:42:54 +0100107 !(px->options & PR_O_USE_ALL_BK))
Willy Tarreaub625a082007-11-26 01:15:43 +0100108 px->lbprm.fbck = srv;
109 px->srv_bck++;
110 px->lbprm.tot_wbck += srv->eweight;
111 } else {
112 px->srv_act++;
113 px->lbprm.tot_wact += srv->eweight;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200114 }
115 }
Willy Tarreaub625a082007-11-26 01:15:43 +0100116}
Willy Tarreau20697042007-11-15 23:26:18 +0100117
Willy Tarreaub625a082007-11-26 01:15:43 +0100118/* This function simply updates the backend's tot_weight and tot_used values
119 * after servers weights have been updated. It is designed to be used after
120 * recount_servers() or equivalent.
121 */
Willy Tarreauc5d9c802009-10-01 09:17:05 +0200122void update_backend_weight(struct proxy *px)
Willy Tarreaub625a082007-11-26 01:15:43 +0100123{
Willy Tarreau20697042007-11-15 23:26:18 +0100124 if (px->srv_act) {
125 px->lbprm.tot_weight = px->lbprm.tot_wact;
126 px->lbprm.tot_used = px->srv_act;
127 }
Willy Tarreaub625a082007-11-26 01:15:43 +0100128 else if (px->lbprm.fbck) {
129 /* use only the first backup server */
130 px->lbprm.tot_weight = px->lbprm.fbck->eweight;
131 px->lbprm.tot_used = 1;
Willy Tarreau20697042007-11-15 23:26:18 +0100132 }
133 else {
Willy Tarreaub625a082007-11-26 01:15:43 +0100134 px->lbprm.tot_weight = px->lbprm.tot_wbck;
135 px->lbprm.tot_used = px->srv_bck;
Willy Tarreau20697042007-11-15 23:26:18 +0100136 }
Willy Tarreaub625a082007-11-26 01:15:43 +0100137}
138
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200139/*
140 * This function tries to find a running server for the proxy <px> following
141 * the source hash method. Depending on the number of active/backup servers,
142 * it will either look for active servers, or for backup servers.
143 * If any server is found, it will be returned. If no valid server is found,
144 * NULL is returned.
145 */
146struct server *get_server_sh(struct proxy *px, const char *addr, int len)
147{
148 unsigned int h, l;
149
150 if (px->lbprm.tot_weight == 0)
151 return NULL;
152
153 l = h = 0;
154
155 /* note: we won't hash if there's only one server left */
156 if (px->lbprm.tot_used == 1)
157 goto hash_done;
158
159 while ((l + sizeof (int)) <= len) {
160 h ^= ntohl(*(unsigned int *)(&addr[l]));
161 l += sizeof (int);
162 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500163 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100164 h = full_hash(h);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200165 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200166 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
167 return chash_get_server_hash(px, h);
168 else
169 return map_get_server_hash(px, h);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200170}
171
172/*
173 * This function tries to find a running server for the proxy <px> following
174 * the URI hash method. In order to optimize cache hits, the hash computation
175 * ends at the question mark. Depending on the number of active/backup servers,
176 * it will either look for active servers, or for backup servers.
177 * If any server is found, it will be returned. If no valid server is found,
178 * NULL is returned.
179 *
180 * This code was contributed by Guillaume Dallaire, who also selected this hash
181 * algorithm out of a tens because it gave him the best results.
182 *
183 */
184struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
185{
Dan Dubovik82456752014-07-08 08:51:03 -0700186 unsigned int hash = 0;
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200187 int c;
188 int slashes = 0;
Bhaskar98634f02013-10-29 23:30:51 -0400189 const char *start, *end;
natalie.chendf7a7142015-03-31 15:54:07 +0800190 int depth = 1;
natalie.chen4fcfe812018-08-15 19:14:40 +0800191 int orig_uri_len = uri_len;
192 const char *orig_start;
193 const char *p, *params;
194 int buflen = 0;
195 char *buf;
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200196
197 if (px->lbprm.tot_weight == 0)
198 return NULL;
199
200 /* note: we won't hash if there's only one server left */
201 if (px->lbprm.tot_used == 1)
202 goto hash_done;
203
204 if (px->uri_len_limit)
205 uri_len = MIN(uri_len, px->uri_len_limit);
206
natalie.chen4fcfe812018-08-15 19:14:40 +0800207 orig_start = start = end = uri;
208 if (px->uri_gerrit == 1) {
209 p = memchr(uri, '?', uri_len);
210 params = p;
211 if (p) {
212 p++;
213 uri_len = p - uri;
214 params = p;
215 if (p[7] == '=') {
216 if (memcmp(p, "service", 7) == 0) {
217 p += 8;
218 depth = 2;
219 }
220 }
221 }
222
natalie.chenb320ad42016-08-01 10:57:46 +0800223 end = uri + uri_len - 1;
224 while (uri_len--) {
225 c = *end;
226 if (c == '/') {
natalie.chen4fcfe812018-08-15 19:14:40 +0800227 if (p == NULL)
228 p = end + 1;
natalie.chenb320ad42016-08-01 10:57:46 +0800229 slashes++;
230 if (slashes == depth)
231 break;
232 }
natalie.chenb320ad42016-08-01 10:57:46 +0800233 end--;
234 }
natalie.chen21014c42018-09-03 21:57:53 +0800235 if (p != NULL && (!strncmp(p, "git-receive-pack", 16) || !strncmp(p, "git-upload-pack", 15))) {
nataliedbd795e2021-08-24 13:30:19 +0800236 if (!strncmp(start, "/a/", 3) || !strncmp(start, "/p/", 3))
237 start += 2;
natalie.chen4fcfe812018-08-15 19:14:40 +0800238 // we have git request here
239 // get rid of redundant '/'
240 while ((end - start) > 1 && *(start+1) == '/')
241 start++;
242 while ((end - start) > 1 && *(end-1) == '/')
243 end--;
244 // get rid of trailing ".git"
245 if ((end - start) > 4 && strncmp(end-4, ".git", 4) == 0)
246 end -= 4;
nataliedbd795e2021-08-24 13:30:19 +0800247 // get rid of redundant '/'
248 while ((end - start) > 1 && *(end-1) == '/')
249 end--;
natalie.chen4fcfe812018-08-15 19:14:40 +0800250 hash = gen_hash(px, start, (end - start));
251 } else {
252 if (px->uri_dirs_depth1 > 0){
253 // reset state
254 uri_len = orig_uri_len;
255 if (params != NULL)
256 uri_len = params - uri;
257 depth = px->uri_dirs_depth1;
258 slashes = 0;
259 buf = (char *)malloc(uri_len);
260 orig_start = start = end = uri;
261 while (uri_len--) {
262 c = *end;
263 if (c == '/') {
264 if (slashes == 1 && end - start == 2) {
265 depth += 1;
266 orig_start = start = end;
267 }
268 slashes++;
269 if (slashes == depth - 1) {
270 if (memcmp(start, "/changes", end - start) != 0 && memcmp(start, "/projects", end - start) != 0)
271 break;
272 start = end;
273 p = start;
274 }
275 else if (slashes == depth) { /* depth+1 */
276 memcpy(buf + buflen, p, end - p);
277 buflen += (end - p);
278 break;
279 }
280 }
281 else if (c == '%') {
natalie8213c562019-09-02 18:15:19 +0800282 if (orig_start != start && uri_len > 2 && (memcmp(end, "%2F", 3) == 0 || memcmp(end, "%2f", 3) == 0)) {
natalie.chen4fcfe812018-08-15 19:14:40 +0800283 memcpy(buf + buflen, p, end - p);
284 buflen += (end - p) + 1;
285 buf[buflen - 1] = '/';
286 p = end + 3;
287 }
288 }
289 else if (c == '~') {
natalie.chen26479dd2018-12-11 11:54:47 +0800290 if (orig_start != start) {
291 memcpy(buf + buflen, p, end - p);
292 buflen += (end - p);
293 break;
294 }
natalie.chen4fcfe812018-08-15 19:14:40 +0800295 }
296 end++;
297 }
298 }
299 if (buflen > 0)
300 hash = gen_hash(px, buf, buflen);
301 if (buf != NULL)
302 free(buf);
303 if (buflen <= 0) /*let's fallback to round robin */
304 return NULL;
305 }
natalie.chenb320ad42016-08-01 10:57:46 +0800306 } else {
307 while (uri_len--) {
308 c = *end;
309 if (c == '/') {
310 slashes++;
311 if (slashes == px->uri_dirs_depth1) /* depth+1 */
312 break;
313 }
314 else if (c == '?' && !px->uri_whole)
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200315 break;
natalie.chenb320ad42016-08-01 10:57:46 +0800316 end++;
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200317 }
natalie.chen4fcfe812018-08-15 19:14:40 +0800318 hash = gen_hash(px, start, (end - start));
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200319 }
natalie.chene22be3d2015-06-25 09:33:52 +0800320
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500321 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100322 hash = full_hash(hash);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200323 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200324 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
325 return chash_get_server_hash(px, hash);
326 else
327 return map_get_server_hash(px, hash);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200328}
329
Willy Tarreau01732802007-11-01 22:48:15 +0100330/*
331 * This function tries to find a running server for the proxy <px> following
332 * the URL parameter hash method. It looks for a specific parameter in the
333 * URL and hashes it to compute the server ID. This is useful to optimize
334 * performance by avoiding bounces between servers in contexts where sessions
335 * are shared but cookies are not usable. If the parameter is not found, NULL
336 * is returned. If any server is found, it will be returned. If no valid server
337 * is found, NULL is returned.
Willy Tarreau01732802007-11-01 22:48:15 +0100338 */
339struct server *get_server_ph(struct proxy *px, const char *uri, int uri_len)
340{
Dan Dubovik82456752014-07-08 08:51:03 -0700341 unsigned int hash = 0;
Bhaskar98634f02013-10-29 23:30:51 -0400342 const char *start, *end;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200343 const char *p;
344 const char *params;
Willy Tarreau01732802007-11-01 22:48:15 +0100345 int plen;
346
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200347 /* when tot_weight is 0 then so is srv_count */
Willy Tarreau20697042007-11-15 23:26:18 +0100348 if (px->lbprm.tot_weight == 0)
Willy Tarreau01732802007-11-01 22:48:15 +0100349 return NULL;
350
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200351 if ((p = memchr(uri, '?', uri_len)) == NULL)
352 return NULL;
353
Willy Tarreau01732802007-11-01 22:48:15 +0100354 p++;
355
356 uri_len -= (p - uri);
357 plen = px->url_param_len;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200358 params = p;
Willy Tarreau01732802007-11-01 22:48:15 +0100359
360 while (uri_len > plen) {
361 /* Look for the parameter name followed by an equal symbol */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200362 if (params[plen] == '=') {
363 if (memcmp(params, px->url_param_name, plen) == 0) {
364 /* OK, we have the parameter here at <params>, and
Willy Tarreau01732802007-11-01 22:48:15 +0100365 * the value after the equal sign, at <p>
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200366 * skip the equal symbol
Willy Tarreau01732802007-11-01 22:48:15 +0100367 */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200368 p += plen + 1;
Bhaskar98634f02013-10-29 23:30:51 -0400369 start = end = p;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200370 uri_len -= plen + 1;
371
Bhaskar98634f02013-10-29 23:30:51 -0400372 while (uri_len && *end != '&') {
Willy Tarreau01732802007-11-01 22:48:15 +0100373 uri_len--;
Bhaskar98634f02013-10-29 23:30:51 -0400374 end++;
Willy Tarreau01732802007-11-01 22:48:15 +0100375 }
Bhaskar98634f02013-10-29 23:30:51 -0400376 hash = gen_hash(px, start, (end - start));
377
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500378 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100379 hash = full_hash(hash);
Bhaskar98634f02013-10-29 23:30:51 -0400380
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200381 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
382 return chash_get_server_hash(px, hash);
383 else
384 return map_get_server_hash(px, hash);
Willy Tarreau01732802007-11-01 22:48:15 +0100385 }
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200386 }
387 /* skip to next parameter */
388 p = memchr(params, '&', uri_len);
389 if (!p)
390 return NULL;
391 p++;
392 uri_len -= (p - params);
393 params = p;
394 }
395 return NULL;
396}
397
398/*
399 * this does the same as the previous server_ph, but check the body contents
400 */
401struct server *get_server_ph_post(struct session *s)
402{
Dan Dubovik82456752014-07-08 08:51:03 -0700403 unsigned int hash = 0;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200404 struct http_txn *txn = &s->txn;
Willy Tarreau7421efb2012-07-02 15:11:27 +0200405 struct channel *req = s->req;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200406 struct http_msg *msg = &txn->req;
407 struct proxy *px = s->be;
408 unsigned int plen = px->url_param_len;
Willy Tarreau2d8e4852014-04-17 20:08:17 +0200409 unsigned long len = http_body_bytes(msg);
Willy Tarreau0d090502014-04-17 20:31:44 +0200410 const char *params = b_ptr(req->buf, -http_data_rewind(msg));
Willy Tarreau157dd632009-12-06 19:18:09 +0100411 const char *p = params;
Bhaskar98634f02013-10-29 23:30:51 -0400412 const char *start, *end;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200413
Willy Tarreau157dd632009-12-06 19:18:09 +0100414 if (len == 0)
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200415 return NULL;
416
Willy Tarreau522aab32015-05-02 00:05:47 +0200417 if (len > req->buf->data + req->buf->size - p)
418 len = req->buf->data + req->buf->size - p;
419
Willy Tarreau157dd632009-12-06 19:18:09 +0100420 if (px->lbprm.tot_weight == 0)
421 return NULL;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200422
423 while (len > plen) {
424 /* Look for the parameter name followed by an equal symbol */
425 if (params[plen] == '=') {
426 if (memcmp(params, px->url_param_name, plen) == 0) {
427 /* OK, we have the parameter here at <params>, and
428 * the value after the equal sign, at <p>
429 * skip the equal symbol
430 */
431 p += plen + 1;
Bhaskar98634f02013-10-29 23:30:51 -0400432 start = end = p;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200433 len -= plen + 1;
434
Bhaskar98634f02013-10-29 23:30:51 -0400435 while (len && *end != '&') {
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200436 if (unlikely(!HTTP_IS_TOKEN(*p))) {
Willy Tarreau157dd632009-12-06 19:18:09 +0100437 /* if in a POST, body must be URI encoded or it's not a URI.
Bhaskar98634f02013-10-29 23:30:51 -0400438 * Do not interpret any possible binary data as a parameter.
Willy Tarreau157dd632009-12-06 19:18:09 +0100439 */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200440 if (likely(HTTP_IS_LWS(*p))) /* eol, uncertain uri len */
441 break;
442 return NULL; /* oh, no; this is not uri-encoded.
443 * This body does not contain parameters.
444 */
445 }
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200446 len--;
Bhaskar98634f02013-10-29 23:30:51 -0400447 end++;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200448 /* should we break if vlen exceeds limit? */
449 }
Bhaskar98634f02013-10-29 23:30:51 -0400450 hash = gen_hash(px, start, (end - start));
451
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500452 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100453 hash = full_hash(hash);
Bhaskar98634f02013-10-29 23:30:51 -0400454
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200455 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
456 return chash_get_server_hash(px, hash);
457 else
458 return map_get_server_hash(px, hash);
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200459 }
460 }
Willy Tarreau01732802007-11-01 22:48:15 +0100461 /* skip to next parameter */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200462 p = memchr(params, '&', len);
Willy Tarreau01732802007-11-01 22:48:15 +0100463 if (!p)
464 return NULL;
465 p++;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200466 len -= (p - params);
467 params = p;
Willy Tarreau01732802007-11-01 22:48:15 +0100468 }
469 return NULL;
470}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200471
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200472
Willy Tarreaubaaee002006-06-26 02:48:02 +0200473/*
Benoitaffb4812009-03-25 13:02:10 +0100474 * This function tries to find a running server for the proxy <px> following
475 * the Header parameter hash method. It looks for a specific parameter in the
476 * URL and hashes it to compute the server ID. This is useful to optimize
477 * performance by avoiding bounces between servers in contexts where sessions
478 * are shared but cookies are not usable. If the parameter is not found, NULL
479 * is returned. If any server is found, it will be returned. If no valid server
480 * is found, NULL is returned.
481 */
482struct server *get_server_hh(struct session *s)
483{
Dan Dubovik82456752014-07-08 08:51:03 -0700484 unsigned int hash = 0;
Benoitaffb4812009-03-25 13:02:10 +0100485 struct http_txn *txn = &s->txn;
Benoitaffb4812009-03-25 13:02:10 +0100486 struct proxy *px = s->be;
487 unsigned int plen = px->hh_len;
488 unsigned long len;
489 struct hdr_ctx ctx;
490 const char *p;
Bhaskar98634f02013-10-29 23:30:51 -0400491 const char *start, *end;
Benoitaffb4812009-03-25 13:02:10 +0100492
493 /* tot_weight appears to mean srv_count */
494 if (px->lbprm.tot_weight == 0)
495 return NULL;
496
Benoitaffb4812009-03-25 13:02:10 +0100497 ctx.idx = 0;
498
499 /* if the message is chunked, we skip the chunk size, but use the value as len */
Willy Tarreau211cdec2014-04-17 20:18:08 +0200500 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 +0100501
502 /* if the header is not found or empty, let's fallback to round robin */
503 if (!ctx.idx || !ctx.vlen)
504 return NULL;
505
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200506 /* note: we won't hash if there's only one server left */
507 if (px->lbprm.tot_used == 1)
508 goto hash_done;
509
Benoitaffb4812009-03-25 13:02:10 +0100510 /* Found a the hh_name in the headers.
511 * we will compute the hash based on this value ctx.val.
512 */
513 len = ctx.vlen;
514 p = (char *)ctx.line + ctx.val;
515 if (!px->hh_match_domain) {
Bhaskar98634f02013-10-29 23:30:51 -0400516 hash = gen_hash(px, p, len);
Benoitaffb4812009-03-25 13:02:10 +0100517 } else {
518 int dohash = 0;
Cyril Bonté7ccea262015-01-04 15:17:36 +0100519 p += len;
Benoitaffb4812009-03-25 13:02:10 +0100520 /* special computation, use only main domain name, not tld/host
521 * going back from the end of string, start hashing at first
522 * dot stop at next.
523 * This is designed to work with the 'Host' header, and requires
524 * a special option to activate this.
525 */
Cyril Bonté7ccea262015-01-04 15:17:36 +0100526 end = p;
Benoitaffb4812009-03-25 13:02:10 +0100527 while (len) {
Cyril Bonté7ccea262015-01-04 15:17:36 +0100528 if (dohash) {
529 /* Rewind the pointer until the previous char
530 * is a dot, this will allow to set the start
531 * position of the domain. */
532 if (*(p - 1) == '.')
Benoitaffb4812009-03-25 13:02:10 +0100533 break;
Benoitaffb4812009-03-25 13:02:10 +0100534 }
Cyril Bonté7ccea262015-01-04 15:17:36 +0100535 else if (*p == '.') {
536 /* The pointer is rewinded to the dot before the
537 * tld, we memorize the end of the domain and
538 * can enter the domain processing. */
539 end = p;
540 dohash = 1;
541 }
Benoitaffb4812009-03-25 13:02:10 +0100542 p--;
Cyril Bonté7ccea262015-01-04 15:17:36 +0100543 len--;
Benoitaffb4812009-03-25 13:02:10 +0100544 }
Cyril Bonté7ccea262015-01-04 15:17:36 +0100545 start = p;
Bhaskar98634f02013-10-29 23:30:51 -0400546 hash = gen_hash(px, start, (end - start));
Benoitaffb4812009-03-25 13:02:10 +0100547 }
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500548 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100549 hash = full_hash(hash);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200550 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200551 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
552 return chash_get_server_hash(px, hash);
553 else
554 return map_get_server_hash(px, hash);
Benoitaffb4812009-03-25 13:02:10 +0100555}
556
Willy Tarreau34db1082012-04-19 17:16:54 +0200557/* RDP Cookie HASH. */
Emeric Brun736aa232009-06-30 17:56:00 +0200558struct server *get_server_rch(struct session *s)
559{
Dan Dubovik82456752014-07-08 08:51:03 -0700560 unsigned int hash = 0;
Emeric Brun736aa232009-06-30 17:56:00 +0200561 struct proxy *px = s->be;
562 unsigned long len;
Emeric Brun736aa232009-06-30 17:56:00 +0200563 int ret;
Willy Tarreau37406352012-04-23 16:16:37 +0200564 struct sample smp;
Willy Tarreaud1de8af2012-05-18 22:12:14 +0200565 int rewind;
Emeric Brun736aa232009-06-30 17:56:00 +0200566
567 /* tot_weight appears to mean srv_count */
568 if (px->lbprm.tot_weight == 0)
569 return NULL;
570
Willy Tarreau37406352012-04-23 16:16:37 +0200571 memset(&smp, 0, sizeof(smp));
Emeric Brun736aa232009-06-30 17:56:00 +0200572
Willy Tarreau9b28e032012-10-12 23:49:43 +0200573 b_rew(s->req->buf, rewind = s->req->buf->o);
Willy Tarreaud1de8af2012-05-18 22:12:14 +0200574
Willy Tarreaucadd8c92013-07-22 18:09:52 +0200575 ret = fetch_rdp_cookie_name(s, &smp, px->hh_name, px->hh_len);
Willy Tarreauf853c462012-04-23 18:53:56 +0200576 len = smp.data.str.len;
Willy Tarreau664092c2011-12-16 19:11:42 +0100577
Willy Tarreau9b28e032012-10-12 23:49:43 +0200578 b_adv(s->req->buf, rewind);
Willy Tarreaud1de8af2012-05-18 22:12:14 +0200579
Willy Tarreau37406352012-04-23 16:16:37 +0200580 if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || len == 0)
Emeric Brun736aa232009-06-30 17:56:00 +0200581 return NULL;
582
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200583 /* note: we won't hash if there's only one server left */
584 if (px->lbprm.tot_used == 1)
585 goto hash_done;
586
Emeric Brun736aa232009-06-30 17:56:00 +0200587 /* Found a the hh_name in the headers.
588 * we will compute the hash based on this value ctx.val.
589 */
Bhaskar98634f02013-10-29 23:30:51 -0400590 hash = gen_hash(px, smp.data.str.str, len);
591
Bhaskar Maddalab6c0ac92013-11-05 11:54:02 -0500592 if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL)
Willy Tarreau798a39c2010-11-24 15:04:29 +0100593 hash = full_hash(hash);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200594 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200595 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
596 return chash_get_server_hash(px, hash);
597 else
598 return map_get_server_hash(px, hash);
Emeric Brun736aa232009-06-30 17:56:00 +0200599}
Benoitaffb4812009-03-25 13:02:10 +0100600
601/*
Willy Tarreau7c669d72008-06-20 15:04:11 +0200602 * This function applies the load-balancing algorithm to the session, as
603 * defined by the backend it is assigned to. The session is then marked as
604 * 'assigned'.
605 *
606 * This function MAY NOT be called with SN_ASSIGNED already set. If the session
607 * had a server previously assigned, it is rebalanced, trying to avoid the same
Willy Tarreau827aee92011-03-10 16:55:02 +0100608 * server, which should still be present in target_srv(&s->target) before the call.
Willy Tarreau7c669d72008-06-20 15:04:11 +0200609 * The function tries to keep the original connection slot if it reconnects to
610 * the same server, otherwise it releases it and tries to offer it.
611 *
612 * It is illegal to call this function with a session in a queue.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200613 *
614 * It may return :
Willy Tarreau664beb82011-03-10 11:38:29 +0100615 * SRV_STATUS_OK if everything is OK. ->srv and ->target are assigned.
Willy Tarreau7c669d72008-06-20 15:04:11 +0200616 * SRV_STATUS_NOSRV if no server is available. Session is not ASSIGNED
617 * SRV_STATUS_FULL if all servers are saturated. Session is not ASSIGNED
Willy Tarreaubaaee002006-06-26 02:48:02 +0200618 * SRV_STATUS_INTERNAL for other unrecoverable errors.
619 *
Willy Tarreau7c669d72008-06-20 15:04:11 +0200620 * Upon successful return, the session flag SN_ASSIGNED is set to indicate that
Willy Tarreau827aee92011-03-10 16:55:02 +0100621 * it does not need to be called anymore. This means that target_srv(&s->target)
622 * can be trusted in balance and direct modes.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200623 *
624 */
625
626int assign_server(struct session *s)
627{
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200628 struct connection *conn;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200629 struct server *conn_slot;
Willy Tarreau827aee92011-03-10 16:55:02 +0100630 struct server *srv, *prev_srv;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200631 int err;
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100632
Simon Horman8effd3d2011-08-13 08:03:52 +0900633 DPRINTF(stderr,"assign_server : s=%p\n",s);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200634
Willy Tarreau7c669d72008-06-20 15:04:11 +0200635 err = SRV_STATUS_INTERNAL;
636 if (unlikely(s->pend_pos || s->flags & SN_ASSIGNED))
637 goto out_err;
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100638
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100639 prev_srv = objt_server(s->target);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200640 conn_slot = s->srv_conn;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200641
Willy Tarreau7c669d72008-06-20 15:04:11 +0200642 /* We have to release any connection slot before applying any LB algo,
643 * otherwise we may erroneously end up with no available slot.
644 */
645 if (conn_slot)
646 sess_change_server(s, NULL);
647
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100648 /* We will now try to find the good server and store it into <objt_server(s->target)>.
649 * Note that <objt_server(s->target)> may be NULL in case of dispatch or proxy mode,
Willy Tarreau7c669d72008-06-20 15:04:11 +0200650 * as well as if no server is available (check error code).
651 */
Willy Tarreau1a20a5d2007-11-01 21:08:19 +0100652
Willy Tarreau827aee92011-03-10 16:55:02 +0100653 srv = NULL;
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100654 s->target = NULL;
Willy Tarreau9420b122013-12-15 18:58:25 +0100655 conn = objt_conn(s->req->cons->end);
Willy Tarreau664beb82011-03-10 11:38:29 +0100656
Willy Tarreau068621e2013-12-23 15:11:25 +0100657 if (conn &&
Willy Tarreau2481d162014-02-19 18:40:43 +0100658 (conn->flags & CO_FL_CONNECTED) &&
Willy Tarreau9420b122013-12-15 18:58:25 +0100659 objt_server(conn->target) && __objt_server(conn->target)->proxy == s->be &&
Willy Tarreauc35362a2014-04-25 13:58:37 +0200660 ((s->txn.flags & TX_PREFER_LAST) ||
661 ((s->be->options & PR_O_PREF_LAST) &&
662 (!s->be->max_ka_queue ||
663 server_has_room(__objt_server(conn->target)) ||
664 (__objt_server(conn->target)->nbpend + 1) < s->be->max_ka_queue))) &&
Willy Tarreau87eb1d62014-05-13 18:51:40 +0200665 srv_is_usable(__objt_server(conn->target))) {
Willy Tarreau9420b122013-12-15 18:58:25 +0100666 /* This session was relying on a server in a previous request
Godbachcfbb93f2014-12-10 10:21:30 +0800667 * and the proxy has "option prefer-last-server" set, so
Willy Tarreau9420b122013-12-15 18:58:25 +0100668 * let's try to reuse the same server.
669 */
670 srv = __objt_server(conn->target);
671 s->target = &srv->obj_type;
672 }
673 else if (s->be->lbprm.algo & BE_LB_KIND) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200674 /* we must check if we have at least one server available */
675 if (!s->be->lbprm.tot_weight) {
676 err = SRV_STATUS_NOSRV;
677 goto out;
678 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200679
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200680 /* First check whether we need to fetch some data or simply call
681 * the LB lookup function. Only the hashing functions will need
682 * some input data in fact, and will support multiple algorithms.
683 */
684 switch (s->be->lbprm.algo & BE_LB_LKUP) {
685 case BE_LB_LKUP_RRTREE:
Willy Tarreau827aee92011-03-10 16:55:02 +0100686 srv = fwrr_get_next_server(s->be, prev_srv);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200687 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200688
Willy Tarreauf09c6602012-02-13 17:12:08 +0100689 case BE_LB_LKUP_FSTREE:
690 srv = fas_get_next_server(s->be, prev_srv);
691 break;
692
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200693 case BE_LB_LKUP_LCTREE:
Willy Tarreau827aee92011-03-10 16:55:02 +0100694 srv = fwlc_get_next_server(s->be, prev_srv);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200695 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200696
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200697 case BE_LB_LKUP_CHTREE:
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200698 case BE_LB_LKUP_MAP:
Willy Tarreau9757a382009-10-03 12:56:50 +0200699 if ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR) {
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200700 if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
Willy Tarreau827aee92011-03-10 16:55:02 +0100701 srv = chash_get_next_server(s->be, prev_srv);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200702 else
Willy Tarreau827aee92011-03-10 16:55:02 +0100703 srv = map_get_server_rr(s->be, prev_srv);
Willy Tarreau9757a382009-10-03 12:56:50 +0200704 break;
705 }
706 else if ((s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_HI) {
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200707 /* unknown balancing algorithm */
Willy Tarreau7c669d72008-06-20 15:04:11 +0200708 err = SRV_STATUS_INTERNAL;
709 goto out;
710 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200711
712 switch (s->be->lbprm.algo & BE_LB_PARM) {
713 case BE_LB_HASH_SRC:
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200714 conn = objt_conn(s->req->prod->end);
715 if (conn && conn->addr.from.ss_family == AF_INET) {
Willy Tarreau5dd7fa12012-03-31 19:53:37 +0200716 srv = get_server_sh(s->be,
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200717 (void *)&((struct sockaddr_in *)&conn->addr.from)->sin_addr,
Willy Tarreau5dd7fa12012-03-31 19:53:37 +0200718 4);
719 }
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200720 else if (conn && conn->addr.from.ss_family == AF_INET6) {
Willy Tarreau5dd7fa12012-03-31 19:53:37 +0200721 srv = get_server_sh(s->be,
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200722 (void *)&((struct sockaddr_in6 *)&conn->addr.from)->sin6_addr,
Willy Tarreau5dd7fa12012-03-31 19:53:37 +0200723 16);
724 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200725 else {
726 /* unknown IP family */
727 err = SRV_STATUS_INTERNAL;
728 goto out;
729 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200730 break;
731
732 case BE_LB_HASH_URI:
733 /* URI hashing */
Willy Tarreaueaed5a12010-03-24 14:54:30 +0100734 if (s->txn.req.msg_state < HTTP_MSG_BODY)
735 break;
Willy Tarreau827aee92011-03-10 16:55:02 +0100736 srv = get_server_uh(s->be,
Willy Tarreauda6eed62014-04-17 20:24:24 +0200737 b_ptr(s->req->buf, -http_uri_rewind(&s->txn.req)),
Willy Tarreau827aee92011-03-10 16:55:02 +0100738 s->txn.req.sl.rq.u_l);
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200739 break;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200740
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200741 case BE_LB_HASH_PRM:
742 /* URL Parameter hashing */
Willy Tarreaueaed5a12010-03-24 14:54:30 +0100743 if (s->txn.req.msg_state < HTTP_MSG_BODY)
744 break;
Willy Tarreau61a21a32011-03-01 20:35:49 +0100745
Willy Tarreau827aee92011-03-10 16:55:02 +0100746 srv = get_server_ph(s->be,
Willy Tarreauda6eed62014-04-17 20:24:24 +0200747 b_ptr(s->req->buf, -http_uri_rewind(&s->txn.req)),
Willy Tarreau827aee92011-03-10 16:55:02 +0100748 s->txn.req.sl.rq.u_l);
Willy Tarreau61a21a32011-03-01 20:35:49 +0100749
Willy Tarreau827aee92011-03-10 16:55:02 +0100750 if (!srv && s->txn.meth == HTTP_METH_POST)
751 srv = get_server_ph_post(s);
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200752 break;
Benoitaffb4812009-03-25 13:02:10 +0100753
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200754 case BE_LB_HASH_HDR:
755 /* Header Parameter hashing */
Willy Tarreaueaed5a12010-03-24 14:54:30 +0100756 if (s->txn.req.msg_state < HTTP_MSG_BODY)
757 break;
Willy Tarreau827aee92011-03-10 16:55:02 +0100758 srv = get_server_hh(s);
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200759 break;
760
761 case BE_LB_HASH_RDP:
762 /* RDP Cookie hashing */
Willy Tarreau827aee92011-03-10 16:55:02 +0100763 srv = get_server_rch(s);
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200764 break;
765
766 default:
767 /* unknown balancing algorithm */
768 err = SRV_STATUS_INTERNAL;
769 goto out;
Benoitaffb4812009-03-25 13:02:10 +0100770 }
Emeric Brun736aa232009-06-30 17:56:00 +0200771
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200772 /* If the hashing parameter was not found, let's fall
773 * back to round robin on the map.
774 */
Willy Tarreau827aee92011-03-10 16:55:02 +0100775 if (!srv) {
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200776 if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
Willy Tarreau827aee92011-03-10 16:55:02 +0100777 srv = chash_get_next_server(s->be, prev_srv);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200778 else
Willy Tarreau827aee92011-03-10 16:55:02 +0100779 srv = map_get_server_rr(s->be, prev_srv);
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200780 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200781
782 /* end of map-based LB */
Emeric Brun736aa232009-06-30 17:56:00 +0200783 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200784
Willy Tarreau7c669d72008-06-20 15:04:11 +0200785 default:
786 /* unknown balancing algorithm */
787 err = SRV_STATUS_INTERNAL;
788 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200789 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200790
Willy Tarreau827aee92011-03-10 16:55:02 +0100791 if (!srv) {
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200792 err = SRV_STATUS_FULL;
793 goto out;
794 }
Willy Tarreau827aee92011-03-10 16:55:02 +0100795 else if (srv != prev_srv) {
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100796 s->be->be_counters.cum_lbconn++;
Willy Tarreau827aee92011-03-10 16:55:02 +0100797 srv->counters.cum_lbconn++;
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100798 }
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100799 s->target = &srv->obj_type;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200800 }
Willy Tarreau1620ec32011-08-06 17:05:02 +0200801 else if (s->be->options & (PR_O_DISPATCH | PR_O_TRANSP)) {
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100802 s->target = &s->be->obj_type;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200803 }
David du Colombier6f5ccb12011-03-10 22:26:24 +0100804 else if ((s->be->options & PR_O_HTTP_PROXY) &&
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200805 (conn = objt_conn(s->req->cons->end)) &&
806 is_addr(&conn->addr.to)) {
Willy Tarreau664beb82011-03-10 11:38:29 +0100807 /* in proxy mode, we need a valid destination address */
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100808 s->target = &s->be->obj_type;
Willy Tarreau664beb82011-03-10 11:38:29 +0100809 }
810 else {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200811 err = SRV_STATUS_NOSRV;
812 goto out;
813 }
814
815 s->flags |= SN_ASSIGNED;
816 err = SRV_STATUS_OK;
817 out:
818
819 /* Either we take back our connection slot, or we offer it to someone
820 * else if we don't need it anymore.
821 */
822 if (conn_slot) {
Willy Tarreau827aee92011-03-10 16:55:02 +0100823 if (conn_slot == srv) {
824 sess_change_server(s, srv);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200825 } else {
826 if (may_dequeue_tasks(conn_slot, s->be))
827 process_srv_queue(conn_slot);
828 }
829 }
830
831 out_err:
832 return err;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200833}
834
835
836/*
837 * This function assigns a server address to a session, and sets SN_ADDR_SET.
838 * The address is taken from the currently assigned server, or from the
839 * dispatch or transparent address.
840 *
841 * It may return :
842 * SRV_STATUS_OK if everything is OK.
843 * SRV_STATUS_INTERNAL for other unrecoverable errors.
844 *
845 * Upon successful return, the session flag SN_ADDR_SET is set. This flag is
846 * not cleared, so it's to the caller to clear it if required.
847 *
Willy Tarreau32e3c6a2013-10-11 19:34:20 +0200848 * The caller is responsible for having already assigned a connection
849 * to si->end.
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200850 *
Willy Tarreaubaaee002006-06-26 02:48:02 +0200851 */
852int assign_server_address(struct session *s)
853{
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200854 struct connection *cli_conn = objt_conn(s->req->prod->end);
Willy Tarreau32e3c6a2013-10-11 19:34:20 +0200855 struct connection *srv_conn = objt_conn(s->req->cons->end);
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200856
Willy Tarreaubaaee002006-06-26 02:48:02 +0200857#ifdef DEBUG_FULL
858 fprintf(stderr,"assign_server_address : s=%p\n",s);
859#endif
860
Willy Tarreauf3e49f92009-10-03 12:21:20 +0200861 if ((s->flags & SN_DIRECT) || (s->be->lbprm.algo & BE_LB_KIND)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200862 /* A server is necessarily known for this session */
863 if (!(s->flags & SN_ASSIGNED))
864 return SRV_STATUS_INTERNAL;
865
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200866 srv_conn->addr.to = objt_server(s->target)->addr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200867
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200868 if (!is_addr(&srv_conn->addr.to) && cli_conn) {
Willy Tarreaud669a4f2010-07-13 14:49:50 +0200869 /* if the server has no address, we use the same address
870 * the client asked, which is handy for remapping ports
Willy Tarreau9cf8d3f2014-05-09 22:56:10 +0200871 * locally on multiple addresses at once. Nothing is done
872 * for AF_UNIX addresses.
Willy Tarreaud669a4f2010-07-13 14:49:50 +0200873 */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200874 conn_get_to_addr(cli_conn);
Willy Tarreaud669a4f2010-07-13 14:49:50 +0200875
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200876 if (cli_conn->addr.to.ss_family == AF_INET) {
877 ((struct sockaddr_in *)&srv_conn->addr.to)->sin_addr = ((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr;
878 } else if (cli_conn->addr.to.ss_family == AF_INET6) {
879 ((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 +0200880 }
Willy Tarreaud669a4f2010-07-13 14:49:50 +0200881 }
882
Willy Tarreaubaaee002006-06-26 02:48:02 +0200883 /* if this server remaps proxied ports, we'll use
884 * the port the client connected to with an offset. */
Willy Tarreauc93cd162014-05-13 15:54:22 +0200885 if ((objt_server(s->target)->flags & SRV_F_MAPPORTS) && cli_conn) {
David du Colombier6f5ccb12011-03-10 22:26:24 +0100886 int base_port;
887
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200888 conn_get_to_addr(cli_conn);
David du Colombier6f5ccb12011-03-10 22:26:24 +0100889
890 /* First, retrieve the port from the incoming connection */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200891 base_port = get_host_port(&cli_conn->addr.to);
David du Colombier6f5ccb12011-03-10 22:26:24 +0100892
893 /* Second, assign the outgoing connection's port */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200894 base_port += get_host_port(&srv_conn->addr.to);
895 set_host_port(&srv_conn->addr.to, base_port);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200896 }
897 }
Willy Tarreau1620ec32011-08-06 17:05:02 +0200898 else if (s->be->options & PR_O_DISPATCH) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200899 /* connect to the defined dispatch addr */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200900 srv_conn->addr.to = s->be->dispatch_addr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200901 }
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200902 else if ((s->be->options & PR_O_TRANSP) && cli_conn) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200903 /* in transparent mode, use the original dest addr if no dispatch specified */
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200904 conn_get_to_addr(cli_conn);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200905
Willy Tarreaub363a1f2013-10-01 10:45:07 +0200906 if (cli_conn->addr.to.ss_family == AF_INET || cli_conn->addr.to.ss_family == AF_INET6)
907 srv_conn->addr.to = cli_conn->addr.to;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200908 }
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100909 else if (s->be->options & PR_O_HTTP_PROXY) {
910 /* If HTTP PROXY option is set, then server is already assigned
911 * during incoming client request parsing. */
912 }
Willy Tarreau1a1158b2007-01-20 11:07:46 +0100913 else {
914 /* no server and no LB algorithm ! */
915 return SRV_STATUS_INTERNAL;
916 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200917
918 s->flags |= SN_ADDR_SET;
919 return SRV_STATUS_OK;
920}
921
922
923/* This function assigns a server to session <s> if required, and can add the
924 * connection to either the assigned server's queue or to the proxy's queue.
Willy Tarreau7c669d72008-06-20 15:04:11 +0200925 * If ->srv_conn is set, the session is first released from the server.
926 * It may also be called with SN_DIRECT and/or SN_ASSIGNED though. It will
927 * be called before any connection and after any retry or redispatch occurs.
928 *
929 * It is not allowed to call this function with a session in a queue.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200930 *
931 * Returns :
932 *
933 * SRV_STATUS_OK if everything is OK.
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100934 * SRV_STATUS_NOSRV if no server is available. objt_server(s->target) = NULL.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200935 * SRV_STATUS_QUEUED if the connection has been queued.
936 * SRV_STATUS_FULL if the server(s) is/are saturated and the
Willy Tarreau827aee92011-03-10 16:55:02 +0100937 * connection could not be queued at the server's,
Willy Tarreau7c669d72008-06-20 15:04:11 +0200938 * which may be NULL if we queue on the backend.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200939 * SRV_STATUS_INTERNAL for other unrecoverable errors.
940 *
941 */
942int assign_server_and_queue(struct session *s)
943{
944 struct pendconn *p;
Willy Tarreau827aee92011-03-10 16:55:02 +0100945 struct server *srv;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200946 int err;
947
948 if (s->pend_pos)
949 return SRV_STATUS_INTERNAL;
950
Willy Tarreau7c669d72008-06-20 15:04:11 +0200951 err = SRV_STATUS_OK;
952 if (!(s->flags & SN_ASSIGNED)) {
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100953 struct server *prev_srv = objt_server(s->target);
Willy Tarreau3d80d912011-03-10 11:42:13 +0100954
Willy Tarreau7c669d72008-06-20 15:04:11 +0200955 err = assign_server(s);
Willy Tarreau3d80d912011-03-10 11:42:13 +0100956 if (prev_srv) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200957 /* This session was previously assigned to a server. We have to
958 * update the session's and the server's stats :
959 * - if the server changed :
960 * - set TX_CK_DOWN if txn.flags was TX_CK_VALID
961 * - set SN_REDISP if it was successfully redispatched
962 * - increment srv->redispatches and be->redispatches
963 * - if the server remained the same : update retries.
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100964 */
965
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100966 if (prev_srv != objt_server(s->target)) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200967 if ((s->txn.flags & TX_CK_MASK) == TX_CK_VALID) {
968 s->txn.flags &= ~TX_CK_MASK;
969 s->txn.flags |= TX_CK_DOWN;
970 }
971 s->flags |= SN_REDISP;
Willy Tarreau3d80d912011-03-10 11:42:13 +0100972 prev_srv->counters.redispatches++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100973 s->be->be_counters.redispatches++;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200974 } else {
Willy Tarreau3d80d912011-03-10 11:42:13 +0100975 prev_srv->counters.retries++;
Willy Tarreau7d0aaf32011-03-10 23:25:56 +0100976 s->be->be_counters.retries++;
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100977 }
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100978 }
979 }
980
Willy Tarreaubaaee002006-06-26 02:48:02 +0200981 switch (err) {
982 case SRV_STATUS_OK:
Willy Tarreau7c669d72008-06-20 15:04:11 +0200983 /* we have SN_ASSIGNED set */
Willy Tarreau3fdb3662012-11-12 00:42:33 +0100984 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +0100985 if (!srv)
Willy Tarreau7c669d72008-06-20 15:04:11 +0200986 return SRV_STATUS_OK; /* dispatch or proxy mode */
987
988 /* If we already have a connection slot, no need to check any queue */
Willy Tarreau827aee92011-03-10 16:55:02 +0100989 if (s->srv_conn == srv)
Willy Tarreau7c669d72008-06-20 15:04:11 +0200990 return SRV_STATUS_OK;
991
992 /* OK, this session already has an assigned server, but no
993 * connection slot yet. Either it is a redispatch, or it was
994 * assigned from persistence information (direct mode).
995 */
Willy Tarreau827aee92011-03-10 16:55:02 +0100996 if ((s->flags & SN_REDIRECTABLE) && srv->rdr_len) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200997 /* server scheduled for redirection, and already assigned. We
998 * don't want to go further nor check the queue.
Willy Tarreau21d2af32008-02-14 20:25:24 +0100999 */
Willy Tarreau827aee92011-03-10 16:55:02 +01001000 sess_change_server(s, srv); /* not really needed in fact */
Willy Tarreau21d2af32008-02-14 20:25:24 +01001001 return SRV_STATUS_OK;
1002 }
1003
Willy Tarreau7c669d72008-06-20 15:04:11 +02001004 /* We might have to queue this session if the assigned server is full.
1005 * We know we have to queue it into the server's queue, so if a maxqueue
1006 * is set on the server, we must also check that the server's queue is
1007 * not full, in which case we have to return FULL.
1008 */
Willy Tarreau827aee92011-03-10 16:55:02 +01001009 if (srv->maxconn &&
1010 (srv->nbpend || srv->served >= srv_dynamic_maxconn(srv))) {
Willy Tarreau7c669d72008-06-20 15:04:11 +02001011
Willy Tarreau827aee92011-03-10 16:55:02 +01001012 if (srv->maxqueue > 0 && srv->nbpend >= srv->maxqueue)
Willy Tarreau7c669d72008-06-20 15:04:11 +02001013 return SRV_STATUS_FULL;
1014
Willy Tarreaubaaee002006-06-26 02:48:02 +02001015 p = pendconn_add(s);
1016 if (p)
1017 return SRV_STATUS_QUEUED;
1018 else
Willy Tarreau7c669d72008-06-20 15:04:11 +02001019 return SRV_STATUS_INTERNAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001020 }
Willy Tarreau7c669d72008-06-20 15:04:11 +02001021
1022 /* OK, we can use this server. Let's reserve our place */
Willy Tarreau827aee92011-03-10 16:55:02 +01001023 sess_change_server(s, srv);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001024 return SRV_STATUS_OK;
1025
1026 case SRV_STATUS_FULL:
1027 /* queue this session into the proxy's queue */
1028 p = pendconn_add(s);
1029 if (p)
1030 return SRV_STATUS_QUEUED;
1031 else
Willy Tarreau7c669d72008-06-20 15:04:11 +02001032 return SRV_STATUS_INTERNAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001033
1034 case SRV_STATUS_NOSRV:
Willy Tarreau7c669d72008-06-20 15:04:11 +02001035 return err;
1036
Willy Tarreaubaaee002006-06-26 02:48:02 +02001037 case SRV_STATUS_INTERNAL:
1038 return err;
Willy Tarreau7c669d72008-06-20 15:04:11 +02001039
Willy Tarreaubaaee002006-06-26 02:48:02 +02001040 default:
1041 return SRV_STATUS_INTERNAL;
1042 }
Willy Tarreau5b6995c2008-01-13 16:31:17 +01001043}
Willy Tarreaubaaee002006-06-26 02:48:02 +02001044
Willy Tarreaub1d67742010-03-29 19:36:59 +02001045/* If an explicit source binding is specified on the server and/or backend, and
1046 * this source makes use of the transparent proxy, then it is extracted now and
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001047 * assigned to the session's pending connection. This function assumes that an
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02001048 * outgoing connection has already been assigned to s->req->cons->end.
Willy Tarreaub1d67742010-03-29 19:36:59 +02001049 */
1050static void assign_tproxy_address(struct session *s)
1051{
Pieter Baauwd551fb52013-05-08 22:49:23 +02001052#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_TRANSPARENT)
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001053 struct server *srv = objt_server(s->target);
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001054 struct conn_src *src;
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001055 struct connection *cli_conn;
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02001056 struct connection *srv_conn = objt_conn(s->req->cons->end);
Willy Tarreau827aee92011-03-10 16:55:02 +01001057
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001058 if (srv && srv->conn_src.opts & CO_SRC_BIND)
1059 src = &srv->conn_src;
1060 else if (s->be->conn_src.opts & CO_SRC_BIND)
1061 src = &s->be->conn_src;
1062 else
1063 return;
Willy Tarreau294c4732011-12-16 21:35:50 +01001064
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001065 switch (src->opts & CO_SRC_TPROXY_MASK) {
1066 case CO_SRC_TPROXY_ADDR:
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001067 srv_conn->addr.from = src->tproxy_addr;
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001068 break;
1069 case CO_SRC_TPROXY_CLI:
1070 case CO_SRC_TPROXY_CIP:
1071 /* FIXME: what can we do if the client connects in IPv6 or unix socket ? */
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001072 cli_conn = objt_conn(s->req->prod->end);
1073 if (cli_conn)
1074 srv_conn->addr.from = cli_conn->addr.from;
1075 else
1076 memset(&srv_conn->addr.from, 0, sizeof(srv_conn->addr.from));
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001077 break;
1078 case CO_SRC_TPROXY_DYN:
1079 if (src->bind_hdr_occ) {
1080 char *vptr;
1081 int vlen;
1082 int rewind;
Willy Tarreau294c4732011-12-16 21:35:50 +01001083
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001084 /* bind to the IP in a header */
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001085 ((struct sockaddr_in *)&srv_conn->addr.from)->sin_family = AF_INET;
1086 ((struct sockaddr_in *)&srv_conn->addr.from)->sin_port = 0;
1087 ((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr = 0;
Willy Tarreau294c4732011-12-16 21:35:50 +01001088
Willy Tarreau211cdec2014-04-17 20:18:08 +02001089 b_rew(s->req->buf, rewind = http_hdr_rewind(&s->txn.req));
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001090 if (http_get_hdr(&s->txn.req, src->bind_hdr_name, src->bind_hdr_len,
1091 &s->txn.hdr_idx, src->bind_hdr_occ, NULL, &vptr, &vlen)) {
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001092 ((struct sockaddr_in *)&srv_conn->addr.from)->sin_addr.s_addr =
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001093 htonl(inetaddr_host_lim(vptr, vptr + vlen));
Willy Tarreaubce70882009-09-07 11:51:47 +02001094 }
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001095 b_adv(s->req->buf, rewind);
Willy Tarreaub1d67742010-03-29 19:36:59 +02001096 }
Willy Tarreau9cd7d6c2012-12-08 23:13:33 +01001097 break;
1098 default:
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001099 memset(&srv_conn->addr.from, 0, sizeof(srv_conn->addr.from));
Willy Tarreaub1d67742010-03-29 19:36:59 +02001100 }
1101#endif
1102}
1103
1104
Willy Tarreaubaaee002006-06-26 02:48:02 +02001105/*
1106 * This function initiates a connection to the server assigned to this session
Willy Tarreau6471afb2011-09-23 10:54:59 +02001107 * (s->target, s->req->cons->addr.to). It will assign a server if none
Willy Tarreau664beb82011-03-10 11:38:29 +01001108 * is assigned yet.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001109 * It can return one of :
1110 * - SN_ERR_NONE if everything's OK
1111 * - SN_ERR_SRVTO if there are no more servers
1112 * - SN_ERR_SRVCL if the connection was refused by the server
1113 * - SN_ERR_PRXCOND if the connection has been limited by the proxy (maxconn)
1114 * - SN_ERR_RESOURCE if a system resource is lacking (eg: fd limits, ports, ...)
1115 * - SN_ERR_INTERNAL for any other purely internal errors
1116 * Additionnally, in the case of SN_ERR_RESOURCE, an emergency log will be emitted.
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001117 * The server-facing stream interface is expected to hold a pre-allocated connection
1118 * in s->req->cons->conn.
Willy Tarreaubaaee002006-06-26 02:48:02 +02001119 */
1120int connect_server(struct session *s)
1121{
Willy Tarreaub363a1f2013-10-01 10:45:07 +02001122 struct connection *cli_conn;
Willy Tarreau34601a82013-12-15 16:33:46 +01001123 struct connection *srv_conn;
Willy Tarreau827aee92011-03-10 16:55:02 +01001124 struct server *srv;
Willy Tarreau34601a82013-12-15 16:33:46 +01001125 int reuse = 0;
Willy Tarreau9650f372009-08-16 14:02:45 +02001126 int err;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001127
Willy Tarreau34601a82013-12-15 16:33:46 +01001128 srv_conn = objt_conn(s->req->cons->end);
1129 if (srv_conn)
1130 reuse = s->target == srv_conn->target;
1131
1132 if (reuse) {
1133 /* Disable connection reuse if a dynamic source is used.
1134 * As long as we don't share connections between servers,
1135 * we don't need to disable connection reuse on no-idempotent
1136 * requests nor when PROXY protocol is used.
1137 */
1138 srv = objt_server(s->target);
1139 if (srv && srv->conn_src.opts & CO_SRC_BIND) {
1140 if ((srv->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_DYN)
1141 reuse = 0;
1142 }
1143 else if (s->be->conn_src.opts & CO_SRC_BIND) {
1144 if ((s->be->conn_src.opts & CO_SRC_TPROXY_MASK) == CO_SRC_TPROXY_DYN)
1145 reuse = 0;
1146 }
1147 }
1148
1149 srv_conn = si_alloc_conn(s->req->cons, reuse);
Willy Tarreau32e3c6a2013-10-11 19:34:20 +02001150 if (!srv_conn)
1151 return SN_ERR_RESOURCE;
1152
Willy Tarreaubaaee002006-06-26 02:48:02 +02001153 if (!(s->flags & SN_ADDR_SET)) {
1154 err = assign_server_address(s);
1155 if (err != SRV_STATUS_OK)
1156 return SN_ERR_INTERNAL;
1157 }
1158
Willy Tarreauff605db2013-12-20 11:09:51 +01001159 if (!conn_xprt_ready(srv_conn)) {
1160 /* the target was only on the session, assign it to the SI now */
1161 srv_conn->target = s->target;
Willy Tarreaud88edf22009-06-14 15:48:17 +02001162
Willy Tarreauff605db2013-12-20 11:09:51 +01001163 /* set the correct protocol on the output stream interface */
1164 if (objt_server(s->target)) {
1165 conn_prepare(srv_conn, objt_server(s->target)->proto, objt_server(s->target)->xprt);
1166 }
1167 else if (obj_type(s->target) == OBJ_TYPE_PROXY) {
1168 /* proxies exclusively run on raw_sock right now */
1169 conn_prepare(srv_conn, protocol_by_family(srv_conn->addr.to.ss_family), &raw_sock);
1170 if (!objt_conn(s->req->cons->end) || !objt_conn(s->req->cons->end)->ctrl)
1171 return SN_ERR_INTERNAL;
1172 }
1173 else
1174 return SN_ERR_INTERNAL; /* how did we get there ? */
Willy Tarreaud02394b2012-05-11 18:32:18 +02001175
Willy Tarreauff605db2013-12-20 11:09:51 +01001176 /* process the case where the server requires the PROXY protocol to be sent */
1177 srv_conn->send_proxy_ofs = 0;
David Safb76832014-05-08 23:42:08 -04001178 if (objt_server(s->target) && objt_server(s->target)->pp_opts) {
Willy Tarreauff605db2013-12-20 11:09:51 +01001179 srv_conn->send_proxy_ofs = 1; /* must compute size */
1180 cli_conn = objt_conn(s->req->prod->end);
1181 if (cli_conn)
1182 conn_get_to_addr(cli_conn);
1183 }
Willy Tarreau2a6e8802013-10-24 15:50:53 +02001184
Willy Tarreauff605db2013-12-20 11:09:51 +01001185 si_attach_conn(s->req->cons, srv_conn);
Willy Tarreau26d8c592012-05-07 18:12:14 +02001186
Willy Tarreauff605db2013-12-20 11:09:51 +01001187 assign_tproxy_address(s);
1188 }
1189 else {
1190 /* the connection is being reused, just re-attach it */
1191 si_attach_conn(s->req->cons, srv_conn);
Willy Tarreau36346242014-02-24 18:26:30 +01001192 s->flags |= SN_SRV_REUSED;
Willy Tarreauff605db2013-12-20 11:09:51 +01001193 }
Willy Tarreaub1d67742010-03-29 19:36:59 +02001194
William Lallemandb7ff6a32012-03-02 14:35:21 +01001195 /* flag for logging source ip/port */
1196 if (s->fe->options2 & PR_O2_SRC_ADDR)
1197 s->req->cons->flags |= SI_FL_SRC_ADDR;
1198
Willy Tarreau14f8e862012-08-30 22:23:13 +02001199 /* disable lingering */
1200 if (s->be->options & PR_O_TCP_NOLING)
1201 s->req->cons->flags |= SI_FL_NOLINGER;
1202
Willy Tarreau73b013b2012-05-21 16:31:45 +02001203 err = si_connect(s->req->cons);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001204
Willy Tarreau9650f372009-08-16 14:02:45 +02001205 if (err != SN_ERR_NONE)
1206 return err;
Willy Tarreau788e2842008-08-26 13:25:39 +02001207
Willy Tarreau14f8e862012-08-30 22:23:13 +02001208 /* set connect timeout */
1209 s->req->cons->exp = tick_add_ifset(now_ms, s->be->timeout.connect);
1210
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001211 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +01001212 if (srv) {
Willy Tarreau1e62de62008-11-11 20:20:02 +01001213 s->flags |= SN_CURR_SESS;
Willy Tarreau827aee92011-03-10 16:55:02 +01001214 srv->cur_sess++;
1215 if (srv->cur_sess > srv->counters.cur_sess_max)
1216 srv->counters.cur_sess_max = srv->cur_sess;
Willy Tarreau51406232008-03-10 22:04:20 +01001217 if (s->be->lbprm.server_take_conn)
Willy Tarreau827aee92011-03-10 16:55:02 +01001218 s->be->lbprm.server_take_conn(srv);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001219 }
1220
Willy Tarreaubaaee002006-06-26 02:48:02 +02001221 return SN_ERR_NONE; /* connection is OK */
1222}
1223
1224
Willy Tarreaubaaee002006-06-26 02:48:02 +02001225/* This function performs the "redispatch" part of a connection attempt. It
1226 * will assign a server if required, queue the connection if required, and
1227 * handle errors that might arise at this level. It can change the server
1228 * state. It will return 1 if it encounters an error, switches the server
1229 * state, or has to queue a connection. Otherwise, it will return 0 indicating
1230 * that the connection is ready to use.
1231 */
1232
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001233int srv_redispatch_connect(struct session *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +02001234{
Willy Tarreau827aee92011-03-10 16:55:02 +01001235 struct server *srv;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001236 int conn_err;
1237
1238 /* We know that we don't have any connection pending, so we will
1239 * try to get a new one, and wait in this state if it's queued
1240 */
Willy Tarreau7c669d72008-06-20 15:04:11 +02001241 redispatch:
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001242 conn_err = assign_server_and_queue(s);
1243 srv = objt_server(s->target);
Willy Tarreau827aee92011-03-10 16:55:02 +01001244
Willy Tarreaubaaee002006-06-26 02:48:02 +02001245 switch (conn_err) {
1246 case SRV_STATUS_OK:
1247 break;
1248
Willy Tarreau7c669d72008-06-20 15:04:11 +02001249 case SRV_STATUS_FULL:
1250 /* The server has reached its maxqueue limit. Either PR_O_REDISP is set
1251 * and we can redispatch to another server, or it is not and we return
1252 * 503. This only makes sense in DIRECT mode however, because normal LB
1253 * algorithms would never select such a server, and hash algorithms
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001254 * would bring us on the same server again. Note that s->target is set
Willy Tarreau827aee92011-03-10 16:55:02 +01001255 * in this case.
Willy Tarreau7c669d72008-06-20 15:04:11 +02001256 */
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001257 if (((s->flags & (SN_DIRECT|SN_FORCE_PRST)) == SN_DIRECT) &&
1258 (s->be->options & PR_O_REDISP)) {
1259 s->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET);
Willy Tarreau7c669d72008-06-20 15:04:11 +02001260 goto redispatch;
1261 }
1262
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001263 if (!s->req->cons->err_type) {
1264 s->req->cons->err_type = SI_ET_QUEUE_ERR;
Willy Tarreaufa7e1022008-10-19 07:30:41 +02001265 }
Willy Tarreau7c669d72008-06-20 15:04:11 +02001266
Willy Tarreau827aee92011-03-10 16:55:02 +01001267 srv->counters.failed_conns++;
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001268 s->be->be_counters.failed_conns++;
Willy Tarreau7c669d72008-06-20 15:04:11 +02001269 return 1;
1270
Willy Tarreaubaaee002006-06-26 02:48:02 +02001271 case SRV_STATUS_NOSRV:
Willy Tarreau827aee92011-03-10 16:55:02 +01001272 /* note: it is guaranteed that srv == NULL here */
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001273 if (!s->req->cons->err_type) {
1274 s->req->cons->err_type = SI_ET_CONN_ERR;
Willy Tarreaufa7e1022008-10-19 07:30:41 +02001275 }
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +01001276
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001277 s->be->be_counters.failed_conns++;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001278 return 1;
1279
1280 case SRV_STATUS_QUEUED:
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001281 s->req->cons->exp = tick_add_ifset(now_ms, s->be->timeout.queue);
1282 s->req->cons->state = SI_ST_QUE;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001283 /* do nothing else and do not wake any other session up */
1284 return 1;
1285
Willy Tarreaubaaee002006-06-26 02:48:02 +02001286 case SRV_STATUS_INTERNAL:
1287 default:
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001288 if (!s->req->cons->err_type) {
1289 s->req->cons->err_type = SI_ET_CONN_OTHER;
Willy Tarreaufa7e1022008-10-19 07:30:41 +02001290 }
1291
Willy Tarreau827aee92011-03-10 16:55:02 +01001292 if (srv)
1293 srv_inc_sess_ctr(srv);
1294 if (srv)
Bhaskar Maddalaa20cb852014-02-03 16:26:46 -05001295 srv_set_sess_last(srv);
1296 if (srv)
Willy Tarreau827aee92011-03-10 16:55:02 +01001297 srv->counters.failed_conns++;
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001298 s->be->be_counters.failed_conns++;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001299
1300 /* release other sessions waiting for this server */
Willy Tarreauf1fd9dc2014-04-24 20:47:57 +02001301 if (may_dequeue_tasks(srv, s->be))
Willy Tarreau827aee92011-03-10 16:55:02 +01001302 process_srv_queue(srv);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001303 return 1;
1304 }
1305 /* if we get here, it's because we got SRV_STATUS_OK, which also
1306 * means that the connection has not been queued.
1307 */
1308 return 0;
1309}
1310
Willy Tarreau4aac7db2014-05-16 11:48:10 +02001311/* sends a log message when a backend goes down, and also sets last
1312 * change date.
1313 */
1314void set_backend_down(struct proxy *be)
1315{
1316 be->last_change = now.tv_sec;
1317 be->down_trans++;
1318
1319 Alert("%s '%s' has no server available!\n", proxy_type_str(be), be->id);
1320 send_log(be, LOG_EMERG, "%s %s has no server available!\n", proxy_type_str(be), be->id);
1321}
1322
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001323/* Apply RDP cookie persistence to the current session. For this, the function
1324 * tries to extract an RDP cookie from the request buffer, and look for the
1325 * matching server in the list. If the server is found, it is assigned to the
1326 * session. This always returns 1, and the analyser removes itself from the
1327 * list. Nothing is performed if a server was already assigned.
1328 */
Willy Tarreau7421efb2012-07-02 15:11:27 +02001329int tcp_persist_rdp_cookie(struct session *s, struct channel *req, int an_bit)
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001330{
1331 struct proxy *px = s->be;
1332 int ret;
Willy Tarreau37406352012-04-23 16:16:37 +02001333 struct sample smp;
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001334 struct server *srv = px->srv;
1335 struct sockaddr_in addr;
1336 char *p;
1337
Willy Tarreau02d6cfc2012-03-01 18:19:58 +01001338 DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001339 now_ms, __FUNCTION__,
1340 s,
1341 req,
1342 req->rex, req->wex,
1343 req->flags,
Willy Tarreau9b28e032012-10-12 23:49:43 +02001344 req->buf->i,
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001345 req->analysers);
1346
1347 if (s->flags & SN_ASSIGNED)
1348 goto no_cookie;
1349
Willy Tarreau37406352012-04-23 16:16:37 +02001350 memset(&smp, 0, sizeof(smp));
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001351
Willy Tarreaucadd8c92013-07-22 18:09:52 +02001352 ret = fetch_rdp_cookie_name(s, &smp, s->be->rdp_cookie_name, s->be->rdp_cookie_len);
Willy Tarreauf853c462012-04-23 18:53:56 +02001353 if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || smp.data.str.len == 0)
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001354 goto no_cookie;
1355
1356 memset(&addr, 0, sizeof(addr));
1357 addr.sin_family = AF_INET;
1358
Willy Tarreau664092c2011-12-16 19:11:42 +01001359 /* Considering an rdp cookie detected using acl, str ended with <cr><lf> and should return */
Willy Tarreauf853c462012-04-23 18:53:56 +02001360 addr.sin_addr.s_addr = strtoul(smp.data.str.str, &p, 10);
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001361 if (*p != '.')
1362 goto no_cookie;
1363 p++;
1364 addr.sin_port = (unsigned short)strtoul(p, &p, 10);
1365 if (*p != '.')
1366 goto no_cookie;
1367
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001368 s->target = NULL;
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001369 while (srv) {
Willy Tarreau28e9d062014-05-09 22:47:50 +02001370 if (srv->addr.ss_family == AF_INET &&
1371 memcmp(&addr, &(srv->addr), sizeof(addr)) == 0) {
Willy Tarreau892337c2014-05-13 23:41:20 +02001372 if ((srv->state != SRV_ST_STOPPED) || (px->options & PR_O_PERSIST)) {
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001373 /* we found the server and it is usable */
1374 s->flags |= SN_DIRECT | SN_ASSIGNED;
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001375 s->target = &srv->obj_type;
Willy Tarreau44b90cc2010-05-24 20:27:29 +02001376 break;
1377 }
1378 }
1379 srv = srv->next;
1380 }
1381
1382no_cookie:
1383 req->analysers &= ~an_bit;
1384 req->analyse_exp = TICK_ETERNITY;
1385 return 1;
1386}
1387
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001388int be_downtime(struct proxy *px) {
Willy Tarreaub625a082007-11-26 01:15:43 +01001389 if (px->lbprm.tot_weight && px->last_change < now.tv_sec) // ignore negative time
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001390 return px->down_time;
1391
1392 return now.tv_sec - px->last_change + px->down_time;
1393}
Willy Tarreaubaaee002006-06-26 02:48:02 +02001394
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001395/*
1396 * This function returns a string containing the balancing
1397 * mode of the proxy in a format suitable for stats.
1398 */
1399
1400const char *backend_lb_algo_str(int algo) {
1401
1402 if (algo == BE_LB_ALGO_RR)
1403 return "roundrobin";
1404 else if (algo == BE_LB_ALGO_SRR)
1405 return "static-rr";
Willy Tarreauf09c6602012-02-13 17:12:08 +01001406 else if (algo == BE_LB_ALGO_FAS)
1407 return "first";
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001408 else if (algo == BE_LB_ALGO_LC)
1409 return "leastconn";
1410 else if (algo == BE_LB_ALGO_SH)
1411 return "source";
1412 else if (algo == BE_LB_ALGO_UH)
1413 return "uri";
1414 else if (algo == BE_LB_ALGO_PH)
1415 return "url_param";
1416 else if (algo == BE_LB_ALGO_HH)
1417 return "hdr";
1418 else if (algo == BE_LB_ALGO_RCH)
1419 return "rdp-cookie";
Willy Tarreau8f554b52016-11-26 15:52:04 +01001420 else if (algo == BE_LB_ALGO_NONE)
1421 return "none";
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001422 else
Willy Tarreau8f554b52016-11-26 15:52:04 +01001423 return "unknown";
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001424}
1425
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001426/* This function parses a "balance" statement in a backend section describing
1427 * <curproxy>. It returns -1 if there is any error, otherwise zero. If it
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001428 * returns -1, it will write an error message into the <err> buffer which will
1429 * automatically be allocated and must be passed as NULL. The trailing '\n'
1430 * will not be written. The function must be called with <args> pointing to the
1431 * first word after "balance".
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001432 */
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001433int backend_parse_balance(const char **args, char **err, struct proxy *curproxy)
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001434{
1435 if (!*(args[0])) {
1436 /* if no option is set, use round-robin by default */
Willy Tarreau31682232007-11-29 15:38:04 +01001437 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1438 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001439 return 0;
1440 }
1441
1442 if (!strcmp(args[0], "roundrobin")) {
Willy Tarreau31682232007-11-29 15:38:04 +01001443 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1444 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001445 }
Willy Tarreau9757a382009-10-03 12:56:50 +02001446 else if (!strcmp(args[0], "static-rr")) {
1447 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1448 curproxy->lbprm.algo |= BE_LB_ALGO_SRR;
1449 }
Willy Tarreauf09c6602012-02-13 17:12:08 +01001450 else if (!strcmp(args[0], "first")) {
1451 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1452 curproxy->lbprm.algo |= BE_LB_ALGO_FAS;
1453 }
Willy Tarreau51406232008-03-10 22:04:20 +01001454 else if (!strcmp(args[0], "leastconn")) {
1455 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1456 curproxy->lbprm.algo |= BE_LB_ALGO_LC;
1457 }
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001458 else if (!strcmp(args[0], "source")) {
Willy Tarreau31682232007-11-29 15:38:04 +01001459 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1460 curproxy->lbprm.algo |= BE_LB_ALGO_SH;
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001461 }
1462 else if (!strcmp(args[0], "uri")) {
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001463 int arg = 1;
1464
Willy Tarreau31682232007-11-29 15:38:04 +01001465 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1466 curproxy->lbprm.algo |= BE_LB_ALGO_UH;
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001467
Oskar Stolc8dc41842012-05-19 10:19:54 +01001468 curproxy->uri_whole = 0;
natalie.chen4fcfe812018-08-15 19:14:40 +08001469 curproxy->uri_gerrit = 0;
Oskar Stolc8dc41842012-05-19 10:19:54 +01001470
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001471 while (*args[arg]) {
1472 if (!strcmp(args[arg], "len")) {
1473 if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001474 memprintf(err, "%s : '%s' expects a positive integer (got '%s').", args[0], args[arg], args[arg+1]);
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001475 return -1;
1476 }
1477 curproxy->uri_len_limit = atoi(args[arg+1]);
1478 arg += 2;
1479 }
1480 else if (!strcmp(args[arg], "depth")) {
1481 if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001482 memprintf(err, "%s : '%s' expects a positive integer (got '%s').", args[0], args[arg], args[arg+1]);
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001483 return -1;
1484 }
1485 /* hint: we store the position of the ending '/' (depth+1) so
1486 * that we avoid a comparison while computing the hash.
1487 */
1488 curproxy->uri_dirs_depth1 = atoi(args[arg+1]) + 1;
1489 arg += 2;
1490 }
Oskar Stolc8dc41842012-05-19 10:19:54 +01001491 else if (!strcmp(args[arg], "whole")) {
1492 curproxy->uri_whole = 1;
1493 arg += 1;
natalie.chen4fcfe812018-08-15 19:14:40 +08001494 }
1495 else if (!strcmp(args[arg], "gerrit")) {
1496 if (!*args[arg+1] || (atoi(args[arg+1]) < 0)) {
1497 memprintf(err, "%s : '%s' expects a non negative integer (got '%s').", args[0], args[arg], args[arg+1]);
1498 return -1;
1499 }
1500 curproxy->uri_gerrit = 1;
1501 // 0 means whole uri
1502 curproxy->uri_dirs_depth1 = atoi(args[arg+1]);
1503 arg += 2;
Oskar Stolc8dc41842012-05-19 10:19:54 +01001504 }
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001505 else {
Oskar Stolc8dc41842012-05-19 10:19:54 +01001506 memprintf(err, "%s only accepts parameters 'len', 'depth', and 'whole' (got '%s').", args[0], args[arg]);
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001507 return -1;
1508 }
1509 }
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001510 }
Willy Tarreau01732802007-11-01 22:48:15 +01001511 else if (!strcmp(args[0], "url_param")) {
1512 if (!*args[1]) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001513 memprintf(err, "%s requires an URL parameter name.", args[0]);
Willy Tarreau01732802007-11-01 22:48:15 +01001514 return -1;
1515 }
Willy Tarreau31682232007-11-29 15:38:04 +01001516 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1517 curproxy->lbprm.algo |= BE_LB_ALGO_PH;
Willy Tarreaua534fea2008-08-03 12:19:50 +02001518
1519 free(curproxy->url_param_name);
Willy Tarreau01732802007-11-01 22:48:15 +01001520 curproxy->url_param_name = strdup(args[1]);
Willy Tarreaua534fea2008-08-03 12:19:50 +02001521 curproxy->url_param_len = strlen(args[1]);
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001522 if (*args[2]) {
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001523 if (strcmp(args[2], "check_post")) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001524 memprintf(err, "%s only accepts 'check_post' modifier (got '%s').", args[0], args[2]);
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001525 return -1;
1526 }
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001527 }
Benoitaffb4812009-03-25 13:02:10 +01001528 }
1529 else if (!strncmp(args[0], "hdr(", 4)) {
1530 const char *beg, *end;
1531
1532 beg = args[0] + 4;
1533 end = strchr(beg, ')');
1534
1535 if (!end || end == beg) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001536 memprintf(err, "hdr requires an http header field name.");
Benoitaffb4812009-03-25 13:02:10 +01001537 return -1;
1538 }
1539
1540 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1541 curproxy->lbprm.algo |= BE_LB_ALGO_HH;
1542
1543 free(curproxy->hh_name);
1544 curproxy->hh_len = end - beg;
1545 curproxy->hh_name = my_strndup(beg, end - beg);
1546 curproxy->hh_match_domain = 0;
1547
1548 if (*args[1]) {
1549 if (strcmp(args[1], "use_domain_only")) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001550 memprintf(err, "%s only accepts 'use_domain_only' modifier (got '%s').", args[0], args[1]);
Benoitaffb4812009-03-25 13:02:10 +01001551 return -1;
1552 }
1553 curproxy->hh_match_domain = 1;
1554 }
Emeric Brun736aa232009-06-30 17:56:00 +02001555 }
1556 else if (!strncmp(args[0], "rdp-cookie", 10)) {
1557 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1558 curproxy->lbprm.algo |= BE_LB_ALGO_RCH;
1559
1560 if ( *(args[0] + 10 ) == '(' ) { /* cookie name */
1561 const char *beg, *end;
1562
1563 beg = args[0] + 11;
1564 end = strchr(beg, ')');
1565
1566 if (!end || end == beg) {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001567 memprintf(err, "rdp-cookie : missing cookie name.");
Emeric Brun736aa232009-06-30 17:56:00 +02001568 return -1;
1569 }
1570
1571 free(curproxy->hh_name);
1572 curproxy->hh_name = my_strndup(beg, end - beg);
1573 curproxy->hh_len = end - beg;
1574 }
1575 else if ( *(args[0] + 10 ) == '\0' ) { /* default cookie name 'mstshash' */
1576 free(curproxy->hh_name);
1577 curproxy->hh_name = strdup("mstshash");
1578 curproxy->hh_len = strlen(curproxy->hh_name);
1579 }
1580 else { /* syntax */
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001581 memprintf(err, "rdp-cookie : missing cookie name.");
Emeric Brun736aa232009-06-30 17:56:00 +02001582 return -1;
1583 }
Willy Tarreau01732802007-11-01 22:48:15 +01001584 }
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001585 else {
Willy Tarreaua93c74b2012-05-08 18:14:39 +02001586 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 +01001587 return -1;
1588 }
1589 return 0;
1590}
1591
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001592
1593/************************************************************************/
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001594/* All supported sample and ACL keywords must be declared here. */
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001595/************************************************************************/
1596
Willy Tarreau34db1082012-04-19 17:16:54 +02001597/* set temp integer to the number of enabled servers on the proxy.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001598 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001599 * undefined behaviour.
1600 */
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001601static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001602smp_fetch_nbsrv(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001603 const struct arg *args, struct sample *smp, const char *kw)
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001604{
Willy Tarreau37406352012-04-23 16:16:37 +02001605 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001606 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001607 px = args->data.prx;
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001608
Marcin Deranek1ad1c0b2016-12-22 16:21:08 +01001609 if (px->state == PR_STSTOPPED)
1610 smp->data.uint = 0;
1611 else if (px->srv_act)
Willy Tarreauf853c462012-04-23 18:53:56 +02001612 smp->data.uint = px->srv_act;
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001613 else if (px->lbprm.fbck)
Willy Tarreauf853c462012-04-23 18:53:56 +02001614 smp->data.uint = 1;
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001615 else
Willy Tarreauf853c462012-04-23 18:53:56 +02001616 smp->data.uint = px->srv_bck;
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001617
1618 return 1;
1619}
1620
Willy Tarreau37406352012-04-23 16:16:37 +02001621/* report in smp->flags a success or failure depending on the designated
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001622 * server's state. There is no match function involved since there's no pattern.
Willy Tarreau34db1082012-04-19 17:16:54 +02001623 * Accepts exactly 1 argument. Argument is a server, other types will lead to
1624 * undefined behaviour.
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001625 */
1626static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001627smp_fetch_srv_is_up(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001628 const struct arg *args, struct sample *smp, const char *kw)
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001629{
Willy Tarreau24e32d82012-04-23 23:55:44 +02001630 struct server *srv = args->data.srv;
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001631
Willy Tarreau37406352012-04-23 16:16:37 +02001632 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001633 smp->type = SMP_T_BOOL;
Willy Tarreau20125212014-05-13 19:44:56 +02001634 if (!(srv->admin & SRV_ADMF_MAINT) &&
Willy Tarreau892337c2014-05-13 23:41:20 +02001635 (!(srv->check.state & CHK_ST_CONFIGURED) || (srv->state != SRV_ST_STOPPED)))
Willy Tarreau197e10a2012-04-23 19:18:42 +02001636 smp->data.uint = 1;
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001637 else
Willy Tarreau197e10a2012-04-23 19:18:42 +02001638 smp->data.uint = 0;
Willy Tarreau0b1cd942010-05-16 22:18:27 +02001639 return 1;
1640}
1641
Willy Tarreau34db1082012-04-19 17:16:54 +02001642/* set temp integer to the number of enabled servers on the proxy.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001643 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001644 * undefined behaviour.
1645 */
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001646static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001647smp_fetch_connslots(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001648 const struct arg *args, struct sample *smp, const char *kw)
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001649{
1650 struct server *iterator;
Willy Tarreaud28c3532012-04-19 19:28:33 +02001651
Willy Tarreau37406352012-04-23 16:16:37 +02001652 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001653 smp->type = SMP_T_UINT;
1654 smp->data.uint = 0;
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001655
Willy Tarreau24e32d82012-04-23 23:55:44 +02001656 for (iterator = args->data.prx->srv; iterator; iterator = iterator->next) {
Willy Tarreau892337c2014-05-13 23:41:20 +02001657 if (iterator->state == SRV_ST_STOPPED)
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001658 continue;
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001659
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001660 if (iterator->maxconn == 0 || iterator->maxqueue == 0) {
Willy Tarreaua5e37562011-12-16 17:06:15 +01001661 /* configuration is stupid */
Willy Tarreauf853c462012-04-23 18:53:56 +02001662 smp->data.uint = -1; /* FIXME: stupid value! */
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001663 return 1;
1664 }
1665
Willy Tarreauf853c462012-04-23 18:53:56 +02001666 smp->data.uint += (iterator->maxconn - iterator->cur_sess)
Willy Tarreau422aa072012-04-20 20:49:27 +02001667 + (iterator->maxqueue - iterator->nbpend);
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001668 }
1669
1670 return 1;
1671}
1672
Willy Tarreaua5e37562011-12-16 17:06:15 +01001673/* set temp integer to the id of the backend */
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +01001674static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001675smp_fetch_be_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001676 const struct arg *args, struct sample *smp, const char *kw)
Willy Tarreau37406352012-04-23 16:16:37 +02001677{
Willy Tarreauf853c462012-04-23 18:53:56 +02001678 smp->flags = SMP_F_VOL_TXN;
1679 smp->type = SMP_T_UINT;
1680 smp->data.uint = l4->be->uuid;
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +01001681 return 1;
1682}
1683
Willy Tarreaua5e37562011-12-16 17:06:15 +01001684/* set temp integer to the id of the server */
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +01001685static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001686smp_fetch_srv_id(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001687 const struct arg *args, struct sample *smp, const char *kw)
Willy Tarreau37406352012-04-23 16:16:37 +02001688{
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001689 if (!objt_server(l4->target))
Willy Tarreau17af4192011-02-23 14:27:06 +01001690 return 0;
1691
Willy Tarreauf853c462012-04-23 18:53:56 +02001692 smp->type = SMP_T_UINT;
Willy Tarreau3fdb3662012-11-12 00:42:33 +01001693 smp->data.uint = objt_server(l4->target)->puid;
Hervé COMMOWICK35ed8012010-12-15 14:04:51 +01001694
1695 return 1;
1696}
1697
Willy Tarreau34db1082012-04-19 17:16:54 +02001698/* set temp integer to the number of connections per second reaching the backend.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001699 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001700 * undefined behaviour.
1701 */
Willy Tarreau079ff0a2009-03-05 21:34:28 +01001702static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001703smp_fetch_be_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001704 const struct arg *args, struct sample *smp, const char *kw)
Willy Tarreau079ff0a2009-03-05 21:34:28 +01001705{
Willy Tarreau37406352012-04-23 16:16:37 +02001706 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001707 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001708 smp->data.uint = read_freq_ctr(&args->data.prx->be_sess_per_sec);
Willy Tarreau079ff0a2009-03-05 21:34:28 +01001709 return 1;
1710}
1711
Willy Tarreau34db1082012-04-19 17:16:54 +02001712/* set temp integer to the number of concurrent connections on the backend.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001713 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001714 * undefined behaviour.
1715 */
Willy Tarreaua36af912009-10-10 12:02:45 +02001716static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001717smp_fetch_be_conn(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001718 const struct arg *args, struct sample *smp, const char *kw)
Willy Tarreaua36af912009-10-10 12:02:45 +02001719{
Willy Tarreau37406352012-04-23 16:16:37 +02001720 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001721 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001722 smp->data.uint = args->data.prx->beconn;
Willy Tarreaua36af912009-10-10 12:02:45 +02001723 return 1;
1724}
1725
Willy Tarreau34db1082012-04-19 17:16:54 +02001726/* set temp integer to the total number of queued connections on the backend.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001727 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001728 * undefined behaviour.
1729 */
Willy Tarreaua36af912009-10-10 12:02:45 +02001730static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001731smp_fetch_queue_size(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001732 const struct arg *args, struct sample *smp, const char *kw)
Willy Tarreaua36af912009-10-10 12:02:45 +02001733{
Willy Tarreau37406352012-04-23 16:16:37 +02001734 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001735 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001736 smp->data.uint = args->data.prx->totpend;
Willy Tarreaua36af912009-10-10 12:02:45 +02001737 return 1;
1738}
1739
Willy Tarreaua5e37562011-12-16 17:06:15 +01001740/* set temp integer to the total number of queued connections on the backend divided
Willy Tarreaua36af912009-10-10 12:02:45 +02001741 * by the number of running servers and rounded up. If there is no running
1742 * server, we return twice the total, just as if we had half a running server.
1743 * This is more or less correct anyway, since we expect the last server to come
1744 * back soon.
Willy Tarreau0146c2e2012-04-20 11:37:56 +02001745 * Accepts exactly 1 argument. Argument is a backend, other types will lead to
Willy Tarreau34db1082012-04-19 17:16:54 +02001746 * undefined behaviour.
Willy Tarreaua36af912009-10-10 12:02:45 +02001747 */
1748static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001749smp_fetch_avg_queue_size(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001750 const struct arg *args, struct sample *smp, const char *kw)
Willy Tarreaua36af912009-10-10 12:02:45 +02001751{
1752 int nbsrv;
1753
Willy Tarreau37406352012-04-23 16:16:37 +02001754 smp->flags = SMP_F_VOL_TEST;
Willy Tarreauf853c462012-04-23 18:53:56 +02001755 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001756 px = args->data.prx;
Willy Tarreaua36af912009-10-10 12:02:45 +02001757
1758 if (px->srv_act)
1759 nbsrv = px->srv_act;
1760 else if (px->lbprm.fbck)
1761 nbsrv = 1;
1762 else
1763 nbsrv = px->srv_bck;
1764
1765 if (nbsrv > 0)
Willy Tarreauf853c462012-04-23 18:53:56 +02001766 smp->data.uint = (px->totpend + nbsrv - 1) / nbsrv;
Willy Tarreaua36af912009-10-10 12:02:45 +02001767 else
Willy Tarreauf853c462012-04-23 18:53:56 +02001768 smp->data.uint = px->totpend * 2;
Willy Tarreaua36af912009-10-10 12:02:45 +02001769
1770 return 1;
1771}
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001772
Willy Tarreau34db1082012-04-19 17:16:54 +02001773/* set temp integer to the number of concurrent connections on the server in the backend.
1774 * Accepts exactly 1 argument. Argument is a server, other types will lead to
1775 * undefined behaviour.
1776 */
Hervé COMMOWICKdaa824e2011-08-05 12:09:44 +02001777static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001778smp_fetch_srv_conn(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001779 const struct arg *args, struct sample *smp, const char *kw)
Hervé COMMOWICKdaa824e2011-08-05 12:09:44 +02001780{
Willy Tarreauf853c462012-04-23 18:53:56 +02001781 smp->flags = SMP_F_VOL_TEST;
1782 smp->type = SMP_T_UINT;
Willy Tarreau24e32d82012-04-23 23:55:44 +02001783 smp->data.uint = args->data.srv->cur_sess;
Hervé COMMOWICKdaa824e2011-08-05 12:09:44 +02001784 return 1;
1785}
1786
Tait Clarridge7896d522012-12-05 21:39:31 -05001787/* set temp integer to the number of enabled servers on the proxy.
1788 * Accepts exactly 1 argument. Argument is a server, other types will lead to
1789 * undefined behaviour.
1790 */
1791static int
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001792smp_fetch_srv_sess_rate(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
Willy Tarreauef38c392013-07-22 16:29:32 +02001793 const struct arg *args, struct sample *smp, const char *kw)
Tait Clarridge7896d522012-12-05 21:39:31 -05001794{
1795 smp->flags = SMP_F_VOL_TEST;
1796 smp->type = SMP_T_UINT;
1797 smp->data.uint = read_freq_ctr(&args->data.srv->sess_per_sec);
1798 return 1;
1799}
1800
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001801
1802/* Note: must not be declared <const> as its list will be overwritten.
1803 * Please take care of keeping this list alphabetically sorted.
1804 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001805static struct sample_fetch_kw_list smp_kws = {ILH, {
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001806 { "avg_queue", smp_fetch_avg_queue_size, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1807 { "be_conn", smp_fetch_be_conn, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1808 { "be_id", smp_fetch_be_id, 0, NULL, SMP_T_UINT, SMP_USE_BKEND, },
1809 { "be_sess_rate", smp_fetch_be_sess_rate, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1810 { "connslots", smp_fetch_connslots, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1811 { "nbsrv", smp_fetch_nbsrv, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1812 { "queue", smp_fetch_queue_size, ARG1(1,BE), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1813 { "srv_conn", smp_fetch_srv_conn, ARG1(1,SRV), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1814 { "srv_id", smp_fetch_srv_id, 0, NULL, SMP_T_UINT, SMP_USE_SERVR, },
1815 { "srv_is_up", smp_fetch_srv_is_up, ARG1(1,SRV), NULL, SMP_T_BOOL, SMP_USE_INTRN, },
1816 { "srv_sess_rate", smp_fetch_srv_sess_rate, ARG1(1,SRV), NULL, SMP_T_UINT, SMP_USE_INTRN, },
1817 { /* END */ },
1818}};
1819
1820
Willy Tarreau61612d42012-04-19 18:42:05 +02001821/* Note: must not be declared <const> as its list will be overwritten.
1822 * Please take care of keeping this list alphabetically sorted.
1823 */
Willy Tarreaudc13c112013-06-21 23:16:39 +02001824static struct acl_kw_list acl_kws = {ILH, {
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001825 { /* END */ },
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001826}};
1827
1828
1829__attribute__((constructor))
1830static void __backend_init(void)
1831{
Willy Tarreau1a7eca12013-01-07 22:38:03 +01001832 sample_register_fetches(&smp_kws);
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001833 acl_register_keywords(&acl_kws);
1834}
1835
Willy Tarreaubaaee002006-06-26 02:48:02 +02001836/*
1837 * Local variables:
1838 * c-indent-level: 8
1839 * c-basic-offset: 8
1840 * End:
1841 */