blob: 4c1f032ec6bdb02d4208d8bc53e9e5113d356874 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Configuration parser
3 *
4 * Copyright 2000-2006 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <netdb.h>
17#include <ctype.h>
Willy Tarreau95c20ac2007-03-25 15:39:23 +020018#include <pwd.h>
19#include <grp.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020020
Willy Tarreau2dd0d472006-06-29 17:53:05 +020021#include <common/cfgparse.h>
22#include <common/config.h>
23#include <common/memory.h>
24#include <common/standard.h>
25#include <common/time.h>
26#include <common/uri_auth.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020027
28#include <types/capture.h>
29#include <types/global.h>
Willy Tarreau0f772532006-12-23 20:51:41 +010030#include <types/httperr.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020031#include <types/polling.h>
32#include <types/proxy.h>
33#include <types/queue.h>
34
35#include <proto/backend.h>
Willy Tarreau0f772532006-12-23 20:51:41 +010036#include <proto/buffers.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020037#include <proto/checks.h>
Willy Tarreau0f772532006-12-23 20:51:41 +010038#include <proto/httperr.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020039#include <proto/log.h>
Willy Tarreau2b5652f2006-12-31 17:46:05 +010040#include <proto/proxy.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020041#include <proto/server.h>
42#include <proto/task.h>
43
44
Willy Tarreauf3c69202006-07-09 16:42:34 +020045/* This is the SSLv3 CLIENT HELLO packet used in conjunction with the
46 * ssl-hello-chk option to ensure that the remote server speaks SSL.
47 *
48 * Check RFC 2246 (TLSv1.0) sections A.3 and A.4 for details.
49 */
50const char sslv3_client_hello_pkt[] = {
51 "\x16" /* ContentType : 0x16 = Hanshake */
52 "\x03\x00" /* ProtocolVersion : 0x0300 = SSLv3 */
53 "\x00\x79" /* ContentLength : 0x79 bytes after this one */
54 "\x01" /* HanshakeType : 0x01 = CLIENT HELLO */
55 "\x00\x00\x75" /* HandshakeLength : 0x75 bytes after this one */
56 "\x03\x00" /* Hello Version : 0x0300 = v3 */
57 "\x00\x00\x00\x00" /* Unix GMT Time (s) : filled with <now> (@0x0B) */
58 "HAPROXYSSLCHK\nHAPROXYSSLCHK\n" /* Random : must be exactly 28 bytes */
59 "\x00" /* Session ID length : empty (no session ID) */
60 "\x00\x4E" /* Cipher Suite Length : 78 bytes after this one */
61 "\x00\x01" "\x00\x02" "\x00\x03" "\x00\x04" /* 39 most common ciphers : */
62 "\x00\x05" "\x00\x06" "\x00\x07" "\x00\x08" /* 0x01...0x1B, 0x2F...0x3A */
63 "\x00\x09" "\x00\x0A" "\x00\x0B" "\x00\x0C" /* This covers RSA/DH, */
64 "\x00\x0D" "\x00\x0E" "\x00\x0F" "\x00\x10" /* various bit lengths, */
65 "\x00\x11" "\x00\x12" "\x00\x13" "\x00\x14" /* SHA1/MD5, DES/3DES/AES... */
66 "\x00\x15" "\x00\x16" "\x00\x17" "\x00\x18"
67 "\x00\x19" "\x00\x1A" "\x00\x1B" "\x00\x2F"
68 "\x00\x30" "\x00\x31" "\x00\x32" "\x00\x33"
69 "\x00\x34" "\x00\x35" "\x00\x36" "\x00\x37"
70 "\x00\x38" "\x00\x39" "\x00\x3A"
71 "\x01" /* Compression Length : 0x01 = 1 byte for types */
72 "\x00" /* Compression Type : 0x00 = NULL compression */
73};
74
Willy Tarreau13943ab2006-12-31 00:24:10 +010075/* some of the most common options which are also the easiest to handle */
76static const struct {
77 const char *name;
78 unsigned int val;
79 unsigned int cap;
Willy Tarreau4fee4e92007-01-06 21:09:17 +010080 unsigned int checks;
Willy Tarreau13943ab2006-12-31 00:24:10 +010081} cfg_opts[] =
82{
83#ifdef TPROXY
84 { "transparent", PR_O_TRANSP, PR_CAP_FE },
85#endif
Willy Tarreau4fee4e92007-01-06 21:09:17 +010086 { "redispatch", PR_O_REDISP, PR_CAP_BE, 0 },
87 { "keepalive", PR_O_KEEPALIVE, PR_CAP_NONE, 0 },
88 { "forwardfor", PR_O_FWDFOR, PR_CAP_FE | PR_CAP_BE, 0 },
89 { "httpclose", PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0 },
90 { "logasap", PR_O_LOGASAP, PR_CAP_FE, 0 },
91 { "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0 },
92 { "checkcache", PR_O_CHK_CACHE, PR_CAP_BE, 0 },
93 { "dontlognull", PR_O_NULLNOLOG, PR_CAP_FE, 0 },
94 { "clitcpka", PR_O_TCP_CLI_KA, PR_CAP_FE, 0 },
95 { "srvtcpka", PR_O_TCP_SRV_KA, PR_CAP_BE, 0 },
96 { "allbackups", PR_O_USE_ALL_BK, PR_CAP_BE, 0 },
97 { "persist", PR_O_PERSIST, PR_CAP_BE, 0 },
98 { "forceclose", PR_O_FORCE_CLO | PR_O_HTTP_CLOSE, PR_CAP_BE, 0 },
Willy Tarreau8f922fc2007-01-06 21:11:49 +010099#ifdef CONFIG_HAP_TCPSPLICE
100 { "tcpsplice", PR_O_TCPSPLICE , PR_CAP_BE|PR_CAP_FE, LSTCHK_TCPSPLICE|LSTCHK_NETADM },
101#endif
102
Willy Tarreau13943ab2006-12-31 00:24:10 +0100103 { NULL, 0, 0 }
104};
105
Willy Tarreaubaaee002006-06-26 02:48:02 +0200106
107static struct proxy defproxy; /* fake proxy used to assign default values on all instances */
108int cfg_maxpconn = DEFAULT_MAXCONN; /* # of simultaneous connections per proxy (-N) */
109int cfg_maxconn = 0; /* # of simultaneous connections, (-n) */
110
111/*
112 * converts <str> to a list of listeners which are dynamically allocated.
113 * The format is "{addr|'*'}:port[-end][,{addr|'*'}:port[-end]]*", where :
114 * - <addr> can be empty or "*" to indicate INADDR_ANY ;
115 * - <port> is a numerical port from 1 to 65535 ;
116 * - <end> indicates to use the range from <port> to <end> instead (inclusive).
117 * This can be repeated as many times as necessary, separated by a coma.
118 * The <tail> argument is a pointer to a current list which should be appended
119 * to the tail of the new list. The pointer to the new list is returned.
120 */
121static struct listener *str2listener(char *str, struct listener *tail)
122{
123 struct listener *l;
124 char *c, *next, *range, *dupstr;
125 int port, end;
126
127 next = dupstr = strdup(str);
128
129 while (next && *next) {
130 struct sockaddr_storage ss;
131
132 str = next;
133 /* 1) look for the end of the first address */
134 if ((next = strrchr(str, ',')) != NULL) {
135 *next++ = 0;
136 }
137
138 /* 2) look for the addr/port delimiter, it's the last colon. */
139 if ((range = strrchr(str, ':')) == NULL) {
140 Alert("Missing port number: '%s'\n", str);
141 goto fail;
142 }
143
144 *range++ = 0;
145
146 if (strrchr(str, ':') != NULL) {
147 /* IPv6 address contains ':' */
148 memset(&ss, 0, sizeof(ss));
149 ss.ss_family = AF_INET6;
150
151 if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in6 *)&ss)->sin6_addr)) {
152 Alert("Invalid server address: '%s'\n", str);
153 goto fail;
154 }
155 }
156 else {
157 memset(&ss, 0, sizeof(ss));
158 ss.ss_family = AF_INET;
159
160 if (*str == '*' || *str == '\0') { /* INADDR_ANY */
161 ((struct sockaddr_in *)&ss)->sin_addr.s_addr = INADDR_ANY;
162 }
163 else if (!inet_pton(ss.ss_family, str, &((struct sockaddr_in *)&ss)->sin_addr)) {
164 struct hostent *he;
165
166 if ((he = gethostbyname(str)) == NULL) {
167 Alert("Invalid server name: '%s'\n", str);
168 goto fail;
169 }
170 else
171 ((struct sockaddr_in *)&ss)->sin_addr =
172 *(struct in_addr *) *(he->h_addr_list);
173 }
174 }
175
176 /* 3) look for the port-end delimiter */
177 if ((c = strchr(range, '-')) != NULL) {
178 *c++ = 0;
179 end = atol(c);
180 }
181 else {
182 end = atol(range);
183 }
184
185 port = atol(range);
186
187 if (port < 1 || port > 65535) {
188 Alert("Invalid port '%d' specified for address '%s'.\n", port, str);
189 goto fail;
190 }
191
192 if (end < 1 || end > 65535) {
193 Alert("Invalid port '%d' specified for address '%s'.\n", end, str);
194 goto fail;
195 }
196
197 for (; port <= end; port++) {
198 l = (struct listener *)calloc(1, sizeof(struct listener));
199 l->next = tail;
200 tail = l;
201
202 l->fd = -1;
203 l->addr = ss;
204 if (ss.ss_family == AF_INET6)
205 ((struct sockaddr_in6 *)(&l->addr))->sin6_port = htons(port);
206 else
207 ((struct sockaddr_in *)(&l->addr))->sin_port = htons(port);
208
209 } /* end for(port) */
210 } /* end while(next) */
211 free(dupstr);
212 return tail;
213 fail:
214 free(dupstr);
215 return NULL;
216}
217
Willy Tarreau977b8e42006-12-29 14:19:17 +0100218/*
219 * Sends a warning if proxy <proxy> does not have at least one of the
220 * capabilities in <cap>. An optionnal <hint> may be added at the end
221 * of the warning to help the user. Returns 1 if a warning was emitted
222 * or 0 if the condition is valid.
223 */
224int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, char *arg, char *hint)
225{
226 char *msg;
227
228 switch (cap) {
229 case PR_CAP_BE: msg = "no backend"; break;
230 case PR_CAP_FE: msg = "no frontend"; break;
231 case PR_CAP_RS: msg = "no ruleset"; break;
232 case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break;
233 default: msg = "not enough"; break;
234 }
235
236 if (!(proxy->cap & cap)) {
237 Warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +0100238 file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : "");
Willy Tarreau977b8e42006-12-29 14:19:17 +0100239 return 1;
240 }
241 return 0;
242}
Willy Tarreaubaaee002006-06-26 02:48:02 +0200243
244/*
245 * parse a line in a <global> section. Returns 0 if OK, -1 if error.
246 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200247int cfg_parse_global(const char *file, int linenum, char **args)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200248{
249
250 if (!strcmp(args[0], "global")) { /* new section */
251 /* no option, nothing special to do */
252 return 0;
253 }
254 else if (!strcmp(args[0], "daemon")) {
255 global.mode |= MODE_DAEMON;
256 }
257 else if (!strcmp(args[0], "debug")) {
258 global.mode |= MODE_DEBUG;
259 }
260 else if (!strcmp(args[0], "noepoll")) {
261 cfg_polling_mechanism &= ~POLL_USE_EPOLL;
262 }
263 else if (!strcmp(args[0], "nopoll")) {
264 cfg_polling_mechanism &= ~POLL_USE_POLL;
265 }
266 else if (!strcmp(args[0], "quiet")) {
267 global.mode |= MODE_QUIET;
268 }
269 else if (!strcmp(args[0], "stats")) {
270 global.mode |= MODE_STATS;
271 }
272 else if (!strcmp(args[0], "uid")) {
273 if (global.uid != 0) {
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200274 Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200275 return 0;
276 }
277 if (*(args[1]) == 0) {
278 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
279 return -1;
280 }
281 global.uid = atol(args[1]);
282 }
283 else if (!strcmp(args[0], "gid")) {
284 if (global.gid != 0) {
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200285 Alert("parsing [%s:%d] : group/gid already specified. Continuing.\n", file, linenum);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200286 return 0;
287 }
288 if (*(args[1]) == 0) {
289 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
290 return -1;
291 }
292 global.gid = atol(args[1]);
293 }
Willy Tarreau95c20ac2007-03-25 15:39:23 +0200294 /* user/group name handling */
295 else if (!strcmp(args[0], "user")) {
296 struct passwd *ha_user;
297 if (global.uid != 0) {
298 Alert("parsing [%s:%d] : user/uid already specified. Continuing.\n", file, linenum);
299 return 0;
300 }
301 errno = 0;
302 ha_user = getpwnam(args[1]);
303 if (ha_user != NULL) {
304 global.uid = (int)ha_user->pw_uid;
305 }
306 else {
307 Alert("parsing [%s:%d] : cannot find user id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
308 exit(1);
309 }
310 }
311 else if (!strcmp(args[0], "group")) {
312 struct group *ha_group;
313 if (global.gid != 0) {
314 Alert("parsing [%s:%d] : gid/group was already specified. Continuing.\n", file, linenum, args[0]);
315 return 0;
316 }
317 errno = 0;
318 ha_group = getgrnam(args[1]);
319 if (ha_group != NULL) {
320 global.gid = (int)ha_group->gr_gid;
321 }
322 else {
323 Alert("parsing [%s:%d] : cannot find group id for '%s' (%d:%s)\n", file, linenum, args[1], errno, strerror(errno));
324 exit(1);
325 }
326 }
327 /* end of user/group name handling*/
Willy Tarreaubaaee002006-06-26 02:48:02 +0200328 else if (!strcmp(args[0], "nbproc")) {
329 if (global.nbproc != 0) {
330 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
331 return 0;
332 }
333 if (*(args[1]) == 0) {
334 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
335 return -1;
336 }
337 global.nbproc = atol(args[1]);
338 }
339 else if (!strcmp(args[0], "maxconn")) {
340 if (global.maxconn != 0) {
341 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
342 return 0;
343 }
344 if (*(args[1]) == 0) {
345 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
346 return -1;
347 }
348 global.maxconn = atol(args[1]);
349#ifdef SYSTEM_MAXCONN
350 if (global.maxconn > DEFAULT_MAXCONN && cfg_maxconn <= DEFAULT_MAXCONN) {
351 Alert("parsing [%s:%d] : maxconn value %d too high for this system.\nLimiting to %d. Please use '-n' to force the value.\n", file, linenum, global.maxconn, DEFAULT_MAXCONN);
352 global.maxconn = DEFAULT_MAXCONN;
353 }
354#endif /* SYSTEM_MAXCONN */
355 }
356 else if (!strcmp(args[0], "ulimit-n")) {
357 if (global.rlimit_nofile != 0) {
358 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
359 return 0;
360 }
361 if (*(args[1]) == 0) {
362 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
363 return -1;
364 }
365 global.rlimit_nofile = atol(args[1]);
366 }
367 else if (!strcmp(args[0], "chroot")) {
368 if (global.chroot != NULL) {
369 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
370 return 0;
371 }
372 if (*(args[1]) == 0) {
373 Alert("parsing [%s:%d] : '%s' expects a directory as an argument.\n", file, linenum, args[0]);
374 return -1;
375 }
376 global.chroot = strdup(args[1]);
377 }
378 else if (!strcmp(args[0], "pidfile")) {
379 if (global.pidfile != NULL) {
380 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
381 return 0;
382 }
383 if (*(args[1]) == 0) {
384 Alert("parsing [%s:%d] : '%s' expects a file name as an argument.\n", file, linenum, args[0]);
385 return -1;
386 }
387 global.pidfile = strdup(args[1]);
388 }
389 else if (!strcmp(args[0], "log")) { /* syslog server address */
390 struct sockaddr_in *sa;
391 int facility, level;
392
393 if (*(args[1]) == 0 || *(args[2]) == 0) {
394 Alert("parsing [%s:%d] : '%s' expects <address> and <facility> as arguments.\n", file, linenum, args[0]);
395 return -1;
396 }
397
398 facility = get_log_facility(args[2]);
399 if (facility < 0) {
400 Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]);
401 exit(1);
402 }
403
404 level = 7; /* max syslog level = debug */
405 if (*(args[3])) {
406 level = get_log_level(args[3]);
407 if (level < 0) {
408 Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]);
409 exit(1);
410 }
411 }
412
413 sa = str2sa(args[1]);
414 if (!sa->sin_port)
415 sa->sin_port = htons(SYSLOG_PORT);
416
417 if (global.logfac1 == -1) {
418 global.logsrv1 = *sa;
419 global.logfac1 = facility;
420 global.loglev1 = level;
421 }
422 else if (global.logfac2 == -1) {
423 global.logsrv2 = *sa;
424 global.logfac2 = facility;
425 global.loglev2 = level;
426 }
427 else {
428 Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum);
429 return -1;
430 }
431
432 }
433 else {
434 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "global");
435 return -1;
436 }
437 return 0;
438}
439
440
441static void init_default_instance()
442{
443 memset(&defproxy, 0, sizeof(defproxy));
444 defproxy.mode = PR_MODE_TCP;
445 defproxy.state = PR_STNEW;
446 defproxy.maxconn = cfg_maxpconn;
447 defproxy.conn_retries = CONN_RETRIES;
448 defproxy.logfac1 = defproxy.logfac2 = -1; /* log disabled */
449}
450
451/*
Willy Tarreau977b8e42006-12-29 14:19:17 +0100452 * Parse a line in a <listen>, <frontend>, <backend> or <ruleset> section.
453 * Returns 0 if OK, -1 if error.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200454 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200455int cfg_parse_listen(const char *file, int linenum, char **args)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200456{
457 static struct proxy *curproxy = NULL;
458 struct server *newsrv = NULL;
Willy Tarreaub17916e2006-10-15 15:17:57 +0200459 const char *err;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200460 int rc;
461
Willy Tarreau977b8e42006-12-29 14:19:17 +0100462 if (!strcmp(args[0], "listen"))
463 rc = PR_CAP_LISTEN;
464 else if (!strcmp(args[0], "frontend"))
465 rc = PR_CAP_FE | PR_CAP_RS;
466 else if (!strcmp(args[0], "backend"))
467 rc = PR_CAP_BE | PR_CAP_RS;
468 else if (!strcmp(args[0], "ruleset"))
469 rc = PR_CAP_RS;
470 else
471 rc = PR_CAP_NONE;
472
473 if (rc != PR_CAP_NONE) { /* new proxy */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200474 if (!*args[1]) {
475 Alert("parsing [%s:%d] : '%s' expects an <id> argument and\n"
476 " optionnally supports [addr1]:port1[-end1]{,[addr]:port[-end]}...\n",
477 file, linenum, args[0]);
478 return -1;
479 }
480
481 if ((curproxy = (struct proxy *)calloc(1, sizeof(struct proxy))) == NULL) {
482 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
483 return -1;
484 }
485
486 curproxy->next = proxy;
487 proxy = curproxy;
488 LIST_INIT(&curproxy->pendconns);
489
490 curproxy->id = strdup(args[1]);
Willy Tarreau977b8e42006-12-29 14:19:17 +0100491 curproxy->cap = rc;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200492
493 /* parse the listener address if any */
Willy Tarreau977b8e42006-12-29 14:19:17 +0100494 if ((curproxy->cap & PR_CAP_FE) && *args[2]) {
Willy Tarreaubaaee002006-06-26 02:48:02 +0200495 curproxy->listen = str2listener(args[2], curproxy->listen);
496 if (!curproxy->listen)
497 return -1;
498 global.maxsock++;
499 }
500
501 /* set default values */
502 curproxy->state = defproxy.state;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200503 curproxy->options = defproxy.options;
504
Willy Tarreau977b8e42006-12-29 14:19:17 +0100505 if (curproxy->cap & PR_CAP_FE) {
506 curproxy->maxconn = defproxy.maxconn;
507
508 /* initialize error relocations */
509 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
510 if (defproxy.errmsg[rc].str)
511 chunk_dup(&curproxy->errmsg[rc], &defproxy.errmsg[rc]);
512 }
513
514 curproxy->to_log = defproxy.to_log & ~LW_COOKIE & ~LW_REQHDR & ~ LW_RSPHDR;
515 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200516
Willy Tarreau977b8e42006-12-29 14:19:17 +0100517 if (curproxy->cap & PR_CAP_BE) {
518 curproxy->fullconn = defproxy.fullconn;
519 curproxy->conn_retries = defproxy.conn_retries;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200520
Willy Tarreau977b8e42006-12-29 14:19:17 +0100521 if (defproxy.check_req)
522 curproxy->check_req = strdup(defproxy.check_req);
523 curproxy->check_len = defproxy.check_len;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200524
Willy Tarreau977b8e42006-12-29 14:19:17 +0100525 if (defproxy.cookie_name)
526 curproxy->cookie_name = strdup(defproxy.cookie_name);
527 curproxy->cookie_len = defproxy.cookie_len;
528 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200529
Willy Tarreau977b8e42006-12-29 14:19:17 +0100530 if (curproxy->cap & PR_CAP_RS) {
531 if (defproxy.capture_name)
532 curproxy->capture_name = strdup(defproxy.capture_name);
533 curproxy->capture_namelen = defproxy.capture_namelen;
534 curproxy->capture_len = defproxy.capture_len;
Willy Tarreau0f772532006-12-23 20:51:41 +0100535 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200536
Willy Tarreau977b8e42006-12-29 14:19:17 +0100537 if (curproxy->cap & PR_CAP_FE) {
538 curproxy->clitimeout = defproxy.clitimeout;
539 curproxy->uri_auth = defproxy.uri_auth;
540 curproxy->mon_net = defproxy.mon_net;
541 curproxy->mon_mask = defproxy.mon_mask;
542 if (defproxy.monitor_uri)
543 curproxy->monitor_uri = strdup(defproxy.monitor_uri);
544 curproxy->monitor_uri_len = defproxy.monitor_uri_len;
Willy Tarreau5fdfb912007-01-01 23:11:07 +0100545 if (defproxy.defbe.name)
546 curproxy->defbe.name = strdup(defproxy.defbe.name);
Willy Tarreau977b8e42006-12-29 14:19:17 +0100547 }
548
549 if (curproxy->cap & PR_CAP_BE) {
550 curproxy->contimeout = defproxy.contimeout;
551 curproxy->srvtimeout = defproxy.srvtimeout;
552 curproxy->source_addr = defproxy.source_addr;
553 }
554
Willy Tarreaubaaee002006-06-26 02:48:02 +0200555 curproxy->mode = defproxy.mode;
556 curproxy->logfac1 = defproxy.logfac1;
557 curproxy->logsrv1 = defproxy.logsrv1;
558 curproxy->loglev1 = defproxy.loglev1;
559 curproxy->logfac2 = defproxy.logfac2;
560 curproxy->logsrv2 = defproxy.logsrv2;
561 curproxy->loglev2 = defproxy.loglev2;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200562 curproxy->grace = defproxy.grace;
Willy Tarreau1c47f852006-07-09 08:22:27 +0200563
Willy Tarreaubaaee002006-06-26 02:48:02 +0200564 return 0;
565 }
566 else if (!strcmp(args[0], "defaults")) { /* use this one to assign default values */
567 /* some variables may have already been initialized earlier */
Willy Tarreau5fdfb912007-01-01 23:11:07 +0100568 /* FIXME-20070101: we should do this too at the end of the
569 * config parsing to free all default values.
570 */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200571 if (defproxy.check_req) free(defproxy.check_req);
572 if (defproxy.cookie_name) free(defproxy.cookie_name);
573 if (defproxy.capture_name) free(defproxy.capture_name);
Willy Tarreau1c47f852006-07-09 08:22:27 +0200574 if (defproxy.monitor_uri) free(defproxy.monitor_uri);
Willy Tarreau5fdfb912007-01-01 23:11:07 +0100575 if (defproxy.defbe.name) free(defproxy.defbe.name);
Willy Tarreau0f772532006-12-23 20:51:41 +0100576
577 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
578 if (defproxy.errmsg[rc].len)
579 free(defproxy.errmsg[rc].str);
580 }
581
Willy Tarreaubaaee002006-06-26 02:48:02 +0200582 /* we cannot free uri_auth because it might already be used */
583 init_default_instance();
584 curproxy = &defproxy;
Willy Tarreau977b8e42006-12-29 14:19:17 +0100585 defproxy.cap = PR_CAP_LISTEN; /* all caps for now */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200586 return 0;
587 }
588 else if (curproxy == NULL) {
589 Alert("parsing [%s:%d] : 'listen' or 'defaults' expected.\n", file, linenum);
590 return -1;
591 }
592
Willy Tarreau977b8e42006-12-29 14:19:17 +0100593
594 /* Now let's parse the proxy-specific keywords */
Willy Tarreaubaaee002006-06-26 02:48:02 +0200595 if (!strcmp(args[0], "bind")) { /* new listen addresses */
596 if (curproxy == &defproxy) {
597 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
598 return -1;
599 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100600 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
601 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200602
603 if (strchr(args[1], ':') == NULL) {
604 Alert("parsing [%s:%d] : '%s' expects [addr1]:port1[-end1]{,[addr]:port[-end]}... as arguments.\n",
605 file, linenum, args[0]);
606 return -1;
607 }
608 curproxy->listen = str2listener(args[1], curproxy->listen);
609 if (!curproxy->listen)
610 return -1;
611 global.maxsock++;
612 return 0;
613 }
614 else if (!strcmp(args[0], "monitor-net")) { /* set the range of IPs to ignore */
615 if (!*args[1] || !str2net(args[1], &curproxy->mon_net, &curproxy->mon_mask)) {
616 Alert("parsing [%s:%d] : '%s' expects address[/mask].\n",
617 file, linenum, args[0]);
618 return -1;
619 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100620 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
621 return 0;
622
Willy Tarreaubaaee002006-06-26 02:48:02 +0200623 /* flush useless bits */
624 curproxy->mon_net.s_addr &= curproxy->mon_mask.s_addr;
625 return 0;
626 }
Willy Tarreau1c47f852006-07-09 08:22:27 +0200627 else if (!strcmp(args[0], "monitor-uri")) { /* set the URI to intercept */
Willy Tarreau977b8e42006-12-29 14:19:17 +0100628 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
629 return 0;
630
Willy Tarreau1c47f852006-07-09 08:22:27 +0200631 if (!*args[1]) {
632 Alert("parsing [%s:%d] : '%s' expects an URI.\n",
633 file, linenum, args[0]);
634 return -1;
635 }
636
637 if (curproxy->monitor_uri != NULL)
638 free(curproxy->monitor_uri);
639
Willy Tarreau8d5d7f22007-01-21 19:16:41 +0100640 curproxy->monitor_uri_len = strlen(args[1]);
Willy Tarreau1c47f852006-07-09 08:22:27 +0200641 curproxy->monitor_uri = (char *)calloc(1, curproxy->monitor_uri_len + 1);
Willy Tarreau8d5d7f22007-01-21 19:16:41 +0100642 memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
Willy Tarreau1c47f852006-07-09 08:22:27 +0200643 curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
644
645 return 0;
646 }
Willy Tarreaubaaee002006-06-26 02:48:02 +0200647 else if (!strcmp(args[0], "mode")) { /* sets the proxy mode */
648 if (!strcmp(args[1], "http")) curproxy->mode = PR_MODE_HTTP;
649 else if (!strcmp(args[1], "tcp")) curproxy->mode = PR_MODE_TCP;
650 else if (!strcmp(args[1], "health")) curproxy->mode = PR_MODE_HEALTH;
651 else {
652 Alert("parsing [%s:%d] : unknown proxy mode '%s'.\n", file, linenum, args[1]);
653 return -1;
654 }
655 }
656 else if (!strcmp(args[0], "disabled")) { /* disables this proxy */
657 curproxy->state = PR_STSTOPPED;
658 }
659 else if (!strcmp(args[0], "enabled")) { /* enables this proxy (used to revert a disabled default) */
660 curproxy->state = PR_STNEW;
661 }
662 else if (!strcmp(args[0], "cookie")) { /* cookie name */
663 int cur_arg;
664 // if (curproxy == &defproxy) {
665 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
666 // return -1;
667 // }
668
Willy Tarreau977b8e42006-12-29 14:19:17 +0100669 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
670 return 0;
671
Willy Tarreaubaaee002006-06-26 02:48:02 +0200672 if (curproxy->cookie_name != NULL) {
673 // Alert("parsing [%s:%d] : cookie name already specified. Continuing.\n",
674 // file, linenum);
675 // return 0;
676 free(curproxy->cookie_name);
677 }
678
679 if (*(args[1]) == 0) {
680 Alert("parsing [%s:%d] : '%s' expects <cookie_name> as argument.\n",
681 file, linenum, args[0]);
682 return -1;
683 }
684 curproxy->cookie_name = strdup(args[1]);
685 curproxy->cookie_len = strlen(curproxy->cookie_name);
686
687 cur_arg = 2;
688 while (*(args[cur_arg])) {
689 if (!strcmp(args[cur_arg], "rewrite")) {
690 curproxy->options |= PR_O_COOK_RW;
691 }
692 else if (!strcmp(args[cur_arg], "indirect")) {
693 curproxy->options |= PR_O_COOK_IND;
694 }
695 else if (!strcmp(args[cur_arg], "insert")) {
696 curproxy->options |= PR_O_COOK_INS;
697 }
698 else if (!strcmp(args[cur_arg], "nocache")) {
699 curproxy->options |= PR_O_COOK_NOC;
700 }
701 else if (!strcmp(args[cur_arg], "postonly")) {
702 curproxy->options |= PR_O_COOK_POST;
703 }
704 else if (!strcmp(args[cur_arg], "prefix")) {
705 curproxy->options |= PR_O_COOK_PFX;
706 }
707 else {
708 Alert("parsing [%s:%d] : '%s' supports 'rewrite', 'insert', 'prefix', 'indirect', 'nocache' and 'postonly' options.\n",
709 file, linenum, args[0]);
710 return -1;
711 }
712 cur_arg++;
713 }
714 if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_IND))) {
715 Alert("parsing [%s:%d] : cookie 'rewrite' and 'indirect' modes are incompatible.\n",
716 file, linenum);
717 return -1;
718 }
719
720 if (!POWEROF2(curproxy->options & (PR_O_COOK_RW|PR_O_COOK_INS|PR_O_COOK_PFX))) {
721 Alert("parsing [%s:%d] : cookie 'rewrite', 'insert' and 'prefix' modes are incompatible.\n",
722 file, linenum);
723 return -1;
724 }
725 }/* end else if (!strcmp(args[0], "cookie")) */
726 else if (!strcmp(args[0], "appsession")) { /* cookie name */
727 // if (curproxy == &defproxy) {
728 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
729 // return -1;
730 // }
731
Willy Tarreau977b8e42006-12-29 14:19:17 +0100732 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
733 return 0;
734
Willy Tarreaubaaee002006-06-26 02:48:02 +0200735 if (curproxy->appsession_name != NULL) {
736 // Alert("parsing [%s:%d] : cookie name already specified. Continuing.\n",
737 // file, linenum);
738 // return 0;
739 free(curproxy->appsession_name);
740 }
741
742 if (*(args[5]) == 0) {
743 Alert("parsing [%s:%d] : '%s' expects 'appsession' <cookie_name> 'len' <len> 'timeout' <timeout>.\n",
744 file, linenum, args[0]);
745 return -1;
746 }
747 have_appsession = 1;
748 curproxy->appsession_name = strdup(args[1]);
749 curproxy->appsession_name_len = strlen(curproxy->appsession_name);
750 curproxy->appsession_len = atoi(args[3]);
751 curproxy->appsession_timeout = atoi(args[5]);
752 rc = chtbl_init(&(curproxy->htbl_proxy), TBLSIZ, hashpjw, match_str, destroy);
753 if (rc) {
754 Alert("Error Init Appsession Hashtable.\n");
755 return -1;
756 }
757 } /* Url App Session */
758 else if (!strcmp(args[0], "capture")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +0100759 if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
760 return 0;
761
Willy Tarreaubaaee002006-06-26 02:48:02 +0200762 if (!strcmp(args[1], "cookie")) { /* name of a cookie to capture */
763 // if (curproxy == &defproxy) {
764 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
765 // return -1;
766 // }
767
768 if (curproxy->capture_name != NULL) {
769 // Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n",
770 // file, linenum, args[0]);
771 // return 0;
772 free(curproxy->capture_name);
773 }
774
775 if (*(args[4]) == 0) {
776 Alert("parsing [%s:%d] : '%s' expects 'cookie' <cookie_name> 'len' <len>.\n",
777 file, linenum, args[0]);
778 return -1;
779 }
780 curproxy->capture_name = strdup(args[2]);
781 curproxy->capture_namelen = strlen(curproxy->capture_name);
782 curproxy->capture_len = atol(args[4]);
783 if (curproxy->capture_len >= CAPTURE_LEN) {
784 Warning("parsing [%s:%d] : truncating capture length to %d bytes.\n",
785 file, linenum, CAPTURE_LEN - 1);
786 curproxy->capture_len = CAPTURE_LEN - 1;
787 }
788 curproxy->to_log |= LW_COOKIE;
789 }
790 else if (!strcmp(args[1], "request") && !strcmp(args[2], "header")) {
791 struct cap_hdr *hdr;
792
793 if (curproxy == &defproxy) {
794 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
795 return -1;
796 }
797
798 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
799 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
800 file, linenum, args[0], args[1]);
801 return -1;
802 }
803
804 hdr = calloc(sizeof(struct cap_hdr), 1);
805 hdr->next = curproxy->req_cap;
806 hdr->name = strdup(args[3]);
807 hdr->namelen = strlen(args[3]);
808 hdr->len = atol(args[5]);
809 hdr->index = curproxy->nb_req_cap++;
810 curproxy->req_cap = hdr;
811 curproxy->to_log |= LW_REQHDR;
812 }
813 else if (!strcmp(args[1], "response") && !strcmp(args[2], "header")) {
814 struct cap_hdr *hdr;
815
816 if (curproxy == &defproxy) {
817 Alert("parsing [%s:%d] : '%s %s' not allowed in 'defaults' section.\n", file, linenum, args[0], args[1]);
818 return -1;
819 }
820
821 if (*(args[3]) == 0 || strcmp(args[4], "len") != 0 || *(args[5]) == 0) {
822 Alert("parsing [%s:%d] : '%s %s' expects 'header' <header_name> 'len' <len>.\n",
823 file, linenum, args[0], args[1]);
824 return -1;
825 }
826 hdr = calloc(sizeof(struct cap_hdr), 1);
827 hdr->next = curproxy->rsp_cap;
828 hdr->name = strdup(args[3]);
829 hdr->namelen = strlen(args[3]);
830 hdr->len = atol(args[5]);
831 hdr->index = curproxy->nb_rsp_cap++;
832 curproxy->rsp_cap = hdr;
833 curproxy->to_log |= LW_RSPHDR;
834 }
835 else {
836 Alert("parsing [%s:%d] : '%s' expects 'cookie' or 'request header' or 'response header'.\n",
837 file, linenum, args[0]);
838 return -1;
839 }
840 }
841 else if (!strcmp(args[0], "contimeout")) { /* connect timeout */
842 if (curproxy->contimeout != defproxy.contimeout) {
843 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
844 return 0;
845 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100846 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
847 return 0;
848
Willy Tarreaubaaee002006-06-26 02:48:02 +0200849 if (*(args[1]) == 0) {
850 Alert("parsing [%s:%d] : '%s' expects an integer <time_in_ms> as argument.\n",
851 file, linenum, args[0]);
852 return -1;
853 }
854 curproxy->contimeout = atol(args[1]);
855 }
856 else if (!strcmp(args[0], "clitimeout")) { /* client timeout */
857 if (curproxy->clitimeout != defproxy.clitimeout) {
858 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n",
859 file, linenum, args[0]);
860 return 0;
861 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100862 else if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
863 return 0;
864
Willy Tarreaubaaee002006-06-26 02:48:02 +0200865 if (*(args[1]) == 0) {
866 Alert("parsing [%s:%d] : '%s' expects an integer <time_in_ms> as argument.\n",
867 file, linenum, args[0]);
868 return -1;
869 }
870 curproxy->clitimeout = atol(args[1]);
871 }
872 else if (!strcmp(args[0], "srvtimeout")) { /* server timeout */
873 if (curproxy->srvtimeout != defproxy.srvtimeout) {
874 Alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]);
875 return 0;
876 }
Willy Tarreau977b8e42006-12-29 14:19:17 +0100877 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
878 return 0;
879
Willy Tarreaubaaee002006-06-26 02:48:02 +0200880 if (*(args[1]) == 0) {
881 Alert("parsing [%s:%d] : '%s' expects an integer <time_in_ms> as argument.\n",
882 file, linenum, args[0]);
883 return -1;
884 }
885 curproxy->srvtimeout = atol(args[1]);
886 }
887 else if (!strcmp(args[0], "retries")) { /* connection retries */
Willy Tarreau977b8e42006-12-29 14:19:17 +0100888 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
889 return 0;
890
Willy Tarreaubaaee002006-06-26 02:48:02 +0200891 if (*(args[1]) == 0) {
892 Alert("parsing [%s:%d] : '%s' expects an integer argument (dispatch counts for one).\n",
893 file, linenum, args[0]);
894 return -1;
895 }
896 curproxy->conn_retries = atol(args[1]);
897 }
898 else if (!strcmp(args[0], "stats")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +0100899 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
900 return 0;
901
Willy Tarreaubaaee002006-06-26 02:48:02 +0200902 if (curproxy != &defproxy && curproxy->uri_auth == defproxy.uri_auth)
903 curproxy->uri_auth = NULL; /* we must detach from the default config */
904
905 if (*(args[1]) == 0) {
906 Alert("parsing [%s:%d] : '%s' expects 'uri', 'realm', 'auth', 'scope' or 'enable'.\n", file, linenum, args[0]);
907 return -1;
908 } else if (!strcmp(args[1], "uri")) {
909 if (*(args[2]) == 0) {
910 Alert("parsing [%s:%d] : 'uri' needs an URI prefix.\n", file, linenum);
911 return -1;
912 } else if (!stats_set_uri(&curproxy->uri_auth, args[2])) {
913 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
914 return -1;
915 }
916 } else if (!strcmp(args[1], "realm")) {
917 if (*(args[2]) == 0) {
918 Alert("parsing [%s:%d] : 'realm' needs an realm name.\n", file, linenum);
919 return -1;
920 } else if (!stats_set_realm(&curproxy->uri_auth, args[2])) {
921 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
922 return -1;
923 }
924 } else if (!strcmp(args[1], "auth")) {
925 if (*(args[2]) == 0) {
926 Alert("parsing [%s:%d] : 'auth' needs a user:password account.\n", file, linenum);
927 return -1;
928 } else if (!stats_add_auth(&curproxy->uri_auth, args[2])) {
929 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
930 return -1;
931 }
932 } else if (!strcmp(args[1], "scope")) {
933 if (*(args[2]) == 0) {
934 Alert("parsing [%s:%d] : 'scope' needs a proxy name.\n", file, linenum);
935 return -1;
936 } else if (!stats_add_scope(&curproxy->uri_auth, args[2])) {
937 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
938 return -1;
939 }
940 } else if (!strcmp(args[1], "enable")) {
941 if (!stats_check_init_uri_auth(&curproxy->uri_auth)) {
942 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
943 return -1;
944 }
945 } else {
946 Alert("parsing [%s:%d] : unknown stats parameter '%s' (expects 'uri', 'realm', 'auth' or 'enable').\n",
947 file, linenum, args[0]);
948 return -1;
949 }
950 }
951 else if (!strcmp(args[0], "option")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +0100952 int optnum;
953
Willy Tarreaubaaee002006-06-26 02:48:02 +0200954 if (*(args[1]) == 0) {
955 Alert("parsing [%s:%d] : '%s' expects an option name.\n", file, linenum, args[0]);
956 return -1;
957 }
Willy Tarreau13943ab2006-12-31 00:24:10 +0100958
959 for (optnum = 0; cfg_opts[optnum].name; optnum++) {
960 if (!strcmp(args[1], cfg_opts[optnum].name)) {
961 if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL))
962 return 0;
963 curproxy->options |= cfg_opts[optnum].val;
Willy Tarreau4fee4e92007-01-06 21:09:17 +0100964 global.last_checks |= cfg_opts[optnum].checks;
Willy Tarreau13943ab2006-12-31 00:24:10 +0100965 return 0;
966 }
967 }
968
969 if (!strcmp(args[1], "httplog"))
Willy Tarreaubaaee002006-06-26 02:48:02 +0200970 /* generate a complete HTTP log */
971 curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_REQ | LW_PXID | LW_RESP | LW_BYTES;
972 else if (!strcmp(args[1], "tcplog"))
973 /* generate a detailed TCP log */
974 curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_PXID | LW_BYTES;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200975 else if (!strcmp(args[1], "tcpka")) {
976 /* enable TCP keep-alives on client and server sessions */
Willy Tarreau13943ab2006-12-31 00:24:10 +0100977 if (warnifnotcap(curproxy, PR_CAP_BE | PR_CAP_FE, file, linenum, args[1], NULL))
978 return 0;
979
980 if (curproxy->cap & PR_CAP_FE)
981 curproxy->options |= PR_O_TCP_CLI_KA;
982 if (curproxy->cap & PR_CAP_BE)
983 curproxy->options |= PR_O_TCP_SRV_KA;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200984 }
985 else if (!strcmp(args[1], "httpchk")) {
Willy Tarreau13943ab2006-12-31 00:24:10 +0100986 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
987 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200988 /* use HTTP request to check servers' health */
989 if (curproxy->check_req != NULL) {
990 free(curproxy->check_req);
991 }
992 curproxy->options |= PR_O_HTTP_CHK;
Willy Tarreauf3c69202006-07-09 16:42:34 +0200993 curproxy->options &= ~PR_O_SSL3_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200994 if (!*args[2]) { /* no argument */
995 curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
996 curproxy->check_len = strlen(DEF_CHECK_REQ);
997 } else if (!*args[3]) { /* one argument : URI */
998 int reqlen = strlen(args[2]) + strlen("OPTIONS / HTTP/1.0\r\n\r\n");
999 curproxy->check_req = (char *)malloc(reqlen);
1000 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
1001 "OPTIONS %s HTTP/1.0\r\n\r\n", args[2]); /* URI to use */
1002 } else { /* more arguments : METHOD URI [HTTP_VER] */
1003 int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n\r\n");
1004 if (*args[4])
1005 reqlen += strlen(args[4]);
1006 else
1007 reqlen += strlen("HTTP/1.0");
1008
1009 curproxy->check_req = (char *)malloc(reqlen);
1010 curproxy->check_len = snprintf(curproxy->check_req, reqlen,
1011 "%s %s %s\r\n\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0");
1012 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02001013 }
1014 else if (!strcmp(args[1], "ssl-hello-chk")) {
1015 /* use SSLv3 CLIENT HELLO to check servers' health */
Willy Tarreau13943ab2006-12-31 00:24:10 +01001016 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
1017 return 0;
1018
Willy Tarreauf3c69202006-07-09 16:42:34 +02001019 if (curproxy->check_req != NULL) {
1020 free(curproxy->check_req);
1021 }
1022 curproxy->options &= ~PR_O_HTTP_CHK;
1023 curproxy->options |= PR_O_SSL3_CHK;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001024 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001025 else {
1026 Alert("parsing [%s:%d] : unknown option '%s'.\n", file, linenum, args[1]);
1027 return -1;
1028 }
1029 return 0;
1030 }
Willy Tarreau5fdfb912007-01-01 23:11:07 +01001031 else if (!strcmp(args[0], "default_backend")) {
1032 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], NULL))
1033 return 0;
1034
1035 if (*(args[1]) == 0) {
1036 Alert("parsing [%s:%d] : '%s' expects a backend name.\n", file, linenum, args[0]);
1037 return -1;
1038 }
1039 if (curproxy->defbe.name)
1040 free(curproxy->defbe.name);
1041 curproxy->defbe.name = strdup(args[1]);
1042 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001043 else if (!strcmp(args[0], "redispatch") || !strcmp(args[0], "redisp")) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01001044 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1045 return 0;
1046
Willy Tarreaubaaee002006-06-26 02:48:02 +02001047 /* enable reconnections to dispatch */
1048 curproxy->options |= PR_O_REDISP;
1049 }
1050#ifdef TPROXY
1051 else if (!strcmp(args[0], "transparent")) {
1052 /* enable transparent proxy connections */
1053 curproxy->options |= PR_O_TRANSP;
1054 }
1055#endif
1056 else if (!strcmp(args[0], "maxconn")) { /* maxconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01001057 if (warnifnotcap(curproxy, PR_CAP_FE, file, linenum, args[0], " Maybe you want 'fullconn' instead ?"))
1058 return 0;
1059
Willy Tarreaubaaee002006-06-26 02:48:02 +02001060 if (*(args[1]) == 0) {
1061 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
1062 return -1;
1063 }
1064 curproxy->maxconn = atol(args[1]);
1065 }
Willy Tarreau86034312006-12-29 00:10:33 +01001066 else if (!strcmp(args[0], "fullconn")) { /* fullconn */
Willy Tarreau977b8e42006-12-29 14:19:17 +01001067 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], " Maybe you want 'maxconn' instead ?"))
1068 return 0;
1069
Willy Tarreau86034312006-12-29 00:10:33 +01001070 if (*(args[1]) == 0) {
1071 Alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
1072 return -1;
1073 }
1074 curproxy->fullconn = atol(args[1]);
1075 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001076 else if (!strcmp(args[0], "grace")) { /* grace time (ms) */
1077 if (*(args[1]) == 0) {
1078 Alert("parsing [%s:%d] : '%s' expects a time in milliseconds.\n", file, linenum, args[0]);
1079 return -1;
1080 }
1081 curproxy->grace = atol(args[1]);
1082 }
1083 else if (!strcmp(args[0], "dispatch")) { /* dispatch address */
1084 if (curproxy == &defproxy) {
1085 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1086 return -1;
1087 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001088 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1089 return 0;
1090
Willy Tarreaubaaee002006-06-26 02:48:02 +02001091 if (strchr(args[1], ':') == NULL) {
1092 Alert("parsing [%s:%d] : '%s' expects <addr:port> as argument.\n", file, linenum, args[0]);
1093 return -1;
1094 }
1095 curproxy->dispatch_addr = *str2sa(args[1]);
1096 }
1097 else if (!strcmp(args[0], "balance")) { /* set balancing with optional algorithm */
Willy Tarreau977b8e42006-12-29 14:19:17 +01001098 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1099 return 0;
1100
Willy Tarreaubaaee002006-06-26 02:48:02 +02001101 if (*(args[1])) {
1102 if (!strcmp(args[1], "roundrobin")) {
1103 curproxy->options |= PR_O_BALANCE_RR;
1104 }
1105 else if (!strcmp(args[1], "source")) {
1106 curproxy->options |= PR_O_BALANCE_SH;
1107 }
1108 else {
1109 Alert("parsing [%s:%d] : '%s' only supports 'roundrobin' and 'source' options.\n", file, linenum, args[0]);
1110 return -1;
1111 }
1112 }
1113 else /* if no option is set, use round-robin by default */
1114 curproxy->options |= PR_O_BALANCE_RR;
1115 }
1116 else if (!strcmp(args[0], "server")) { /* server address */
1117 int cur_arg;
1118 char *rport;
1119 char *raddr;
1120 short realport;
1121 int do_check;
1122
1123 if (curproxy == &defproxy) {
1124 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1125 return -1;
1126 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001127 else if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1128 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001129
1130 if (!*args[2]) {
1131 Alert("parsing [%s:%d] : '%s' expects <name> and <addr>[:<port>] as arguments.\n",
1132 file, linenum, args[0]);
1133 return -1;
1134 }
1135 if ((newsrv = (struct server *)calloc(1, sizeof(struct server))) == NULL) {
1136 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1137 return -1;
1138 }
1139
1140 /* the servers are linked backwards first */
1141 newsrv->next = curproxy->srv;
1142 curproxy->srv = newsrv;
1143 newsrv->proxy = curproxy;
1144
1145 LIST_INIT(&newsrv->pendconns);
1146 do_check = 0;
1147 newsrv->state = SRV_RUNNING; /* early server setup */
1148 newsrv->id = strdup(args[1]);
1149
1150 /* several ways to check the port component :
1151 * - IP => port=+0, relative
1152 * - IP: => port=+0, relative
1153 * - IP:N => port=N, absolute
1154 * - IP:+N => port=+N, relative
1155 * - IP:-N => port=-N, relative
1156 */
1157 raddr = strdup(args[2]);
1158 rport = strchr(raddr, ':');
1159 if (rport) {
1160 *rport++ = 0;
1161 realport = atol(rport);
1162 if (!isdigit((int)*rport))
1163 newsrv->state |= SRV_MAPPORTS;
1164 } else {
1165 realport = 0;
1166 newsrv->state |= SRV_MAPPORTS;
1167 }
1168
1169 newsrv->addr = *str2sa(raddr);
1170 newsrv->addr.sin_port = htons(realport);
1171 free(raddr);
1172
1173 newsrv->curfd = -1; /* no health-check in progress */
1174 newsrv->inter = DEF_CHKINTR;
1175 newsrv->rise = DEF_RISETIME;
1176 newsrv->fall = DEF_FALLTIME;
1177 newsrv->health = newsrv->rise; /* up, but will fall down at first failure */
1178 cur_arg = 3;
1179 while (*args[cur_arg]) {
1180 if (!strcmp(args[cur_arg], "cookie")) {
1181 newsrv->cookie = strdup(args[cur_arg + 1]);
1182 newsrv->cklen = strlen(args[cur_arg + 1]);
1183 cur_arg += 2;
1184 }
1185 else if (!strcmp(args[cur_arg], "rise")) {
1186 newsrv->rise = atol(args[cur_arg + 1]);
1187 newsrv->health = newsrv->rise;
1188 cur_arg += 2;
1189 }
1190 else if (!strcmp(args[cur_arg], "fall")) {
1191 newsrv->fall = atol(args[cur_arg + 1]);
1192 cur_arg += 2;
1193 }
1194 else if (!strcmp(args[cur_arg], "inter")) {
1195 newsrv->inter = atol(args[cur_arg + 1]);
1196 cur_arg += 2;
1197 }
1198 else if (!strcmp(args[cur_arg], "port")) {
1199 newsrv->check_port = atol(args[cur_arg + 1]);
1200 cur_arg += 2;
1201 }
1202 else if (!strcmp(args[cur_arg], "backup")) {
1203 newsrv->state |= SRV_BACKUP;
1204 cur_arg ++;
1205 }
1206 else if (!strcmp(args[cur_arg], "weight")) {
1207 int w;
1208 w = atol(args[cur_arg + 1]);
1209 if (w < 1 || w > 256) {
1210 Alert("parsing [%s:%d] : weight of server %s is not within 1 and 256 (%d).\n",
1211 file, linenum, newsrv->id, w);
1212 return -1;
1213 }
1214 newsrv->uweight = w - 1;
1215 cur_arg += 2;
1216 }
1217 else if (!strcmp(args[cur_arg], "minconn")) {
1218 newsrv->minconn = atol(args[cur_arg + 1]);
1219 cur_arg += 2;
1220 }
1221 else if (!strcmp(args[cur_arg], "maxconn")) {
1222 newsrv->maxconn = atol(args[cur_arg + 1]);
1223 cur_arg += 2;
1224 }
1225 else if (!strcmp(args[cur_arg], "check")) {
1226 global.maxsock++;
1227 do_check = 1;
1228 cur_arg += 1;
1229 }
1230 else if (!strcmp(args[cur_arg], "source")) { /* address to which we bind when connecting */
1231 if (!*args[cur_arg + 1]) {
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001232#ifdef CONFIG_HAP_CTTPROXY
1233 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optional '%s' <addr> as argument.\n",
1234 file, linenum, "source", "usesrc");
1235#else
Willy Tarreaubaaee002006-06-26 02:48:02 +02001236 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>] as argument.\n",
1237 file, linenum, "source");
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001238#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001239 return -1;
1240 }
1241 newsrv->state |= SRV_BIND_SRC;
1242 newsrv->source_addr = *str2sa(args[cur_arg + 1]);
1243 cur_arg += 2;
Willy Tarreau77074d52006-11-12 23:57:19 +01001244 if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside */
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001245#ifdef CONFIG_HAP_CTTPROXY
Willy Tarreau77074d52006-11-12 23:57:19 +01001246 if (newsrv->source_addr.sin_addr.s_addr == INADDR_ANY) {
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001247 Alert("parsing [%s:%d] : '%s' requires an explicit '%s' address.\n",
1248 file, linenum, "usesrc", "source");
Willy Tarreau77074d52006-11-12 23:57:19 +01001249 return -1;
1250 }
1251 if (!*args[cur_arg + 1]) {
1252 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
1253 file, linenum, "usesrc");
1254 return -1;
1255 }
1256 if (!strcmp(args[cur_arg + 1], "client")) {
1257 newsrv->state |= SRV_TPROXY_CLI;
1258 } else if (!strcmp(args[cur_arg + 1], "clientip")) {
1259 newsrv->state |= SRV_TPROXY_CIP;
1260 } else {
1261 newsrv->state |= SRV_TPROXY_ADDR;
1262 newsrv->tproxy_addr = *str2sa(args[cur_arg + 1]);
1263 }
1264 global.last_checks |= LSTCHK_CTTPROXY | LSTCHK_NETADM;
1265 cur_arg += 2;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001266#else /* no CTTPROXY support */
1267 Alert("parsing [%s:%d] : '%s' not allowed here because support for cttproxy was not compiled in.\n",
1268 file, linenum, "usesrc");
1269 return -1;
Willy Tarreau77074d52006-11-12 23:57:19 +01001270#endif
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001271 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001272 }
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001273#ifdef CONFIG_HAP_CTTPROXY
1274 else if (!strcmp(args[cur_arg], "usesrc")) { /* address to use outside: needs "source" first */
1275 Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
1276 file, linenum, "usesrc", "source");
1277 return -1;
1278 }
1279#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001280 else {
1281 Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'check', 'inter', 'rise', 'fall', 'port', 'source', 'minconn', 'maxconn' and 'weight'.\n",
1282 file, linenum, newsrv->id);
1283 return -1;
1284 }
1285 }
1286
1287 if (do_check) {
1288 if (!newsrv->check_port && !(newsrv->state & SRV_MAPPORTS))
1289 newsrv->check_port = realport; /* by default */
1290 if (!newsrv->check_port) {
Willy Tarreauef00b502007-01-07 02:40:09 +01001291 /* not yet valid, because no port was set on
1292 * the server either. We'll check if we have
1293 * a known port on the first listener.
1294 */
1295 struct listener *l;
1296 l = curproxy->listen;
1297 if (l) {
1298 int port;
1299 port = (l->addr.ss_family == AF_INET6)
1300 ? ntohs(((struct sockaddr_in6 *)(&l->addr))->sin6_port)
1301 : ntohs(((struct sockaddr_in *)(&l->addr))->sin_port);
1302 newsrv->check_port = port;
1303 }
1304 }
1305 if (!newsrv->check_port) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02001306 Alert("parsing [%s:%d] : server %s has neither service port nor check port. Check has been disabled.\n",
1307 file, linenum, newsrv->id);
1308 return -1;
1309 }
1310 newsrv->state |= SRV_CHECKED;
1311 }
1312
1313 if (newsrv->state & SRV_BACKUP)
1314 curproxy->srv_bck++;
1315 else
1316 curproxy->srv_act++;
1317 }
1318 else if (!strcmp(args[0], "log")) { /* syslog server address */
1319 struct sockaddr_in *sa;
1320 int facility;
1321
1322 if (*(args[1]) && *(args[2]) == 0 && !strcmp(args[1], "global")) {
1323 curproxy->logfac1 = global.logfac1;
1324 curproxy->logsrv1 = global.logsrv1;
1325 curproxy->loglev1 = global.loglev1;
1326 curproxy->logfac2 = global.logfac2;
1327 curproxy->logsrv2 = global.logsrv2;
1328 curproxy->loglev2 = global.loglev2;
1329 }
1330 else if (*(args[1]) && *(args[2])) {
1331 int level;
1332
1333 facility = get_log_facility(args[2]);
1334 if (facility < 0) {
1335 Alert("parsing [%s:%d] : unknown log facility '%s'\n", file, linenum, args[2]);
1336 exit(1);
1337 }
1338
1339 level = 7; /* max syslog level = debug */
1340 if (*(args[3])) {
1341 level = get_log_level(args[3]);
1342 if (level < 0) {
1343 Alert("parsing [%s:%d] : unknown optional log level '%s'\n", file, linenum, args[3]);
1344 exit(1);
1345 }
1346 }
1347
1348 sa = str2sa(args[1]);
1349 if (!sa->sin_port)
1350 sa->sin_port = htons(SYSLOG_PORT);
1351
1352 if (curproxy->logfac1 == -1) {
1353 curproxy->logsrv1 = *sa;
1354 curproxy->logfac1 = facility;
1355 curproxy->loglev1 = level;
1356 }
1357 else if (curproxy->logfac2 == -1) {
1358 curproxy->logsrv2 = *sa;
1359 curproxy->logfac2 = facility;
1360 curproxy->loglev2 = level;
1361 }
1362 else {
1363 Alert("parsing [%s:%d] : too many syslog servers\n", file, linenum);
1364 return -1;
1365 }
1366 }
1367 else {
1368 Alert("parsing [%s:%d] : 'log' expects either <address[:port]> and <facility> or 'global' as arguments.\n",
1369 file, linenum);
1370 return -1;
1371 }
1372 }
1373 else if (!strcmp(args[0], "source")) { /* address to which we bind when connecting */
Willy Tarreau977b8e42006-12-29 14:19:17 +01001374 if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
1375 return 0;
1376
Willy Tarreaubaaee002006-06-26 02:48:02 +02001377 if (!*args[1]) {
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001378#ifdef CONFIG_HAP_CTTPROXY
1379 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], and optional '%s' <addr> as argument.\n",
1380 file, linenum, "source", "usesrc");
1381#else
Willy Tarreaubaaee002006-06-26 02:48:02 +02001382 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>] as argument.\n",
1383 file, linenum, "source");
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001384#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001385 return -1;
1386 }
1387
1388 curproxy->source_addr = *str2sa(args[1]);
1389 curproxy->options |= PR_O_BIND_SRC;
Willy Tarreau77074d52006-11-12 23:57:19 +01001390 if (!strcmp(args[2], "usesrc")) { /* address to use outside */
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001391#ifdef CONFIG_HAP_CTTPROXY
Willy Tarreau77074d52006-11-12 23:57:19 +01001392 if (curproxy->source_addr.sin_addr.s_addr == INADDR_ANY) {
1393 Alert("parsing [%s:%d] : '%s' requires an explicit 'source' address.\n",
1394 file, linenum, "usesrc");
1395 return -1;
1396 }
1397 if (!*args[3]) {
1398 Alert("parsing [%s:%d] : '%s' expects <addr>[:<port>], 'client', or 'clientip' as argument.\n",
1399 file, linenum, "usesrc");
1400 return -1;
1401 }
1402
1403 if (!strcmp(args[3], "client")) {
1404 curproxy->options |= PR_O_TPXY_CLI;
1405 } else if (!strcmp(args[3], "clientip")) {
1406 curproxy->options |= PR_O_TPXY_CIP;
1407 } else {
1408 curproxy->options |= PR_O_TPXY_ADDR;
1409 curproxy->tproxy_addr = *str2sa(args[3]);
1410 }
1411 global.last_checks |= LSTCHK_CTTPROXY | LSTCHK_NETADM;
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001412#else /* no CTTPROXY support */
1413 Alert("parsing [%s:%d] : '%s' not allowed here because support for cttproxy was not compiled in.\n",
1414 file, linenum, "usesrc");
1415 return -1;
Willy Tarreau77074d52006-11-12 23:57:19 +01001416#endif
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001417 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001418 }
Willy Tarreau8d9246d2007-03-24 12:47:24 +01001419#ifdef CONFIG_HAP_CTTPROXY
1420 else if (!strcmp(args[0], "usesrc")) { /* address to use outside: needs "source" first */
1421 Alert("parsing [%s:%d] : '%s' only allowed after a '%s' statement.\n",
1422 file, linenum, "usesrc", "source");
1423 return -1;
1424 }
1425#endif
Willy Tarreaubaaee002006-06-26 02:48:02 +02001426 else if (!strcmp(args[0], "cliexp") || !strcmp(args[0], "reqrep")) { /* replace request header from a regex */
1427 regex_t *preg;
1428 if (curproxy == &defproxy) {
1429 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1430 return -1;
1431 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001432 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1433 return 0;
1434
Willy Tarreaubaaee002006-06-26 02:48:02 +02001435 if (*(args[1]) == 0 || *(args[2]) == 0) {
1436 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1437 file, linenum, args[0]);
1438 return -1;
1439 }
1440
1441 preg = calloc(1, sizeof(regex_t));
1442 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1443 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1444 return -1;
1445 }
1446
1447 err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]));
1448 if (err) {
1449 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1450 file, linenum, *err);
1451 return -1;
1452 }
1453 }
1454 else if (!strcmp(args[0], "reqdel")) { /* delete request header from a regex */
1455 regex_t *preg;
1456 if (curproxy == &defproxy) {
1457 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1458 return -1;
1459 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001460 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1461 return 0;
1462
Willy Tarreaubaaee002006-06-26 02:48:02 +02001463 if (*(args[1]) == 0) {
1464 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1465 return -1;
1466 }
1467
1468 preg = calloc(1, sizeof(regex_t));
1469 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1470 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1471 return -1;
1472 }
1473
1474 chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL);
1475 }
1476 else if (!strcmp(args[0], "reqdeny")) { /* deny a request if a header matches this regex */
1477 regex_t *preg;
1478 if (curproxy == &defproxy) {
1479 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1480 return -1;
1481 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001482 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1483 return 0;
1484
Willy Tarreaubaaee002006-06-26 02:48:02 +02001485 if (*(args[1]) == 0) {
1486 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1487 return -1;
1488 }
1489
1490 preg = calloc(1, sizeof(regex_t));
1491 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1492 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1493 return -1;
1494 }
1495
1496 chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL);
1497 }
1498 else if (!strcmp(args[0], "reqpass")) { /* pass this header without allowing or denying the request */
1499 regex_t *preg;
1500 if (curproxy == &defproxy) {
1501 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1502 return -1;
1503 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001504 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1505 return 0;
1506
Willy Tarreaubaaee002006-06-26 02:48:02 +02001507 if (*(args[1]) == 0) {
1508 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1509 return -1;
1510 }
1511
1512 preg = calloc(1, sizeof(regex_t));
1513 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1514 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1515 return -1;
1516 }
1517
1518 chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL);
1519 }
1520 else if (!strcmp(args[0], "reqallow")) { /* allow a request if a header matches this regex */
1521 regex_t *preg;
1522 if (curproxy == &defproxy) {
1523 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1524 return -1;
1525 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001526 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1527 return 0;
1528
Willy Tarreaubaaee002006-06-26 02:48:02 +02001529 if (*(args[1]) == 0) {
1530 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1531 return -1;
1532 }
1533
1534 preg = calloc(1, sizeof(regex_t));
1535 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1536 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1537 return -1;
1538 }
1539
1540 chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL);
1541 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02001542 else if (!strcmp(args[0], "reqtarpit")) { /* tarpit a request if a header matches this regex */
1543 regex_t *preg;
1544 if (curproxy == &defproxy) {
1545 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1546 return -1;
1547 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001548 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1549 return 0;
1550
Willy Tarreaub8750a82006-09-03 09:56:00 +02001551 if (*(args[1]) == 0) {
1552 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1553 return -1;
1554 }
1555
1556 preg = calloc(1, sizeof(regex_t));
1557 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1558 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1559 return -1;
1560 }
1561
1562 chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL);
1563 }
Willy Tarreaua496b602006-12-17 23:15:24 +01001564 else if (!strcmp(args[0], "reqsetbe")) { /* switch the backend from a regex, respecting case */
1565 regex_t *preg;
Willy Tarreau977b8e42006-12-29 14:19:17 +01001566 if (curproxy == &defproxy) {
Willy Tarreaua496b602006-12-17 23:15:24 +01001567 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1568 return -1;
1569 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001570 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1571 return 0;
Willy Tarreaua496b602006-12-17 23:15:24 +01001572
Willy Tarreau977b8e42006-12-29 14:19:17 +01001573 if (*(args[1]) == 0 || *(args[2]) == 0) {
Willy Tarreaua496b602006-12-17 23:15:24 +01001574 Alert("parsing [%s:%d] : '%s' expects <search> and <target> as arguments.\n",
1575 file, linenum, args[0]);
1576 return -1;
1577 }
1578
1579 preg = calloc(1, sizeof(regex_t));
Willy Tarreau977b8e42006-12-29 14:19:17 +01001580 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
Willy Tarreaua496b602006-12-17 23:15:24 +01001581 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1582 }
1583
1584 chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2]));
1585 }
1586 else if (!strcmp(args[0], "reqisetbe")) { /* switch the backend from a regex, ignoring case */
1587 regex_t *preg;
Willy Tarreau977b8e42006-12-29 14:19:17 +01001588 if (curproxy == &defproxy) {
Willy Tarreaua496b602006-12-17 23:15:24 +01001589 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1590 return -1;
1591 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001592 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1593 return 0;
Willy Tarreaua496b602006-12-17 23:15:24 +01001594
Willy Tarreau977b8e42006-12-29 14:19:17 +01001595 if (*(args[1]) == 0 || *(args[2]) == 0) {
Willy Tarreaua496b602006-12-17 23:15:24 +01001596 Alert("parsing [%s:%d] : '%s' expects <search> and <target> as arguments.\n",
1597 file, linenum, args[0]);
1598 return -1;
1599 }
1600
1601 preg = calloc(1, sizeof(regex_t));
Willy Tarreau977b8e42006-12-29 14:19:17 +01001602 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
Willy Tarreaua496b602006-12-17 23:15:24 +01001603 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1604 }
1605
1606 chain_regex(&curproxy->req_exp, preg, ACT_SETBE, strdup(args[2]));
1607 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001608 else if (!strcmp(args[0], "reqirep")) { /* replace request header from a regex, ignoring case */
1609 regex_t *preg;
1610 if (curproxy == &defproxy) {
1611 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1612 return -1;
1613 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001614 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1615 return 0;
1616
Willy Tarreaubaaee002006-06-26 02:48:02 +02001617 if (*(args[1]) == 0 || *(args[2]) == 0) {
1618 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1619 file, linenum, args[0]);
1620 return -1;
1621 }
1622
1623 preg = calloc(1, sizeof(regex_t));
1624 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1625 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1626 return -1;
1627 }
1628
1629 err = chain_regex(&curproxy->req_exp, preg, ACT_REPLACE, strdup(args[2]));
1630 if (err) {
1631 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1632 file, linenum, *err);
1633 return -1;
1634 }
1635 }
1636 else if (!strcmp(args[0], "reqidel")) { /* delete request header from a regex ignoring case */
1637 regex_t *preg;
1638 if (curproxy == &defproxy) {
1639 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1640 return -1;
1641 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001642 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1643 return 0;
1644
Willy Tarreaubaaee002006-06-26 02:48:02 +02001645 if (*(args[1]) == 0) {
1646 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1647 return -1;
1648 }
1649
1650 preg = calloc(1, sizeof(regex_t));
1651 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1652 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1653 return -1;
1654 }
1655
1656 chain_regex(&curproxy->req_exp, preg, ACT_REMOVE, NULL);
1657 }
1658 else if (!strcmp(args[0], "reqideny")) { /* deny a request if a header matches this regex ignoring case */
1659 regex_t *preg;
1660 if (curproxy == &defproxy) {
1661 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1662 return -1;
1663 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001664 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1665 return 0;
1666
Willy Tarreaubaaee002006-06-26 02:48:02 +02001667 if (*(args[1]) == 0) {
1668 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1669 return -1;
1670 }
1671
1672 preg = calloc(1, sizeof(regex_t));
1673 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1674 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1675 return -1;
1676 }
1677
1678 chain_regex(&curproxy->req_exp, preg, ACT_DENY, NULL);
1679 }
1680 else if (!strcmp(args[0], "reqipass")) { /* pass this header without allowing or denying the request */
1681 regex_t *preg;
1682 if (curproxy == &defproxy) {
1683 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1684 return -1;
1685 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001686 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1687 return 0;
1688
Willy Tarreaubaaee002006-06-26 02:48:02 +02001689 if (*(args[1]) == 0) {
1690 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1691 return -1;
1692 }
1693
1694 preg = calloc(1, sizeof(regex_t));
1695 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1696 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1697 return -1;
1698 }
1699
1700 chain_regex(&curproxy->req_exp, preg, ACT_PASS, NULL);
1701 }
1702 else if (!strcmp(args[0], "reqiallow")) { /* allow a request if a header matches this regex ignoring case */
1703 regex_t *preg;
1704 if (curproxy == &defproxy) {
1705 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1706 return -1;
1707 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001708 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1709 return 0;
1710
Willy Tarreaubaaee002006-06-26 02:48:02 +02001711 if (*(args[1]) == 0) {
1712 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1713 return -1;
1714 }
1715
1716 preg = calloc(1, sizeof(regex_t));
1717 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1718 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1719 return -1;
1720 }
1721
1722 chain_regex(&curproxy->req_exp, preg, ACT_ALLOW, NULL);
1723 }
Willy Tarreaub8750a82006-09-03 09:56:00 +02001724 else if (!strcmp(args[0], "reqitarpit")) { /* tarpit a request if a header matches this regex ignoring case */
1725 regex_t *preg;
1726 if (curproxy == &defproxy) {
1727 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1728 return -1;
1729 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001730 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1731 return 0;
1732
Willy Tarreaub8750a82006-09-03 09:56:00 +02001733 if (*(args[1]) == 0) {
1734 Alert("parsing [%s:%d] : '%s' expects <regex> as an argument.\n", file, linenum, args[0]);
1735 return -1;
1736 }
1737
1738 preg = calloc(1, sizeof(regex_t));
1739 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1740 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1741 return -1;
1742 }
1743
1744 chain_regex(&curproxy->req_exp, preg, ACT_TARPIT, NULL);
1745 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001746 else if (!strcmp(args[0], "reqadd")) { /* add request header */
1747 if (curproxy == &defproxy) {
1748 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1749 return -1;
1750 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001751 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1752 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001753
1754 if (curproxy->nb_reqadd >= MAX_NEWHDR) {
1755 Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]);
1756 return 0;
1757 }
1758
1759 if (*(args[1]) == 0) {
1760 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
1761 return -1;
1762 }
1763
1764 curproxy->req_add[curproxy->nb_reqadd++] = strdup(args[1]);
1765 }
1766 else if (!strcmp(args[0], "srvexp") || !strcmp(args[0], "rsprep")) { /* replace response header from a regex */
1767 regex_t *preg;
1768
1769 if (*(args[1]) == 0 || *(args[2]) == 0) {
1770 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1771 file, linenum, args[0]);
1772 return -1;
1773 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001774 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1775 return 0;
1776
Willy Tarreaubaaee002006-06-26 02:48:02 +02001777 preg = calloc(1, sizeof(regex_t));
1778 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1779 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1780 return -1;
1781 }
1782
1783 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]));
1784 if (err) {
1785 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1786 file, linenum, *err);
1787 return -1;
1788 }
1789 }
1790 else if (!strcmp(args[0], "rspdel")) { /* delete response header from a regex */
1791 regex_t *preg;
1792 if (curproxy == &defproxy) {
1793 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1794 return -1;
1795 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001796 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1797 return 0;
1798
Willy Tarreaubaaee002006-06-26 02:48:02 +02001799 if (*(args[1]) == 0) {
1800 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1801 return -1;
1802 }
1803
1804 preg = calloc(1, sizeof(regex_t));
1805 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1806 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1807 return -1;
1808 }
1809
1810 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]));
1811 if (err) {
1812 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1813 file, linenum, *err);
1814 return -1;
1815 }
1816 }
1817 else if (!strcmp(args[0], "rspdeny")) { /* block response header from a regex */
1818 regex_t *preg;
1819 if (curproxy == &defproxy) {
1820 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1821 return -1;
1822 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001823 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1824 return 0;
1825
Willy Tarreaubaaee002006-06-26 02:48:02 +02001826 if (*(args[1]) == 0) {
1827 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1828 return -1;
1829 }
1830
1831 preg = calloc(1, sizeof(regex_t));
1832 if (regcomp(preg, args[1], REG_EXTENDED) != 0) {
1833 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1834 return -1;
1835 }
1836
1837 err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]));
1838 if (err) {
1839 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1840 file, linenum, *err);
1841 return -1;
1842 }
1843 }
1844 else if (!strcmp(args[0], "rspirep")) { /* replace response header from a regex ignoring case */
1845 regex_t *preg;
1846 if (curproxy == &defproxy) {
1847 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1848 return -1;
1849 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001850 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1851 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001852
1853 if (*(args[1]) == 0 || *(args[2]) == 0) {
1854 Alert("parsing [%s:%d] : '%s' expects <search> and <replace> as arguments.\n",
1855 file, linenum, args[0]);
1856 return -1;
1857 }
1858
1859 preg = calloc(1, sizeof(regex_t));
1860 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1861 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1862 return -1;
1863 }
1864
1865 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REPLACE, strdup(args[2]));
1866 if (err) {
1867 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1868 file, linenum, *err);
1869 return -1;
1870 }
1871 }
1872 else if (!strcmp(args[0], "rspidel")) { /* delete response header from a regex ignoring case */
1873 regex_t *preg;
1874 if (curproxy == &defproxy) {
1875 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1876 return -1;
1877 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001878 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1879 return 0;
1880
Willy Tarreaubaaee002006-06-26 02:48:02 +02001881 if (*(args[1]) == 0) {
1882 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1883 return -1;
1884 }
1885
1886 preg = calloc(1, sizeof(regex_t));
1887 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1888 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1889 return -1;
1890 }
1891
1892 err = chain_regex(&curproxy->rsp_exp, preg, ACT_REMOVE, strdup(args[2]));
1893 if (err) {
1894 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1895 file, linenum, *err);
1896 return -1;
1897 }
1898 }
1899 else if (!strcmp(args[0], "rspideny")) { /* block response header from a regex ignoring case */
1900 regex_t *preg;
1901 if (curproxy == &defproxy) {
1902 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1903 return -1;
1904 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001905 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1906 return 0;
1907
Willy Tarreaubaaee002006-06-26 02:48:02 +02001908 if (*(args[1]) == 0) {
1909 Alert("parsing [%s:%d] : '%s' expects <search> as an argument.\n", file, linenum, args[0]);
1910 return -1;
1911 }
1912
1913 preg = calloc(1, sizeof(regex_t));
1914 if (regcomp(preg, args[1], REG_EXTENDED | REG_ICASE) != 0) {
1915 Alert("parsing [%s:%d] : bad regular expression '%s'.\n", file, linenum, args[1]);
1916 return -1;
1917 }
1918
1919 err = chain_regex(&curproxy->rsp_exp, preg, ACT_DENY, strdup(args[2]));
1920 if (err) {
1921 Alert("parsing [%s:%d] : invalid character or unterminated sequence in replacement string near '%c'.\n",
1922 file, linenum, *err);
1923 return -1;
1924 }
1925 }
1926 else if (!strcmp(args[0], "rspadd")) { /* add response header */
1927 if (curproxy == &defproxy) {
1928 Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1929 return -1;
1930 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01001931 else if (warnifnotcap(curproxy, PR_CAP_RS, file, linenum, args[0], NULL))
1932 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001933
1934 if (curproxy->nb_rspadd >= MAX_NEWHDR) {
1935 Alert("parsing [%s:%d] : too many '%s'. Continuing.\n", file, linenum, args[0]);
1936 return 0;
1937 }
1938
1939 if (*(args[1]) == 0) {
1940 Alert("parsing [%s:%d] : '%s' expects <header> as an argument.\n", file, linenum, args[0]);
1941 return -1;
1942 }
1943
1944 curproxy->rsp_add[curproxy->nb_rspadd++] = strdup(args[1]);
1945 }
1946 else if (!strcmp(args[0], "errorloc") ||
1947 !strcmp(args[0], "errorloc302") ||
1948 !strcmp(args[0], "errorloc303")) { /* error location */
1949 int errnum, errlen;
1950 char *err;
1951
1952 // if (curproxy == &defproxy) {
1953 // Alert("parsing [%s:%d] : '%s' not allowed in 'defaults' section.\n", file, linenum, args[0]);
1954 // return -1;
1955 // }
1956
Willy Tarreau977b8e42006-12-29 14:19:17 +01001957 if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
1958 return 0;
1959
Willy Tarreaubaaee002006-06-26 02:48:02 +02001960 if (*(args[2]) == 0) {
Willy Tarreau0f772532006-12-23 20:51:41 +01001961 Alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001962 return -1;
1963 }
1964
1965 errnum = atol(args[1]);
1966 if (!strcmp(args[0], "errorloc303")) {
1967 err = malloc(strlen(HTTP_303) + strlen(args[2]) + 5);
1968 errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_303, args[2]);
1969 } else {
1970 err = malloc(strlen(HTTP_302) + strlen(args[2]) + 5);
1971 errlen = sprintf(err, "%s%s\r\n\r\n", HTTP_302, args[2]);
1972 }
1973
Willy Tarreau0f772532006-12-23 20:51:41 +01001974 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
1975 if (http_err_codes[rc] == errnum) {
1976 if (curproxy->errmsg[rc].str)
1977 free(curproxy->errmsg[rc].str);
1978 curproxy->errmsg[rc].str = err;
1979 curproxy->errmsg[rc].len = errlen;
1980 break;
Willy Tarreaubaaee002006-06-26 02:48:02 +02001981 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02001982 }
Willy Tarreau0f772532006-12-23 20:51:41 +01001983
1984 if (rc >= HTTP_ERR_SIZE) {
1985 Warning("parsing [%s:%d] : status code %d not handled, error relocation will be ignored.\n",
1986 file, linenum, errnum);
Willy Tarreaubaaee002006-06-26 02:48:02 +02001987 free(err);
1988 }
1989 }
1990 else {
1991 Alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], "listen");
1992 return -1;
1993 }
1994 return 0;
1995}
1996
1997
1998/*
1999 * This function reads and parses the configuration file given in the argument.
2000 * returns 0 if OK, -1 if error.
2001 */
Willy Tarreaub17916e2006-10-15 15:17:57 +02002002int readcfgfile(const char *file)
Willy Tarreaubaaee002006-06-26 02:48:02 +02002003{
2004 char thisline[256];
2005 char *line;
2006 FILE *f;
2007 int linenum = 0;
2008 char *end;
2009 char *args[MAX_LINE_ARGS];
2010 int arg;
2011 int cfgerr = 0;
Willy Tarreau80587432006-12-24 17:47:20 +01002012 int nbchk, mininter;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002013 int confsect = CFG_NONE;
2014
2015 struct proxy *curproxy = NULL;
2016 struct server *newsrv = NULL;
2017
2018 if ((f=fopen(file,"r")) == NULL)
2019 return -1;
2020
2021 init_default_instance();
2022
2023 while (fgets(line = thisline, sizeof(thisline), f) != NULL) {
2024 linenum++;
2025
2026 end = line + strlen(line);
2027
2028 /* skip leading spaces */
2029 while (isspace((int)*line))
2030 line++;
2031
2032 arg = 0;
2033 args[arg] = line;
2034
2035 while (*line && arg < MAX_LINE_ARGS) {
2036 /* first, we'll replace \\, \<space>, \#, \r, \n, \t, \xXX with their
2037 * C equivalent value. Other combinations left unchanged (eg: \1).
2038 */
2039 if (*line == '\\') {
2040 int skip = 0;
2041 if (line[1] == ' ' || line[1] == '\\' || line[1] == '#') {
2042 *line = line[1];
2043 skip = 1;
2044 }
2045 else if (line[1] == 'r') {
2046 *line = '\r';
2047 skip = 1;
2048 }
2049 else if (line[1] == 'n') {
2050 *line = '\n';
2051 skip = 1;
2052 }
2053 else if (line[1] == 't') {
2054 *line = '\t';
2055 skip = 1;
2056 }
2057 else if (line[1] == 'x') {
2058 if ((line + 3 < end ) && ishex(line[2]) && ishex(line[3])) {
2059 unsigned char hex1, hex2;
2060 hex1 = toupper(line[2]) - '0';
2061 hex2 = toupper(line[3]) - '0';
2062 if (hex1 > 9) hex1 -= 'A' - '9' - 1;
2063 if (hex2 > 9) hex2 -= 'A' - '9' - 1;
2064 *line = (hex1<<4) + hex2;
2065 skip = 3;
2066 }
2067 else {
2068 Alert("parsing [%s:%d] : invalid or incomplete '\\x' sequence in '%s'.\n", file, linenum, args[0]);
2069 return -1;
2070 }
2071 }
2072 if (skip) {
2073 memmove(line + 1, line + 1 + skip, end - (line + skip + 1));
2074 end -= skip;
2075 }
2076 line++;
2077 }
2078 else if (*line == '#' || *line == '\n' || *line == '\r') {
2079 /* end of string, end of loop */
2080 *line = 0;
2081 break;
2082 }
2083 else if (isspace((int)*line)) {
2084 /* a non-escaped space is an argument separator */
2085 *line++ = 0;
2086 while (isspace((int)*line))
2087 line++;
2088 args[++arg] = line;
2089 }
2090 else {
2091 line++;
2092 }
2093 }
2094
2095 /* empty line */
2096 if (!**args)
2097 continue;
2098
2099 /* zero out remaining args */
2100 while (++arg < MAX_LINE_ARGS) {
2101 args[arg] = line;
2102 }
2103
Willy Tarreau977b8e42006-12-29 14:19:17 +01002104 if (!strcmp(args[0], "listen") ||
2105 !strcmp(args[0], "frontend") ||
2106 !strcmp(args[0], "backend") ||
2107 !strcmp(args[0], "ruleset") ||
2108 !strcmp(args[0], "defaults")) /* new proxy */
Willy Tarreaubaaee002006-06-26 02:48:02 +02002109 confsect = CFG_LISTEN;
2110 else if (!strcmp(args[0], "global")) /* global config */
2111 confsect = CFG_GLOBAL;
2112 /* else it's a section keyword */
2113
2114 switch (confsect) {
2115 case CFG_LISTEN:
2116 if (cfg_parse_listen(file, linenum, args) < 0)
2117 return -1;
2118 break;
2119 case CFG_GLOBAL:
2120 if (cfg_parse_global(file, linenum, args) < 0)
2121 return -1;
2122 break;
2123 default:
2124 Alert("parsing [%s:%d] : unknown keyword '%s' out of section.\n", file, linenum, args[0]);
2125 return -1;
2126 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002127 }
2128 fclose(f);
2129
2130 /*
2131 * Now, check for the integrity of all that we have collected.
2132 */
2133
2134 /* will be needed further to delay some tasks */
2135 tv_now(&now);
2136
2137 if ((curproxy = proxy) == NULL) {
2138 Alert("parsing %s : no <listen> line. Nothing to do !\n",
2139 file);
2140 return -1;
2141 }
2142
2143 while (curproxy != NULL) {
Willy Tarreau97a738f2006-12-17 18:02:30 +01002144 curproxy->fiprm = curproxy->beprm = curproxy;
2145
Willy Tarreaubaaee002006-06-26 02:48:02 +02002146 if (curproxy->state == PR_STSTOPPED) {
2147 curproxy = curproxy->next;
2148 continue;
2149 }
2150
Willy Tarreau977b8e42006-12-29 14:19:17 +01002151 if (curproxy->cap & PR_CAP_FE && curproxy->listen == NULL) {
2152 Alert("parsing %s : %s '%s' has no listen address. Please either specify a valid address on the <listen> line, or use the <bind> keyword.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002153 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002154 cfgerr++;
2155 }
Willy Tarreau977b8e42006-12-29 14:19:17 +01002156 else if (curproxy->cap & PR_CAP_BE &&
2157 ((curproxy->mode != PR_MODE_HEALTH) &&
2158 !(curproxy->options & (PR_O_TRANSP | PR_O_BALANCE)) &&
2159 (*(int *)&curproxy->dispatch_addr.sin_addr == 0))) {
2160 Alert("parsing %s : %s '%s' has no dispatch address and is not in transparent or balance mode.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002161 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002162 cfgerr++;
2163 }
2164 else if ((curproxy->mode != PR_MODE_HEALTH) && (curproxy->options & PR_O_BALANCE)) {
2165 if (curproxy->options & PR_O_TRANSP) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002166 Alert("parsing %s : %s '%s' cannot use both transparent and balance mode.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002167 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002168 cfgerr++;
2169 }
2170#ifdef WE_DONT_SUPPORT_SERVERLESS_LISTENERS
2171 else if (curproxy->srv == NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002172 Alert("parsing %s : %s '%s' needs at least 1 server in balance mode.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002173 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002174 cfgerr++;
2175 }
2176#endif
2177 else if (*(int *)&curproxy->dispatch_addr.sin_addr != 0) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002178 Warning("parsing %s : dispatch address of %s '%s' will be ignored in balance mode.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002179 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002180 }
2181 }
2182 else if (curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HEALTH) { /* TCP PROXY or HEALTH CHECK */
2183 if (curproxy->cookie_name != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002184 Warning("parsing %s : cookie will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002185 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002186 }
2187 if ((newsrv = curproxy->srv) != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002188 Warning("parsing %s : servers will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002189 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002190 }
2191 if (curproxy->rsp_exp != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002192 Warning("parsing %s : server regular expressions will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002193 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002194 }
2195 if (curproxy->req_exp != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002196 Warning("parsing %s : client regular expressions will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002197 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaubaaee002006-06-26 02:48:02 +02002198 }
Willy Tarreau1c47f852006-07-09 08:22:27 +02002199 if (curproxy->monitor_uri != NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002200 Warning("parsing %s : monitor-uri will be ignored for %s '%s'.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002201 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau1c47f852006-07-09 08:22:27 +02002202 }
Willy Tarreaubaaee002006-06-26 02:48:02 +02002203 }
2204 else if (curproxy->mode == PR_MODE_HTTP) { /* HTTP PROXY */
2205 if ((curproxy->cookie_name != NULL) && ((newsrv = curproxy->srv) == NULL)) {
2206 Alert("parsing %s : HTTP proxy %s has a cookie but no server list !\n",
2207 file, curproxy->id);
2208 cfgerr++;
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002209 }
2210 }
2211
2212 /* if a default backend was specified, let's find it */
2213 if (curproxy->defbe.name) {
2214 struct proxy *target;
2215
2216 for (target = proxy; target != NULL; target = target->next) {
2217 if (strcmp(target->id, curproxy->defbe.name) == 0)
2218 break;
2219 }
2220 if (target == NULL) {
2221 Alert("parsing %s : default backend '%s' in HTTP %s '%s' was not found !\n",
2222 file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id);
2223 cfgerr++;
2224 } else if (target == curproxy) {
2225 Alert("parsing %s : loop detected for default backend %s !\n", file, curproxy->defbe.name);
2226 cfgerr++;
2227 } else if (!(target->cap & PR_CAP_BE)) {
2228 Alert("parsing %s : default backend '%s' in HTTP %s '%s' has no backend capability !\n",
2229 file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id);
2230 cfgerr++;
2231 } else if (target->mode != curproxy->mode) {
2232 Alert("parsing %s : default backend '%s' in HTTP %s '%s' is not of same mode (tcp/http) !\n",
2233 file, curproxy->defbe.name, proxy_type_str(curproxy), curproxy->id);
2234 cfgerr++;
2235 } else {
2236 free(curproxy->defbe.name);
2237 curproxy->defbe.be = target;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002238 }
2239 }
2240
Willy Tarreau5fdfb912007-01-01 23:11:07 +01002241 /* find the target proxy in setbe */
Willy Tarreaua496b602006-12-17 23:15:24 +01002242 if (curproxy->mode == PR_MODE_HTTP && curproxy->req_exp != NULL) {
2243 /* map jump target for ACT_SETBE in req_rep chain */
2244 struct hdr_exp *exp;
2245 struct proxy *target;
2246 for (exp = curproxy->req_exp; exp != NULL; exp = exp->next) {
2247 if (exp->action != ACT_SETBE)
2248 continue;
2249 for (target = proxy; target != NULL; target = target->next) {
2250 if (strcmp(target->id, exp->replace) == 0)
2251 break;
2252 }
2253 if (target == NULL) {
Willy Tarreau977b8e42006-12-29 14:19:17 +01002254 Alert("parsing %s : backend '%s' in HTTP %s '%s' was not found !\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002255 file, exp->replace, proxy_type_str(curproxy), curproxy->id);
Willy Tarreaua496b602006-12-17 23:15:24 +01002256 cfgerr++;
2257 } else if (target == curproxy) {
2258 Alert("parsing %s : loop detected for backend %s !\n", file, exp->replace);
2259 cfgerr++;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002260 } else if (!(target->cap & PR_CAP_BE)) {
2261 Alert("parsing %s : target '%s' in HTTP %s '%s' has no backend capability !\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002262 file, exp->replace, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau977b8e42006-12-29 14:19:17 +01002263 cfgerr++;
2264 } else if (target->mode != PR_MODE_HTTP) {
2265 Alert("parsing %s : backend '%s' in HTTP %s '%s' is not HTTP (use 'mode http') !\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002266 file, exp->replace, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau977b8e42006-12-29 14:19:17 +01002267 cfgerr++;
Willy Tarreaua496b602006-12-17 23:15:24 +01002268 } else {
2269 free((void *)exp->replace);
2270 exp->replace = (const char *)target;
2271 }
2272 }
2273 }
Willy Tarreau2738a142006-07-08 17:28:09 +02002274 if ((curproxy->mode == PR_MODE_TCP || curproxy->mode == PR_MODE_HTTP) &&
Willy Tarreau977b8e42006-12-29 14:19:17 +01002275 (((curproxy->cap & PR_CAP_FE) && !curproxy->clitimeout) ||
2276 ((curproxy->cap & PR_CAP_BE) && (curproxy->srv) && (!curproxy->contimeout || !curproxy->srvtimeout)))) {
2277 Warning("parsing %s : missing timeouts for %s '%s'.\n"
Willy Tarreau2738a142006-07-08 17:28:09 +02002278 " | While not properly invalid, you will certainly encounter various problems\n"
2279 " | with such a configuration. To fix this, please ensure that all following\n"
2280 " | values are set to a non-zero value: clitimeout, contimeout, srvtimeout.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002281 file, proxy_type_str(curproxy), curproxy->id);
Willy Tarreau2738a142006-07-08 17:28:09 +02002282 }
Willy Tarreauf3c69202006-07-09 16:42:34 +02002283
2284 if (curproxy->options & PR_O_SSL3_CHK) {
2285 curproxy->check_len = sizeof(sslv3_client_hello_pkt);
2286 curproxy->check_req = (char *)malloc(sizeof(sslv3_client_hello_pkt));
2287 memcpy(curproxy->check_req, sslv3_client_hello_pkt, sizeof(sslv3_client_hello_pkt));
2288 }
2289
Willy Tarreau86034312006-12-29 00:10:33 +01002290 /* for backwards compatibility with "listen" instances, if
2291 * fullconn is not set but maxconn is set, then maxconn
2292 * is used.
2293 */
2294 if (!curproxy->fullconn)
2295 curproxy->fullconn = curproxy->maxconn;
2296
Willy Tarreaubaaee002006-06-26 02:48:02 +02002297 /* first, we will invert the servers list order */
2298 newsrv = NULL;
2299 while (curproxy->srv) {
2300 struct server *next;
2301
2302 next = curproxy->srv->next;
2303 curproxy->srv->next = newsrv;
2304 newsrv = curproxy->srv;
2305 if (!next)
2306 break;
2307 curproxy->srv = next;
2308 }
2309
2310 /* now, newsrv == curproxy->srv */
2311 if (newsrv) {
2312 struct server *srv;
2313 int pgcd;
2314 int act, bck;
2315
2316 /* We will factor the weights to reduce the table,
2317 * using Euclide's largest common divisor algorithm
2318 */
2319 pgcd = newsrv->uweight + 1;
2320 for (srv = newsrv->next; srv && pgcd > 1; srv = srv->next) {
2321 int t, w;
2322
2323 w = srv->uweight + 1;
2324 while (w) {
2325 t = pgcd % w;
2326 pgcd = w;
2327 w = t;
2328 }
2329 }
2330
2331 act = bck = 0;
2332 for (srv = newsrv; srv; srv = srv->next) {
2333 srv->eweight = ((srv->uweight + 1) / pgcd) - 1;
2334 if (srv->state & SRV_BACKUP)
2335 bck += srv->eweight + 1;
2336 else
2337 act += srv->eweight + 1;
2338 }
2339
2340 /* this is the largest map we will ever need for this servers list */
2341 if (act < bck)
2342 act = bck;
2343
2344 curproxy->srv_map = (struct server **)calloc(act, sizeof(struct server *));
2345 /* recounts servers and their weights */
2346 recount_servers(curproxy);
2347 recalc_server_map(curproxy);
2348 }
2349
2350 if (curproxy->options & PR_O_LOGASAP)
2351 curproxy->to_log &= ~LW_BYTES;
2352
Willy Tarreaubaaee002006-06-26 02:48:02 +02002353 /*
2354 * If this server supports a maxconn parameter, it needs a dedicated
2355 * tasks to fill the emptied slots when a connection leaves.
2356 */
2357 newsrv = curproxy->srv;
2358 while (newsrv != NULL) {
Willy Tarreau86034312006-12-29 00:10:33 +01002359 if (newsrv->minconn > newsrv->maxconn) {
Willy Tarreaubaaee002006-06-26 02:48:02 +02002360 /* Only 'minconn' was specified, or it was higher than or equal
2361 * to 'maxconn'. Let's turn this into maxconn and clean it, as
2362 * this will avoid further useless expensive computations.
2363 */
2364 newsrv->maxconn = newsrv->minconn;
Willy Tarreau86034312006-12-29 00:10:33 +01002365 } else if (newsrv->maxconn && !newsrv->minconn) {
2366 /* minconn was not specified, so we set it to maxconn */
2367 newsrv->minconn = newsrv->maxconn;
Willy Tarreau977b8e42006-12-29 14:19:17 +01002368 } else if (newsrv->minconn != newsrv->maxconn && !curproxy->fullconn) {
2369 Alert("parsing %s, %s '%s' : fullconn is mandatory when minconn is set on a server.\n",
Willy Tarreau2b5652f2006-12-31 17:46:05 +01002370 file, proxy_type_str(curproxy), curproxy->id, linenum);
Willy Tarreau86034312006-12-29 00:10:33 +01002371 return -1;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002372 }
2373
2374 if (newsrv->maxconn > 0) {
2375 struct task *t;
2376
2377 if ((t = pool_alloc(task)) == NULL) {
2378 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2379 return -1;
2380 }
2381
Willy Tarreau964c9362007-01-07 00:38:00 +01002382 t->rqnext = NULL;
2383 t->wq = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002384 t->state = TASK_IDLE;
2385 t->process = process_srv_queue;
2386 t->context = newsrv;
2387 newsrv->queue_mgt = t;
2388
2389 /* never run it unless specifically woken up */
2390 tv_eternity(&t->expire);
2391 task_queue(t);
2392 }
2393 newsrv = newsrv->next;
2394 }
2395
2396 /* now we'll start this proxy's health checks if any */
2397 /* 1- count the checkers to run simultaneously */
2398 nbchk = 0;
2399 mininter = 0;
2400 newsrv = curproxy->srv;
2401 while (newsrv != NULL) {
2402 if (newsrv->state & SRV_CHECKED) {
2403 if (!mininter || mininter > newsrv->inter)
2404 mininter = newsrv->inter;
2405 nbchk++;
2406 }
2407 newsrv = newsrv->next;
2408 }
2409
2410 /* 2- start them as far as possible from each others while respecting
2411 * their own intervals. For this, we will start them after their own
2412 * interval added to the min interval divided by the number of servers,
2413 * weighted by the server's position in the list.
2414 */
2415 if (nbchk > 0) {
2416 struct task *t;
2417 int srvpos;
2418
2419 newsrv = curproxy->srv;
2420 srvpos = 0;
2421 while (newsrv != NULL) {
2422 /* should this server be checked ? */
2423 if (newsrv->state & SRV_CHECKED) {
2424 if ((t = pool_alloc(task)) == NULL) {
2425 Alert("parsing [%s:%d] : out of memory.\n", file, linenum);
2426 return -1;
2427 }
2428
Willy Tarreau964c9362007-01-07 00:38:00 +01002429 t->wq = NULL;
2430 t->rqnext = NULL;
Willy Tarreaubaaee002006-06-26 02:48:02 +02002431 t->state = TASK_IDLE;
2432 t->process = process_chk;
2433 t->context = newsrv;
2434
2435 /* check this every ms */
2436 tv_delayfrom(&t->expire, &now,
2437 newsrv->inter + mininter * srvpos / nbchk);
2438 task_queue(t);
2439 //task_wakeup(&rq, t);
2440 srvpos++;
2441 }
2442 newsrv = newsrv->next;
2443 }
2444 }
2445
2446 curproxy = curproxy->next;
2447 }
2448 if (cfgerr > 0) {
2449 Alert("Errors found in configuration file, aborting.\n");
2450 return -1;
2451 }
2452 else
2453 return 0;
2454}
2455
2456
2457
2458/*
2459 * Local variables:
2460 * c-indent-level: 8
2461 * c-basic-offset: 8
2462 * End:
2463 */