blob: ffd3bcab543a84ed6686787fd29bbb96a69519a8 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Backend variables and functions.
3 *
Willy Tarreauf89c1872009-10-01 11:19:37 +02004 * Copyright 2000-2009 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 Tarreau2dd0d472006-06-29 17:53:05 +020022#include <common/compat.h>
Willy Tarreaue3ba5f02006-06-29 18:54:54 +020023#include <common/config.h>
Willy Tarreau7c669d72008-06-20 15:04:11 +020024#include <common/debug.h>
Willy Tarreau0c303ee2008-07-07 00:09:58 +020025#include <common/ticks.h>
Willy Tarreau2dd0d472006-06-29 17:53:05 +020026#include <common/time.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020027
Willy Tarreaubaaee002006-06-26 02:48:02 +020028#include <types/global.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020029
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +010030#include <proto/acl.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020031#include <proto/backend.h>
Willy Tarreau14c8aac2007-05-08 19:46:30 +020032#include <proto/client.h>
Willy Tarreau6b2e11b2009-10-01 07:52:15 +020033#include <proto/lb_chash.h>
Willy Tarreauf89c1872009-10-01 11:19:37 +020034#include <proto/lb_fwlc.h>
35#include <proto/lb_fwrr.h>
36#include <proto/lb_map.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020037#include <proto/proto_http.h>
Willy Tarreaue8c66af2008-01-13 18:40:14 +010038#include <proto/proto_tcp.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020039#include <proto/queue.h>
Willy Tarreau7f062c42009-03-05 18:43:00 +010040#include <proto/server.h>
Willy Tarreau7c669d72008-06-20 15:04:11 +020041#include <proto/session.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020042#include <proto/task.h>
43
Willy Tarreaubaaee002006-06-26 02:48:02 +020044/*
45 * This function recounts the number of usable active and backup servers for
46 * proxy <p>. These numbers are returned into the p->srv_act and p->srv_bck.
Willy Tarreaub625a082007-11-26 01:15:43 +010047 * This function also recomputes the total active and backup weights. However,
Willy Tarreauf4cca452008-03-08 21:42:54 +010048 * it does not update tot_weight nor tot_used. Use update_backend_weight() for
Willy Tarreaub625a082007-11-26 01:15:43 +010049 * this.
Willy Tarreaubaaee002006-06-26 02:48:02 +020050 */
Willy Tarreauc5d9c802009-10-01 09:17:05 +020051void recount_servers(struct proxy *px)
Willy Tarreaubaaee002006-06-26 02:48:02 +020052{
53 struct server *srv;
54
Willy Tarreau20697042007-11-15 23:26:18 +010055 px->srv_act = px->srv_bck = 0;
56 px->lbprm.tot_wact = px->lbprm.tot_wbck = 0;
Willy Tarreaub625a082007-11-26 01:15:43 +010057 px->lbprm.fbck = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +020058 for (srv = px->srv; srv != NULL; srv = srv->next) {
Willy Tarreaub625a082007-11-26 01:15:43 +010059 if (!srv_is_usable(srv->state, srv->eweight))
60 continue;
61
62 if (srv->state & SRV_BACKUP) {
63 if (!px->srv_bck &&
Willy Tarreauf4cca452008-03-08 21:42:54 +010064 !(px->options & PR_O_USE_ALL_BK))
Willy Tarreaub625a082007-11-26 01:15:43 +010065 px->lbprm.fbck = srv;
66 px->srv_bck++;
67 px->lbprm.tot_wbck += srv->eweight;
68 } else {
69 px->srv_act++;
70 px->lbprm.tot_wact += srv->eweight;
Willy Tarreaubaaee002006-06-26 02:48:02 +020071 }
72 }
Willy Tarreaub625a082007-11-26 01:15:43 +010073}
Willy Tarreau20697042007-11-15 23:26:18 +010074
Willy Tarreaub625a082007-11-26 01:15:43 +010075/* This function simply updates the backend's tot_weight and tot_used values
76 * after servers weights have been updated. It is designed to be used after
77 * recount_servers() or equivalent.
78 */
Willy Tarreauc5d9c802009-10-01 09:17:05 +020079void update_backend_weight(struct proxy *px)
Willy Tarreaub625a082007-11-26 01:15:43 +010080{
Willy Tarreau20697042007-11-15 23:26:18 +010081 if (px->srv_act) {
82 px->lbprm.tot_weight = px->lbprm.tot_wact;
83 px->lbprm.tot_used = px->srv_act;
84 }
Willy Tarreaub625a082007-11-26 01:15:43 +010085 else if (px->lbprm.fbck) {
86 /* use only the first backup server */
87 px->lbprm.tot_weight = px->lbprm.fbck->eweight;
88 px->lbprm.tot_used = 1;
Willy Tarreau20697042007-11-15 23:26:18 +010089 }
90 else {
Willy Tarreaub625a082007-11-26 01:15:43 +010091 px->lbprm.tot_weight = px->lbprm.tot_wbck;
92 px->lbprm.tot_used = px->srv_bck;
Willy Tarreau20697042007-11-15 23:26:18 +010093 }
Willy Tarreaub625a082007-11-26 01:15:43 +010094}
95
Willy Tarreau39c9ba72009-10-01 21:11:15 +020096/*
97 * This function tries to find a running server for the proxy <px> following
98 * the source hash method. Depending on the number of active/backup servers,
99 * it will either look for active servers, or for backup servers.
100 * If any server is found, it will be returned. If no valid server is found,
101 * NULL is returned.
102 */
103struct server *get_server_sh(struct proxy *px, const char *addr, int len)
104{
105 unsigned int h, l;
106
107 if (px->lbprm.tot_weight == 0)
108 return NULL;
109
110 l = h = 0;
111
112 /* note: we won't hash if there's only one server left */
113 if (px->lbprm.tot_used == 1)
114 goto hash_done;
115
116 while ((l + sizeof (int)) <= len) {
117 h ^= ntohl(*(unsigned int *)(&addr[l]));
118 l += sizeof (int);
119 }
120 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200121 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
122 return chash_get_server_hash(px, h);
123 else
124 return map_get_server_hash(px, h);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200125}
126
127/*
128 * This function tries to find a running server for the proxy <px> following
129 * the URI hash method. In order to optimize cache hits, the hash computation
130 * ends at the question mark. Depending on the number of active/backup servers,
131 * it will either look for active servers, or for backup servers.
132 * If any server is found, it will be returned. If no valid server is found,
133 * NULL is returned.
134 *
135 * This code was contributed by Guillaume Dallaire, who also selected this hash
136 * algorithm out of a tens because it gave him the best results.
137 *
138 */
139struct server *get_server_uh(struct proxy *px, char *uri, int uri_len)
140{
141 unsigned long hash = 0;
142 int c;
143 int slashes = 0;
144
145 if (px->lbprm.tot_weight == 0)
146 return NULL;
147
148 /* note: we won't hash if there's only one server left */
149 if (px->lbprm.tot_used == 1)
150 goto hash_done;
151
152 if (px->uri_len_limit)
153 uri_len = MIN(uri_len, px->uri_len_limit);
154
155 while (uri_len--) {
156 c = *uri++;
157 if (c == '/') {
158 slashes++;
159 if (slashes == px->uri_dirs_depth1) /* depth+1 */
160 break;
161 }
162 else if (c == '?')
163 break;
164
165 hash = c + (hash << 6) + (hash << 16) - hash;
166 }
167 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200168 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
169 return chash_get_server_hash(px, hash);
170 else
171 return map_get_server_hash(px, hash);
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200172}
173
Willy Tarreau01732802007-11-01 22:48:15 +0100174/*
175 * This function tries to find a running server for the proxy <px> following
176 * the URL parameter hash method. It looks for a specific parameter in the
177 * URL and hashes it to compute the server ID. This is useful to optimize
178 * performance by avoiding bounces between servers in contexts where sessions
179 * are shared but cookies are not usable. If the parameter is not found, NULL
180 * is returned. If any server is found, it will be returned. If no valid server
181 * is found, NULL is returned.
Willy Tarreau01732802007-11-01 22:48:15 +0100182 */
183struct server *get_server_ph(struct proxy *px, const char *uri, int uri_len)
184{
185 unsigned long hash = 0;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200186 const char *p;
187 const char *params;
Willy Tarreau01732802007-11-01 22:48:15 +0100188 int plen;
189
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200190 /* when tot_weight is 0 then so is srv_count */
Willy Tarreau20697042007-11-15 23:26:18 +0100191 if (px->lbprm.tot_weight == 0)
Willy Tarreau01732802007-11-01 22:48:15 +0100192 return NULL;
193
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200194 if ((p = memchr(uri, '?', uri_len)) == NULL)
195 return NULL;
196
Willy Tarreau01732802007-11-01 22:48:15 +0100197 p++;
198
199 uri_len -= (p - uri);
200 plen = px->url_param_len;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200201 params = p;
Willy Tarreau01732802007-11-01 22:48:15 +0100202
203 while (uri_len > plen) {
204 /* Look for the parameter name followed by an equal symbol */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200205 if (params[plen] == '=') {
206 if (memcmp(params, px->url_param_name, plen) == 0) {
207 /* OK, we have the parameter here at <params>, and
Willy Tarreau01732802007-11-01 22:48:15 +0100208 * the value after the equal sign, at <p>
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200209 * skip the equal symbol
Willy Tarreau01732802007-11-01 22:48:15 +0100210 */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200211 p += plen + 1;
212 uri_len -= plen + 1;
213
Willy Tarreau01732802007-11-01 22:48:15 +0100214 while (uri_len && *p != '&') {
215 hash = *p + (hash << 6) + (hash << 16) - hash;
216 uri_len--;
217 p++;
218 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200219 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
220 return chash_get_server_hash(px, hash);
221 else
222 return map_get_server_hash(px, hash);
Willy Tarreau01732802007-11-01 22:48:15 +0100223 }
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200224 }
225 /* skip to next parameter */
226 p = memchr(params, '&', uri_len);
227 if (!p)
228 return NULL;
229 p++;
230 uri_len -= (p - params);
231 params = p;
232 }
233 return NULL;
234}
235
236/*
237 * this does the same as the previous server_ph, but check the body contents
238 */
239struct server *get_server_ph_post(struct session *s)
240{
241 unsigned long hash = 0;
242 struct http_txn *txn = &s->txn;
243 struct buffer *req = s->req;
244 struct http_msg *msg = &txn->req;
245 struct proxy *px = s->be;
246 unsigned int plen = px->url_param_len;
Willy Tarreau157dd632009-12-06 19:18:09 +0100247 unsigned long len = msg->hdr_content_len;
248 const char *params = req->data + msg->sov;
249 const char *p = params;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200250
Willy Tarreau7c96f672009-12-27 22:47:25 +0100251 if (len > req->l - (msg->sov - msg->som))
252 len = req->l - (msg->sov - msg->som);
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200253
Willy Tarreau157dd632009-12-06 19:18:09 +0100254 if (len == 0)
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200255 return NULL;
256
Willy Tarreau157dd632009-12-06 19:18:09 +0100257 if (px->lbprm.tot_weight == 0)
258 return NULL;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200259
260 while (len > plen) {
261 /* Look for the parameter name followed by an equal symbol */
262 if (params[plen] == '=') {
263 if (memcmp(params, px->url_param_name, plen) == 0) {
264 /* OK, we have the parameter here at <params>, and
265 * the value after the equal sign, at <p>
266 * skip the equal symbol
267 */
268 p += plen + 1;
269 len -= plen + 1;
270
271 while (len && *p != '&') {
272 if (unlikely(!HTTP_IS_TOKEN(*p))) {
Willy Tarreau157dd632009-12-06 19:18:09 +0100273 /* if in a POST, body must be URI encoded or it's not a URI.
274 * Do not interprete any possible binary data as a parameter.
275 */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200276 if (likely(HTTP_IS_LWS(*p))) /* eol, uncertain uri len */
277 break;
278 return NULL; /* oh, no; this is not uri-encoded.
279 * This body does not contain parameters.
280 */
281 }
282 hash = *p + (hash << 6) + (hash << 16) - hash;
283 len--;
284 p++;
285 /* should we break if vlen exceeds limit? */
286 }
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200287 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
288 return chash_get_server_hash(px, hash);
289 else
290 return map_get_server_hash(px, hash);
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200291 }
292 }
Willy Tarreau01732802007-11-01 22:48:15 +0100293 /* skip to next parameter */
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200294 p = memchr(params, '&', len);
Willy Tarreau01732802007-11-01 22:48:15 +0100295 if (!p)
296 return NULL;
297 p++;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200298 len -= (p - params);
299 params = p;
Willy Tarreau01732802007-11-01 22:48:15 +0100300 }
301 return NULL;
302}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200303
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200304
Willy Tarreaubaaee002006-06-26 02:48:02 +0200305/*
Benoitaffb4812009-03-25 13:02:10 +0100306 * This function tries to find a running server for the proxy <px> following
307 * the Header parameter hash method. It looks for a specific parameter in the
308 * URL and hashes it to compute the server ID. This is useful to optimize
309 * performance by avoiding bounces between servers in contexts where sessions
310 * are shared but cookies are not usable. If the parameter is not found, NULL
311 * is returned. If any server is found, it will be returned. If no valid server
312 * is found, NULL is returned.
313 */
314struct server *get_server_hh(struct session *s)
315{
316 unsigned long hash = 0;
317 struct http_txn *txn = &s->txn;
318 struct http_msg *msg = &txn->req;
319 struct proxy *px = s->be;
320 unsigned int plen = px->hh_len;
321 unsigned long len;
322 struct hdr_ctx ctx;
323 const char *p;
324
325 /* tot_weight appears to mean srv_count */
326 if (px->lbprm.tot_weight == 0)
327 return NULL;
328
Benoitaffb4812009-03-25 13:02:10 +0100329 ctx.idx = 0;
330
331 /* if the message is chunked, we skip the chunk size, but use the value as len */
332 http_find_header2(px->hh_name, plen, msg->sol, &txn->hdr_idx, &ctx);
333
334 /* if the header is not found or empty, let's fallback to round robin */
335 if (!ctx.idx || !ctx.vlen)
336 return NULL;
337
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200338 /* note: we won't hash if there's only one server left */
339 if (px->lbprm.tot_used == 1)
340 goto hash_done;
341
Benoitaffb4812009-03-25 13:02:10 +0100342 /* Found a the hh_name in the headers.
343 * we will compute the hash based on this value ctx.val.
344 */
345 len = ctx.vlen;
346 p = (char *)ctx.line + ctx.val;
347 if (!px->hh_match_domain) {
348 while (len) {
349 hash = *p + (hash << 6) + (hash << 16) - hash;
350 len--;
351 p++;
352 }
353 } else {
354 int dohash = 0;
355 p += len - 1;
356 /* special computation, use only main domain name, not tld/host
357 * going back from the end of string, start hashing at first
358 * dot stop at next.
359 * This is designed to work with the 'Host' header, and requires
360 * a special option to activate this.
361 */
362 while (len) {
363 if (*p == '.') {
364 if (!dohash)
365 dohash = 1;
366 else
367 break;
368 } else {
369 if (dohash)
370 hash = *p + (hash << 6) + (hash << 16) - hash;
371 }
372 len--;
373 p--;
374 }
375 }
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200376 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200377 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
378 return chash_get_server_hash(px, hash);
379 else
380 return map_get_server_hash(px, hash);
Benoitaffb4812009-03-25 13:02:10 +0100381}
382
Emeric Brun736aa232009-06-30 17:56:00 +0200383struct server *get_server_rch(struct session *s)
384{
385 unsigned long hash = 0;
386 struct proxy *px = s->be;
387 unsigned long len;
388 const char *p;
389 int ret;
390 struct acl_expr expr;
391 struct acl_test test;
392
393 /* tot_weight appears to mean srv_count */
394 if (px->lbprm.tot_weight == 0)
395 return NULL;
396
Emeric Brun736aa232009-06-30 17:56:00 +0200397 memset(&expr, 0, sizeof(expr));
398 memset(&test, 0, sizeof(test));
399
400 expr.arg.str = px->hh_name;
401 expr.arg_len = px->hh_len;
402
403 ret = acl_fetch_rdp_cookie(px, s, NULL, ACL_DIR_REQ, &expr, &test);
404 if (ret == 0 || (test.flags & ACL_TEST_F_MAY_CHANGE) || test.len == 0)
405 return NULL;
406
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200407 /* note: we won't hash if there's only one server left */
408 if (px->lbprm.tot_used == 1)
409 goto hash_done;
410
Emeric Brun736aa232009-06-30 17:56:00 +0200411 /* Found a the hh_name in the headers.
412 * we will compute the hash based on this value ctx.val.
413 */
414 len = test.len;
415 p = (char *)test.ptr;
416 while (len) {
417 hash = *p + (hash << 6) + (hash << 16) - hash;
418 len--;
419 p++;
420 }
Willy Tarreau39c9ba72009-10-01 21:11:15 +0200421 hash_done:
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200422 if (px->lbprm.algo & BE_LB_LKUP_CHTREE)
423 return chash_get_server_hash(px, hash);
424 else
425 return map_get_server_hash(px, hash);
Emeric Brun736aa232009-06-30 17:56:00 +0200426}
Benoitaffb4812009-03-25 13:02:10 +0100427
428/*
Willy Tarreau7c669d72008-06-20 15:04:11 +0200429 * This function applies the load-balancing algorithm to the session, as
430 * defined by the backend it is assigned to. The session is then marked as
431 * 'assigned'.
432 *
433 * This function MAY NOT be called with SN_ASSIGNED already set. If the session
434 * had a server previously assigned, it is rebalanced, trying to avoid the same
435 * server.
436 * The function tries to keep the original connection slot if it reconnects to
437 * the same server, otherwise it releases it and tries to offer it.
438 *
439 * It is illegal to call this function with a session in a queue.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200440 *
441 * It may return :
Willy Tarreau7c669d72008-06-20 15:04:11 +0200442 * SRV_STATUS_OK if everything is OK. Session assigned to ->srv
443 * SRV_STATUS_NOSRV if no server is available. Session is not ASSIGNED
444 * SRV_STATUS_FULL if all servers are saturated. Session is not ASSIGNED
Willy Tarreaubaaee002006-06-26 02:48:02 +0200445 * SRV_STATUS_INTERNAL for other unrecoverable errors.
446 *
Willy Tarreau7c669d72008-06-20 15:04:11 +0200447 * Upon successful return, the session flag SN_ASSIGNED is set to indicate that
448 * it does not need to be called anymore. This means that s->srv can be trusted
449 * in balance and direct modes.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200450 *
451 */
452
453int assign_server(struct session *s)
454{
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100455
Willy Tarreau7c669d72008-06-20 15:04:11 +0200456 struct server *conn_slot;
457 int err;
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100458
Willy Tarreaubaaee002006-06-26 02:48:02 +0200459#ifdef DEBUG_FULL
460 fprintf(stderr,"assign_server : s=%p\n",s);
461#endif
462
Willy Tarreau7c669d72008-06-20 15:04:11 +0200463 err = SRV_STATUS_INTERNAL;
464 if (unlikely(s->pend_pos || s->flags & SN_ASSIGNED))
465 goto out_err;
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100466
Willy Tarreau7c669d72008-06-20 15:04:11 +0200467 s->prev_srv = s->prev_srv;
468 conn_slot = s->srv_conn;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200469
Willy Tarreau7c669d72008-06-20 15:04:11 +0200470 /* We have to release any connection slot before applying any LB algo,
471 * otherwise we may erroneously end up with no available slot.
472 */
473 if (conn_slot)
474 sess_change_server(s, NULL);
475
476 /* We will now try to find the good server and store it into <s->srv>.
477 * Note that <s->srv> may be NULL in case of dispatch or proxy mode,
478 * as well as if no server is available (check error code).
479 */
Willy Tarreau1a20a5d2007-11-01 21:08:19 +0100480
Willy Tarreau7c669d72008-06-20 15:04:11 +0200481 s->srv = NULL;
Willy Tarreauf3e49f92009-10-03 12:21:20 +0200482 if (s->be->lbprm.algo & BE_LB_KIND) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200483 int len;
484 /* we must check if we have at least one server available */
485 if (!s->be->lbprm.tot_weight) {
486 err = SRV_STATUS_NOSRV;
487 goto out;
488 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200489
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200490 /* First check whether we need to fetch some data or simply call
491 * the LB lookup function. Only the hashing functions will need
492 * some input data in fact, and will support multiple algorithms.
493 */
494 switch (s->be->lbprm.algo & BE_LB_LKUP) {
495 case BE_LB_LKUP_RRTREE:
Willy Tarreau7c669d72008-06-20 15:04:11 +0200496 s->srv = fwrr_get_next_server(s->be, s->prev_srv);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200497 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200498
499 case BE_LB_LKUP_LCTREE:
Willy Tarreau7c669d72008-06-20 15:04:11 +0200500 s->srv = fwlc_get_next_server(s->be, s->prev_srv);
Willy Tarreau7c669d72008-06-20 15:04:11 +0200501 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200502
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200503 case BE_LB_LKUP_CHTREE:
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200504 case BE_LB_LKUP_MAP:
Willy Tarreau9757a382009-10-03 12:56:50 +0200505 if ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR) {
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200506 if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
507 s->srv = chash_get_next_server(s->be, s->prev_srv);
508 else
509 s->srv = map_get_server_rr(s->be, s->prev_srv);
Willy Tarreau9757a382009-10-03 12:56:50 +0200510 break;
511 }
512 else if ((s->be->lbprm.algo & BE_LB_KIND) != BE_LB_KIND_HI) {
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200513 /* unknown balancing algorithm */
Willy Tarreau7c669d72008-06-20 15:04:11 +0200514 err = SRV_STATUS_INTERNAL;
515 goto out;
516 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200517
518 switch (s->be->lbprm.algo & BE_LB_PARM) {
519 case BE_LB_HASH_SRC:
520 if (s->cli_addr.ss_family == AF_INET)
521 len = 4;
522 else if (s->cli_addr.ss_family == AF_INET6)
523 len = 16;
524 else {
525 /* unknown IP family */
526 err = SRV_STATUS_INTERNAL;
527 goto out;
528 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200529
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200530 s->srv = get_server_sh(s->be,
531 (void *)&((struct sockaddr_in *)&s->cli_addr)->sin_addr,
532 len);
533 break;
534
535 case BE_LB_HASH_URI:
536 /* URI hashing */
Willy Tarreaueaed5a12010-03-24 14:54:30 +0100537 if (s->txn.req.msg_state < HTTP_MSG_BODY)
538 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200539 s->srv = get_server_uh(s->be,
Willy Tarreau962c3f42010-01-10 00:15:35 +0100540 s->txn.req.sol + s->txn.req.sl.rq.u,
Willy Tarreau2fcb5002007-05-08 13:35:26 +0200541 s->txn.req.sl.rq.u_l);
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200542 break;
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +0200543
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200544 case BE_LB_HASH_PRM:
545 /* URL Parameter hashing */
Willy Tarreaueaed5a12010-03-24 14:54:30 +0100546 if (s->txn.req.msg_state < HTTP_MSG_BODY)
547 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200548 if (s->txn.meth == HTTP_METH_POST &&
Willy Tarreau962c3f42010-01-10 00:15:35 +0100549 memchr(s->txn.req.sol + s->txn.req.sl.rq.u, '&',
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200550 s->txn.req.sl.rq.u_l ) == NULL)
551 s->srv = get_server_ph_post(s);
552 else
553 s->srv = get_server_ph(s->be,
Willy Tarreau962c3f42010-01-10 00:15:35 +0100554 s->txn.req.sol + s->txn.req.sl.rq.u,
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200555 s->txn.req.sl.rq.u_l);
556 break;
Benoitaffb4812009-03-25 13:02:10 +0100557
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200558 case BE_LB_HASH_HDR:
559 /* Header Parameter hashing */
Willy Tarreaueaed5a12010-03-24 14:54:30 +0100560 if (s->txn.req.msg_state < HTTP_MSG_BODY)
561 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200562 s->srv = get_server_hh(s);
563 break;
564
565 case BE_LB_HASH_RDP:
566 /* RDP Cookie hashing */
567 s->srv = get_server_rch(s);
568 break;
569
570 default:
571 /* unknown balancing algorithm */
572 err = SRV_STATUS_INTERNAL;
573 goto out;
Benoitaffb4812009-03-25 13:02:10 +0100574 }
Emeric Brun736aa232009-06-30 17:56:00 +0200575
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200576 /* If the hashing parameter was not found, let's fall
577 * back to round robin on the map.
578 */
Willy Tarreau6b2e11b2009-10-01 07:52:15 +0200579 if (!s->srv) {
580 if (s->be->lbprm.algo & BE_LB_LKUP_CHTREE)
581 s->srv = chash_get_next_server(s->be, s->prev_srv);
582 else
583 s->srv = map_get_server_rr(s->be, s->prev_srv);
584 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200585
586 /* end of map-based LB */
Emeric Brun736aa232009-06-30 17:56:00 +0200587 break;
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200588
Willy Tarreau7c669d72008-06-20 15:04:11 +0200589 default:
590 /* unknown balancing algorithm */
591 err = SRV_STATUS_INTERNAL;
592 goto out;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200593 }
Willy Tarreauda76f4f2009-10-03 12:36:05 +0200594
595 if (!s->srv) {
596 err = SRV_STATUS_FULL;
597 goto out;
598 }
599 else if (s->srv != s->prev_srv) {
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200600 s->be->counters.cum_lbconn++;
601 s->srv->counters.cum_lbconn++;
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100602 }
Willy Tarreau7c669d72008-06-20 15:04:11 +0200603 }
604 else if (s->be->options & PR_O_HTTP_PROXY) {
605 if (!s->srv_addr.sin_addr.s_addr) {
606 err = SRV_STATUS_NOSRV;
607 goto out;
Willy Tarreau5d65bbb2007-01-21 12:47:26 +0100608 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200609 }
Willy Tarreau7c669d72008-06-20 15:04:11 +0200610 else if (!*(int *)&s->be->dispatch_addr.sin_addr &&
Willy Tarreau4b1f8592008-12-23 23:13:55 +0100611 !(s->be->options & PR_O_TRANSP)) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200612 err = SRV_STATUS_NOSRV;
613 goto out;
614 }
615
616 s->flags |= SN_ASSIGNED;
617 err = SRV_STATUS_OK;
618 out:
619
620 /* Either we take back our connection slot, or we offer it to someone
621 * else if we don't need it anymore.
622 */
623 if (conn_slot) {
624 if (conn_slot == s->srv) {
625 sess_change_server(s, s->srv);
626 } else {
627 if (may_dequeue_tasks(conn_slot, s->be))
628 process_srv_queue(conn_slot);
629 }
630 }
631
632 out_err:
633 return err;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200634}
635
636
637/*
638 * This function assigns a server address to a session, and sets SN_ADDR_SET.
639 * The address is taken from the currently assigned server, or from the
640 * dispatch or transparent address.
641 *
642 * It may return :
643 * SRV_STATUS_OK if everything is OK.
644 * SRV_STATUS_INTERNAL for other unrecoverable errors.
645 *
646 * Upon successful return, the session flag SN_ADDR_SET is set. This flag is
647 * not cleared, so it's to the caller to clear it if required.
648 *
649 */
650int assign_server_address(struct session *s)
651{
652#ifdef DEBUG_FULL
653 fprintf(stderr,"assign_server_address : s=%p\n",s);
654#endif
655
Willy Tarreauf3e49f92009-10-03 12:21:20 +0200656 if ((s->flags & SN_DIRECT) || (s->be->lbprm.algo & BE_LB_KIND)) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200657 /* A server is necessarily known for this session */
658 if (!(s->flags & SN_ASSIGNED))
659 return SRV_STATUS_INTERNAL;
660
661 s->srv_addr = s->srv->addr;
662
663 /* if this server remaps proxied ports, we'll use
664 * the port the client connected to with an offset. */
665 if (s->srv->state & SRV_MAPPORTS) {
Willy Tarreau4b1f8592008-12-23 23:13:55 +0100666 if (!(s->be->options & PR_O_TRANSP) && !(s->flags & SN_FRT_ADDR_SET))
Willy Tarreau14c8aac2007-05-08 19:46:30 +0200667 get_frt_addr(s);
668 if (s->frt_addr.ss_family == AF_INET) {
669 s->srv_addr.sin_port = htons(ntohs(s->srv_addr.sin_port) +
670 ntohs(((struct sockaddr_in *)&s->frt_addr)->sin_port));
671 } else {
672 s->srv_addr.sin_port = htons(ntohs(s->srv_addr.sin_port) +
673 ntohs(((struct sockaddr_in6 *)&s->frt_addr)->sin6_port));
674 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200675 }
676 }
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200677 else if (*(int *)&s->be->dispatch_addr.sin_addr) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200678 /* connect to the defined dispatch addr */
Willy Tarreaue2e27a52007-04-01 00:01:37 +0200679 s->srv_addr = s->be->dispatch_addr;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200680 }
Willy Tarreau4b1f8592008-12-23 23:13:55 +0100681 else if (s->be->options & PR_O_TRANSP) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200682 /* in transparent mode, use the original dest addr if no dispatch specified */
Willy Tarreaubd414282008-01-19 13:46:35 +0100683 if (!(s->flags & SN_FRT_ADDR_SET))
684 get_frt_addr(s);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200685
Willy Tarreaubd414282008-01-19 13:46:35 +0100686 memcpy(&s->srv_addr, &s->frt_addr, MIN(sizeof(s->srv_addr), sizeof(s->frt_addr)));
687 /* when we support IPv6 on the backend, we may add other tests */
688 //qfprintf(stderr, "Cannot get original server address.\n");
689 //return SRV_STATUS_INTERNAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200690 }
Alexandre Cassen5eb1a902007-11-29 15:43:32 +0100691 else if (s->be->options & PR_O_HTTP_PROXY) {
692 /* If HTTP PROXY option is set, then server is already assigned
693 * during incoming client request parsing. */
694 }
Willy Tarreau1a1158b2007-01-20 11:07:46 +0100695 else {
696 /* no server and no LB algorithm ! */
697 return SRV_STATUS_INTERNAL;
698 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200699
700 s->flags |= SN_ADDR_SET;
701 return SRV_STATUS_OK;
702}
703
704
705/* This function assigns a server to session <s> if required, and can add the
706 * connection to either the assigned server's queue or to the proxy's queue.
Willy Tarreau7c669d72008-06-20 15:04:11 +0200707 * If ->srv_conn is set, the session is first released from the server.
708 * It may also be called with SN_DIRECT and/or SN_ASSIGNED though. It will
709 * be called before any connection and after any retry or redispatch occurs.
710 *
711 * It is not allowed to call this function with a session in a queue.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200712 *
713 * Returns :
714 *
715 * SRV_STATUS_OK if everything is OK.
716 * SRV_STATUS_NOSRV if no server is available. s->srv = NULL.
717 * SRV_STATUS_QUEUED if the connection has been queued.
718 * SRV_STATUS_FULL if the server(s) is/are saturated and the
Willy Tarreau7c669d72008-06-20 15:04:11 +0200719 * connection could not be queued in s->srv,
720 * which may be NULL if we queue on the backend.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200721 * SRV_STATUS_INTERNAL for other unrecoverable errors.
722 *
723 */
724int assign_server_and_queue(struct session *s)
725{
726 struct pendconn *p;
727 int err;
728
729 if (s->pend_pos)
730 return SRV_STATUS_INTERNAL;
731
Willy Tarreau7c669d72008-06-20 15:04:11 +0200732 err = SRV_STATUS_OK;
733 if (!(s->flags & SN_ASSIGNED)) {
734 err = assign_server(s);
735 if (s->prev_srv) {
736 /* This session was previously assigned to a server. We have to
737 * update the session's and the server's stats :
738 * - if the server changed :
739 * - set TX_CK_DOWN if txn.flags was TX_CK_VALID
740 * - set SN_REDISP if it was successfully redispatched
741 * - increment srv->redispatches and be->redispatches
742 * - if the server remained the same : update retries.
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100743 */
744
Willy Tarreau7c669d72008-06-20 15:04:11 +0200745 if (s->prev_srv != s->srv) {
746 if ((s->txn.flags & TX_CK_MASK) == TX_CK_VALID) {
747 s->txn.flags &= ~TX_CK_MASK;
748 s->txn.flags |= TX_CK_DOWN;
749 }
750 s->flags |= SN_REDISP;
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200751 s->prev_srv->counters.redispatches++;
752 s->be->counters.redispatches++;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200753 } else {
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200754 s->prev_srv->counters.retries++;
755 s->be->counters.retries++;
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100756 }
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100757 }
758 }
759
Willy Tarreaubaaee002006-06-26 02:48:02 +0200760 switch (err) {
761 case SRV_STATUS_OK:
Willy Tarreau7c669d72008-06-20 15:04:11 +0200762 /* we have SN_ASSIGNED set */
763 if (!s->srv)
764 return SRV_STATUS_OK; /* dispatch or proxy mode */
765
766 /* If we already have a connection slot, no need to check any queue */
767 if (s->srv_conn == s->srv)
768 return SRV_STATUS_OK;
769
770 /* OK, this session already has an assigned server, but no
771 * connection slot yet. Either it is a redispatch, or it was
772 * assigned from persistence information (direct mode).
773 */
774 if ((s->flags & SN_REDIRECTABLE) && s->srv->rdr_len) {
775 /* server scheduled for redirection, and already assigned. We
776 * don't want to go further nor check the queue.
Willy Tarreau21d2af32008-02-14 20:25:24 +0100777 */
Willy Tarreau7c669d72008-06-20 15:04:11 +0200778 sess_change_server(s, s->srv); /* not really needed in fact */
Willy Tarreau21d2af32008-02-14 20:25:24 +0100779 return SRV_STATUS_OK;
780 }
781
Willy Tarreau7c669d72008-06-20 15:04:11 +0200782 /* We might have to queue this session if the assigned server is full.
783 * We know we have to queue it into the server's queue, so if a maxqueue
784 * is set on the server, we must also check that the server's queue is
785 * not full, in which case we have to return FULL.
786 */
787 if (s->srv->maxconn &&
788 (s->srv->nbpend || s->srv->served >= srv_dynamic_maxconn(s->srv))) {
789
790 if (s->srv->maxqueue > 0 && s->srv->nbpend >= s->srv->maxqueue)
791 return SRV_STATUS_FULL;
792
Willy Tarreaubaaee002006-06-26 02:48:02 +0200793 p = pendconn_add(s);
794 if (p)
795 return SRV_STATUS_QUEUED;
796 else
Willy Tarreau7c669d72008-06-20 15:04:11 +0200797 return SRV_STATUS_INTERNAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200798 }
Willy Tarreau7c669d72008-06-20 15:04:11 +0200799
800 /* OK, we can use this server. Let's reserve our place */
801 sess_change_server(s, s->srv);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200802 return SRV_STATUS_OK;
803
804 case SRV_STATUS_FULL:
805 /* queue this session into the proxy's queue */
806 p = pendconn_add(s);
807 if (p)
808 return SRV_STATUS_QUEUED;
809 else
Willy Tarreau7c669d72008-06-20 15:04:11 +0200810 return SRV_STATUS_INTERNAL;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200811
812 case SRV_STATUS_NOSRV:
Willy Tarreau7c669d72008-06-20 15:04:11 +0200813 return err;
814
Willy Tarreaubaaee002006-06-26 02:48:02 +0200815 case SRV_STATUS_INTERNAL:
816 return err;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200817
Willy Tarreaubaaee002006-06-26 02:48:02 +0200818 default:
819 return SRV_STATUS_INTERNAL;
820 }
Willy Tarreau5b6995c2008-01-13 16:31:17 +0100821}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200822
Willy Tarreaub1d67742010-03-29 19:36:59 +0200823/* If an explicit source binding is specified on the server and/or backend, and
824 * this source makes use of the transparent proxy, then it is extracted now and
825 * assigned to the session's from_addr entry.
826 */
827static void assign_tproxy_address(struct session *s)
828{
829#if defined(CONFIG_HAP_CTTPROXY) || defined(CONFIG_HAP_LINUX_TPROXY)
830 if (s->srv != NULL && s->srv->state & SRV_BIND_SRC) {
831 switch (s->srv->state & SRV_TPROXY_MASK) {
832 case SRV_TPROXY_ADDR:
833 s->from_addr = *(struct sockaddr_in *)&s->srv->tproxy_addr;
834 break;
835 case SRV_TPROXY_CLI:
836 case SRV_TPROXY_CIP:
837 /* FIXME: what can we do if the client connects in IPv6 ? */
838 s->from_addr = *(struct sockaddr_in *)&s->cli_addr;
839 break;
Willy Tarreaubce70882009-09-07 11:51:47 +0200840 case SRV_TPROXY_DYN:
841 if (s->srv->bind_hdr_occ) {
842 /* bind to the IP in a header */
843 s->from_addr.sin_port = 0;
844 s->from_addr.sin_addr.s_addr = htonl(get_ip_from_hdr2(&s->txn.req,
845 s->srv->bind_hdr_name,
846 s->srv->bind_hdr_len,
847 &s->txn.hdr_idx,
848 s->srv->bind_hdr_occ));
849 }
850 break;
Willy Tarreaub1d67742010-03-29 19:36:59 +0200851 default:
Willy Tarreaubce70882009-09-07 11:51:47 +0200852 memset(&s->from_addr, 0, sizeof(s->from_addr));
Willy Tarreaub1d67742010-03-29 19:36:59 +0200853 }
854 }
855 else if (s->be->options & PR_O_BIND_SRC) {
856 switch (s->be->options & PR_O_TPXY_MASK) {
857 case PR_O_TPXY_ADDR:
858 s->from_addr = *(struct sockaddr_in *)&s->be->tproxy_addr;
859 break;
860 case PR_O_TPXY_CLI:
861 case PR_O_TPXY_CIP:
862 /* FIXME: what can we do if the client connects in IPv6 ? */
863 s->from_addr = *(struct sockaddr_in *)&s->cli_addr;
864 break;
Willy Tarreaubce70882009-09-07 11:51:47 +0200865 case PR_O_TPXY_DYN:
866 if (s->be->bind_hdr_occ) {
867 /* bind to the IP in a header */
868 s->from_addr.sin_port = 0;
869 s->from_addr.sin_addr.s_addr = htonl(get_ip_from_hdr2(&s->txn.req,
870 s->be->bind_hdr_name,
871 s->be->bind_hdr_len,
872 &s->txn.hdr_idx,
873 s->be->bind_hdr_occ));
874 }
875 break;
Willy Tarreaub1d67742010-03-29 19:36:59 +0200876 default:
Willy Tarreaubce70882009-09-07 11:51:47 +0200877 memset(&s->from_addr, 0, sizeof(s->from_addr));
Willy Tarreaub1d67742010-03-29 19:36:59 +0200878 }
879 }
880#endif
881}
882
883
Willy Tarreaubaaee002006-06-26 02:48:02 +0200884/*
885 * This function initiates a connection to the server assigned to this session
886 * (s->srv, s->srv_addr). It will assign a server if none is assigned yet.
887 * It can return one of :
888 * - SN_ERR_NONE if everything's OK
889 * - SN_ERR_SRVTO if there are no more servers
890 * - SN_ERR_SRVCL if the connection was refused by the server
891 * - SN_ERR_PRXCOND if the connection has been limited by the proxy (maxconn)
892 * - SN_ERR_RESOURCE if a system resource is lacking (eg: fd limits, ports, ...)
893 * - SN_ERR_INTERNAL for any other purely internal errors
894 * Additionnally, in the case of SN_ERR_RESOURCE, an emergency log will be emitted.
895 */
896int connect_server(struct session *s)
897{
Willy Tarreau9650f372009-08-16 14:02:45 +0200898 int err;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200899
900 if (!(s->flags & SN_ADDR_SET)) {
901 err = assign_server_address(s);
902 if (err != SRV_STATUS_OK)
903 return SN_ERR_INTERNAL;
904 }
905
Willy Tarreau9650f372009-08-16 14:02:45 +0200906 if (!s->req->cons->connect)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200907 return SN_ERR_INTERNAL;
Willy Tarreaud88edf22009-06-14 15:48:17 +0200908
Willy Tarreaub1d67742010-03-29 19:36:59 +0200909 assign_tproxy_address(s);
910
Willy Tarreau9650f372009-08-16 14:02:45 +0200911 err = s->req->cons->connect(s->req->cons, s->be, s->srv,
912 (struct sockaddr *)&s->srv_addr,
Willy Tarreaub1d67742010-03-29 19:36:59 +0200913 (struct sockaddr *)&s->from_addr);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200914
Willy Tarreau9650f372009-08-16 14:02:45 +0200915 if (err != SN_ERR_NONE)
916 return err;
Willy Tarreau788e2842008-08-26 13:25:39 +0200917
Willy Tarreaubaaee002006-06-26 02:48:02 +0200918 if (s->srv) {
Willy Tarreau1e62de62008-11-11 20:20:02 +0100919 s->flags |= SN_CURR_SESS;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200920 s->srv->cur_sess++;
Willy Tarreauac68c5d2009-10-04 23:12:44 +0200921 if (s->srv->cur_sess > s->srv->counters.cur_sess_max)
922 s->srv->counters.cur_sess_max = s->srv->cur_sess;
Willy Tarreau51406232008-03-10 22:04:20 +0100923 if (s->be->lbprm.server_take_conn)
924 s->be->lbprm.server_take_conn(s->srv);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200925 }
926
Willy Tarreaubaaee002006-06-26 02:48:02 +0200927 return SN_ERR_NONE; /* connection is OK */
928}
929
930
Willy Tarreaubaaee002006-06-26 02:48:02 +0200931/* This function performs the "redispatch" part of a connection attempt. It
932 * will assign a server if required, queue the connection if required, and
933 * handle errors that might arise at this level. It can change the server
934 * state. It will return 1 if it encounters an error, switches the server
935 * state, or has to queue a connection. Otherwise, it will return 0 indicating
936 * that the connection is ready to use.
937 */
938
939int srv_redispatch_connect(struct session *t)
940{
941 int conn_err;
942
943 /* We know that we don't have any connection pending, so we will
944 * try to get a new one, and wait in this state if it's queued
945 */
Willy Tarreau7c669d72008-06-20 15:04:11 +0200946 redispatch:
Willy Tarreaubaaee002006-06-26 02:48:02 +0200947 conn_err = assign_server_and_queue(t);
948 switch (conn_err) {
949 case SRV_STATUS_OK:
950 break;
951
Willy Tarreau7c669d72008-06-20 15:04:11 +0200952 case SRV_STATUS_FULL:
953 /* The server has reached its maxqueue limit. Either PR_O_REDISP is set
954 * and we can redispatch to another server, or it is not and we return
955 * 503. This only makes sense in DIRECT mode however, because normal LB
956 * algorithms would never select such a server, and hash algorithms
957 * would bring us on the same server again. Note that t->srv is set in
958 * this case.
959 */
Willy Tarreau4de91492010-01-22 19:10:05 +0100960 if (((t->flags & (SN_DIRECT|SN_FORCE_PRST)) == SN_DIRECT) &&
961 (t->be->options & PR_O_REDISP)) {
Willy Tarreau7c669d72008-06-20 15:04:11 +0200962 t->flags &= ~(SN_DIRECT | SN_ASSIGNED | SN_ADDR_SET);
963 t->prev_srv = t->srv;
964 goto redispatch;
965 }
966
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200967 if (!t->req->cons->err_type) {
968 t->req->cons->err_type = SI_ET_QUEUE_ERR;
969 t->req->cons->err_loc = t->srv;
970 }
Willy Tarreau7c669d72008-06-20 15:04:11 +0200971
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200972 t->srv->counters.failed_conns++;
973 t->be->counters.failed_conns++;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200974 return 1;
975
Willy Tarreaubaaee002006-06-26 02:48:02 +0200976 case SRV_STATUS_NOSRV:
977 /* note: it is guaranteed that t->srv == NULL here */
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200978 if (!t->req->cons->err_type) {
979 t->req->cons->err_type = SI_ET_CONN_ERR;
980 t->req->cons->err_loc = NULL;
981 }
Krzysztof Piotr Oledzki5a329cf2008-02-22 03:50:19 +0100982
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +0200983 t->be->counters.failed_conns++;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200984 return 1;
985
986 case SRV_STATUS_QUEUED:
Willy Tarreau35374672008-09-03 18:11:02 +0200987 t->req->cons->exp = tick_add_ifset(now_ms, t->be->timeout.queue);
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200988 t->req->cons->state = SI_ST_QUE;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200989 /* do nothing else and do not wake any other session up */
990 return 1;
991
Willy Tarreaubaaee002006-06-26 02:48:02 +0200992 case SRV_STATUS_INTERNAL:
993 default:
Willy Tarreaufa7e1022008-10-19 07:30:41 +0200994 if (!t->req->cons->err_type) {
995 t->req->cons->err_type = SI_ET_CONN_OTHER;
996 t->req->cons->err_loc = t->srv;
997 }
998
Willy Tarreaubaaee002006-06-26 02:48:02 +0200999 if (t->srv)
Willy Tarreau7f062c42009-03-05 18:43:00 +01001000 srv_inc_sess_ctr(t->srv);
Willy Tarreau98937b82007-12-10 15:05:42 +01001001 if (t->srv)
Krzysztof Piotr Oledzki052d4fd2009-10-04 14:52:57 +02001002 t->srv->counters.failed_conns++;
1003 t->be->counters.failed_conns++;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001004
1005 /* release other sessions waiting for this server */
Willy Tarreaue2e27a52007-04-01 00:01:37 +02001006 if (may_dequeue_tasks(t->srv, t->be))
Willy Tarreau7c669d72008-06-20 15:04:11 +02001007 process_srv_queue(t->srv);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001008 return 1;
1009 }
1010 /* if we get here, it's because we got SRV_STATUS_OK, which also
1011 * means that the connection has not been queued.
1012 */
1013 return 0;
1014}
1015
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001016int be_downtime(struct proxy *px) {
Willy Tarreaub625a082007-11-26 01:15:43 +01001017 if (px->lbprm.tot_weight && px->last_change < now.tv_sec) // ignore negative time
Krzysztof Oledzki85130942007-10-22 16:21:10 +02001018 return px->down_time;
1019
1020 return now.tv_sec - px->last_change + px->down_time;
1021}
Willy Tarreaubaaee002006-06-26 02:48:02 +02001022
Krzysztof Piotr Oledzki15514c22010-01-04 16:03:09 +01001023/*
1024 * This function returns a string containing the balancing
1025 * mode of the proxy in a format suitable for stats.
1026 */
1027
1028const char *backend_lb_algo_str(int algo) {
1029
1030 if (algo == BE_LB_ALGO_RR)
1031 return "roundrobin";
1032 else if (algo == BE_LB_ALGO_SRR)
1033 return "static-rr";
1034 else if (algo == BE_LB_ALGO_LC)
1035 return "leastconn";
1036 else if (algo == BE_LB_ALGO_SH)
1037 return "source";
1038 else if (algo == BE_LB_ALGO_UH)
1039 return "uri";
1040 else if (algo == BE_LB_ALGO_PH)
1041 return "url_param";
1042 else if (algo == BE_LB_ALGO_HH)
1043 return "hdr";
1044 else if (algo == BE_LB_ALGO_RCH)
1045 return "rdp-cookie";
1046 else
1047 return NULL;
1048}
1049
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001050/* This function parses a "balance" statement in a backend section describing
1051 * <curproxy>. It returns -1 if there is any error, otherwise zero. If it
1052 * returns -1, it may write an error message into ther <err> buffer, for at
1053 * most <errlen> bytes, trailing zero included. The trailing '\n' will not be
1054 * written. The function must be called with <args> pointing to the first word
1055 * after "balance".
1056 */
1057int backend_parse_balance(const char **args, char *err, int errlen, struct proxy *curproxy)
1058{
1059 if (!*(args[0])) {
1060 /* if no option is set, use round-robin by default */
Willy Tarreau31682232007-11-29 15:38:04 +01001061 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1062 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001063 return 0;
1064 }
1065
1066 if (!strcmp(args[0], "roundrobin")) {
Willy Tarreau31682232007-11-29 15:38:04 +01001067 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1068 curproxy->lbprm.algo |= BE_LB_ALGO_RR;
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001069 }
Willy Tarreau9757a382009-10-03 12:56:50 +02001070 else if (!strcmp(args[0], "static-rr")) {
1071 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1072 curproxy->lbprm.algo |= BE_LB_ALGO_SRR;
1073 }
Willy Tarreau51406232008-03-10 22:04:20 +01001074 else if (!strcmp(args[0], "leastconn")) {
1075 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1076 curproxy->lbprm.algo |= BE_LB_ALGO_LC;
1077 }
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001078 else if (!strcmp(args[0], "source")) {
Willy Tarreau31682232007-11-29 15:38:04 +01001079 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1080 curproxy->lbprm.algo |= BE_LB_ALGO_SH;
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001081 }
1082 else if (!strcmp(args[0], "uri")) {
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001083 int arg = 1;
1084
Willy Tarreau31682232007-11-29 15:38:04 +01001085 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1086 curproxy->lbprm.algo |= BE_LB_ALGO_UH;
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001087
1088 while (*args[arg]) {
1089 if (!strcmp(args[arg], "len")) {
1090 if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) {
1091 snprintf(err, errlen, "'balance uri len' expects a positive integer (got '%s').", args[arg+1]);
1092 return -1;
1093 }
1094 curproxy->uri_len_limit = atoi(args[arg+1]);
1095 arg += 2;
1096 }
1097 else if (!strcmp(args[arg], "depth")) {
1098 if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) {
1099 snprintf(err, errlen, "'balance uri depth' expects a positive integer (got '%s').", args[arg+1]);
1100 return -1;
1101 }
1102 /* hint: we store the position of the ending '/' (depth+1) so
1103 * that we avoid a comparison while computing the hash.
1104 */
1105 curproxy->uri_dirs_depth1 = atoi(args[arg+1]) + 1;
1106 arg += 2;
1107 }
1108 else {
1109 snprintf(err, errlen, "'balance uri' only accepts parameters 'len' and 'depth' (got '%s').", args[arg]);
1110 return -1;
1111 }
1112 }
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001113 }
Willy Tarreau01732802007-11-01 22:48:15 +01001114 else if (!strcmp(args[0], "url_param")) {
1115 if (!*args[1]) {
1116 snprintf(err, errlen, "'balance url_param' requires an URL parameter name.");
1117 return -1;
1118 }
Willy Tarreau31682232007-11-29 15:38:04 +01001119 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1120 curproxy->lbprm.algo |= BE_LB_ALGO_PH;
Willy Tarreaua534fea2008-08-03 12:19:50 +02001121
1122 free(curproxy->url_param_name);
Willy Tarreau01732802007-11-01 22:48:15 +01001123 curproxy->url_param_name = strdup(args[1]);
Willy Tarreaua534fea2008-08-03 12:19:50 +02001124 curproxy->url_param_len = strlen(args[1]);
Marek Majkowski9c30fc12008-04-27 23:25:55 +02001125 if (*args[2]) {
matt.farnsworth@nokia.com1c2ab962008-04-14 20:47:37 +02001126 if (strcmp(args[2], "check_post")) {
1127 snprintf(err, errlen, "'balance url_param' only accepts check_post modifier.");
1128 return -1;
1129 }
1130 if (*args[3]) {
1131 /* TODO: maybe issue a warning if there is no value, no digits or too long */
1132 curproxy->url_param_post_limit = str2ui(args[3]);
1133 }
1134 /* if no limit, or faul value in args[3], then default to a moderate wordlen */
1135 if (!curproxy->url_param_post_limit)
1136 curproxy->url_param_post_limit = 48;
1137 else if ( curproxy->url_param_post_limit < 3 )
1138 curproxy->url_param_post_limit = 3; /* minimum example: S=3 or \r\nS=6& */
1139 }
Benoitaffb4812009-03-25 13:02:10 +01001140 }
1141 else if (!strncmp(args[0], "hdr(", 4)) {
1142 const char *beg, *end;
1143
1144 beg = args[0] + 4;
1145 end = strchr(beg, ')');
1146
1147 if (!end || end == beg) {
1148 snprintf(err, errlen, "'balance hdr(name)' requires an http header field name.");
1149 return -1;
1150 }
1151
1152 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1153 curproxy->lbprm.algo |= BE_LB_ALGO_HH;
1154
1155 free(curproxy->hh_name);
1156 curproxy->hh_len = end - beg;
1157 curproxy->hh_name = my_strndup(beg, end - beg);
1158 curproxy->hh_match_domain = 0;
1159
1160 if (*args[1]) {
1161 if (strcmp(args[1], "use_domain_only")) {
1162 snprintf(err, errlen, "'balance hdr(name)' only accepts 'use_domain_only' modifier.");
1163 return -1;
1164 }
1165 curproxy->hh_match_domain = 1;
1166 }
1167
Emeric Brun736aa232009-06-30 17:56:00 +02001168 }
1169 else if (!strncmp(args[0], "rdp-cookie", 10)) {
1170 curproxy->lbprm.algo &= ~BE_LB_ALGO;
1171 curproxy->lbprm.algo |= BE_LB_ALGO_RCH;
1172
1173 if ( *(args[0] + 10 ) == '(' ) { /* cookie name */
1174 const char *beg, *end;
1175
1176 beg = args[0] + 11;
1177 end = strchr(beg, ')');
1178
1179 if (!end || end == beg) {
1180 snprintf(err, errlen, "'balance rdp-cookie(name)' requires an rdp cookie name.");
1181 return -1;
1182 }
1183
1184 free(curproxy->hh_name);
1185 curproxy->hh_name = my_strndup(beg, end - beg);
1186 curproxy->hh_len = end - beg;
1187 }
1188 else if ( *(args[0] + 10 ) == '\0' ) { /* default cookie name 'mstshash' */
1189 free(curproxy->hh_name);
1190 curproxy->hh_name = strdup("mstshash");
1191 curproxy->hh_len = strlen(curproxy->hh_name);
1192 }
1193 else { /* syntax */
1194 snprintf(err, errlen, "'balance rdp-cookie(name)' requires an rdp cookie name.");
1195 return -1;
1196 }
Willy Tarreau01732802007-11-01 22:48:15 +01001197 }
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001198 else {
Willy Tarreau9757a382009-10-03 12:56:50 +02001199 snprintf(err, errlen, "'balance' only supports 'roundrobin', 'static-rr', 'leastconn', 'source', 'uri', 'url_param', 'hdr(name)' and 'rdp-cookie(name)' options.");
Willy Tarreaua0cbda62007-11-01 21:39:54 +01001200 return -1;
1201 }
1202 return 0;
1203}
1204
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001205
1206/************************************************************************/
1207/* All supported keywords must be declared here. */
1208/************************************************************************/
1209
1210/* set test->i to the number of enabled servers on the proxy */
1211static int
1212acl_fetch_nbsrv(struct proxy *px, struct session *l4, void *l7, int dir,
1213 struct acl_expr *expr, struct acl_test *test)
1214{
1215 test->flags = ACL_TEST_F_VOL_TEST;
1216 if (expr->arg_len) {
1217 /* another proxy was designated, we must look for it */
1218 for (px = proxy; px; px = px->next)
1219 if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str))
1220 break;
1221 }
1222 if (!px)
1223 return 0;
1224
1225 if (px->srv_act)
1226 test->i = px->srv_act;
1227 else if (px->lbprm.fbck)
1228 test->i = 1;
1229 else
1230 test->i = px->srv_bck;
1231
1232 return 1;
1233}
1234
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001235/* set test->i to the number of enabled servers on the proxy */
1236static int
1237acl_fetch_connslots(struct proxy *px, struct session *l4, void *l7, int dir,
1238 struct acl_expr *expr, struct acl_test *test)
1239{
1240 struct server *iterator;
1241 test->flags = ACL_TEST_F_VOL_TEST;
1242 if (expr->arg_len) {
1243 /* another proxy was designated, we must look for it */
1244 for (px = proxy; px; px = px->next)
1245 if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str))
1246 break;
1247 }
1248 if (!px)
1249 return 0;
1250
1251 test->i = 0;
1252 iterator = px->srv;
1253 while (iterator) {
Willy Tarreaua36af912009-10-10 12:02:45 +02001254 if ((iterator->state & SRV_RUNNING) == 0) {
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001255 iterator = iterator->next;
1256 continue;
1257 }
1258 if (iterator->maxconn == 0 || iterator->maxqueue == 0) {
1259 test->i = -1;
1260 return 1;
1261 }
1262
1263 test->i += (iterator->maxconn - iterator->cur_sess)
1264 + (iterator->maxqueue - iterator->nbpend);
1265 iterator = iterator->next;
1266 }
1267
1268 return 1;
1269}
1270
Willy Tarreau079ff0a2009-03-05 21:34:28 +01001271/* set test->i to the number of connections per second reaching the frontend */
1272static int
1273acl_fetch_fe_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir,
1274 struct acl_expr *expr, struct acl_test *test)
1275{
1276 test->flags = ACL_TEST_F_VOL_TEST;
1277 if (expr->arg_len) {
1278 /* another proxy was designated, we must look for it */
1279 for (px = proxy; px; px = px->next)
1280 if ((px->cap & PR_CAP_FE) && !strcmp(px->id, expr->arg.str))
1281 break;
1282 }
1283 if (!px)
1284 return 0;
1285
1286 test->i = read_freq_ctr(&px->fe_sess_per_sec);
1287 return 1;
1288}
1289
1290/* set test->i to the number of connections per second reaching the backend */
1291static int
1292acl_fetch_be_sess_rate(struct proxy *px, struct session *l4, void *l7, int dir,
1293 struct acl_expr *expr, struct acl_test *test)
1294{
1295 test->flags = ACL_TEST_F_VOL_TEST;
1296 if (expr->arg_len) {
1297 /* another proxy was designated, we must look for it */
1298 for (px = proxy; px; px = px->next)
1299 if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str))
1300 break;
1301 }
1302 if (!px)
1303 return 0;
1304
1305 test->i = read_freq_ctr(&px->be_sess_per_sec);
1306 return 1;
1307}
1308
Willy Tarreaua36af912009-10-10 12:02:45 +02001309/* set test->i to the number of concurrent connections on the frontend */
1310static int
1311acl_fetch_fe_conn(struct proxy *px, struct session *l4, void *l7, int dir,
1312 struct acl_expr *expr, struct acl_test *test)
1313{
1314 test->flags = ACL_TEST_F_VOL_TEST;
1315 if (expr->arg_len) {
1316 /* another proxy was designated, we must look for it */
1317 for (px = proxy; px; px = px->next)
1318 if ((px->cap & PR_CAP_FE) && !strcmp(px->id, expr->arg.str))
1319 break;
1320 }
1321 if (!px)
1322 return 0;
1323
1324 test->i = px->feconn;
1325 return 1;
1326}
1327
1328/* set test->i to the number of concurrent connections on the backend */
1329static int
1330acl_fetch_be_conn(struct proxy *px, struct session *l4, void *l7, int dir,
1331 struct acl_expr *expr, struct acl_test *test)
1332{
1333 test->flags = ACL_TEST_F_VOL_TEST;
1334 if (expr->arg_len) {
1335 /* another proxy was designated, we must look for it */
1336 for (px = proxy; px; px = px->next)
1337 if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str))
1338 break;
1339 }
1340 if (!px)
1341 return 0;
1342
1343 test->i = px->beconn;
1344 return 1;
1345}
1346
1347/* set test->i to the total number of queued connections on the backend */
1348static int
1349acl_fetch_queue_size(struct proxy *px, struct session *l4, void *l7, int dir,
1350 struct acl_expr *expr, struct acl_test *test)
1351{
1352 test->flags = ACL_TEST_F_VOL_TEST;
1353 if (expr->arg_len) {
1354 /* another proxy was designated, we must look for it */
1355 for (px = proxy; px; px = px->next)
1356 if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str))
1357 break;
1358 }
1359 if (!px)
1360 return 0;
1361
1362 test->i = px->totpend;
1363 return 1;
1364}
1365
1366/* set test->i to the total number of queued connections on the backend divided
1367 * by the number of running servers and rounded up. If there is no running
1368 * server, we return twice the total, just as if we had half a running server.
1369 * This is more or less correct anyway, since we expect the last server to come
1370 * back soon.
1371 */
1372static int
1373acl_fetch_avg_queue_size(struct proxy *px, struct session *l4, void *l7, int dir,
1374 struct acl_expr *expr, struct acl_test *test)
1375{
1376 int nbsrv;
1377
1378 test->flags = ACL_TEST_F_VOL_TEST;
1379 if (expr->arg_len) {
1380 /* another proxy was designated, we must look for it */
1381 for (px = proxy; px; px = px->next)
1382 if ((px->cap & PR_CAP_BE) && !strcmp(px->id, expr->arg.str))
1383 break;
1384 }
1385 if (!px)
1386 return 0;
1387
1388 if (px->srv_act)
1389 nbsrv = px->srv_act;
1390 else if (px->lbprm.fbck)
1391 nbsrv = 1;
1392 else
1393 nbsrv = px->srv_bck;
1394
1395 if (nbsrv > 0)
1396 test->i = (px->totpend + nbsrv - 1) / nbsrv;
1397 else
1398 test->i = px->totpend * 2;
1399
1400 return 1;
1401}
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001402
1403/* Note: must not be declared <const> as its list will be overwritten */
1404static struct acl_kw_list acl_kws = {{ },{
Jeffrey 'jf' Lim5051d7b2008-09-04 01:03:03 +08001405 { "nbsrv", acl_parse_int, acl_fetch_nbsrv, acl_match_int, ACL_USE_NOTHING },
Willy Tarreau3a8efeb2009-03-05 19:15:37 +01001406 { "connslots", acl_parse_int, acl_fetch_connslots, acl_match_int, ACL_USE_NOTHING },
Willy Tarreau079ff0a2009-03-05 21:34:28 +01001407 { "fe_sess_rate", acl_parse_int, acl_fetch_fe_sess_rate, acl_match_int, ACL_USE_NOTHING },
1408 { "be_sess_rate", acl_parse_int, acl_fetch_be_sess_rate, acl_match_int, ACL_USE_NOTHING },
Willy Tarreaua36af912009-10-10 12:02:45 +02001409 { "fe_conn", acl_parse_int, acl_fetch_fe_conn, acl_match_int, ACL_USE_NOTHING },
1410 { "be_conn", acl_parse_int, acl_fetch_be_conn, acl_match_int, ACL_USE_NOTHING },
1411 { "queue", acl_parse_int, acl_fetch_queue_size, acl_match_int, ACL_USE_NOTHING },
1412 { "avg_queue", acl_parse_int, acl_fetch_avg_queue_size, acl_match_int, ACL_USE_NOTHING },
Willy Tarreaua9d3c1e2007-11-30 20:48:53 +01001413 { NULL, NULL, NULL, NULL },
1414}};
1415
1416
1417__attribute__((constructor))
1418static void __backend_init(void)
1419{
1420 acl_register_keywords(&acl_kws);
1421}
1422
Willy Tarreaubaaee002006-06-26 02:48:02 +02001423/*
1424 * Local variables:
1425 * c-indent-level: 8
1426 * c-basic-offset: 8
1427 * End:
1428 */